114using namespace Aleph;
161 template <
typename Key,
class Cmp = Aleph::equal_to<Key>>
179 using Hash_Fct = std::function<size_t(
const Key &)>;
200 const auto base =
reinterpret_cast<std::uintptr_t
>(
rec);
222 if (
table ==
nullptr)
225 const auto begin =
reinterpret_cast<std::uintptr_t
>(&
table[0]);
226 const auto end =
reinterpret_cast<std::uintptr_t
>(&
table[
len]);
227 const auto addr =
reinterpret_cast<std::uintptr_t
>(bucket);
233 static_cast<std::ptrdiff_t
>(
addr -
begin);
292 if (
table !=
nullptr)
356 for (
size_t c = 0; c <
len; ++c)
365 return &
table[i].key;
381 for (
size_t c = 0; c <
len; ++c)
394 if (b.status ==
BUSY)
428 for (
size_t c = 0; c <
len; ++c)
439 return {bucket,
false};
441 else if (b.status ==
BUSY)
463 return {
nullptr,
false};
469 return (i == 0) ?
len - 1 : i - 1;
475 return (i + 1 ==
len) ? 0 : i + 1;
512 <<
"record address is not inside table's range";
515 <<
"Bucket containing record is not busy";
518 const auto idx =
static_cast<size_t>(bucket - &
table[0]);
532 for (
size_t c = 0; c <
len; ++c)
563 size_t num_deleted = 0;
564 size_t num_empty = 0;
565 size_t max_len = std::numeric_limits<size_t>::min();
566 for (
size_t i = 0; i <
len; ++i)
567 switch (
table[i].status)
585 max_len = std::max(max_len,
count);
600 for (
size_t i = 0; i < lens.
size(); ++i)
608 for (
size_t i = 0; i < lens.
size(); ++i)
610 const float s = i - avg;
611 var += lens(i) * s * s;
616 stats.num_busy = num_busy;
617 stats.num_deleted = num_deleted;
618 stats.num_empty = num_empty;
619 std::swap(lens,
stats.lens);
622 stats.max_len = max_len;
628 template <
typename Key,
class Cmp = Aleph::equal_to<Key>>
C++20 concepts for constraining comparison functors.
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.
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
OLhashTable(size_t len=Primes::DefaultPrime, Hash_Fct_Ptr hash_fct=Aleph::dft_hash_ptr_fct< Key >, Cmp cmp=Cmp(), float lower_alpha=hash_default_lower_alpha, float upper_alpha=0.70f, bool with_resize=true)
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.
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.
constexpr bool contains(const Key &key) const noexcept
Alias for has().
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.
Equivalence relation constraint for equality comparators.
Doubly linked circular list implementation.
Common hash table utilities and base classes.
#define OHASH_COMMON(class_name)
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.
and
Check uniqueness with explicit hash + equality functors.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
const float hash_default_lower_alpha
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.