aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/btree/minmaxaggrcalc.h
blob: 6abbd8a6d4361147c1bdd392628b54477a489e12 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "minmaxaggregated.h"

namespace vespalib::btree {

class MinMaxAggrCalc
{
public:
    constexpr MinMaxAggrCalc() = default;
    constexpr static bool hasAggregated() { return true; }
    constexpr static bool aggregate_over_values() { return true; }
    static int32_t getVal(int32_t val) { return val; }
    static void add(MinMaxAggregated &a, int32_t val) { a.add(val); }
    static void add(MinMaxAggregated &a, const MinMaxAggregated &ca) { a.add(ca); }
    static void add(MinMaxAggregated &a, const MinMaxAggregated &oldca, const MinMaxAggregated &ca) { a.add(oldca, ca); }

    /* Returns true if recalculation is needed */
    static bool
    remove(MinMaxAggregated &a, int32_t val)
    {
        return a.remove(val);
    }

    /* Returns true if recalculation is needed */
    static bool
    remove(MinMaxAggregated &a, const MinMaxAggregated &oldca,
           const MinMaxAggregated &ca)
    {
        return a.remove(oldca, ca);
    }

    /* Returns true if recalculation is needed */
    static bool
    update(MinMaxAggregated &a, int32_t oldVal, int32_t val)
    {
        return a.update(oldVal, val);
    }

    /* Returns true if recalculation is needed */
    static bool
    update(MinMaxAggregated &a, const MinMaxAggregated &oldca,
           const MinMaxAggregated &ca)
    {
        return a.update(oldca, ca);
    }
};

}