summaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/btree/btreeremover.h
blob: bc78a6be3a9342f87656d4be12e25df4490396fa (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
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "btreenode.h"
#include "btreenodeallocator.h"
#include "btreerootbase.h"
#include "btreeaggregator.h"
#include "noaggrcalc.h"
#include "minmaxaggrcalc.h"
#include "btreeiterator.h" 

namespace search
{

namespace btree
{

template <typename KeyT,
          typename DataT,
          typename AggrT,
          size_t INTERNAL_SLOTS,
          size_t LEAF_SLOTS,
          class AggrCalcT>
class BTreeRemoverBase
{
public:
    typedef BTreeNodeAllocator<KeyT, DataT, AggrT,
                               INTERNAL_SLOTS,
                               LEAF_SLOTS> NodeAllocatorType;
    typedef BTreeAggregator<KeyT, DataT, AggrT,
                            INTERNAL_SLOTS,
                            LEAF_SLOTS,
                            AggrCalcT> Aggregator;
    typedef BTreeInternalNode<KeyT, AggrT, INTERNAL_SLOTS> InternalNodeType;
    typedef BTreeLeafNode<KeyT, DataT, AggrT, LEAF_SLOTS>  LeafNodeType;
    typedef typename InternalNodeType::RefPair InternalNodeTypeRefPair;
    typedef typename LeafNodeType::RefPair LeafNodeTypeRefPair;

    template <typename NodeType, typename NodeTypeRefPair,
              class Iterator>
    static void
    steal(InternalNodeType *pNode,
          BTreeNode::Ref sNodeRef,
          NodeType *sNode,
          uint32_t idx,
          NodeAllocatorType &allocator,
          const AggrCalcT &aggrCalc,
          Iterator &itr,
          uint32_t level);
};

template <typename KeyT,
          typename DataT,
          typename AggrT,
          typename CompareT = std::less<KeyT>,
          typename TraitsT = BTreeDefaultTraits,
          class AggrCalcT = NoAggrCalc>
class BTreeRemover : public BTreeRemoverBase<KeyT, DataT, AggrT,
                                             TraitsT::INTERNAL_SLOTS,
                                             TraitsT::LEAF_SLOTS,
                                             AggrCalcT>
    
{
public:
    typedef BTreeRemoverBase<KeyT, DataT, AggrT,
                             TraitsT::INTERNAL_SLOTS,
                             TraitsT::LEAF_SLOTS,
                             AggrCalcT> ParentType;
    typedef BTreeNodeAllocator<KeyT, DataT, AggrT,
                               TraitsT::INTERNAL_SLOTS,
                               TraitsT::LEAF_SLOTS> NodeAllocatorType;
    typedef BTreeAggregator<KeyT, DataT, AggrT,
                            TraitsT::INTERNAL_SLOTS,
                            TraitsT::LEAF_SLOTS,
                            AggrCalcT> Aggregator;
    typedef BTreeInternalNode<KeyT, AggrT, TraitsT::INTERNAL_SLOTS>
    InternalNodeType;
    typedef BTreeLeafNode<KeyT, DataT, AggrT, TraitsT::LEAF_SLOTS>
    LeafNodeType;
    typedef KeyT  KeyType;
    typedef DataT DataType;
    typedef typename InternalNodeType::RefPair InternalNodeTypeRefPair;
    typedef typename LeafNodeType::RefPair LeafNodeTypeRefPair;
    typedef BTreeIterator<KeyT, DataT, AggrT,
                          CompareT, TraitsT> Iterator;

    static void
    remove(BTreeNode::Ref &root,
           Iterator &itr,
           const AggrCalcT &aggrCalc);
};

extern template class BTreeRemover<uint32_t, uint32_t, NoAggregated>;
extern template class BTreeRemover<uint32_t, BTreeNoLeafData, NoAggregated>;
extern template class BTreeRemover<uint32_t, int32_t,
                                   MinMaxAggregated,
                                   std::less<uint32_t>,
                                   BTreeDefaultTraits,
                                   MinMaxAggrCalc>;

} // namespace search::btree
} // namespace search