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

#pragma once

#include <vespa/vespalib/util/reusable_set_handle.h>

namespace search::tensor {

class HnswIndex;

/*
 * Tracker for visited nodes based on vespalib::ReusableSet.
 */
class ReusableSetVisitedTracker
{
    vespalib::ReusableSetHandle _visited;
public:
    ReusableSetVisitedTracker(const HnswIndex& index, uint32_t doc_id_limit, uint32_t);
    ~ReusableSetVisitedTracker();
    void mark(uint32_t doc_id) { _visited.mark(doc_id); }
    bool try_mark(uint32_t doc_id) {
        if (_visited.is_marked(doc_id)) {
            return false;
        } else {
            _visited.mark(doc_id);
            return true;
        }
    }
};

}