Skip to content

Commit

Permalink
fix to reset stream after reads
Browse files Browse the repository at this point in the history
  • Loading branch information
hliu18 committed Oct 12, 2023
1 parent 381bae6 commit 4031bc2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/pq_flash_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ template <typename T, typename LabelT = uint32_t> class PQFlashIndex
uint32_t &num_total_labels);
DISKANN_DLLEXPORT void generate_random_labels(std::vector<LabelT> &labels, const uint32_t num_labels,
const uint32_t nthreads);
void reset_stream_for_reading(std::basic_istream<char> &infile);

// sector # on disk where node_id is present with in the graph part
DISKANN_DLLEXPORT uint64_t get_node_sector(uint64_t node_id);
Expand Down
11 changes: 9 additions & 2 deletions src/pq_flash_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,13 @@ LabelT PQFlashIndex<T, LabelT>::get_converted_label(const std::string &filter_la
throw diskann::ANNException(stream.str(), -1, __FUNCSIG__, __FILE__, __LINE__);
}

template <typename T, typename LabelT>
void PQFlashIndex<T, LabelT>::reset_stream_for_reading(std::basic_istream<char> &infile)
{
infile.clear();
infile.seekg(0);
}

template <typename T, typename LabelT>
void PQFlashIndex<T, LabelT>::get_label_file_metadata(std::basic_istream<char> &infile, uint32_t &num_pts,
uint32_t &num_total_labels)
Expand All @@ -624,7 +631,7 @@ void PQFlashIndex<T, LabelT>::get_label_file_metadata(std::basic_istream<char> &

diskann::cout << "Labels file metadata: num_points: " << num_pts << ", #total_labels: " << num_total_labels
<< std::endl;
infile.seekg(0);
reset_stream_for_reading(infile);
}

template <typename T, typename LabelT>
Expand Down Expand Up @@ -685,8 +692,8 @@ void PQFlashIndex<T, LabelT>::parse_label_file(std::basic_istream<char> &infile,
}
line_cnt++;
}
infile.seekg(0);
num_points_labels = line_cnt;
reset_stream_for_reading(infile);
}

template <typename T, typename LabelT> void PQFlashIndex<T, LabelT>::set_universal_label(const LabelT &label)
Expand Down

0 comments on commit 4031bc2

Please sign in to comment.