Skip to content

Commit 733751d

Browse files
committed
Remove some of the auto declarations in response to review comments
Will remove the rest in a follow-up commit.
1 parent 34d30c8 commit 733751d

File tree

7 files changed

+11
-8
lines changed

7 files changed

+11
-8
lines changed

examples/cpp/example_epsilon_search.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ int main() {
5353
}
5454
std::cout << "Query #" << i << "\n";
5555
hnswlib::EpsilonSearchStopCondition<dist_t> stop_condition(epsilon2, min_num_candidates, max_elements);
56-
auto result = alg_hnsw->searchStopConditionClosest(query_data, stop_condition);
56+
std::vector<std::pair<float, hnswlib::labeltype>> result =
57+
alg_hnsw->searchStopConditionClosest(query_data, stop_condition);
5758
size_t num_vectors = result.size();
5859
std::cout << "Found " << num_vectors << " vectors\n";
5960
delete[] query_data;

examples/cpp/example_filter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ int main() {
4545
// Query the elements for themselves with filter and check returned labels
4646
int k = 10;
4747
for (int i = 0; i < max_elements; i++) {
48-
auto result = alg_hnsw->searchKnnCloserFirst(data + i * dim, k, &pickIdsDivisibleByTwo);
48+
std::vector<std::pair<float, hnswlib::labeltype>> result =
49+
alg_hnsw->searchKnnCloserFirst(data + i * dim, k, &pickIdsDivisibleByTwo);
4950
for (auto item: result) {
5051
if (item.second % 2 == 1) std::cout << "Error: found odd label\n";
5152
}

examples/cpp/example_multivector_search.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ int main() {
6363
}
6464
std::cout << "Query #" << i << "\n";
6565
hnswlib::MultiVectorSearchStopCondition<docidtype, dist_t> stop_condition(space, num_docs, ef_collection);
66-
auto result = alg_hnsw->searchStopConditionClosest(query_data, stop_condition);
66+
std::vector<std::pair<float, hnswlib::labeltype>> result =
67+
alg_hnsw->searchStopConditionClosest(query_data, stop_condition);
6768
size_t num_vectors = result.size();
6869

6970
std::unordered_map<docidtype, size_t> doc_counter;

hnswlib/hnswlib.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,13 @@ class [[nodiscard]] Status {
146146
Status(const char* message) : message_(message) {}
147147

148148
// Returns true if the status is OK
149-
bool ok() const { return message_ == nullptr; }
149+
bool ok() const { return !message_; }
150150

151151
// Returns the error message, or nullptr if OK
152152
const char* message() const { return message_; }
153153

154154
private:
155-
// Null if OK, a message otherwise.
155+
// nullptr if OK, a message otherwise.
156156
const char* message_;
157157
};
158158

tests/cpp/epsilon_search_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ int main() {
9494
int min_candidates_small = 500;
9595
for (size_t i = 0; i < max_elements; i++) {
9696
hnswlib::EpsilonSearchStopCondition<dist_t> stop_condition(epsilon2_small, min_candidates_small, max_num_candidates);
97-
auto result =
97+
std::vector<std::pair<float, hnswlib::labeltype>> result =
9898
alg_hnsw->searchStopConditionClosest(alg_hnsw->getDataByInternalId(i), stop_condition);
9999
size_t num_vectors = result.size();
100100
// get closest distance

tests/cpp/multiThreadLoad_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ int main() {
115115
data[i] = distrib_real(rng);
116116
}
117117
alg_hnsw->addPoint(data.data(), label);
118-
auto data = alg_hnsw->getDataByLabel<float>(label);
118+
std::vector<float> data = alg_hnsw->getDataByLabel<float>(label);
119119
float max_val = *max_element(data.begin(), data.end());
120120
// never happens but prevents compiler from deleting unused code
121121
if (max_val > 10) {

tests/cpp/updates_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ test_approx(std::vector<float> &queries, size_t qsize, hnswlib::HierarchicalNSW<
111111
size_t total = 0;
112112

113113
for (int i = 0; i < qsize; i++) {
114-
auto result = appr_alg.searchKnn((char *)(queries.data() + vecdim * i), K);
114+
std::priority_queue<std::pair<d_type, hnswlib::labeltype>> result = appr_alg.searchKnn((char *)(queries.data() + vecdim * i), K);
115115
total += K;
116116
while (result.size()) {
117117
if (answers[i].find(result.top().second) != answers[i].end()) {

0 commit comments

Comments
 (0)