124#ifndef __ADS_DenseHashMap
125 #define __ADS_DenseHashMap
148#include <type_traits>
167template<
class K ,
class V ,
class H = DefaultHash< K > ,
168 class Eq = std::equal_to< K > ,
169 class A = std::allocator< std::pair< const K , V > > ,
170 class Policy = NoObservers >
196 template<
class... O >
198 const A & alloc = A() , O &... o );
216 requires detail::alwaysEqualAlloc< A >;
220 requires( ! detail::alwaysEqualAlloc< A > && Subject::none )
222 return( detail::copyAssign( *
this , o ) );
228 requires( ! detail::alwaysEqualAlloc< A > && Subject::none )
230 return( detail::moveAssign( *
this , std::move( o ) ) );
259 [[nodiscard]] std::optional< V >
lookup(
const K & k )
const;
262 [[nodiscard]]
const V *
find(
const K & k )
const;
266 [[nodiscard]] V *
find(
const K & k );
289 bool insert(
const K & k ,
const V & v );
300 template<
class... Args >
301 std::pair< V * , bool >
try_emplace(
const K & k , Args &&... a );
304 template<
class... Args >
333 [[nodiscard]] std::size_t
size(
void )
const;
336 [[nodiscard]]
bool empty(
void )
const;
343 [[nodiscard]]
double load(
void )
const;
348 [[nodiscard]] std::size_t
deleted(
void )
const;
361 [[nodiscard]]
const std::pair< K , V > *
data(
void )
const;
379 requires( Subject::dynamic )
381 return( f_sub.attach( o ) );
387 requires( Subject::dynamic )
431 static constexpr std::uint8_t EMPTY = 0;
432 static constexpr std::size_t SLOTS = 12;
433 static constexpr std::size_t OVER = 15;
434 static constexpr std::uint32_t PLACES = 0xFFF;
438 struct alignas( 64 )
Group
440 std::uint8_t c[ 16 ];
441 std::uint32_t at[ SLOTS ];
446 using Mask = std::uint32_t;
450 static constexpr bool AVALANCHING = detail::kAvalanching64< H , K >;
454 inline static Group s_none[ 2 ] = {};
457 [[nodiscard]] std::uint64_t mix(
const K & k )
const;
460 [[nodiscard]]
static std::uint8_t bit( std::uint64_t x );
463 [[nodiscard]] std::size_t home( std::uint64_t x )
const;
467 [[nodiscard]]
static Mask match(
const Group & c , std::uint32_t t );
470 [[nodiscard]]
static Mask empties(
const Group & c );
474 static void vacate( Group & c , std::size_t j );
478 [[nodiscard]] std::size_t locate( std::uint64_t x ,
const K & k )
const;
481 using KeyArg = std::conditional_t< std::is_trivially_copyable_v< K > &&
482 (
sizeof( K ) <= 2 *
sizeof(
void * ) ) ,
489 further( std::uint64_t x , std::size_t g , KeyArg k )
const;
494 std::size_t claim( std::uint64_t x );
498 std::uint32_t & holder( std::uint64_t x , std::size_t p );
501 template<
class KK ,
class VV >
502 bool put( KK && k , VV && v );
508 template<
bool Assign ,
class KK ,
class... Args >
509 std::pair< V * , bool > place( KK && k , Args &&... a );
512 bool removePlain(
const K & k );
516 template<
class KK ,
class VV >
517 bool putTold( KK && k , VV && v );
518 template<
class KK ,
class... Args >
519 std::pair< V * , bool > emplaceTold( KK && k ,
521 bool removeTold(
const K & k );
524 template<
class KK ,
class VV >
526 return( putTold( std::forward< KK >( k ) , std::forward< VV >( v ) ) );
528 template<
class KK ,
class... Args >
529 ADS_COLD_PATH std::pair< V * , bool > emplaceCold( KK && k , Args &&... a ) {
531 emplaceTold( std::forward< KK >( k ) , std::forward< Args >( a )... ) );
533 ADS_COLD_PATH bool removeCold(
const K & k ) {
return( removeTold( k ) ); }
536 void tellCleared(
void )
noexcept;
537 void tellRebuilt(
void )
noexcept;
541 void unlink( Group & g , std::size_t j , std::size_t p );
546 void rebuild( std::size_t G );
552 [[nodiscard]]
static std::size_t groups( std::size_t n );
556 [[nodiscard]]
static constexpr std::size_t bound( std::size_t m );
561 [[nodiscard]]
bool consistent( std::uint64_t x )
const;
567 void operator()( Group * g )
const noexcept;
571 static constexpr bool STD = detail::isStdAllocator< A >;
574 using Pairs = detail::AllocVector< A , std::pair< K , V > >;
577 using Groups = std::conditional_t< STD , std::unique_ptr< Group[] , Free > ,
578 detail::AllocVector< A , Group > >;
581 [[nodiscard]]
static Groups noGroups(
const Pairs & kv ) {
585 return( Groups( kv.get_allocator() ) );
590 [[nodiscard]]
static Groups newGroups( std::size_t G ,
const Pairs & kv ) {
592 return( Groups(
static_cast< Group *
>( ::operator
new(
593 G *
sizeof( Group ) , std::align_val_t(
alignof( Group ) ) ) ) ) );
595 Groups g( kv.get_allocator() );
602 [[nodiscard]]
static Group * first( Groups & g ) {
613 Groups f_g = noGroups( f_kv );
614 Group * f_ctrl = s_none;
615 std::size_t f_mask = 0;
616 std::size_t f_cap = 0;
618 std::size_t f_max = 0;
619 std::size_t f_deleted = 0;
636#include "ADS/dictionary/impl/DenseHashMap.tpp"
The name of the configuration of the layouts, an inline namespace: the headers whose classes change t...
The rules of the allocator-aware containers of the standard ([container.reqmts], [allocator....
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The engineered hash functions of ADS, beyond the book [see HashFunctions.h for those of section 7....
A hash table with open addressing and control bytes, beyond the book: the engineered DICTIONARY of AD...
The typed modifications, beyond the book: the vocabulary by which a structure tells the observers att...
const_iterator begin(void) const
the iterator on the first item
Definition DenseHashMap.h:421
void clear(void)
removes all the pairs, keeping the places
DenseHashMap(const DenseHashMap &o)
a copy of other, on the allocator that select_on_container_copy_construction() gives
K Key
the type of the keys
Definition DenseHashMap.h:176
DenseHashMap(const DenseHashMap &o, const A &alloc)
a copy of other, on alloc
mod::Assigned< K, V > Assigned
a change of the value of a key
Definition DenseHashMap.h:184
void swap(DenseHashMap &o) noexcept(detail::swapNoexcept< A >)
exchanges the contents with other in , and the allocators if they propagate on a swap
std::optional< V > lookup(const K &k) const
the value of the key , or nothing
void detach(int id)
detaches the observer number
Definition DenseHashMap.h:386
std::pair< V *, bool > try_emplace(const K &k, Args &&... a)
the value of the key , built from a if was not there, and true in that case; a key already there kee...
bool remove(const K &k)
removes the key , if it is there, moving the last pair into its position; true if it was
DenseHashMap(DenseHashMap &&o) noexcept
the pairs of o, which is left empty, with no places
~DenseHashMap()=default
frees the pairs and the groups
const Subject & subject(void) const
the subject
Definition DenseHashMap.h:373
DenseHashMap(std::size_t n=0, H h=H(), Eq eq=Eq(), const A &alloc=A(), O &... o)
the empty map, with room for pairs before it grows, its pairs and groups from alloc,...
V * find(const K &k)
the value of the key , to change in place, nil if it is not there
V Value
the type of the values
Definition DenseHashMap.h:177
bool contains(const K &k) const
true if the key is there
const V * find(const K &k) const
the value of the key , nil if it is not there
void reserve(std::size_t n)
room for pairs before the map grows
mod::Erased< K, K, V > Erased
an erasure of a key, told before the removal
Definition DenseHashMap.h:182
DenseHashMap & operator=(DenseHashMap &&o)
the move assignment: the memory of o if its allocator propagates or is equal, else its pairs moved on...
Definition DenseHashMap.h:227
mod::list< Inserted, Erased, Assigned, mod::Cleared, mod::Rebuilt > modifications
the events: a key inserted or erased with its value, its value changed, the map emptied or rebuilt
Definition DenseHashMap.h:188
std::size_t capacity(void) const
the number of places of the index, 12 times 0 or a power of 2 at least 2
const_iterator cend(void) const
the constant iterator past the last item
Definition DenseHashMap.h:427
std::pair< K, V > value_type
the type of the items, for the standard library
Definition DenseHashMap.h:398
std::size_t size_type
the type of the sizes
Definition DenseHashMap.h:400
typename Policy::template bind< modifications, DenseHashMap > Subject
the subject
Definition DenseHashMap.h:191
bool insert(K &&k, V &&v)
as insert( k , v ), moving the key and the value
const std::pair< K, V > & const_reference
a constant reference to an item
Definition DenseHashMap.h:406
const std::pair< K, V > & reference
a reference to an item
Definition DenseHashMap.h:404
void forEach(F &&f) const
f( k , v ) on the pairs, in the order of the vector
double load(void) const
the load factor of the index, 0 with no places
const_iterator iterator
the iterator on the items
Definition DenseHashMap.h:411
std::pair< V *, bool > try_emplace(K &&k, Args &&... a)
as try_emplace( k , a ), moving the key
DenseHashMap & operator=(DenseHashMap o) noexcept
the assignment, by copy and swap, when the allocators are all equal
std::ptrdiff_t difference_type
the type of the distances between two iterators
Definition DenseHashMap.h:402
DenseHashMap(DenseHashMap &&o, const A &alloc)
the pairs of o, which is left empty, on alloc: moved one by one if the allocators are not equal
std::size_t size(void) const
the number of pairs
bool empty(void) const
true if there are no pairs
mod::Inserted< K, K, V > Inserted
an insertion of a key, the key its handle
Definition DenseHashMap.h:180
int attach(O &o)
attaches the observer and gives its number
Definition DenseHashMap.h:378
std::size_t deleted(void) const
the places of the index emptied by remove() in groups that some inspection went past,...
Subject & subject(void)
the subject, for ADS::batch() and ADS::quiet()
Definition DenseHashMap.h:371
typename detail::AllocVector< A, std::pair< K, V > >::const_iterator const_iterator
the iterator on the items, constant
Definition DenseHashMap.h:408
bool insert(const K &k, const V &v)
associates the value to the key ; true if was not there
const std::pair< K, V > * data(void) const
the pairs, in the order of the vector
const_iterator cbegin(void) const
the constant iterator on the first item
Definition DenseHashMap.h:425
DenseHashMap & operator=(const DenseHashMap &o)
the copy assignment, with the allocator of o if it propagates
Definition DenseHashMap.h:219
A allocator_type
the type of the allocator
Definition DenseHashMap.h:414
const_iterator end(void) const
the iterator past the last item
Definition DenseHashMap.h:423
allocator_type get_allocator(void) const
the allocator of the pairs and of the groups
Definition DenseHashMap.h:416
a monoid with the inverse G::inverse( a ), i.e., combine( inverse( a) , a ) and combine( a ,...
Definition Algebra.h:130
#define ADS_ABI_BEGIN
opens the inline namespace of the configuration
Definition Abi.h:106
#define ADS_ABI_END
closes the inline namespace of the configuration
Definition Abi.h:111
Changed< Value, H, V > Assigned
the value of an item changed
Definition Modification.h:623
#define ADS_COLD_PATH
a function of a rare path: never inlined, laid out away from the hot code
Definition Portable.h:107
#define ADS_NO_UNIQUE_ADDRESS
an empty member that takes no storage, by the attribute that does so (the standard one is accepted bu...
Definition Portable.h:81
#define ADS_FLAT_NOINLINE
a function never inlined, the rare path out of a loop
Definition FlatHashTable.h:214
the item of handle , key and value erased, told before the removal outside a batch
Definition Modification.h:568
the item of handle , key and value inserted
Definition Modification.h:536
a list of types, the events of a structure [see Modification.h]
Definition Modification.h:482