Changeset b22ccaa in mainline
- Timestamp:
- 2018-07-05T21:41:22Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7ea90cf
- Parents:
- 1fafb3e
- git-author:
- Dzejrou <dzejrou@…> (2018-04-27 23:47:12)
- git-committer:
- Dzejrou <dzejrou@…> (2018-07-05 21:41:22)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/cpp/include/internal/hash_table.hpp
r1fafb3e rb22ccaa 577 577 if (idx_ < max_idx_) 578 578 { 579 while (!table_[++idx_].head )579 while (!table_[++idx_].head && idx_ < max_idx_) 580 580 { /* DUMMY BODY */ } 581 581 … … 602 602 if (idx_ < max_idx_) 603 603 { 604 while (!table_[++idx_].head )604 while (!table_[++idx_].head && idx_ < max_idx_) 605 605 { /* DUMMY BODY */ } 606 606 … … 693 693 if (idx_ < max_idx_) 694 694 { 695 while (!table_[++idx_].head )695 while (!table_[++idx_].head && idx_ < max_idx_) 696 696 { /* DUMMY BODY */ } 697 697 … … 718 718 if (idx_ < max_idx_) 719 719 { 720 while (!table_[++idx_].head )720 while (!table_[++idx_].head && idx_ < max_idx_) 721 721 { /* DUMMY BODY */ } 722 722 … … 996 996 { 997 997 for (const auto& x: other) 998 { 999 auto spot = find_insertion_spot(key_extractor_(x)); 1000 insert(spot, x); 1001 } 998 insert(x); 1002 999 } 1003 1000 … … 1048 1045 iterator begin() noexcept 1049 1046 { 1047 auto idx = first_filled_bucket_(); 1050 1048 return iterator{ 1051 table_, size_type{}, bucket_count_,1052 table_[ 0].head1049 table_, idx, bucket_count_, 1050 table_[idx].head 1053 1051 }; 1054 1052 } … … 1071 1069 const_iterator cbegin() const noexcept 1072 1070 { 1071 auto idx = first_filled_bucket_(); 1073 1072 return const_iterator{ 1074 table_, size_type{}, bucket_count_,1075 table_[ 0].head1073 table_, idx, bucket_count_, 1074 table_[idx].head 1076 1075 }; 1077 1076 } … … 1348 1347 bool is_eq_to(const hash_table& other) const 1349 1348 { 1350 // TODO: implement 1351 return false; 1349 if (size() != other.size()) 1350 return false; 1351 1352 auto it = begin(); 1353 while (it != end()) 1354 { 1355 /** 1356 * For each key K we will check how many 1357 * instances of K are there in the table. 1358 * Then we will check if the count for K 1359 * is equal to that amount. 1360 */ 1361 1362 size_type cnt{}; 1363 auto tmp = it; 1364 1365 while (key_eq_(key_extractor_(*it), key_extractor_(*tmp))) 1366 { 1367 ++cnt; 1368 if (++tmp == end()) 1369 break; 1370 } 1371 1372 auto other_cnt = other.count(key_extractor_(*it)); 1373 if (cnt != other_cnt) 1374 return false; 1375 1376 it = tmp; // tmp is one past *it's key. 1377 } 1378 1379 return true; 1352 1380 } 1353 1381 … … 1431 1459 } 1432 1460 1461 size_type first_filled_bucket_() const 1462 { 1463 size_type res{}; 1464 while (res < bucket_count_) 1465 { 1466 if (table_[res].head) 1467 return res; 1468 ++res; 1469 } 1470 1471 /** 1472 * Note: This is used for iterators, 1473 * so we need to return a valid index. 1474 * But since table_[0].head is nullptr 1475 * we know that if we return 0 the 1476 * created iterator will test as equal 1477 * to end(). 1478 */ 1479 return 0; 1480 } 1481 1433 1482 friend Policy; 1434 1483 };
Note:
See TracChangeset
for help on using the changeset viewer.