mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-15 10:52:30 +00:00
4088c0a7f3
Automated register all functions with below naming convention by iterating through the symbols: void DB::registerXXX(DB::FunctionFactory &)
35 lines
914 B
C++
35 lines
914 B
C++
#include "FunctionsConsistentHashing.h"
|
|
#include <Functions/FunctionFactory.h>
|
|
|
|
#include <consistent_hashing.h>
|
|
|
|
namespace DB
|
|
{
|
|
|
|
/// An O(1) time and space consistent hash algorithm by Konstantin Oblakov
|
|
struct KostikConsistentHashImpl
|
|
{
|
|
static constexpr auto name = "kostikConsistentHash";
|
|
|
|
using HashType = UInt64;
|
|
/// Actually it supports UInt64, but it is efficient only if n <= 32768
|
|
using ResultType = UInt16;
|
|
using BucketsType = ResultType;
|
|
static constexpr auto max_buckets = 32768;
|
|
|
|
static inline ResultType apply(UInt64 hash, BucketsType n)
|
|
{
|
|
return ConsistentHashing(hash, n);
|
|
}
|
|
};
|
|
|
|
using FunctionKostikConsistentHash = FunctionConsistentHashImpl<KostikConsistentHashImpl>;
|
|
|
|
REGISTER_FUNCTION(KostikConsistentHash)
|
|
{
|
|
factory.registerFunction<FunctionKostikConsistentHash>();
|
|
factory.registerAlias("yandexConsistentHash", "kostikConsistentHash");
|
|
}
|
|
|
|
}
|