aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/tensor/bitvector_visited_tracker.h
blob: 170df1c4c5bc0f3ed31a38268fea63993548ff5e (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <vespa/searchlib/common/allocatedbitvector.h>

namespace search::tensor {

/*
 * Tracker for visited nodes based on search::AllocatedBitVector. Best when
 * many nodes are visited.
 */
class BitVectorVisitedTracker
{
    search::AllocatedBitVector _visited;
public:
    BitVectorVisitedTracker(uint32_t nodeid_limit, uint32_t);
    ~BitVectorVisitedTracker();
    void mark(uint32_t nodeid) { _visited.setBit(nodeid); }
    bool try_mark(uint32_t nodeid) {
        if (_visited.testBit(nodeid)) {
            return false;
        } else {
            _visited.setBit(nodeid);
            return true;
        }
    }
};

}