advisedy commented on code in PR #3562:
URL: https://github.com/apache/kvrocks/pull/3562#discussion_r3638357882
##########
src/search/hnsw_indexer.cc:
##########
@@ -173,16 +173,20 @@ StatusOr<double> ComputeSimilarity(const VectorItem&
left, const VectorItem& rig
}
HnswIndex::HnswIndex(const SearchKey& search_key, HnswVectorFieldMetadata*
vector, engine::Storage* storage,
- std::random_device::result_type seed)
+ std::optional<std::random_device::result_type> seed)
: search_key(search_key),
metadata(vector),
storage(storage),
- generator(std::mt19937(seed)),
+ seed(seed),
m_level_normalization_factor(1.0 / std::log(metadata->m)) {}
uint16_t HnswIndex::RandomizeLayer() {
+ if (!generator) {
+ const auto actual_seed = seed ? *seed : std::random_device()();
+ generator = std::make_unique<std::mt19937>(actual_seed);
Review Comment:
switched to a single `static thread_local` generator as you suggested.
please take a look.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]