aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/queryeval/sorted_hit_sequence.h
blob: 5fb694193b5c7b9e699430ac31b7bbe77d8cc45a (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <vespa/searchlib/common/feature.h>
#include <memory>

namespace search::queryeval {

/**
 * Utility used to iterate low-level sorted results (typically owned
 * by a HitCollector). The actual results are stored in a backing
 * array and the order is defined by a separate index array.
 **/
class SortedHitSequence
{
public:
    using Hit = std::pair<uint32_t, feature_t>;
    using Ref = uint32_t;

private:
    const Hit *_data;
    const Ref *_pos;
    const Ref *_end;

public:
    SortedHitSequence(const Hit *hits, const Ref *refs, size_t num_refs)
        : _data(hits), _pos(refs), _end(refs + num_refs) {}
    bool valid() const { return (_pos != _end); }
    const Hit &get() const { return _data[*_pos]; }
    void next() { ++_pos; }
};

}