Changeset 86d1939 in mainline
- Timestamp:
- 2018-07-05T21:41:21Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c439e6a
- Parents:
- 86b3ae98
- git-author:
- Dzejrou <dzejrou@…> (2018-04-24 21:12:53)
- git-committer:
- Dzejrou <dzejrou@…> (2018-07-05 21:41:21)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/cpp/include/impl/unordered_map.hpp
r86b3ae98 r86d1939 31 31 32 32 #include <initializer_list> 33 #include <internal/hash_ map.hpp>33 #include <internal/hash_table.hpp> 34 34 #include <functional> 35 35 #include <memory> … … 43 43 44 44 template< 45 class Key, class Value 45 class Key, class Value, 46 46 class Hash = hash<Key>, 47 47 class Pred = equal_to<Key>, … … 81 81 { /* DUMMY BODY */ } 82 82 83 explicit unordered_map(size_type bucket_count = default_bucket_count_,83 explicit unordered_map(size_type bucket_count, 84 84 const hasher& hf = hasher{}, 85 85 const key_equal& eql = key_equal{}, … … 96 96 : unordered_map{bucket_count, hf, eql, alloc} 97 97 { 98 // TODO: insert the range98 insert(first, last); 99 99 } 100 100 … … 126 126 : unordered_map{bucket_count, hf, eql, alloc} 127 127 { 128 // TODO: insert the range128 insert(init.begin(), init.end()); 129 129 } 130 130 … … 179 179 unordered_map& operator=(initializer_list<value_type>& init) 180 180 { 181 // TODO: implement 181 table_.clear(); 182 table_.reserve(init.size()); 183 184 insert(init.begin(), init.end()); 185 182 186 return *this; 183 187 } … … 338 342 iterator erase(const_iterator position) 339 343 { 340 // TODO: implement344 return table_.erase(position); 341 345 } 342 346 343 347 size_type erase(const key_type& key) 344 348 { 345 // TODO: implement349 return table_.erase(key); 346 350 } 347 351 348 352 iterator erase(const_iterator first, const_iterator last) 349 353 { 350 // TODO: implement 354 while (first != last) 355 first = erase(first); 356 357 return iterator{ 358 table_.table(), first.idx(), 359 table_.size(), table_.head(first.idx()) 360 }; 351 361 } 352 362 … … 377 387 iterator find(const key_type& key) 378 388 { 379 // TODO: implement389 return table_.find(key); 380 390 } 381 391 382 392 const_iterator find(const key_type& key) const 383 393 { 384 // TODO: implement394 return table_.find(key); 385 395 } 386 396 387 397 size_type count(const key_type& key) const 388 398 { 389 // TODO: implement399 return table_.count(key); 390 400 } 391 401 392 402 pair<iterator, iterator> equal_range(const key_type& key) 393 403 { 394 // TODO: implement404 return table_.equal_range(key); 395 405 } 396 406 397 407 pair<const_iterator, const_iterator> equal_range(const key_type& key) const 398 408 { 399 // TODO: implement409 return table_.equal_range(key); 400 410 } 401 411 402 412 mapped_type& operator[](const key_type& key) 403 413 { 404 // TODO: implement 414 auto spot = table_.find_insertion_spot(key); 415 auto bucket = get<0>(spot); 416 417 if (bucket->head) 418 { 419 auto head = bucket->head; 420 auto current = bucket->head; 421 422 do 423 { 424 if (table_.keys_equal(key, current->value)) 425 return current->value.second; 426 else 427 current = current->next; 428 } 429 while (current != head); 430 } 431 432 bucket->append(new node_type{key, mapped_type{}}); 433 434 return bucket->head->value.second; 405 435 } 406 436 407 437 mapped_type& operator[](key_type&& key) 408 438 { 409 // TODO: implement 439 auto spot = table_.find_insertion_spot(key); 440 auto bucket = get<0>(spot); 441 442 if (bucket->head) 443 { 444 auto head = bucket->head; 445 auto current = bucket->head; 446 447 do 448 { 449 if (table_.keys_equal(key, current->value)) 450 return current->value.second; 451 else 452 current = current->next; 453 } 454 while (current != head); 455 } 456 457 bucket->append(new node_type{move(key), mapped_type{}}); 458 459 return bucket->head->value.second; 410 460 } 411 461 … … 496 546 497 547 private: 498 aux::hash_map<548 using table_type = aux::hash_table< 499 549 value_type, key_type, aux::key_value_key_extractor<key_type, mapped_type>, 500 550 hasher, key_equal, allocator_type, size_type, 501 551 iterator, const_iterator, local_iterator, const_local_iterator, 502 552 aux::hash_single_policy 503 > table_; 504 553 >; 554 using node_type = typename table_type::node_type; 555 556 table_type table_; 505 557 allocator_type allocator_; 506 558 … … 513 565 514 566 template< 515 class Key, class Value 567 class Key, class Value, 516 568 class Hash = hash<Key>, 517 569 class Pred = equal_to<Key>,
Note:
See TracChangeset
for help on using the changeset viewer.