diff options
author | Eliot Horowitz <eliot@10gen.com> | 2012-12-10 15:15:21 -0500 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2012-12-10 15:15:21 -0500 |
commit | f52ad32e62cfa750e386c257abddf33eaca7ec8b (patch) | |
tree | ad4f5f023fde7f5af7c2b09f1bddc966fe6c9011 /src/mongo/util/unordered_fast_key_table_internal.h | |
parent | 8bc1aa3f748264648af4d53f263ada813a581434 (diff) | |
download | mongo-f52ad32e62cfa750e386c257abddf33eaca7ec8b.tar.gz |
SERVER-7886 - StringMap is now based on StringData
- UnorderedFastKeyTable more methods to match std::map
Diffstat (limited to 'src/mongo/util/unordered_fast_key_table_internal.h')
-rw-r--r-- | src/mongo/util/unordered_fast_key_table_internal.h | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/mongo/util/unordered_fast_key_table_internal.h b/src/mongo/util/unordered_fast_key_table_internal.h index 7cfc0b4b6e4..34a8beb1c2d 100644 --- a/src/mongo/util/unordered_fast_key_table_internal.h +++ b/src/mongo/util/unordered_fast_key_table_internal.h @@ -26,6 +26,16 @@ namespace mongo { } template< typename K_L, typename K_S, typename V, typename H, typename E, typename C, typename C_LS > + inline UnorderedFastKeyTable<K_L, K_S, V, H, E, C, C_LS>::Area::Area(const Area& other ) + : _capacity( other._capacity ), + _maxProbe( other._maxProbe ), + _entries( new Entry[_capacity] ) { + for ( unsigned i = 0; i < _capacity; i++ ) { + _entries[i] = other._entries[i]; + } + } + + template< typename K_L, typename K_S, typename V, typename H, typename E, typename C, typename C_LS > inline int UnorderedFastKeyTable<K_L, K_S, V, H, E, C, C_LS>::Area::find( const K_L& key, size_t hash, @@ -94,6 +104,26 @@ namespace mongo { } template< typename K_L, typename K_S, typename V, typename H, typename E, typename C, typename C_LS > + inline UnorderedFastKeyTable<K_L, K_S, V, H, E, C, C_LS>::UnorderedFastKeyTable( + const UnorderedFastKeyTable& other ) + : _size( other._size ), + _maxProbeRatio( other._maxProbeRatio ), + _area( other._area ), + _hash( other._hash ), + _equals( other._equals ), + _convertor( other._convertor ), + _convertorOther( other._convertorOther ) { + } + + template< typename K_L, typename K_S, typename V, typename H, typename E, typename C, typename C_LS > + inline void UnorderedFastKeyTable<K_L, K_S, V, H, E, C, C_LS>::copyTo( UnorderedFastKeyTable* out ) const { + out->_size = _size; + out->_maxProbeRatio = _maxProbeRatio; + Area x( _area ); + out->_area.swap( &x ); + } + + template< typename K_L, typename K_S, typename V, typename H, typename E, typename C, typename C_LS > inline V& UnorderedFastKeyTable<K_L, K_S, V, H, E, C, C_LS>::get( const K_L& key ) { const size_t hash = _hash( key ); @@ -122,10 +152,46 @@ namespace mongo { } template< typename K_L, typename K_S, typename V, typename H, typename E, typename C, typename C_LS > + inline size_t UnorderedFastKeyTable<K_L, K_S, V, H, E, C, C_LS>::erase( const K_L& key ) { + + const size_t hash = _hash( key ); + int pos = _area.find( key, hash, NULL, *this ); + + if ( pos < 0 ) + return 0; + + _area._entries[pos].used = false; + _area._entries[pos].data.second = V(); + return 1; + } + + template< typename K_L, typename K_S, typename V, typename H, typename E, typename C, typename C_LS > inline void UnorderedFastKeyTable<K_L, K_S, V, H, E, C, C_LS>::_grow() { Area newArea( _area._capacity * 2, _maxProbeRatio ); _area.transfer( &newArea, *this ); _area.swap( &newArea ); } + template< typename K_L, typename K_S, typename V, typename H, typename E, typename C, typename C_LS > + inline typename UnorderedFastKeyTable<K_L, K_S, V, H, E, C, C_LS>::const_iterator + UnorderedFastKeyTable<K_L, K_S, V, H, E, C, C_LS>::find( const K_L& key ) const { + if ( _size == 0 ) + return const_iterator(); + int pos = _area.find( key, _hash(key), 0, *this ); + if ( pos < 0 ) + return const_iterator(); + return const_iterator( &_area, pos ); + } + + template< typename K_L, typename K_S, typename V, typename H, typename E, typename C, typename C_LS > + inline typename UnorderedFastKeyTable<K_L, K_S, V, H, E, C, C_LS>::const_iterator + UnorderedFastKeyTable<K_L, K_S, V, H, E, C, C_LS>::end() const { + return const_iterator(); + } + + template< typename K_L, typename K_S, typename V, typename H, typename E, typename C, typename C_LS > + inline typename UnorderedFastKeyTable<K_L, K_S, V, H, E, C, C_LS>::const_iterator + UnorderedFastKeyTable<K_L, K_S, V, H, E, C, C_LS>::begin() const { + return const_iterator( &_area ); + } } |