blob: d4b92fd67e6041c8e04baa1b803672b59f6bd13f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "weak_and_heap.h"
namespace search::queryeval {
SharedWeakAndPriorityQueue::SharedWeakAndPriorityQueue(uint32_t scoresToTrack) :
WeakAndHeap(scoresToTrack),
_bestScores(),
_lock()
{
_bestScores.reserve(scoresToTrack);
}
SharedWeakAndPriorityQueue::~SharedWeakAndPriorityQueue() = default;
void
SharedWeakAndPriorityQueue::adjust(score_t *begin, score_t *end)
{
if (getScoresToTrack() == 0) {
return;
}
std::lock_guard guard(_lock);
for (score_t *itr = begin; itr != end; ++itr) {
score_t score = *itr;
if (!is_full()) {
_bestScores.push(score);
} else if (_bestScores.front() < score) {
_bestScores.push(score);
_bestScores.pop_front();
}
}
if (is_full()) {
setMinScore(_bestScores.front());
}
}
}
|