aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/matching/match_params.cpp
blob: 68a6f74fa507e881313f5b62138de036fe50a7b1 (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
39
40
41
42
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "match_params.h"
#include <algorithm>
#include <cmath>

namespace proton::matching {

namespace {

uint32_t
computeArraySize(uint32_t hitsPlussOffset, uint32_t heapSize, uint32_t arraySize)
{
    return std::max(hitsPlussOffset, std::max(heapSize, arraySize));
}

}

MatchParams::MatchParams(uint32_t          numDocs_in,
                         uint32_t          heapSize_in,
                         uint32_t          arraySize_in,
                         search::feature_t rankDropLimit_in,
                         uint32_t          offset_in,
                         uint32_t          hits_in,
                         bool              hasFinalRank,
                         bool              needRanking)
    : numDocs(numDocs_in),
      heapSize((hasFinalRank && needRanking) ? std::min(numDocs_in, heapSize_in) : 0),
      arraySize((needRanking && ((heapSize_in + arraySize_in) > 0))
                ? std::min(numDocs_in, computeArraySize(hits_in + offset_in, heapSize, arraySize_in))
                : 0),
      offset(std::min(numDocs_in, offset_in)),
      hits(std::min(numDocs_in - offset, hits_in)),
      rankDropLimit(rankDropLimit_in)
{ }

bool
MatchParams::has_rank_drop_limit() const {
    return ! std::isnan(rankDropLimit);
}

}