aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/btree/btreeaggregator.h
blob: 70ac60afea6e78cca84946ba290340b507a61f81 (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.

#pragma once

#include "btreenode.h"
#include "btreenodeallocator.h"
#include "btreetraits.h"
#include "noaggrcalc.h"

namespace vespalib::btree {

template <typename KeyT,
          typename DataT,
          typename AggrT = NoAggregated,
          size_t INTERNAL_SLOTS = BTreeDefaultTraits::INTERNAL_SLOTS,
          size_t LEAF_SLOTS = BTreeDefaultTraits::LEAF_SLOTS,
          class AggrCalcT = NoAggrCalc>
class BTreeAggregator
{
public:
    using NodeAllocatorType = BTreeNodeAllocator<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS>;
    using InternalNodeType = BTreeInternalNode<KeyT, AggrT, INTERNAL_SLOTS>;
    using LeafNodeType = BTreeLeafNode<KeyT, DataT, AggrT, LEAF_SLOTS>;
    using AggregatedType = AggrT;

    static AggrT aggregate(const LeafNodeType &node, AggrCalcT aggrCalc);
    static AggrT aggregate(const InternalNodeType &node, const NodeAllocatorType &allocator, AggrCalcT aggrCalc);

    static void recalc(LeafNodeType &node, const AggrCalcT &aggrCalc);

    static void recalc(LeafNodeType &node, const NodeAllocatorType &, const AggrCalcT &aggrCalc) {
        recalc(node, aggrCalc);
    }

    static void recalc(InternalNodeType &node, const NodeAllocatorType &allocator, const AggrCalcT &aggrCalc);
    static AggregatedType recalc(LeafNodeType &node, LeafNodeType &splitNode, const AggrCalcT &aggrCalc);

    static AggregatedType recalc(InternalNodeType &node, InternalNodeType &splitNode,
                                 const NodeAllocatorType &allocator, const AggrCalcT &aggrCalc);
};

}