Skip to content

Commit 0640c3f

Browse files
Label Loading Fix (#490)
* improve load time * fix loadTime * revert memory index parse file * parse_label_file change for memory * Revert "parse_label_file change for memory" This reverts commit 56f65a5. * fix * fix bug for loading specific label file
1 parent 1b43421 commit 0640c3f

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

include/pq_flash_index.h

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ template <typename T, typename LabelT = uint32_t> class PQFlashIndex
116116
DISKANN_DLLEXPORT void generate_random_labels(std::vector<LabelT> &labels, const uint32_t num_labels,
117117
const uint32_t nthreads);
118118
void reset_stream_for_reading(std::basic_istream<char> &infile);
119+
size_t search_string_range(const std::string &str, char ch, size_t start, size_t end);
119120
// index info
120121
// nhood of node `i` is in sector: [i / nnodes_per_sector]
121122
// offset in sector: [(i % nnodes_per_sector) * max_node_len]

src/pq_flash_index.cpp

+17-3
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ void PQFlashIndex<T, LabelT>::get_label_file_metadata(const std::string &fileCon
592592
size_t next_lbl_pos = 0;
593593
while (lbl_pos < next_pos && lbl_pos != std::string::npos)
594594
{
595-
next_lbl_pos = fileContent.find(',', lbl_pos);
595+
next_lbl_pos = search_string_range(fileContent, ',', lbl_pos, next_pos);
596596
if (next_lbl_pos == std::string::npos) // the last label
597597
{
598598
next_lbl_pos = next_pos;
@@ -671,7 +671,7 @@ void PQFlashIndex<T, LabelT>::parse_label_file(std::basic_istream<char> &infile,
671671
size_t next_lbl_pos = 0;
672672
while (lbl_pos < next_pos && lbl_pos != std::string::npos)
673673
{
674-
next_lbl_pos = buffer.find(',', lbl_pos);
674+
next_lbl_pos = search_string_range(buffer, ',', lbl_pos, next_pos);
675675
if (next_lbl_pos == std::string::npos) // the last label in the whole file
676676
{
677677
next_lbl_pos = next_pos;
@@ -810,7 +810,7 @@ int PQFlashIndex<T, LabelT>::load_from_separate_paths(uint32_t num_threads, cons
810810
}
811811
#endif
812812
parse_label_file(infile, num_pts_in_label_file);
813-
assert(num_pts_in_label_file == this->_num_points);
813+
assert(num_pts_in_label_file == this->num_points);
814814

815815
#ifndef EXEC_ENV_OLS
816816
infile.close();
@@ -1766,6 +1766,20 @@ template <typename T, typename LabelT> char *PQFlashIndex<T, LabelT>::getHeaderB
17661766
}
17671767
#endif
17681768

1769+
template <typename T, typename LabelT>
1770+
size_t PQFlashIndex<T, LabelT>::search_string_range(const std::string &str, char ch, size_t start, size_t end)
1771+
{
1772+
for (; start != end; start++)
1773+
{
1774+
if (str[start] == ch)
1775+
{
1776+
return start;
1777+
}
1778+
}
1779+
1780+
return std::string::npos;
1781+
}
1782+
17691783
// instantiations
17701784
template class PQFlashIndex<uint8_t>;
17711785
template class PQFlashIndex<int8_t>;

0 commit comments

Comments
 (0)