diff --git a/hnswlib/bruteforce.h b/hnswlib/bruteforce.h index 24260400..691424bc 100644 --- a/hnswlib/bruteforce.h +++ b/hnswlib/bruteforce.h @@ -8,10 +8,14 @@ namespace hnswlib { template class BruteforceSearch : public AlgorithmInterface { public: - BruteforceSearch(SpaceInterface *s) { + BruteforceSearch(SpaceInterface *s) : data_(nullptr), maxelements_(0), + cur_element_count(0), size_per_element_(0), data_size_(0), + dist_func_param_(nullptr) { } - BruteforceSearch(SpaceInterface *s, const std::string &location) { + BruteforceSearch(SpaceInterface *s, const std::string &location) : + data_(nullptr), maxelements_(0), cur_element_count(0), size_per_element_(0), + data_size_(0), dist_func_param_(nullptr) { loadIndex(location, s); } diff --git a/hnswlib/hnswalg.h b/hnswlib/hnswalg.h index e95e0b52..8060683c 100644 --- a/hnswlib/hnswalg.h +++ b/hnswlib/hnswalg.h @@ -85,22 +85,21 @@ namespace hnswlib { delete visited_list_pool_; } - size_t max_elements_; - size_t cur_element_count; - size_t size_data_per_element_; - size_t size_links_per_element_; - size_t num_deleted_; + size_t max_elements_{0}; + size_t cur_element_count{0}; + size_t size_data_per_element_{0}; + size_t size_links_per_element_{0}; + size_t num_deleted_{0}; + size_t M_{0}; + size_t maxM_{0}; + size_t maxM0_{0}; + size_t ef_construction_{0}; - size_t M_; - size_t maxM_; - size_t maxM0_; - size_t ef_construction_; + double mult_{0.0}, revSize_{0.0}; + int maxlevel_{0}; - double mult_, revSize_; - int maxlevel_; - - VisitedListPool *visited_list_pool_; + VisitedListPool *visited_list_pool_{nullptr}; std::mutex cur_element_count_guard_; std::vector link_list_locks_; @@ -108,20 +107,20 @@ namespace hnswlib { // Locks to prevent race condition during update/insert of an element at same time. // Note: Locks for additions can also be used to prevent this race condition if the querying of KNN is not exposed along with update/inserts i.e multithread insert/update/query in parallel. std::vector link_list_update_locks_; - tableint enterpoint_node_; + tableint enterpoint_node_{0}; - size_t size_links_level0_; - size_t offsetData_, offsetLevel0_; + size_t size_links_level0_{0}; + size_t offsetData_{0}, offsetLevel0_{0}; - char *data_level0_memory_; - char **linkLists_; + char *data_level0_memory_{nullptr}; + char **linkLists_{nullptr}; std::vector element_levels_; - size_t data_size_; + size_t data_size_{0}; - size_t label_offset_; + size_t label_offset_{0}; DISTFUNC fstdistfunc_; - void *dist_func_param_; + void *dist_func_param_{nullptr}; std::unordered_map label_lookup_; std::default_random_engine level_generator_; @@ -234,8 +233,8 @@ namespace hnswlib { return top_candidates; } - mutable std::atomic metric_distance_computations; - mutable std::atomic metric_hops; + mutable std::atomic metric_distance_computations{0}; + mutable std::atomic metric_hops{0}; template std::priority_queue, std::vector>, CompareByFirst> @@ -504,7 +503,7 @@ namespace hnswlib { } std::mutex global; - size_t ef_; + size_t ef_{0}; void setEf(size_t ef) { ef_ = ef;