ClickHouse

Форк
0
/
kostikConsistentHash.cpp 
34 строки · 914.0 Байт
1
#include "FunctionsConsistentHashing.h"
2
#include <Functions/FunctionFactory.h>
3

4
#include <consistent_hashing.h>
5

6
namespace DB
7
{
8

9
/// An O(1) time and space consistent hash algorithm by Konstantin Oblakov
10
struct KostikConsistentHashImpl
11
{
12
    static constexpr auto name = "kostikConsistentHash";
13

14
    using HashType = UInt64;
15
    /// Actually it supports UInt64, but it is efficient only if n <= 32768
16
    using ResultType = UInt16;
17
    using BucketsType = ResultType;
18
    static constexpr auto max_buckets = 32768;
19

20
    static inline ResultType apply(UInt64 hash, BucketsType n)
21
    {
22
        return ConsistentHashing(hash, n);
23
    }
24
};
25

26
using FunctionKostikConsistentHash = FunctionConsistentHashImpl<KostikConsistentHashImpl>;
27

28
REGISTER_FUNCTION(KostikConsistentHash)
29
{
30
    factory.registerFunction<FunctionKostikConsistentHash>();
31
    factory.registerAlias("yandexConsistentHash", "kostikConsistentHash");
32
}
33

34
}
35

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.