305 [[nodiscard]] std::optional< V >
find(
const K & k )
const;
388 bool insert(
const K & k ,
const V & v );
439 [[nodiscard]] std::size_t
size(
void )
const;
442 [[nodiscard]]
bool empty(
void )
const;
451 [[nodiscard]] std::size_t
stashed(
void )
const;
476 static constexpr std::size_t refAlign(
void ) {
477 if constexpr( std::is_trivially_copyable_v< T > )
478 return( std::atomic_ref< T >::required_alignment );
480 return(
alignof( T ) );
485 static constexpr bool refLockFree(
void ) {
486 if constexpr( std::is_trivially_copyable_v< T > )
487 return( std::atomic_ref< T >::is_always_lock_free );
496 static constexpr bool optimistic = refLockFree< K >() && refLockFree< V >();
503 alignas( refAlign< K >() ) K key{};
505 alignas( refAlign< V >() ) V value{};
508 static constexpr std::size_t line = 64;
512 struct alignas( ( 4 * sizeof( Slot ) <= line ) &&
514 std::has_single_bit( 4 * sizeof( Slot ) )
518 : alignof( Slot ) ) Bucket
523 static constexpr std::size_t kStripes = 2048;
524 static constexpr int kLgStripes = 11;
525 static constexpr int kLgRegion = 8;
527 static constexpr int kDepth = 5;
528 static constexpr int kNodes = 1024;
529 static constexpr int kOverflow = 4;
533 struct alignas( line ) Stripe
536 std::atomic< std::uint64_t > version{ 0 };
538 std::atomic< std::int64_t > count{ 0 };
554 explicit Table(
int l ,
bool init =
true );
560 [[nodiscard]] std::size_t overflowWords(
void )
const {
561 return( ( ( buckets() * kOverflow ) + 63 ) >> 6 );
566 [[nodiscard]] Slot & S( std::size_t i )
const {
567 return( B[ i >> 2 ].s[ i & 3 ] );
570 [[nodiscard]] std::size_t buckets(
void )
const {
571 return( std::size_t( 1 ) << lg );
580 explicit Hold( Stripe & s ) : f_s( s ) { }
582 Hold(
const Hold & ) =
delete;
584 Hold & operator=(
const Hold & ) =
delete;
586 ~Hold() { unlock( f_s ); }
600 HoldAll(
const HoldAll & ) =
delete;
602 HoldAll & operator=(
const HoldAll & ) =
delete;
606 void extend(
int lg );
608 [[nodiscard]] std::size_t held(
void )
const {
return( f_n ); }
623 int parent , from , depth;
628 static void lock( Stripe & s );
629 static void unlock( Stripe & s );
632 void lockHelping( Stripe & s )
const;
636 bool claim( std::size_t & c )
const;
639 void help(
void )
const;
644 void migrate( std::size_t c )
const;
647 [[nodiscard]]
static int regionLg(
int lg );
650 [[nodiscard]] std::uint64_t hash(
const K & k )
const;
653 [[nodiscard]]
static std::uint32_t tag( std::uint64_t h );
656 [[nodiscard]]
static std::size_t first( std::uint64_t h ,
int lg );
660 [[nodiscard]]
static std::size_t other( std::size_t b , std::uint32_t t ,
664 [[nodiscard]]
static std::uint32_t tags(
const Table & T , std::size_t b );
667 static void setTags( Table & T , std::size_t b , std::uint32_t w );
670 [[nodiscard]]
static std::size_t overflowBit( std::size_t b ,
675 [[nodiscard]]
static bool overflowed(
const Table & T , std::size_t b ,
679 static void markOverflow( Table & T , std::size_t b , std::uint32_t t );
682 [[nodiscard]] Table * lockRegion( std::uint64_t h )
const;
685 [[nodiscard]] Table * waitRegion( std::uint64_t h )
const;
689 [[nodiscard]] std::size_t locate(
const Table & T ,
const K & k ,
690 std::uint32_t t , std::size_t b1 ,
691 std::size_t b2 ,
bool bit =
true )
const;
694 static void fetch(
const Table & T , std::size_t b );
699 int peek(
const K & k , std::uint64_t h , V * out )
const;
703 bool lockedFind(
const K & k , std::uint64_t h , V * out )
const;
706 [[nodiscard]]
static int freePlace(
const Table & T , std::size_t b );
709 template<
class KK ,
class VV >
710 static void put( Table & T , std::size_t b ,
int i , std::uint32_t t ,
715 static void assign( Table & T , std::size_t i ,
const V & v );
718 static void clearPlace( Table & T , std::size_t i );
722 static void move( Table & T , std::size_t a ,
int i , std::size_t d ,
int j );
727 [[nodiscard]]
int search(
const Table & T , std::uint64_t h ,
732 std::size_t makeRoom( Table & T , std::uint64_t h )
const;
737 std::size_t room( Table & T , std::uint64_t h , std::int64_t n )
const;
742 bool placeInto( Table & N , std::uint64_t h , Slot && x )
const;
746 bool add(
const K & k ,
const V & v ,
bool assign );
750 void rehash(
int lg , HoldAll & g );
756 int grow(
int lg , std::uint64_t h ,
const K & k ,
const V & v ,
760 bool fromStash(
const K & k , V * out )
const;
765 bool inStash(
const K & k , F && f );
769 void stashPut( Table & T , std::uint64_t h , Slot && x );
772 [[nodiscard]]
bool inBucket(
const Table & T , std::size_t b )
const;
774 std::unique_ptr< Stripe[] > f_L;
775 std::atomic< int > f_lg{ 1 };
776 std::atomic< Table * > f_table{
nullptr };
777 std::vector< std::unique_ptr< Table > > f_old;
779 std::unique_ptr< Table > f_cur;
780 std::atomic< std::size_t > f_rehashes{ 0 };
784 mutable std::atomic< std::uint64_t > f_claim{ 0 };
785 mutable std::atomic< std::size_t > f_done{ 0 };
786 mutable std::atomic< Table * > f_from{
nullptr };
787 mutable std::atomic< Table * > f_to{
nullptr };
788 mutable std::atomic< std::int64_t * > f_count{
nullptr };
790 mutable std::atomic< std::size_t > f_part{ 0 };
792 mutable std::vector< Slot > f_left;
794 mutable std::atomic< bool > f_leftLock{
false };
795 mutable std::mutex f_xm;
796 std::vector< Slot > f_X;
797 std::atomic< std::size_t > f_xn{ 0 };
An allocator for the large blocks of a structure, beyond the book: a request of at least one huge pag...