in cpp/src/std_utils.h [118:142]
void mergePriorityQueues(
std::priority_queue<std::tuple<dist_t, indexID_t, label_t>> &dest,
std::priority_queue<std::pair<dist_t, label_t>> &src, size_t maxElements,
indexID_t indexID, const label_t idMask, const std::set<label_t> &labels,
const dist_t maximumDistance) {
std::vector<std::pair<dist_t, hnswlib::labeltype>> &items =
GetContainerForQueue(src);
for (auto i = items.begin(); i != items.end(); i++) {
// To avoid copying unnecessarily, only move elements if:
// - We don't have maxElements in `dest` yet
// - `dest` is full, but the element being added would not be the new `top`
// (i.e.: it's smaller)
if (dest.size() < maxElements || i->first < std::get<0>(dest.top())) {
if (idMask == 0 || labels.count(i->second & idMask) != 0) {
if (i->first <= maximumDistance) {
dest.push({i->first, indexID, i->second});
}
}
}
}
while (dest.size() > maxElements)
dest.pop();
}