From feeba8243c375322f6efdda4ad3848061056f641 Mon Sep 17 00:00:00 2001 From: Longwei Liu Date: Fri, 20 Feb 2026 19:04:05 +0800 Subject: [PATCH] chore(flat): replace std::map with std::unordered_map for key_id_mapping_ Reduces key lookup in get_id() from O(log N) to O(1) average, and index load time from O(N log N) to O(N). Also lowers per-entry memory usage by eliminating the three tree-node pointers (parent/left/right). --- src/core/algorithm/flat/flat_searcher.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/algorithm/flat/flat_searcher.h b/src/core/algorithm/flat/flat_searcher.h index 78dcb1d3..207f38f5 100644 --- a/src/core/algorithm/flat/flat_searcher.h +++ b/src/core/algorithm/flat/flat_searcher.h @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. #pragma once - +#include #include #include #include "flat_distance_matrix.h" @@ -163,7 +163,7 @@ class FlatSearcher : public IndexSearcher { private: //! Members const uint64_t *keys_{nullptr}; - std::map key_id_mapping_; + std::unordered_map key_id_mapping_; uint32_t magic_{IndexContext::GenerateMagic()}; uint32_t read_block_size_{FLAT_DEFAULT_READ_BLOCK_SIZE}; bool column_major_order_{false};