bricks: update
* bricks/brick-hashset: here.
This commit is contained in:
parent
8ced74f8e6
commit
1a37a08ba4
1 changed files with 21 additions and 13 deletions
|
|
@ -43,7 +43,8 @@ using hash::hash128_t;
|
||||||
|
|
||||||
struct DefaultHasher
|
struct DefaultHasher
|
||||||
{
|
{
|
||||||
auto hash( int64_t v ) const -> std::pair<int64_t, int64_t>
|
// auto hash( int64_t v ) const -> std::pair<int64_t, int64_t>
|
||||||
|
auto hash( int64_t v ) const
|
||||||
{
|
{
|
||||||
return std::make_pair( v, ~v );
|
return std::make_pair( v, ~v );
|
||||||
}
|
}
|
||||||
|
|
@ -85,7 +86,7 @@ struct FastCell : CellBase< T, Hasher >
|
||||||
hash64_t _hash;
|
hash64_t _hash;
|
||||||
|
|
||||||
template< typename Value >
|
template< typename Value >
|
||||||
bool is( Value v, hash64_t hash, Hasher &h ) {
|
bool is( const Value &v, hash64_t hash, Hasher &h ) {
|
||||||
return _hash == hash && h.equal( _value, v );
|
return _hash == hash && h.equal( _value, v );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -106,7 +107,7 @@ struct CompactCell : CellBase< T, Hasher >
|
||||||
T _value;
|
T _value;
|
||||||
|
|
||||||
template< typename Value >
|
template< typename Value >
|
||||||
bool is( Value v, hash64_t, Hasher &h ) {
|
bool is( const Value &v, hash64_t, Hasher &h ) {
|
||||||
return h.equal( _value, v );
|
return h.equal( _value, v );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -165,7 +166,7 @@ struct FastAtomicCell : CellBase< T, Hasher >
|
||||||
}
|
}
|
||||||
|
|
||||||
template< typename Value >
|
template< typename Value >
|
||||||
bool is( Value v, hash64_t hash, Hasher &h ) {
|
bool is( const Value &v, hash64_t hash, Hasher &h ) {
|
||||||
hash |= 0x1;
|
hash |= 0x1;
|
||||||
if ( ( (hash << 2) | 1) != (_hashlock | 1) )
|
if ( ( (hash << 2) | 1) != (_hashlock | 1) )
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -248,7 +249,7 @@ struct AtomicCell : CellBase< T, Hasher >
|
||||||
}
|
}
|
||||||
|
|
||||||
template< typename Value >
|
template< typename Value >
|
||||||
bool is( Value v, hash64_t hash, Hasher &h ) {
|
bool is( const Value &v, hash64_t hash, Hasher &h ) {
|
||||||
return value.load().tag() == ( highbits( hash, Tagged< T >::tag_bits ) | 1 ) &&
|
return value.load().tag() == ( highbits( hash, Tagged< T >::tag_bits ) | 1 ) &&
|
||||||
h.equal( value.load().t, v );
|
h.equal( value.load().t, v );
|
||||||
}
|
}
|
||||||
|
|
@ -606,7 +607,7 @@ struct _ConcurrentHashSet : HashSetBase< Cell >
|
||||||
}
|
}
|
||||||
|
|
||||||
template< typename T >
|
template< typename T >
|
||||||
iterator find( T x ) {
|
iterator find( const T &x ) {
|
||||||
return findHinted( x, hasher.hash( x ).first );
|
return findHinted( x, hasher.hash( x ).first );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -641,7 +642,7 @@ struct _ConcurrentHashSet : HashSetBase< Cell >
|
||||||
}
|
}
|
||||||
|
|
||||||
template< typename T >
|
template< typename T >
|
||||||
iterator findHinted( T x, hash64_t h ) {
|
iterator findHinted( const T &x, hash64_t h ) {
|
||||||
while ( true ) {
|
while ( true ) {
|
||||||
Find fr = findCell( x, h, _l.currentRow );
|
Find fr = findCell( x, h, _l.currentRow );
|
||||||
switch ( fr.r ) {
|
switch ( fr.r ) {
|
||||||
|
|
@ -661,7 +662,7 @@ struct _ConcurrentHashSet : HashSetBase< Cell >
|
||||||
}
|
}
|
||||||
|
|
||||||
template< typename T >
|
template< typename T >
|
||||||
Find findCell( T v, hash64_t h, unsigned rowIndex )
|
Find findCell( const T &v, hash64_t h, unsigned rowIndex )
|
||||||
{
|
{
|
||||||
if ( changed( rowIndex ) )
|
if ( changed( rowIndex ) )
|
||||||
return Find( Resolution::Growing );
|
return Find( Resolution::Growing );
|
||||||
|
|
@ -848,13 +849,20 @@ struct _ConcurrentHashSet : HashSetBase< Cell >
|
||||||
} while( true );
|
} while( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
void increaseUsage() {
|
void increaseUsage()
|
||||||
if ( ++_l.inserts == syncPoint ) {
|
{
|
||||||
_s->used.fetch_add( syncPoint, std::memory_order_relaxed );
|
if ( ++_l.inserts == syncPoint )
|
||||||
_l.inserts = 0;
|
updateUsage();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateUsage()
|
||||||
|
{
|
||||||
|
_s->used.fetch_add( _l.inserts, std::memory_order_relaxed );
|
||||||
|
_l.inserts = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
~_ConcurrentHashSet() { updateUsage(); }
|
||||||
|
|
||||||
explicit _ConcurrentHashSet( Hasher h = Hasher(), unsigned maxGrows = 64 )
|
explicit _ConcurrentHashSet( Hasher h = Hasher(), unsigned maxGrows = 64 )
|
||||||
: Base( h ), _s( new Shared( maxGrows ) )
|
: Base( h ), _s( new Shared( maxGrows ) )
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue