From 2f5c7a097d59c048fb849d1be3b6dce93e5b4cb7 Mon Sep 17 00:00:00 2001 From: Sanhaoji2 Date: Tue, 5 Mar 2024 18:19:42 +0800 Subject: [PATCH] Fix issue --- include/index.h | 2 ++ src/index.cpp | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/index.h b/include/index.h index 45d185d11..f341a3db2 100644 --- a/include/index.h +++ b/include/index.h @@ -444,6 +444,8 @@ template clas DISKANN_DLLEXPORT size_t load_delete_set(const std::string &filename); #endif + size_t search_string_range(const std::string& str, char ch, size_t start, size_t end); + private: // Distance functions Metric _dist_metric = diskann::L2; diff --git a/src/index.cpp b/src/index.cpp index 70d5be632..d76690c1b 100644 --- a/src/index.cpp +++ b/src/index.cpp @@ -2156,7 +2156,7 @@ void Index::parse_label_file_in_bitset(const std::string& label size_t next_lbl_pos = 0; while (lbl_pos < next_pos && lbl_pos != std::string::npos) { - next_lbl_pos = buffer.find(',', lbl_pos); + next_lbl_pos = search_string_range(buffer, ',', lbl_pos, next_pos); if (next_lbl_pos == std::string::npos) // the last label in the whole file { next_lbl_pos = next_pos; @@ -3566,6 +3566,20 @@ void Index::search_with_optimized_layout(const T *query, size_t } } +template +size_t Index::search_string_range(const std::string& str, char ch, size_t start, size_t end) +{ + for (; start != end; start++) + { + if (str[start] == ch) + { + return start; + } + } + + return std::string::npos; +} + /* Internals of the library */ template const float Index::INDEX_GROWTH_FACTOR = 1.5f;