blob: 86bd617342d21516a30e191dd0db68e1c695804a (
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
|
#pragma once
#include "concepts/size_fitter.h"
#include <util/system/yassert.h>
#include <util/generic/bitops.h>
namespace NFlatHash {
class TAndSizeFitter {
public:
size_t EvalIndex(size_t hs, size_t sz) const noexcept {
Y_ASSERT(Mask_ == sz - 1);
return (hs & Mask_);
}
size_t EvalSize(size_t sz) const noexcept {
return FastClp2(sz);
}
void Update(size_t sz) noexcept {
Y_ASSERT((sz & (sz - 1)) == 0);
Mask_ = sz - 1;
}
private:
size_t Mask_ = 0;
};
static_assert(NConcepts::SizeFitterV<TAndSizeFitter>);
class TModSizeFitter {
public:
constexpr size_t EvalIndex(size_t hs, size_t sz) const noexcept {
return hs % sz;
}
constexpr size_t EvalSize(size_t sz) const noexcept {
return sz;
}
constexpr void Update(size_t) noexcept {}
};
static_assert(NConcepts::SizeFitterV<TModSizeFitter>);
} // NFlatHash
|