diff options
author | Tor Egge <Tor.Egge@online.no> | 2024-04-29 19:55:03 +0200 |
---|---|---|
committer | Tor Egge <Tor.Egge@online.no> | 2024-04-29 19:55:03 +0200 |
commit | f17741c6567a4e7d2def99bbefe423574d5e2df2 (patch) | |
tree | 5960fe70bdba88f5aa1dbb07b9ed7ff62327aeb1 /searchlib | |
parent | 0e955fe9420b1b89d6fccbb77ebf0a698d922e8c (diff) |
Add const specifiers for HnswIndex member functions get_subspaces() and
check_consistency().
Diffstat (limited to 'searchlib')
4 files changed, 15 insertions, 9 deletions
diff --git a/searchlib/src/tests/attribute/tensorattribute/tensorattribute_test.cpp b/searchlib/src/tests/attribute/tensorattribute/tensorattribute_test.cpp index 825c81de107..089f5e2e239 100644 --- a/searchlib/src/tests/attribute/tensorattribute/tensorattribute_test.cpp +++ b/searchlib/src/tests/attribute/tensorattribute/tensorattribute_test.cpp @@ -330,7 +330,7 @@ public: return *my_dist_fun; } - uint32_t check_consistency(uint32_t) noexcept override { + uint32_t check_consistency(uint32_t) const noexcept override { return 0; } }; diff --git a/searchlib/src/vespa/searchlib/tensor/hnsw_index.cpp b/searchlib/src/vespa/searchlib/tensor/hnsw_index.cpp index 8cfa10d918b..b542c422f50 100644 --- a/searchlib/src/vespa/searchlib/tensor/hnsw_index.cpp +++ b/searchlib/src/vespa/searchlib/tensor/hnsw_index.cpp @@ -1125,10 +1125,10 @@ HnswIndex<type>::count_reachable_nodes() const template <HnswIndexType type> uint32_t -HnswIndex<type>::get_subspaces(uint32_t docid) noexcept +HnswIndex<type>::get_subspaces(uint32_t docid) const noexcept { - if (type == HnswIndexType::SINGLE) { - return (docid < _graph.nodes.size() && _graph.nodes[docid].levels_ref().load_relaxed().valid()) ? 1 : 0; + if constexpr (type == HnswIndexType::SINGLE) { + return (docid < _graph.nodes.get_size() && _graph.nodes.get_elem_ref(docid).levels_ref().load_relaxed().valid()) ? 1 : 0; } else { return _id_mapping.get_ids(docid).size(); } @@ -1136,7 +1136,7 @@ HnswIndex<type>::get_subspaces(uint32_t docid) noexcept template <HnswIndexType type> uint32_t -HnswIndex<type>::check_consistency(uint32_t docid_limit) noexcept +HnswIndex<type>::check_consistency(uint32_t docid_limit) const noexcept { uint32_t inconsistencies = 0; for (uint32_t docid = 1; docid < docid_limit; ++docid) { diff --git a/searchlib/src/vespa/searchlib/tensor/hnsw_index.h b/searchlib/src/vespa/searchlib/tensor/hnsw_index.h index 757f4d00666..4d4440c1bcb 100644 --- a/searchlib/src/vespa/searchlib/tensor/hnsw_index.h +++ b/searchlib/src/vespa/searchlib/tensor/hnsw_index.h @@ -193,7 +193,9 @@ protected: LinkArray filter_valid_nodeids(uint32_t level, const internal::PreparedAddNode::Links &neighbors, uint32_t self_nodeid); void internal_complete_add(uint32_t docid, internal::PreparedAddDoc &op); void internal_complete_add_node(uint32_t nodeid, uint32_t docid, uint32_t subspace, internal::PreparedAddNode &prepared_node); - uint32_t get_subspaces(uint32_t docid) noexcept; + + // Called from writer only. + uint32_t get_subspaces(uint32_t docid) const noexcept; public: HnswIndex(const DocVectorAccess& vectors, DistanceFunctionFactory::UP distance_ff, RandomLevelGenerator::UP level_generator, const HnswIndexConfig& cfg); @@ -249,7 +251,8 @@ public: uint32_t get_active_nodes() const noexcept { return _graph.get_active_nodes(); } - uint32_t check_consistency(uint32_t docid_limit) noexcept override; + // Called from writer only. + uint32_t check_consistency(uint32_t docid_limit) const noexcept override; // Should only be used by unit tests. HnswTestNode get_node(uint32_t nodeid) const; diff --git a/searchlib/src/vespa/searchlib/tensor/nearest_neighbor_index.h b/searchlib/src/vespa/searchlib/tensor/nearest_neighbor_index.h index a4309c366b1..c2bbd17ce63 100644 --- a/searchlib/src/vespa/searchlib/tensor/nearest_neighbor_index.h +++ b/searchlib/src/vespa/searchlib/tensor/nearest_neighbor_index.h @@ -115,8 +115,11 @@ public: virtual DistanceFunctionFactory &distance_function_factory() const = 0; - // Used when checking consistency during load - virtual uint32_t check_consistency(uint32_t docid_limit) noexcept = 0; + /* + * Used when checking consistency during load. + * Called from writer only. + */ + virtual uint32_t check_consistency(uint32_t docid_limit) const noexcept = 0; }; } |