1 | #include "FunctionsConsistentHashing.h" |
---|---|
2 | #include <Functions/FunctionFactory.h> |
3 | |
4 | #include <sumbur.h> |
5 | |
6 | |
7 | namespace DB |
8 | { |
9 | |
10 | struct SumburConsistentHashImpl |
11 | { |
12 | static constexpr auto name = "sumburConsistentHash"; |
13 | |
14 | using HashType = UInt32; |
15 | using ResultType = UInt16; |
16 | using BucketsType = ResultType; |
17 | static constexpr auto max_buckets = static_cast<UInt64>(std::numeric_limits<BucketsType>::max()); |
18 | |
19 | static inline ResultType apply(HashType hash, BucketsType n) |
20 | { |
21 | return static_cast<ResultType>(sumburConsistentHash(hash, n)); |
22 | } |
23 | }; |
24 | |
25 | using FunctionSumburConsistentHash = FunctionConsistentHashImpl<SumburConsistentHashImpl>; |
26 | |
27 | void registerFunctionSumburConsistentHash(FunctionFactory & factory) |
28 | { |
29 | factory.registerFunction<FunctionSumburConsistentHash>(); |
30 | } |
31 | |
32 | } |
33 | |
34 | |
35 |