summaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/btree/btreenodestore.hpp
blob: 5a3846416cc9e8cf31c574ec7bd1e20e49f4ee62 (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
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "btreenodestore.h"
#include <vespa/vespalib/datastore/datastore.hpp>

namespace vespalib::btree {

template <typename EntryType>
void
BTreeNodeBufferType<EntryType>::initializeReservedElements(void *buffer, size_t reservedElements)
{
    ParentType::initializeReservedElements(buffer, reservedElements);
    EntryType *e = static_cast<EntryType *>(buffer);
    for (size_t j = reservedElements; j != 0; --j) {
        e->freeze();
        ++e;
    }
}


template <typename EntryType>
void
BTreeNodeBufferType<EntryType>::cleanHold(void *buffer, size_t offset, size_t numElems, CleanContext)
{
    EntryType *e = static_cast<EntryType *>(buffer) + offset;
    for (size_t j = numElems; j != 0; --j) {
        e->cleanFrozen();
        ++e;
    }
}




template <typename KeyT, typename DataT, typename AggrT,
          size_t INTERNAL_SLOTS, size_t LEAF_SLOTS>
BTreeNodeStore<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS>::
BTreeNodeStore()
    : _store(),
      _internalNodeType(MIN_BUFFER_ARRAYS, RefType::offsetSize()),
      _leafNodeType(MIN_BUFFER_ARRAYS, RefType::offsetSize())
{
    _store.addType(&_internalNodeType);
    _store.addType(&_leafNodeType);
    _store.initActiveBuffers();
    _store.enableFreeLists();
}

template <typename KeyT, typename DataT, typename AggrT,
          size_t INTERNAL_SLOTS, size_t LEAF_SLOTS>
BTreeNodeStore<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS>::
~BTreeNodeStore()
{
    _store.dropBuffers(); // Drop buffers before type handlers are dropped
}


template <typename KeyT, typename DataT, typename AggrT,
          size_t INTERNAL_SLOTS, size_t LEAF_SLOTS>
std::vector<uint32_t>
BTreeNodeStore<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS>::
startCompact()
{
    std::vector<uint32_t> iToHold = _store.startCompact(NODETYPE_INTERNAL);
    std::vector<uint32_t> lToHold = _store.startCompact(NODETYPE_LEAF);
    std::vector<uint32_t> ret = iToHold;
    ret.insert(ret.end(), lToHold.begin(), lToHold.end());
    return ret;
}


template <typename KeyT, typename DataT, typename AggrT,
          size_t INTERNAL_SLOTS, size_t LEAF_SLOTS>
void
BTreeNodeStore<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS>::
finishCompact(const std::vector<uint32_t> &toHold)
{
    _store.finishCompact(toHold);
}

}