113using namespace Aleph;
160 template <
typename Key,
class Cmp = Aleph::equal_to<Key>>
198 const auto base =
reinterpret_cast<std::uintptr_t
>(
rec);
220 if (
table ==
nullptr)
223 const auto begin =
reinterpret_cast<std::uintptr_t
>(&
table[0]);
224 const auto end =
reinterpret_cast<std::uintptr_t
>(&
table[
len]);
225 const auto addr =
reinterpret_cast<std::uintptr_t
>(bucket);
231 static_cast<std::ptrdiff_t
>(
addr -
begin);
286 if (
table !=
nullptr)
350 for (
size_t c = 0; c <
len; ++c)
359 return &
table[i].key;
375 for (
size_t c = 0; c <
len; ++c)
388 if (b.status ==
BUSY)
422 for (
size_t c = 0; c <
len; ++c)
433 return {bucket,
false};
435 else if (b.status ==
BUSY)
457 return {
nullptr,
false};
463 return (i == 0) ?
len - 1 : i - 1;
469 return (i + 1 ==
len) ? 0 : i + 1;
506 <<
"record address is not inside table's range";
509 <<
"Bucket containing record is not busy";
512 const auto idx =
static_cast<size_t>(bucket - &
table[0]);
526 for (
size_t c = 0; c <
len; ++c)
557 size_t num_deleted = 0;
558 size_t num_empty = 0;
559 size_t max_len = std::numeric_limits<size_t>::min();
560 for (
size_t i = 0; i <
len; ++i)
561 switch (
table[i].status)
579 max_len = std::max(max_len,
count);
594 for (
size_t i = 0; i < lens.
size(); ++i)
602 for (
size_t i = 0; i < lens.
size(); ++i)
604 const float s = i - avg;
605 var += lens(i) * s * s;
610 stats.num_busy = num_busy;
611 stats.num_deleted = num_deleted;
612 stats.num_empty = num_empty;
613 std::swap(lens,
stats.lens);
616 stats.max_len = max_len;
622 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.
DRY (Don't Repeat Yourself) utilities and macros.
#define Special_Ctors(Set_Type, Type)
Generates special constructors for containers.
size_t size() const noexcept
Return the current dimension of array.
Open addressing hash table with linear probing collision resolution.
OLhashTable(size_t len, Hash_Fct hash_fct, Hash_Fct, Cmp cmp, float lower_alpha, float upper_alpha, bool with_resize)
~OLhashTable()
Release all occupied memory.
OLhashTable(size_t len, Hash_Fct_Ptr hash_fct, Hash_Fct_Ptr, Cmp cmp, float lower_alpha, float upper_alpha, bool with_resize)
void deallocate_bucket(Bucket *bucket)
Removes the record pointed to by record from the table.
OLhashTable(size_t len=Primes::DefaultPrime, Hash_Fct_Ptr hash_fct=Aleph::dft_hash_fct< Key >, Cmp cmp=Cmp(), float lower_alpha=hash_default_lower_alpha, float upper_alpha=0.70f, bool with_resize=true)
Key * search(const Key &key) const noexcept
Finds the key and returns the associated record if key is find inside the table; otherwise,...
std::tuple< Bucket *, bool > hard_allocate_bucket(const Key &key) noexcept
size_t next_index(const size_t i) const noexcept
Index of next bucket (handles wrap-around)
std::function< size_t(const Key &)> Hash_Fct
OLhashTable(OLhashTable &&other) noexcept
OLhashTable(size_t len, Hash_Fct hash_fct, Hash_Fct_Ptr, Cmp cmp, float lower_alpha, float upper_alpha, bool with_resize)
Constructor with two hash functions for metaprogramming compatibility with ODhashTable type.
void cleanup_deleted_chain(size_t idx) noexcept
Cleanup DELETED entries that are at the end of collision chains.
static void update_stat_len(DynArray< size_t > &lens, size_t i)
OLhashTable(const OLhashTable &other)
bool is_valid_bucket(Bucket *bucket) const noexcept
size_t(*)(const Key &) Hash_Fct_Ptr
constexpr const Cmp & get_compare() const noexcept
Bucket * allocate_bucket(const Key &key) noexcept
constexpr Cmp & get_compare() noexcept
void swap(OLhashTable &other) noexcept
OLhashTable(const size_t l, Hash_Fct hash_f, Cmp cmp_f, const float l_alpha, const float u_alpha, const bool resize)
Instantiate a hash table with hash function __hash_fct and dimension len.
OLhashTable & operator=(OLhashTable &&other) noexcept
size_t prev_index(const size_t i) const noexcept
Index of previous bucket (handles wrap-around)
static Bucket * key_to_bucket(Key *rec) noexcept
OLhashTable & operator=(const OLhashTable &other)
typename OhashCommon< OLhashTable< Key, Cmp >, Key >::Stats Stats
void remove(const Key &key)
Remove the key referenced by key.
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.
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.
size_t next_prime(unsigned long n)
Find the smallest prime number >= n from the database.
Prime number utilities for hash tables and mathematical operations.
Generic traversal of the container through its iterator.