- Timestamp:
- 06/19/15 21:45:40 (10 years ago)
- Location:
- trunk/nv/stl
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/stl/container/hash_table.hh
r402 r404 171 171 } 172 172 173 hash_table_storage( const hash_table_storage& ) = delete; 174 hash_table_storage& operator=( const hash_table_storage& ) = delete; 175 176 inline hash_table_storage( hash_table_storage&& other ) 177 : m_buckets( other.m_buckets ) 178 , m_bucket_count( other.m_bucket_count ) 179 , m_element_count( other.m_element_count ) 180 , m_max_load_factor( other.m_max_load_factor ) 181 { 182 other.m_buckets = nullptr; 183 other.m_bucket_count = 0; 184 other.m_element_count = 0; 185 } 186 inline hash_table_storage& operator=( hash_table_storage&& other ) 187 { 188 if ( this != &other ) 189 { 190 free_nodes( m_buckets, m_bucket_count ); 191 free_buckets( m_buckets, m_bucket_count ); 192 m_buckets = other.m_buckets; 193 m_bucket_count = other.m_bucket_count; 194 m_element_count = other.m_element_count; 195 m_max_load_factor = other.max_load_factor; 196 } 197 return *this; 198 } 199 173 200 iterator erase( const_iterator which ) 174 201 { … … 247 274 248 275 template < typename... Args > 249 iterator insert( size_type index, Args&&... args )276 iterator insert( size_type index, hash_type hash_code, Args&&... args ) 250 277 { 251 278 node_type* node = alloc_node(); 252 base_type::entry_construct( node, nv::forward<Args>( args )... );279 base_type::entry_construct( node, hash_code, nv::forward<Args>( args )... ); 253 280 node->next = m_buckets[index]; 254 281 m_buckets[index] = node; … … 420 447 const hash_type c = base_type::get_hash( key ); 421 448 size_type b = base_type::get_bucket_index( c ); 422 return do_find_node( b, key, c);449 return do_find_node( b, c, key ); 423 450 } 424 451 const_iterator find( const key_type& key ) const … … 426 453 const hash_type c = base_type::get_hash( key ); 427 454 size_type b = base_type::get_bucket_index( c ); 428 return do_find_node( b, key, c ); 429 } 430 431 inline insert_return_type insert( const value_type& value ) 455 return do_find_node( b, c, key ); 456 } 457 458 // TODO: implement 459 // template< typename... Args > 460 // insert_return_type emplace( Args&&... args ) 461 // { 462 // 463 // } 464 465 inline insert_return_type insert( value_type&& value ) 432 466 { 433 467 const hash_type h = base_type::get_value_hash( value ); 434 468 size_type b = base_type::get_bucket_index( h ); 435 iterator r = do_find_node( b, value, h);469 iterator r = do_find_node( b, h, value ); 436 470 437 471 if ( r == this->end() ) 438 472 { 439 if ( base_type::rehash_check( 1 ) ) 440 { 441 b = base_type::get_bucket_index( h ); 442 } 443 return insert_return_type( base_type::insert( b, value, h ), true ); 473 if ( base_type::rehash_check( 1 ) ) b = base_type::get_bucket_index( h ); 474 return insert_return_type( base_type::insert( b, h, nv::forward( value ) ), true ); 475 } 476 477 return insert_return_type( r, false ); 478 } 479 480 481 inline insert_return_type insert( const value_type& value ) 482 { 483 const hash_type h = base_type::get_value_hash( value ); 484 size_type b = base_type::get_bucket_index( h ); 485 iterator r = do_find_node( b, h, value ); 486 487 if ( r == this->end() ) 488 { 489 if ( base_type::rehash_check( 1 ) ) b = base_type::get_bucket_index( h ); 490 return insert_return_type( base_type::insert( b, h, value ), true ); 444 491 } 445 492 … … 473 520 while ( i != this->cend( b ) ) 474 521 { 475 if ( base_type::entry_compare( i.entry(), key, c) )522 if ( base_type::entry_compare( i.entry(), c, key ) ) 476 523 { 477 524 i = base_type::erase_local( b, i ); … … 490 537 const hash_type h = base_type::get_hash( key ); 491 538 size_type b = base_type::get_bucket_index( h ); 492 iterator r = do_find_node( b, key, h);539 iterator r = do_find_node( b, h, key ); 493 540 494 541 if ( r == this->end() ) 495 542 { 496 if ( base_type::rehash_check( 1 ) ) 497 { 498 b = base_type::get_bucket_index( h ); 499 } 500 return insert_return_type( base_type::insert( b, value_type( key ), h ), true ); 543 if ( base_type::rehash_check( 1 ) ) b = base_type::get_bucket_index( h ); 544 return insert_return_type( base_type::insert( b, h, key ), true ); 501 545 } 502 546 … … 505 549 506 550 template < typename ComparableType > 507 iterator do_find_node( size_type index, const ComparableType& query, hash_type h) const551 iterator do_find_node( size_type index, hash_type h, const ComparableType& query ) const 508 552 { 509 553 const_local_iterator first = this->cbegin( index ); … … 511 555 while ( first != last ) 512 556 { 513 if ( base_type::entry_compare( first.entry(), query, h) )557 if ( base_type::entry_compare( first.entry(), h, query ) ) 514 558 return base_type::unlocalize( index, first ); 515 559 ++first; -
trunk/nv/stl/container/hash_table_policy.hh
r402 r404 193 193 }; 194 194 195 constexpr bool entry_compare( const entry_type* entry, const key_type& key, hash_type) const195 constexpr bool entry_compare( const entry_type* entry, hash_type, const key_type& key ) const 196 196 { 197 197 return base_type::compare( entry->value.first, key ); 198 198 } 199 199 200 constexpr bool entry_compare( const entry_type* entry, const value_type& value, hash_type ) const200 constexpr bool entry_compare( const entry_type* entry, hash_type, const value_type& value ) const 201 201 { 202 202 return base_type::compare( entry->value.first, value.first ); 203 203 } 204 204 205 inline void entry_construct( entry_type* entry, const value_type& value, hash_type ) const 206 { 207 copy_construct_object( &(entry->value), value ); 205 template < typename... Args > 206 inline void entry_construct( entry_type* entry, hash_type, Args&&... params ) const 207 { 208 construct_object( &(entry->value), ::nv::forward<Args>( params )... ); 209 } 210 211 inline void entry_construct( entry_type* entry, hash_type, Key key ) const 212 { 213 construct_object( &( entry->value ), value_type( ::nv::move( key ), mapped_type() ) ); 208 214 } 209 215 … … 239 245 }; 240 246 241 constexpr bool entry_compare( const entry_type* entry, const key_type& key, hash_type h) const247 constexpr bool entry_compare( const entry_type* entry, hash_type h, const key_type& key ) const 242 248 { 243 249 return entry->hash_code == h && base_type::compare( entry->value.first, key ); 244 250 } 245 constexpr bool entry_compare( const entry_type* entry, const value_type& value, hash_type h) const251 constexpr bool entry_compare( const entry_type* entry, hash_type h, const value_type& value ) const 246 252 { 247 253 return entry->hash_code == h && base_type::compare( entry->value.first, value.first ); 248 254 } 249 255 256 template < typename... Args > 257 inline void entry_construct( entry_type* entry, hash_type hash_code, Args&&... params ) const 258 { 259 copy_construct_object( &( entry->value ), ::nv::forward<Args>( params ) ); 260 entry->hash_code = hash_code; 261 } 262 250 263 constexpr hash_type get_entry_hash( const entry_type* entry ) const 251 264 { … … 256 269 return base_type::get_hash( value.first ); 257 270 } 258 inline void construct( entry_type* entry, const value_type& value, hash_type hash_code ) const 259 { 260 copy_construct_object( &(entry->value), value ); 261 entry->hash_code = hash_code; 262 } 263 }; 271 }; 264 272 265 273 struct hash_table_range_mod_policy -
trunk/nv/stl/memory.hh
r402 r404 124 124 inline void raw_construct_object( void* object, Args&&... params ) 125 125 { 126 new ( object )T( forward<Args>( params )... );126 new ( object )T( ::nv::forward<Args>( params )... ); 127 127 } 128 128 … … 130 130 inline void raw_move_construct_object( void* object, T&& original ) 131 131 { 132 new ( object )T( move( original ) );132 new ( object )T( ::nv::move( original ) ); 133 133 } 134 134 … … 142 142 inline void construct_object( T* object, Args&&... params ) 143 143 { 144 new ( object )T( forward<Args>( params )... );144 new ( object )T( ::nv::forward<Args>( params )... ); 145 145 } 146 146 … … 148 148 inline void move_construct_object( T* object, T&& original ) 149 149 { 150 new ( object )T( move( original ) );150 new ( object )T( ::nv::move( original ) ); 151 151 } 152 152 -
trunk/nv/stl/utility/pair.hh
r395 r404 27 27 28 28 constexpr pair() : first(), second() {} 29 constexpr pair( const T1& f, const T2& s )29 constexpr pair( const first_type& f, const second_type& s ) 30 30 : first( f ), second( s ) {} 31 // TODO: this is non-standard, and I dont like it, 32 // but is used in hash_table. Remove? 33 constexpr pair( const T1& f ) 34 : first( f ), second() {} 31 32 constexpr pair( first_type&& f, second_type&& s ) 33 : first( ::nv::forward<first_type>( f ) ), second( ::nv::forward<second_type>( s ) ) {} 35 34 36 35 pair( const pair& ) = default; … … 39 38 this_type& operator= ( this_type&& rhs ) 40 39 { 41 first = forward<first_type>( rhs.first );42 second = forward<first_type>( rhs.second );40 first = ::nv::forward<first_type>( rhs.first ); 41 second = ::nv::forward<first_type>( rhs.second ); 43 42 } 44 43
Note: See TracChangeset
for help on using the changeset viewer.