Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::DynHashTable< Key, HashTable, Cmp > Class Template Reference

Self-adjusting dynamic hash table. More...

#include <tpl_dynSetHash.H>

Inheritance diagram for Aleph::DynHashTable< Key, HashTable, Cmp >:
[legend]
Collaboration diagram for Aleph::DynHashTable< Key, HashTable, Cmp >:
[legend]

Classes

class  Iterator
 

Public Types

using Hash_Fct = typename Base::Hash_Fct
 Hash function type.
 
using Hash_Fct_Ptr = typename Base::Hash_Fct_Ptr
 
using Key_Type = Key
 
using Item_Type = Key
 
using Const_Iterator = Aleph::Const_Iterator< Iterator >
 Read-only iterator: the iterator of a constant table.
 
- Public Types inherited from StlAlephIterator< SetName >
using iterator = StlIterator< SetName >
 
using const_iterator = StlConstIterator< SetName >
 

Public Member Functions

 DynHashTable (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=hash_default_upper_alpha)
 Creates a dynamic linear hash table.
 
 DynHashTable (size_t len, Hash_Fct hash_fct, Cmp cmp, float lower_alpha, float upper_alpha)
 
 DynHashTable (const DynHashTable &other)
 Copy constructor.
 
 DynHashTable (DynHashTable &&other) noexcept
 Move constructor over a table that a move of its own takes, as the one of chained lists (DynSetLhash): takes the lists and the keys of other.
 
 DynHashTable (DynHashTable &&other) noexcept
 Move constructor over a table that no move of its own takes, as the linear one (DynSetLinHash): builds an empty table of the capacity of other and swaps them.
 
template<template< typename > class List>
 DynHashTable (const List< Key > &l)
 
template<class It >
requires (not std::is_arithmetic_v<It> and requires (It it) { *it; ++it; it != it; })
 DynHashTable (It b, It e)
 
 DynHashTable (std::initializer_list< Key > l)
 
 ~DynHashTable ()
 
void clear ()
 Empties the container.
 
bool contains (const Key &key) const noexcept
 Return true if the key exists in the table.
 
bool is_empty () const noexcept
 Checks if the container is empty.
 
DynHashTable & operator= (const DynHashTable &other)
 Copy assignment.
 
DynHashTable & operator= (DynHashTable &&other) noexcept
 
Key * insert (const Key &key)
 Inserts key into the hash set.
 
Key * insert (Key &&key)
 
Key * search_or_insert (const Key &key)
 
Key * search_or_insert (Key &&key)
 
std::pair< Key *, bool > contains_or_insert (const Key &key)
 
std::pair< Key *, bool > contains_or_insert (Key &&key)
 
Key * add (const Key &key)
 
Key * add (Key &&key)
 
Key * append (const Key &key)
 
Key * append (Key &&key)
 
Key * search (const Key &key) noexcept
 Searches for a key in the hash table.
 
const Key * search (const Key &key) const noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. A pointer to const.
 
bool has (const Key &key) const noexcept
 Checks if a key exists in the hash table.
 
const Key & find (const Key &key) const
 
Key & find (const Key &key)
 
void remove (Key *key)
 Removes a key from the hash table using its pointer.
 
Key remove (const Key &key)
 
const Key & get_first () const
 
Key & get_first ()
 
const Key & get_last () const
 
Key & get_last ()
 
- Public Member Functions inherited from GenericTraverse< Container >
template<class Operation >
requires Aleph::PredicateWith<Operation &, typename Aleph::concepts_detail::traverse_arg<Container, Operation>::type>
bool traverse (Operation &operation) noexcept(traverse_is_noexcept< Operation, typename Aleph::concepts_detail::traverse_arg< Container, Operation >::type, Container & >())
 Traverse the container via its iterator and performs a conditioned operation on each item.
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, typename Aleph::concepts_detail::traverse_carg<Container, Operation>::type>
bool traverse (Operation &operation) const noexcept(traverse_is_noexcept< Operation, typename Aleph::concepts_detail::traverse_carg< Container, Operation >::type, const_source_t< Operation > >())
 Traverse a constant container; each item is handed out as a constant reference.
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, typename Aleph::concepts_detail::traverse_carg<Container, Operation>::type>
bool traverse (Operation &&operation) const noexcept(traverse_is_noexcept< Operation, typename Aleph::concepts_detail::traverse_carg< Container, Operation >::type, const_source_t< Operation > >())
 Overload of traverse(Operation &) const that accepts rvalues.
 
template<class Operation >
requires Aleph::PredicateWith<Operation &, typename Aleph::concepts_detail::traverse_arg<Container, Operation>::type>
bool traverse (Operation &&operation) noexcept(traverse_is_noexcept< Operation, typename Aleph::concepts_detail::traverse_arg< Container, Operation >::type, Container & >())
 Overload of traverse(Operation &) that accepts rvalues.
 
- Public Member Functions inherited from LocateFunctions< Container, Type >
auto get_it ()
 Return a properly initialized iterator positioned at the first item on the container.
 
auto get_it () const
 Read-only iterator positioned at the first item.
 
auto get_it (const size_t pos)
 Return a properly initialized iterator positioned at the pos item on the container.
 
auto get_it (const size_t pos) const
 Read-only iterator positioned at the pos item.
 
auto get_itor ()
 Alias of get_it().
 
auto get_itor () const
 See get_itor().
 
template<class C = Container>
requires Aleph::dry_detail::MutablyTraversable<C, Type>
Type & nth_ne (const size_t n) noexcept(Aleph::dry_detail::mutable_traversal_is_noexcept< C, Type >)
 Return the n‑th element without bounds checking.
 
const Type & nth_ne (const size_t n) const noexcept(Aleph::dry_detail::const_traversal_is_noexcept< Container, Type >)
 Constant overload of nth_ne(size_t).
 
template<class C = Container>
requires Aleph::dry_detail::MutablyTraversable<C, Type>
Type & nth (const size_t n)
 Return the n-th item of the container.
 
const Type & nth (const size_t n) const
 Const overload of nth(size_t).
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, Type &>
and Aleph::dry_detail::MutablyTraversable< typename Aleph::concepts_detail::defer< Container, Operation >::type, Type > Type * find_ptr (Operation &operation) noexcept(mutable_search_is_noexcept< Operation >())
 Find a pointer to an item in the container according to a searching criterion.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const Type &>
const Type * find_ptr (Operation &operation) const noexcept(const_search_is_noexcept< Operation >())
 Const overload of find_ptr(Operation&).
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const Type &>
const Type * find_ptr (Operation &&operation) const noexcept(const_search_is_noexcept< Operation >())
 Overload of find_ptr() const that accepts rvalues.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, Type &>
and Aleph::dry_detail::MutablyTraversable< typename Aleph::concepts_detail::defer< Container, Operation >::type, Type > Type * find_ptr (Operation &&operation) noexcept(mutable_search_is_noexcept< Operation >())
 Overload of find_ptr() that accepts rvalues.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const Type &>
size_t find_index (Operation &operation) const noexcept(const_search_is_noexcept< Operation >())
 Find the position of an item in the container according to a searching criterion.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const Type &>
size_t find_index (Operation &&operation) const noexcept(const_search_is_noexcept< Operation >())
 Overload of find_index() that accepts rvalues.
 
template<class Operation , class T = Type>
requires Aleph::InvocablePredicateWith<Operation &, const Type &>
and std::default_initializable< T > and std::copy_constructible< T > std::tuple< bool, Type > find_item (Operation &operation) const noexcept(find_item_is_noexcept< Operation >())
 Safe sequential searching of an item matching a criterion.
 
template<class Operation , class T = Type>
requires Aleph::InvocablePredicateWith<Operation &, const Type &>
and std::default_initializable< T > and std::copy_constructible< T > std::tuple< bool, Type > find_item (Operation &&operation) const noexcept(find_item_is_noexcept< Operation >())
 Overload of find_item() that accepts rvalues.
 
template<class Operation , class T = Type>
requires Aleph::InvocablePredicateWith<Operation &, const Type &>
and std::copy_constructible< T > std::optional< Type > find_opt (Operation &operation) const
 Copy of the first item satisfying a criterion, if any.
 
template<class Operation , class T = Type>
requires Aleph::InvocablePredicateWith<Operation &, const Type &>
and std::copy_constructible< T > std::optional< Type > find_opt (Operation &&operation) const
 Overload of find_opt() that accepts rvalues.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const Type &>
bool contains_if (Operation &&operation) const noexcept(const_search_is_noexcept< Operation >())
 Test if an item satisfying a criterion is present in the container.
 
template<class T = Type>
requires requires(const T & a, const T & b) { { a == b } -> std::convertible_to<bool>; }
bool contains (const Type &item) const
 Test if an item is present in the container using equality.
 
- Public Member Functions inherited from FunctionalMethods< Container, T >
void emplace (Args &&... args)
 Appends a new element into the container by constructing it from the given args.
 
void emplace_end (Args &&... args)
 See emplace(Args && ... args).
 
void emplace_ins (Args &&... args)
 
template<typename... Args>
requires ((std::convertible_to<Args &&, T> and ...) and (Aleph::InsertableWith<typename Aleph::concepts_detail::defer<Container, std::tuple<Args...>>::type, Item_Arg<Args>> and ...))
size_t ninsert (Args &&... args)
 Insert n variadic items.
 
template<typename... Args>
requires ((std::convertible_to<Args &&, T> and ...) and (Aleph::AppendableWith<typename Aleph::concepts_detail::defer<Container, std::tuple<Args...>>::type, Item_Arg<Args>> and ...))
size_t nappend (Args &&... args)
 Append n variadic items.
 
template<class Operation >
requires Aleph::InvocableWith<Operation &, const T &>
void for_each (Operation &operation) const
 Traverse all the container and performs an operation on each element.
 
template<class Operation >
requires Aleph::InvocableWith<Operation &, const T &>
void for_each (Operation &&operation) const
 Overload of for_each() that accepts rvalues.
 
template<class Operation >
requires Aleph::InvocableWith<Operation &, const T &>
void each (Operation &operation) const
 Alias of for_each().
 
template<class Operation >
requires Aleph::InvocableWith<Operation &, const T &>
void each (Operation &&operation) const
 Alias of for_each() that accepts rvalues.
 
template<class Operation >
requires Aleph::InvocableWith<Operation &, const T &>
void each (const size_t pos, const size_t slice, Operation &operation) const
 Traverse the container starting at pos taking one item every slice, performing an operation on each visited element.
 
template<class Operation >
requires Aleph::InvocableWith<Operation &, const T &>
void each (const size_t pos, const size_t slice, Operation &&operation) const
 See each(size_t pos, size_t slice, Operation & operation) const.
 
template<class Operation >
requires Aleph::InvocableWith<Operation &, T &>
and Aleph::dry_detail::MutablyTraversable< typename Aleph::concepts_detail::defer< Container, Operation >::type, T > void each (const size_t pos, const size_t slice, Operation &operation)
 Traverse the container starting at pos taking one item every slice, performing an operation that may modify each visited item.
 
template<class Operation >
requires Aleph::InvocableWith<Operation &, T &>
and Aleph::dry_detail::MutablyTraversable< typename Aleph::concepts_detail::defer< Container, Operation >::type, T > void each (const size_t pos, const size_t slice, Operation &&operation)
 See each(size_t pos, size_t slice, Operation & operation).
 
template<class Operation >
requires Aleph::InvocableWith<Operation &, T &>
and Aleph::dry_detail::MutablyTraversable< typename Aleph::concepts_detail::defer< Container, Operation >::type, T > void mutable_for_each (Operation &operation)
 Apply a mutable operation to each element of the container.
 
template<class Operation >
requires Aleph::InvocableWith<Operation &, T &>
and Aleph::dry_detail::MutablyTraversable< typename Aleph::concepts_detail::defer< Container, Operation >::type, T > void mutable_for_each (Operation &&operation)
 See mutable_for_each(Operation & operation).
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
bool all (Operation &operation) const
 Check if all the elements of the container satisfy a condition.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
bool all (Operation &&operation) const
 Overload of all() that accepts rvalues.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
bool exists (Operation &op) const
 Test for existence in the container of an element satisfying a criterion.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
bool exists (Operation &&op) const
 Overload of exists() that accepts rvalues.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
bool none (Operation &op) const
 Test that no element satisfies a criterion.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
bool none (Operation &&op) const
 Overload of none() that accepts rvalues.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
size_t count_if (Operation &op) const
 Count the elements that satisfy a criterion.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
size_t count_if (Operation &&op) const
 Overload of count_if() that accepts rvalues.
 
Aleph::DynList< Aleph::dry_detail::map_result_t< R, Operation &, T > > maps (Operation &op) const
 
Aleph::DynList< Aleph::dry_detail::map_result_t< R, Operation &, T > > maps (Operation &&op) const
 
Aleph::DynList< Aleph::dry_detail::map_result_t< R, Operation &, T > > maps_if (Prop prop, Operation &op) const
 
Aleph::DynList< Aleph::dry_detail::map_result_t< R, Operation &, T > > maps_if (Prop prop, Operation &&op) const
 
Aleph::DynList< Aleph::dry_detail::map_result_t< R, Operation &, T > > map (Operation &op) const
 
Aleph::DynList< Aleph::dry_detail::map_result_t< R, Operation &, T > > map (Operation &&op) const
 
Aleph::DynList< Aleph::dry_detail::map_result_t< R, Operation &, T > > map_if (Prop prop, Operation &op) const
 
Aleph::DynList< Aleph::dry_detail::map_result_t< R, Operation &, T > > map_if (Prop prop, Operation &&op) const
 
template<class Operation >
requires Aleph::InvocableWith<Operation &, const T &>
auto flat_map (Operation &op) const
 Map each element to a container and concatenate the results.
 
template<class Operation >
requires Aleph::InvocableWith<Operation &, const T &>
auto flat_map (Operation &&op) const
 Overload of flat_map() that accepts rvalues.
 
Aleph::DynList< T > to_dynlist () const
 Convert container to DynList.
 
std::vector< T > to_vector () const
 Convert container to std::vector.
 
template<typename Acc = T, class Op >
requires Aleph::dry_detail::FoldOperation<Op, Acc, T>
Acc foldl (const Acc &init, Op &op) const
 Fold the elements of the container to a specific result.
 
template<typename Acc = T, class Op >
requires Aleph::dry_detail::FoldOperation<Op, Acc, T>
Acc foldl (const Acc &init, Op &&op) const
 Overload of foldl() that accepts rvalues.
 
template<typename Acc = T, class Op >
requires Aleph::dry_detail::FoldOperation<Op, Acc, T>
Acc fold_left (const Acc &init, Op &op) const
 Alias for foldl().
 
template<typename Acc = T, class Op >
requires Aleph::dry_detail::FoldOperation<Op, Acc, T>
Acc fold_left (const Acc &init, Op &&op) const
 Overload of fold_left() that accepts rvalues.
 
template<class Operation >
requires Aleph::dry_detail::FoldOperation<Operation, T, T>
T fold (const T &init, Operation &operation) const
 Simplified version of foldl() where the folded type is the same type of elements stored in the container.
 
template<class Operation >
requires Aleph::dry_detail::FoldOperation<Operation, T, T>
T fold (const T &init, Operation &&operation) const
 Overload of fold() that accepts rvalues.
 
template<typename Acc = T, class Op >
requires Aleph::dry_detail::FoldRightOperation<Op, Acc, T>
Acc foldr (const Acc &init, Op &op) const
 Fold the elements from the last to the first.
 
template<typename Acc = T, class Op >
requires Aleph::dry_detail::FoldRightOperation<Op, Acc, T>
Acc foldr (const Acc &init, Op &&op) const
 Overload of foldr() that accepts rvalues.
 
template<class Op , class U = T>
requires Aleph::dry_detail::FoldOperation<Op, T, T>
and std::copy_constructible< U > std::optional< T > reduce (Op &op) const
 Fold the elements with no initial value.
 
template<class Op , class U = T>
requires Aleph::dry_detail::FoldOperation<Op, T, T>
and std::copy_constructible< U > std::optional< T > reduce (Op &&op) const
 Overload of reduce() that accepts rvalues.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
Aleph::DynList< T > filter (Operation &operation) const
 Filter the elements of a container according to a matching criterion.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
Aleph::DynList< T > filter (Operation &&operation) const
 Overload of filter() that accepts rvalues.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
Aleph::DynList< const T * > ptr_filter (Operation &operation) const
 Filter the elements of a container according to a matching criterion and return a pointer to the matched items in the container.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
Aleph::DynList< const T * > ptr_filter (Operation &&operation) const
 Overload of ptr_filter() that accepts rvalues.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
Aleph::DynList< std::tuple< T, size_t > > pfilter (Operation &operation) const
 Filter the elements of a container according to a matching criterion and determine its positions respect to the traversal of container.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
Aleph::DynList< std::tuple< T, size_t > > pfilter (Operation &&operation) const
 Overload of pfilter() that accepts rvalues.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
std::pair< Aleph::DynList< T >, Aleph::DynList< T > > partition (Operation &op) const
 Exclusive partition of container according to a filter criterion.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
std::pair< Aleph::DynList< T >, Aleph::DynList< T > > partition (Operation &&op) const
 Overload of partition() that accepts rvalues.
 
std::pair< Aleph::DynList< T >, Aleph::DynList< T > > partition (size_t n) const
 Exclusive partition of container in the nth item.
 
std::pair< Aleph::DynList< T >, Aleph::DynList< T > > split_half () const
 Split the container into two halves by alternating elements.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
std::tuple< Aleph::DynList< T >, Aleph::DynList< T > > tpartition (Operation &op) const
 Exclusive partition of container according to a filter criterion.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
std::tuple< Aleph::DynList< T >, Aleph::DynList< T > > tpartition (Operation &&op) const
 Overload of tpartition() that accepts rvalues.
 
size_t length () const noexcept(Aleph::dry_detail::const_traversal_is_noexcept< Container, T >)
 Count the number of elements of a container.
 
Aleph::DynList< T > rev () const
 Return a list with the elements of container in reverse order respect to its traversal order.
 
Aleph::DynList< T > take (const size_t n) const
 Return a list with the first n elements seen in the container during its traversal.
 
Aleph::DynList< T > take (size_t i, const size_t j, const size_t step=1) const
 Return a list with the elements at positions i, i + step, i + 2 step, ... that are not greater than j, respect to the traversal order.
 
Aleph::DynList< T > drop (const size_t n) const
 Drop the first n elements seen in the container during its traversal.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
Aleph::DynList< T > take_while (Operation &op) const
 The longest prefix of elements that satisfy a criterion.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
Aleph::DynList< T > take_while (Operation &&op) const
 Overload of take_while() that accepts rvalues.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
Aleph::DynList< T > drop_while (Operation &op) const
 The elements after the longest prefix that satisfies a criterion.
 
template<class Operation >
requires Aleph::InvocablePredicateWith<Operation &, const T &>
Aleph::DynList< T > drop_while (Operation &&op) const
 Overload of drop_while() that accepts rvalues.
 
template<class C = Container>
requires requires (C & c) { c.remove(); }
void mutable_drop (const size_t n)
 Drop the first n elements seen from container.
 
- Public Member Functions inherited from GenericItems< Container, T >
Aleph::DynList< T > items () const
 Return a list of all the elements of a container sorted by traversal order.
 
Aleph::DynList< T > keys () const
 See items().
 
- Public Member Functions inherited from EqualToMethod< Container >
template<class C = Container>
requires Aleph::dry_detail::SetSearchable<C>
bool equal_to (const Container &r) const
 Test if elements of this are exactly contained in another container.
 
- Public Member Functions inherited from StlAlephIterator< SetName >
iterator begin () noexcept
 Return an STL-compatible iterator to the first element.
 
iterator end () noexcept
 Return an STL-compatible end iterator.
 
const_iterator begin () const noexcept
 Return a const iterator to the first element.
 
const_iterator end () const noexcept
 Return a const end iterator.
 
const_iterator cbegin () const noexcept
 Return a const iterator to the first element.
 
const_iterator cend () const noexcept
 Return a const end iterator.
 

Protected Types

using Base = HashTable< Key, Cmp >
 
using Bucket = typename HashTable< Key, Cmp >::Bucket
 

Protected Member Functions

Key * insert_bucket (Bucket *bucket)
 
std::pair< Key *, bool > search_or_insert_bucket (Bucket *bucket)
 

Static Protected Member Functions

static Bucket * key_to_bucket (Key *key)
 

Private Member Functions

void copy (const DynHashTable &other)
 

Additional Inherited Members

- Static Public Member Functions inherited from FunctionalMethods< Container, T >
template<typename... Items>
requires ((std::convertible_to<Items &&, T> and ...) and (Aleph::AppendableWith<typename Aleph::concepts_detail::defer<Container, std::tuple<Items...>>::type, Item_Arg<Items>> and ...))
static Container build (Items &&... items)
 Build a container that holds the given items.
 
template<class D , typename... Items>
requires (std::derived_from<D, typename Aleph::concepts_detail::defer<Container, D>::type> and std::default_initializable<D> and (std::convertible_to<Items &&, T> and ...) and (Aleph::AppendableWith<typename Aleph::concepts_detail::defer<Container, std::tuple<D, Items...>>::type, Item_Arg<Items>> and ...))
static D build_as (Items &&... items)
 Build a D, a class derived from the container, holding the given items.
 
- Public Attributes inherited from FunctionalMethods< Container, T >
template<typename... Args>
requires (typename Aleph::concepts_detail::defer<Container, std::tuple<Args...>>::type & c, T && x)
 and { c.append(std::move(x))
 Insert a new element into the container by constructing it from the given args.
 
template<typename R = void, class Prop , class Operation >
requires (Aleph::DynList<Aleph::dry_detail::map_result_t<R, Operation &, T>> & l, Operation & op, const T & item)
and Aleph::InvocableWith< Operation &, const T & > and { l.append(std::invoke(op, item))
 Conditional mapping of the elements of the container.
 

Detailed Description

template<typename Key, template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
requires EqualityComparator<Cmp, Key>
class Aleph::DynHashTable< Key, HashTable, Cmp >

Self-adjusting dynamic hash table.

DynHashTable<Key> implements a linear, dynamic hash table where the user does not need to worry about the table size; it is automatically adjusted according to load-factor thresholds defined at construction time.

Parameters
KeyThe domain type used to index the table.
See also
LinearHashTable

Definition at line 80 of file tpl_dynSetHash.H.

Member Typedef Documentation

◆ Base

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
using Aleph::DynHashTable< Key, HashTable, Cmp >::Base = HashTable<Key, Cmp>
protected

Definition at line 90 of file tpl_dynSetHash.H.

◆ Bucket

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
using Aleph::DynHashTable< Key, HashTable, Cmp >::Bucket = typename HashTable<Key, Cmp>::Bucket
protected

Definition at line 92 of file tpl_dynSetHash.H.

◆ Const_Iterator

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
using Aleph::DynHashTable< Key, HashTable, Cmp >::Const_Iterator = Aleph::Const_Iterator<Iterator>

Read-only iterator: the iterator of a constant table.

Definition at line 508 of file tpl_dynSetHash.H.

◆ Hash_Fct

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
using Aleph::DynHashTable< Key, HashTable, Cmp >::Hash_Fct = typename Base::Hash_Fct

Hash function type.

Definition at line 96 of file tpl_dynSetHash.H.

◆ Hash_Fct_Ptr

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
using Aleph::DynHashTable< Key, HashTable, Cmp >::Hash_Fct_Ptr = typename Base::Hash_Fct_Ptr

Definition at line 98 of file tpl_dynSetHash.H.

◆ Item_Type

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
using Aleph::DynHashTable< Key, HashTable, Cmp >::Item_Type = Key

Definition at line 102 of file tpl_dynSetHash.H.

◆ Key_Type

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
using Aleph::DynHashTable< Key, HashTable, Cmp >::Key_Type = Key

Definition at line 100 of file tpl_dynSetHash.H.

Constructor & Destructor Documentation

◆ DynHashTable() [1/8]

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
Aleph::DynHashTable< Key, HashTable, Cmp >::DynHashTable ( 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 = hash_default_upper_alpha 
)
inline

Creates a dynamic linear hash table.

Parameters
[in]hash_fctHash function.
cmpKey comparison functor.
[in]lenInitial and minimum table size. The table will never shrink below this value.
[in]lower_alphaLower load threshold; the table shrinks when the load factor goes below this value.
[in]upper_alphaUpper load threshold; the table grows when the load factor goes above this value.

Definition at line 115 of file tpl_dynSetHash.H.

◆ DynHashTable() [2/8]

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
Aleph::DynHashTable< Key, HashTable, Cmp >::DynHashTable ( size_t  len,
Hash_Fct  hash_fct,
Cmp  cmp,
float  lower_alpha,
float  upper_alpha 
)
inline

Definition at line 125 of file tpl_dynSetHash.H.

◆ DynHashTable() [3/8]

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
Aleph::DynHashTable< Key, HashTable, Cmp >::DynHashTable ( const DynHashTable< Key, HashTable, Cmp > &  other)
inline

Copy constructor.

Creates a copy with the same table size as the original. This preserves the performance characteristics and avoids the overhead of recalculating an optimal size.

Note
The copy will have the same table size (len) as the original, even if the original has been expanded and then shrunk through deletions. This may temporarily use more memory than strictly necessary, but the dynamic resizing will adjust the size automatically as elements are added or removed. The copy resizes itself if the original does (see set_with_resize()).
The const_cast on get_compare() is necessary because the base class's get_compare() method is not marked const. This is a limitation of the base HashTable class.
The copy of a table that a move left without lists has those of the default capacity.

Definition at line 162 of file tpl_dynSetHash.H.

References Aleph::DynHashTable< Key, HashTable, Cmp >::copy().

◆ DynHashTable() [4/8]

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
Aleph::DynHashTable< Key, HashTable, Cmp >::DynHashTable ( DynHashTable< Key, HashTable, Cmp > &&  other)
inlinenoexcept

Move constructor over a table that a move of its own takes, as the one of chained lists (DynSetLhash): takes the lists and the keys of other.

Parameters
[in,out]otherThe table to move from. It is left empty and without lists, with capacity zero, and it keeps its hash function, its comparator, its load thresholds and its resizing policy. It is still usable: the first insertion gives it the lists of the default capacity.
Note
It allocates nothing: other is not given the lists of a table of its capacity, which could not be allocated without memory.

Definition at line 184 of file tpl_dynSetHash.H.

◆ DynHashTable() [5/8]

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
Aleph::DynHashTable< Key, HashTable, Cmp >::DynHashTable ( DynHashTable< Key, HashTable, Cmp > &&  other)
inlinenoexcept

Move constructor over a table that no move of its own takes, as the linear one (DynSetLinHash): builds an empty table of the capacity of other and swaps them.

Parameters
[in,out]otherThe table to move from. It is left empty, with its capacity, its hash function, its comparator and its load thresholds, and it resizes itself.
Note
On the linear table of the library (LinearHashTable), the table that is built allocates nothing and builds no key: its array makes its directory when it first writes, and the header of a list holds no key. The hash function and the comparator are copied, so that other keeps its own. A hash function that does not fit in the buffer of a std::function is copied in the heap, and the copy of a comparator may allocate or throw too, in this constructor that is noexcept: what they throw ends the program.

Definition at line 207 of file tpl_dynSetHash.H.

References Aleph::swap().

◆ DynHashTable() [6/8]

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
template<template< typename > class List>
Aleph::DynHashTable< Key, HashTable, Cmp >::DynHashTable ( const List< Key > &  l)
inline

Definition at line 215 of file tpl_dynSetHash.H.

◆ DynHashTable() [7/8]

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
template<class It >
requires (not std::is_arithmetic_v<It> and requires (It it) { *it; ++it; it != it; })
Aleph::DynHashTable< Key, HashTable, Cmp >::DynHashTable ( It  b,
It  e 
)
inline

Definition at line 215 of file tpl_dynSetHash.H.

◆ DynHashTable() [8/8]

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
Aleph::DynHashTable< Key, HashTable, Cmp >::DynHashTable ( std::initializer_list< Key >  l)
inline

Definition at line 215 of file tpl_dynSetHash.H.

◆ ~DynHashTable()

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
Aleph::DynHashTable< Key, HashTable, Cmp >::~DynHashTable ( )
inline

Definition at line 217 of file tpl_dynSetHash.H.

Member Function Documentation

◆ add() [1/2]

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
Key * Aleph::DynHashTable< Key, HashTable, Cmp >::add ( const Key &  key)
inline

Definition at line 361 of file tpl_dynSetHash.H.

References Aleph::DynHashTable< Key, HashTable, Cmp >::insert_bucket().

Referenced by TEST().

◆ add() [2/2]

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
Key * Aleph::DynHashTable< Key, HashTable, Cmp >::add ( Key &&  key)
inline

◆ append() [1/2]

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
Key * Aleph::DynHashTable< Key, HashTable, Cmp >::append ( const Key &  key)
inline

Definition at line 371 of file tpl_dynSetHash.H.

References Aleph::DynHashTable< Key, HashTable, Cmp >::insert_bucket().

Referenced by TEST().

◆ append() [2/2]

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
Key * Aleph::DynHashTable< Key, HashTable, Cmp >::append ( Key &&  key)
inline

◆ clear()

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
void Aleph::DynHashTable< Key, HashTable, Cmp >::clear ( )
inline

Empties the container.

Exceptions
none
See also
empty()

Definition at line 227 of file tpl_dynSetHash.H.

Referenced by TEST(), and TEST().

◆ contains()

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
bool Aleph::DynHashTable< Key, HashTable, Cmp >::contains ( const Key &  key) const
inlinenoexcept

Return true if the key exists in the table.

Checks if a key exists in the table.

Parameters
[in]keykey to search for.
Returns
true if key is present, false otherwise.
Exceptions
none

Definition at line 236 of file tpl_dynSetHash.H.

Referenced by demo_dynset_lhash(), demo_dynset_linhash(), demo_performance(), Aleph::intercept(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST_F(), TEST_F(), and TEST_F().

◆ contains_or_insert() [1/2]

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
std::pair< Key *, bool > Aleph::DynHashTable< Key, HashTable, Cmp >::contains_or_insert ( const Key &  key)
inline

◆ contains_or_insert() [2/2]

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
std::pair< Key *, bool > Aleph::DynHashTable< Key, HashTable, Cmp >::contains_or_insert ( Key &&  key)
inline

◆ copy()

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
void Aleph::DynHashTable< Key, HashTable, Cmp >::copy ( const DynHashTable< Key, HashTable, Cmp > &  other)
inlineprivate

◆ find() [1/2]

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
Key & Aleph::DynHashTable< Key, HashTable, Cmp >::find ( const Key &  key)
inline

Definition at line 420 of file tpl_dynSetHash.H.

References ah_domain_error_if.

◆ find() [2/2]

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
const Key & Aleph::DynHashTable< Key, HashTable, Cmp >::find ( const Key &  key) const
inline

Definition at line 412 of file tpl_dynSetHash.H.

References ah_domain_error_if.

Referenced by TEST(), and TEST().

◆ get_first() [1/2]

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
Key & Aleph::DynHashTable< Key, HashTable, Cmp >::get_first ( )
inline

Definition at line 515 of file tpl_dynSetHash.H.

References LocateFunctions< Container, Type >::get_it().

◆ get_first() [2/2]

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
const Key & Aleph::DynHashTable< Key, HashTable, Cmp >::get_first ( ) const
inline

Definition at line 510 of file tpl_dynSetHash.H.

References LocateFunctions< Container, Type >::get_it().

Referenced by TEST().

◆ get_last() [1/2]

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
Key & Aleph::DynHashTable< Key, HashTable, Cmp >::get_last ( )
inline

Definition at line 527 of file tpl_dynSetHash.H.

References LocateFunctions< Container, Type >::get_it().

◆ get_last() [2/2]

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
const Key & Aleph::DynHashTable< Key, HashTable, Cmp >::get_last ( ) const
inline

Definition at line 520 of file tpl_dynSetHash.H.

References LocateFunctions< Container, Type >::get_it().

Referenced by TEST().

◆ has()

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
bool Aleph::DynHashTable< Key, HashTable, Cmp >::has ( const Key &  key) const
inlinenoexcept

Checks if a key exists in the hash table.

Parameters
[in]keythe key to check
Returns
true if the key exists, false otherwise

Definition at line 407 of file tpl_dynSetHash.H.

Referenced by brute_path_distinct(), TEST(), TEST(), and TEST().

◆ insert() [1/2]

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
Key * Aleph::DynHashTable< Key, HashTable, Cmp >::insert ( const Key &  key)
inline

◆ insert() [2/2]

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
Key * Aleph::DynHashTable< Key, HashTable, Cmp >::insert ( Key &&  key)
inline

◆ insert_bucket()

◆ is_empty()

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
bool Aleph::DynHashTable< Key, HashTable, Cmp >::is_empty ( ) const
inlinenoexcept

Checks if the container is empty.

Returns
true if empty, false otherwise.
Exceptions
none

Definition at line 243 of file tpl_dynSetHash.H.

Referenced by TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST_F().

◆ key_to_bucket()

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
static Bucket * Aleph::DynHashTable< Key, HashTable, Cmp >::key_to_bucket ( Key *  key)
inlinestaticprotected

◆ operator=() [1/2]

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
DynHashTable & Aleph::DynHashTable< Key, HashTable, Cmp >::operator= ( const DynHashTable< Key, HashTable, Cmp > &  other)
inline

Copy assignment.

Leaves this table as a copy of other: the same keys, hash function, comparator and load thresholds.

Parameters
[in]otherTable to copy.
Returns
A reference to this table.
Exceptions
std::bad_allocIf there is no memory for the copy. This table is left as it was.

Definition at line 255 of file tpl_dynSetHash.H.

References Aleph::swap().

Referenced by Aleph::DynMapHashTable< Key, Data, HashTable, Cmp >::operator=().

◆ operator=() [2/2]

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
DynHashTable & Aleph::DynHashTable< Key, HashTable, Cmp >::operator= ( DynHashTable< Key, HashTable, Cmp > &&  other)
inlinenoexcept

Definition at line 266 of file tpl_dynSetHash.H.

References Aleph::swap().

◆ remove() [1/2]

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
Key Aleph::DynHashTable< Key, HashTable, Cmp >::remove ( const Key &  key)
inline

Definition at line 457 of file tpl_dynSetHash.H.

References ah_domain_error_if.

◆ remove() [2/2]

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
void Aleph::DynHashTable< Key, HashTable, Cmp >::remove ( Key *  key)
inline

Removes a key from the hash table using its pointer.

Warning
The key pointer MUST be obtained from a previous call to insert() or search(). Passing any other pointer will result in undefined behavior and likely cause a segmentation fault.

This method uses pointer arithmetic to recover the bucket containing the key, which only works if the pointer truly points to a key stored inside the hash table.

Parameters
[in]keypointer to the key to remove (must come from insert/search)
See also
remove(const Key &) for a safer alternative that searches by value

Definition at line 450 of file tpl_dynSetHash.H.

References Aleph::DynHashTable< Key, HashTable, Cmp >::key_to_bucket().

Referenced by demo_dynset_lhash(), Aleph::DynMapHashTable< Key, Data, HashTable, Cmp >::remove(), Aleph::DynMapHashTable< Key, Data, HashTable, Cmp >::remove_by_data(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST_F().

◆ search() [1/2]

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
const Key * Aleph::DynHashTable< Key, HashTable, Cmp >::search ( const Key &  key) const
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. A pointer to const.

Definition at line 396 of file tpl_dynSetHash.H.

◆ search() [2/2]

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
Key * Aleph::DynHashTable< Key, HashTable, Cmp >::search ( const Key &  key)
inlinenoexcept

Searches for a key in the hash table.

Parameters
[in]keythe key to search for
Returns
pointer to the key if found, nullptr otherwise
Note
This method is noexcept if the hash function and comparison function do not throw exceptions.

Definition at line 388 of file tpl_dynSetHash.H.

Referenced by Aleph::DynMapHashTable< Key, Data, HashTable, Cmp >::search_by_pair(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ search_or_insert() [1/2]

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
Key * Aleph::DynHashTable< Key, HashTable, Cmp >::search_or_insert ( const Key &  key)
inline

◆ search_or_insert() [2/2]

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
Key * Aleph::DynHashTable< Key, HashTable, Cmp >::search_or_insert ( Key &&  key)
inline

◆ search_or_insert_bucket()

template<typename Key , template< typename, class > class HashTable = LhashTable, class Cmp = Aleph::equal_to<Key>>
std::pair< Key *, bool > Aleph::DynHashTable< Key, HashTable, Cmp >::search_or_insert_bucket ( Bucket *  bucket)
inlineprotected

The documentation for this class was generated from the following file: