118using namespace Aleph;
172 template <
typename Key,
class Cmp = Aleph::equal_to<Key>>
246 return out <<
"Bucket at " << &bucket <<
'\n'
273 bucket.status =
BUSY;
274 bucket.probe_type = probe_type;
275 ++bucket.probe_counter;
284 --bucket->probe_counter;
285 if (bucket->probe_counter == 0)
286 bucket->status =
EMPTY;
312 if (
table ==
nullptr)
315 const auto begin =
reinterpret_cast<std::uintptr_t
>(&
table[0]);
316 const auto end =
reinterpret_cast<std::uintptr_t
>(&
table[
len]);
317 const auto addr =
reinterpret_cast<std::uintptr_t
>(bucket);
323 static_cast<std::ptrdiff_t
>(
addr -
begin);
330 return bucket - &
table[0];
336 if (
table ==
nullptr)
339 const auto addr =
reinterpret_cast<std::uintptr_t
>(&key);
359 template <
typename RecordBucket>
366 const Key & key = bucket->key;
409 const auto base =
reinterpret_cast<std::uintptr_t
>(
rec);
479 if (
table !=
nullptr)
584 switch (
table[i].status)
600 default:
AH_ERROR(
"ODhashTable search: inconsistent bucket status");
667 for (
size_t c = 0; c <
len; ++c)
702 for (
size_t k = 0;
k < c; ++
k)
794 for (
size_t c = 0; c <
len; ++c)
799 switch (
table[i].status)
803 return {&
table[i],
true};
841 for (
size_t k = 0;
k < c; ++
k)
848 default:
AH_ERROR(
"ODhashTable: Invalid bucket status");
875 return {
nullptr,
false};
904 <<
"Bucket containing key is not BUSY";
924 <<
"Key not in hash table";
944 <<
"Key not in hash table";
949 for (
size_t c = 0; c <
len; ++c)
955 switch (
table[i].status)
982 size_t num_busy = 0, num_deleted = 0, num_empty = 0;
983 size_t max_len = std::numeric_limits<size_t>::min();
984 for (
size_t i = 0; i <
len; ++i)
985 switch (
table[i].status)
1018 max_len = std::max(max_len,
count);
1031 float avg = 0,
sum = 0;
1032 for (
size_t i = 0; i < lens.
size(); ++i)
1040 for (
size_t i = 0; i < lens.
size(); ++i)
1042 const float s = i - avg;
1043 var += lens(i) * s * s;
1048 stats.num_busy = num_busy;
1049 stats.num_deleted = num_deleted;
1050 stats.num_empty = num_empty;
1051 std::swap(lens,
stats.lens);
1054 stats.max_len = max_len;
1061 template <
typename Key,
class Cmp = Aleph::equal_to<Key>>
Exception handling system with formatted messages for Aleph-w.
#define ah_domain_error()
Throws std::domain_error unconditionally.
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
#define ah_invalid_argument_if(C)
Throws std::invalid_argument if condition holds.
#define AH_ERROR(format, args...)
Print an error message (always enabled).
DRY (Don't Repeat Yourself) utilities and macros.
#define Special_Ctors(Set_Type, Type)
Generates special constructors for containers.
Iterator wrapper for C++ raw arrays and circular buffers.
size_t size() const noexcept
Return the current dimension of array.
Open addressing hash table with double hashing collision resolution.
Bucket * key_in_table_to_bucket(const Key &key) noexcept
Converts a key reference inside the table to its containing bucket.
static Bucket * key_to_bucket(Key *rec) noexcept
typename OhashCommon< ODhashTable< Key, Cmp >, Key >::Stats Stats
size_t bucket_to_index(Bucket *bucket) const noexcept
void deallocate_bucket_with_record(Bucket *bucket, RecordBucket &&record_bucket) noexcept
Template version of deallocate_bucket that accepts a callback to record modified buckets before decre...
bool is_key_in_table(const Key &key) const noexcept
Returns true if the key reference points to a key inside the table.
size_t(*)(const Key &) Hash_Fct_Ptr
size_t index_backward(size_t &i) const noexcept
void set_second_hash_fct(Hash_Fct fct) noexcept
Key * search(const Key &key) const noexcept
searches the table for the key.
void decrease_probe_counter(Bucket *bucket) noexcept
constexpr Hash_Fct get_second_hash_fct() const noexcept
~ODhashTable()
Free the whole hash table.
std::function< size_t(const Key &)> Hash_Fct
void swap(ODhashTable &other) noexcept
ODhashTable(const size_t l, Hash_Fct fst_hash_fct, Hash_Fct snd_hash_fct, Cmp cpm_fct, const float lower, const float upper, const bool resize)
ODhashTable(size_t len=Primes::DefaultPrime, Hash_Fct_Ptr first_hash_fct=Aleph::dft_hash_fct< Key >, Hash_Fct_Ptr second_hash_fct=Aleph::snd_hash_fct< Key >, Cmp cmp=Cmp(), float lower_alpha=hash_default_lower_alpha, float upper_alpha=hash_default_upper_alpha, bool with_resize=true)
Instantiate a closed hash table with collision resolution by double hashing.
constexpr Cmp & get_compare() noexcept
ODhashTable(const ODhashTable &other)
void remove_bucket(Bucket *bucket)
Delete the record from the table.
bool is_valid_bucket(Bucket *bucket) const noexcept
ODhashTable(ODhashTable &&other) noexcept
void remove(const Key &key)
Remove a key from the hash table.
Bucket * allocate_bucket(const Key &key) noexcept
void set_second_hash_fct(Hash_Fct_Ptr fct) noexcept
size_t index_forward(size_t &i) const noexcept
static void update_stat_len(DynArray< size_t > &lens, size_t i)
void deallocate_bucket(Bucket *bucket) noexcept
constexpr const Cmp & get_compare() const noexcept
Bucket * allocate_bucket(Bucket &bucket, unsigned char probe_type) noexcept
std::tuple< Bucket *, bool > hard_allocate_bucket(const Key &key) noexcept
ODhashTable & operator=(const ODhashTable &other)
Equality test for containers.
Common methods to the Aleph-w ( ) containers.
Aleph::DynList< __T > maps(Operation &op) const
Map the elements of the container.
Common sequential searching methods on containers.
LocateFunctions< Container, Type > * base() const
CRTP mixin providing common operations for open addressing hash tables.
size_t resize(size_t new_size)
Resizes the hash table to a new capacity.
void clean_table()
Removes all entries from the table without deallocating storage.
void copy_from_table(const HashTbl &other)
Copies all entries from another hash table.
Mixin that adds STL begin()/end() and cbegin()/cend() to Aleph containers.
iterator end() noexcept
Return an STL-compatible end iterator.
iterator begin() noexcept
Return an STL-compatible iterator to the first element.
Doubly linked circular list implementation.
Common hash table utilities and base classes.
#define OHASH_COMMON(class_name)
Collection of general-purpose hash functions.
Common operations for open addressing hash tables (CRTP mixin).
const long double offset[]
Offset values indexed by symbol string length (bounded by MAX_OFFSET_INDEX)
Main namespace for Aleph-w library functions.
size_t snd_hash_fct(const Key &key) noexcept
const float hash_default_upper_alpha
const float hash_default_lower_alpha
DynList< T > maps(const C &c, Op op)
Classic map operation.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.
const unsigned long DefaultPrime
Default prime number used when no specific size is requested.
Prime number utilities for hash tables and mathematical operations.
unsigned int probe_counter
constexpr bool valid() const noexcept
friend std::ostream & operator<<(std::ostream &out, const Bucket &bucket)
Generic traversal of the container through its iterator.
Lazy and scalable dynamic array implementation.