aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/datastore/entry_ref_filter.h
blob: c06d843fbd0be45eeb4fcd915955cbf65f4557e7 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "entryref.h"
#include <vector>

namespace vespalib::datastore {

/*
 * Class to filter entry refs based on which buffer the entry is referencing.
 *
 * Buffers being allowed have corresponding bit in _filter set.
 */
class EntryRefFilter {
    std::vector<bool> _filter;
    uint32_t          _offset_bits;
    EntryRefFilter(std::vector<bool> filter, uint32_t offset_bits);
public:
    EntryRefFilter(uint32_t num_buffers, uint32_t offset_bits);
    ~EntryRefFilter();
    bool has(EntryRef ref) const {
        uint32_t buffer_id = ref.buffer_id(_offset_bits);
        return _filter[buffer_id];
    }
    void add_buffer(uint32_t buffer_id) { _filter[buffer_id] = true; }
    void add_buffers(const std::vector<uint32_t>& ids) {
        for (auto buffer_id : ids) {
            _filter[buffer_id] = true;
        }
    }
    static EntryRefFilter create_all_filter(uint32_t num_buffers, uint32_t offset_bits);
};

}