mirror of
https://github.com/lifegpc/c-utils.git
synced 2026-06-06 13:18:57 +08:00
impl hash map
This commit is contained in:
29
hash_map.cpp
Normal file
29
hash_map.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include "hash_map.h"
|
||||
|
||||
size_t hash_map_get_next_cap(size_t cap) {
|
||||
if (cap >= hashmap_primes[25]) return cap * 2;
|
||||
for (auto i = 0; i < 26; i++) {
|
||||
if (hashmap_primes[i] > cap) return hashmap_primes[i];
|
||||
}
|
||||
return cap * 2;
|
||||
}
|
||||
|
||||
std::function<size_t(size_t)> hash_map_linear_probing(size_t interval) {
|
||||
return std::function([interval](size_t i) {
|
||||
return i * interval;
|
||||
});
|
||||
}
|
||||
|
||||
size_t hash_map_quadratic_probing(size_t i) {
|
||||
return i * i;
|
||||
}
|
||||
|
||||
size_t hash_map_quadratic_probing_alter(size_t i) {
|
||||
size_t t = (i + 1) / 2;
|
||||
t = t * t;
|
||||
return i % 2 == 0 ? -t : t;
|
||||
}
|
||||
|
||||
std::function<size_t(size_t)> hash_map_random_probing(uint64_t seed) {
|
||||
return HashMapRandomProbingGeneator(seed);
|
||||
}
|
||||
Reference in New Issue
Block a user