Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initialize fields in constructor #396

Merged
merged 2 commits into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions hnswlib/bruteforce.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ namespace hnswlib {
template<typename dist_t>
class BruteforceSearch : public AlgorithmInterface<dist_t> {
public:
BruteforceSearch(SpaceInterface <dist_t> *s) {
BruteforceSearch(SpaceInterface <dist_t> *s) : data_(nullptr), maxelements_(0),
cur_element_count(0), size_per_element_(0), data_size_(0),
dist_func_param_(nullptr) {

}
BruteforceSearch(SpaceInterface<dist_t> *s, const std::string &location) {
BruteforceSearch(SpaceInterface<dist_t> *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);
}

Expand Down
47 changes: 23 additions & 24 deletions hnswlib/hnswalg.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,43 +85,42 @@ 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<std::mutex> link_list_locks_;

// 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<std::mutex> 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<int> element_levels_;

size_t data_size_;
size_t data_size_{0};

size_t label_offset_;
size_t label_offset_{0};
DISTFUNC<dist_t> fstdistfunc_;
void *dist_func_param_;
void *dist_func_param_{nullptr};
std::unordered_map<labeltype, tableint> label_lookup_;

std::default_random_engine level_generator_;
Expand Down Expand Up @@ -234,8 +233,8 @@ namespace hnswlib {
return top_candidates;
}

mutable std::atomic<long> metric_distance_computations;
mutable std::atomic<long> metric_hops;
mutable std::atomic<long> metric_distance_computations{0};
mutable std::atomic<long> metric_hops{0};

template <bool has_deletions, bool collect_metrics=false>
std::priority_queue<std::pair<dist_t, tableint>, std::vector<std::pair<dist_t, tableint>>, CompareByFirst>
Expand Down Expand Up @@ -504,7 +503,7 @@ namespace hnswlib {
}

std::mutex global;
size_t ef_;
size_t ef_{0};

void setEf(size_t ef) {
ef_ = ef;
Expand Down