Skip to content

Commit b184798

Browse files
committed
Cleanup
1 parent 3188b5c commit b184798

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

hnswlib/hnswalg.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ class HierarchicalNSW : public AlgorithmInterface<dist_t> {
124124
offsetLevel0_ = 0;
125125

126126
data_level0_memory_ = (char *) malloc(max_elements_ * size_data_per_element_);
127-
// TODO(bautin): handle
128-
// if (data_level0_memory_ == nullptr)
129-
// return Status("Not enough memory");
127+
if (data_level0_memory_ == nullptr) {
128+
HNSWLIB_THROW_RUNTIME_ERROR("Not enough memory to allocate for level 0");
129+
}
130130

131131
cur_element_count = 0;
132132

@@ -137,10 +137,10 @@ class HierarchicalNSW : public AlgorithmInterface<dist_t> {
137137
maxlevel_ = -1;
138138

139139
linkLists_ = (char **) malloc(sizeof(void *) * max_elements_);
140-
141-
// TODO(bautin): handle
142-
// if (linkLists_ == nullptr)
143-
// return Status("Not enough memory: HierarchicalNSW failed to allocate linklists");
140+
if (linkLists_ == nullptr) {
141+
HNSWLIB_THROW_RUNTIME_ERROR(
142+
"Not enough memory: HierarchicalNSW failed to allocate linklists");
143+
}
144144

145145
size_links_per_element_ = maxM_ * sizeof(tableint) + sizeof(linklistsizeint);
146146
mult_ = 1 / log(1.0 * M_);

tests/cpp/epsilon_search_test.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ int main() {
4949
query_data[j] = distrib_real(rng);
5050
}
5151
hnswlib::EpsilonSearchStopCondition<dist_t> stop_condition(epsilon2, min_num_candidates, max_num_candidates);
52-
auto result_hnsw =
52+
std::vector<std::pair<float, hnswlib::labeltype>> result_hnsw =
5353
alg_hnsw->searchStopConditionClosest(query_data, stop_condition);
5454

5555
// check that returned results are in epsilon region
@@ -61,7 +61,8 @@ int main() {
6161
hnsw_labels.insert(label);
6262
assert(dist >=0 && dist <= epsilon2);
6363
}
64-
auto result_brute = alg_brute->searchKnn(query_data, max_elements);
64+
std::priority_queue<std::pair<float, hnswlib::labeltype>> result_brute =
65+
result_brute = alg_brute->searchKnn(query_data, max_elements);
6566

6667
// check recall
6768
std::unordered_set<hnswlib::labeltype> gt_labels;

0 commit comments

Comments
 (0)