aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/test/fakedata/bitdecode64.h
blob: 120a1efdedf72b4e1be4c1ae95debc037f7b9de4 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include "bitencode64.h"
#include <vespa/searchlib/util/comprfile.h>
#include <vespa/searchlib/bitcompression/compression.h>

namespace search
{

namespace fakedata
{

template <bool bigEndian>
class BitDecode64 : public bitcompression::DecodeContext64<bigEndian>
{
private:
    const uint64_t *_comprBase;
    int _bitOffsetBase;
    typedef bitcompression::DecodeContext64<bigEndian> ParentClass;

public:
    using ParentClass::_val;
    using ParentClass::_valI;
    using ParentClass::_preRead;
    using ParentClass::_cacheInt;
    typedef typename bitcompression::DecodeContext64<bigEndian>::EC EC;

    BitDecode64(const uint64_t *compr,
                  int bitOffset)
        : bitcompression::DecodeContext64<bigEndian>(compr, bitOffset),
          _comprBase(compr),
          _bitOffsetBase(bitOffset)
    {
    }

    typedef bitcompression::DecodeContext64<bigEndian> DC;

    void
    seek(uint64_t offset)
    {
        offset += _bitOffsetBase;
        const uint64_t *compr = _comprBase + (offset / 64);
        int bitOffset = offset & 63;
        _valI = compr + 1;
        _val = 0;
        _cacheInt = EC::bswap(*compr);
        _preRead = 64 - bitOffset;
        uint32_t length = 64;
        UC64_READBITS(_val, _valI, _preRead, _cacheInt, EC);
    }

    uint64_t
    getOffset() const
    {
        return 64 * (_valI - _comprBase - 1) - this->_preRead -
            _bitOffsetBase;
    }

    uint64_t
    getOffset(const uint64_t *valI, int preRead) const
    {
        return 64 * (valI - _comprBase - 1) - preRead - _bitOffsetBase;
    }

    const uint64_t *
    getComprBase() const
    {
        return _comprBase;
    }

    int
    getBitOffsetBase() const
    {
        return _bitOffsetBase;
    }
};


extern template class BitDecode64<true>;

extern template class BitDecode64<false>;

typedef BitDecode64<true> BitDecode64BE;

typedef BitDecode64<false> BitDecode64LE;

} // namespace fakedata

} // namespace search