aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/common/partialbitvector.cpp
blob: 1ec0c10e411b866bc0fed48a6e7bb2201cf9fcd1 (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 Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "partialbitvector.h"
#include <cstring>

namespace search {

using vespalib::alloc::Alloc;

PartialBitVector::PartialBitVector(Index start, Index end) :
    BitVector(),
    _alloc(allocatePaddedAndAligned(start, end))
{
    init(_alloc.get(), start, end);
    clear();
}

PartialBitVector::PartialBitVector(const BitVector & org, Index start, Index end) :
    BitVector(),
    _alloc(allocatePaddedAndAligned(start, end))
{
    init(_alloc.get(), start, end);
    Range range = sanitize(org.range());
    if (range.validNonZero()) {
        const Word *startWord = org.getWordIndex(range.start());
        size_t numBytes2Copy = numActiveBytes(range.start(), range.end());
        memcpy(getWordIndex(range.start()), startWord, numBytes2Copy);
        if (range.end() < end) {
            clearInterval(range.end(), end);
        }
        if (start < range.start()) {
            clearInterval(start, range.start());
        }
    } else {
        clear();
    }
    set_bit_no_range_check(size());
}

PartialBitVector::~PartialBitVector() = default;

} // namespace search