Skip to content

Commit b6181d6

Browse files
committed
Using std::sort to sort the result according to the comparator provided by the user.
1 parent 9a3c03d commit b6181d6

File tree

2 files changed

+3
-11
lines changed

2 files changed

+3
-11
lines changed

hnswlib/bruteforce.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,8 @@ namespace hnswlib {
121121
result.push_back(ret.top());
122122
ret.pop();
123123
}
124-
125-
if (result.size() > 1) {
126-
if (!comp(result.front(), result.back())) {
127-
std::reverse(result.begin(), result.end());
128-
}
129-
}
124+
125+
std::sort(result.begin(), result.end(), comp);
130126

131127
return result;
132128
}

hnswlib/hnswalg.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -962,11 +962,7 @@ namespace hnswlib {
962962
ret.pop();
963963
}
964964

965-
if (result.size() > 1) {
966-
if (!comp(result.front(), result.back())) {
967-
std::reverse(result.begin(), result.end());
968-
}
969-
}
965+
std::sort(result.begin(), result.end(), comp);
970966

971967
return result;
972968
}

0 commit comments

Comments
 (0)