aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Common/WeakHash.h
blob: b59624e64f242a8216c2425f6a66c564b4ee45b8 (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
#pragma once
#include <Common/PODArray.h>

namespace DB
{

/// It's a class which represents the result of weak and fast hash function per row in column.
/// It's usually hardware accelerated CRC32-C.
/// Has function result may be combined to calculate hash for tuples.
///
/// The main purpose why this class needed is to support data initialization. Initially, every bit is 1.
class WeakHash32
{
    static constexpr UInt32 kDefaultInitialValue = ~UInt32(0);

public:

    using Container = PaddedPODArray<UInt32>;

    explicit WeakHash32(size_t size, UInt32 initial_value = kDefaultInitialValue) : data(size, initial_value) {}
    WeakHash32(const WeakHash32 & other) { data.assign(other.data); }

    void reset(size_t size, UInt32 initial_value = kDefaultInitialValue) { data.assign(size, initial_value); }

    const Container & getData() const { return data; }
    Container & getData() { return data; }

private:
    PaddedPODArray<UInt32> data;
};

}