14 cache.reserve((
size_t)((
double)size * FLOATING_BUCKET_CACHE_SIZE));
17 inline bool get(
double floatingKey,
double* value)
const {
18 const uint64_t hashKey = hashFloatingKey(floatingKey);
19 auto it = cache.find(hashKey);
20 if (it != cache.end()) {
27 inline void set(
double floatingKey,
double value) {
28 const uint64_t hashKey = hashFloatingKey(floatingKey);
29 cache[hashKey] = value;
32 inline void clear() { cache.clear(); }
35 static constexpr double epsilon = 1e-15;
37 std::unordered_map<uint64_t, double> cache;
39 inline uint64_t hashFloatingKey(
double floatingKey)
const {
40 return static_cast<uint64_t
>(floatingKey / epsilon);
47 cache.reserve((
size_t)((
double)size * FLOATING_BUCKET_CACHE_SIZE));
50 inline bool get(
double floatingKey,
size_t intKey,
double* value)
const {
51 const uint64_t hashKey = hashFloatingKey(floatingKey, intKey);
52 auto it = cache.find(hashKey);
53 if (it != cache.end()) {
60 inline void set(
double floatingKey,
size_t intKey,
double value) {
61 const uint64_t hashKey = hashFloatingKey(floatingKey, intKey);
62 cache[hashKey] = value;
65 inline void clear() { cache.clear(); }
68 static constexpr double epsilon = 1e-9;
69 static constexpr uint64_t floatingBits = 40;
70 static constexpr uint64_t intBits = 24;
72 static constexpr uint64_t floatingMask = (uint64_t(1) << floatingBits) - 1;
73 static constexpr uint64_t intMask = (uint64_t(1) << intBits) - 1;
75 std::unordered_map<uint64_t, double> cache;
77 inline uint64_t hashFloatingKey(
double floatingKey,
size_t intKey)
const {
78 assert(intKey <= intMask);
79 return (
static_cast<uint64_t
>(floatingKey / epsilon) & floatingMask) |
80 ((
static_cast<uint64_t
>(intKey) & intMask) << floatingBits);