Changeset 237476 in webkit
- Timestamp:
- Oct 26, 2018 11:58:50 AM (6 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r237461 r237476 1 2018-10-26 Geoffrey Garen <ggaren@apple.com> 2 3 HashMap should support selecting a random entry 4 https://bugs.webkit.org/show_bug.cgi?id=190814 5 6 Reviewed by Antti Koivisto. 7 8 * wtf/HashTable.h: 9 (WTF::HashTable::random): 10 (WTF::HashTable::random const): Draw a new random bucket any time we 11 have a miss, to avoid bias caused by lopsided tables. 12 1 13 2018-10-26 Antti Koivisto <antti@apple.com> 2 14 -
trunk/Source/WTF/wtf/HashTable.h
r237461 r237476 385 385 if (isEmpty()) 386 386 return end(); 387 auto it = makeIterator(m_table + (weakRandomUint32() & m_tableSizeMask)); 388 if (it == end()) 389 return begin(); 390 return it; 387 388 while (1) { 389 ValueType* entry = m_table + (weakRandomUint32() & m_tableSizeMask); 390 if (isEmptyBucket(*entry) || isDeletedBucket(*entry)) 391 continue; 392 return makeKnownGoodIterator(entry); 393 }; 391 394 } 392 395 -
trunk/Tools/ChangeLog
r237461 r237476 1 2018-10-26 Geoffrey Garen <ggaren@apple.com> 2 3 HashMap should support selecting a random entry 4 https://bugs.webkit.org/show_bug.cgi?id=190814 5 6 Reviewed by Antti Koivisto. 7 8 * TestWebKitAPI/Tests/WTF/HashMap.cpp: Updated the Random_IsRandom to 9 more thoroughly test for randomness. 10 1 11 2018-10-26 Antti Koivisto <antti@apple.com> 2 12 -
trunk/Tools/TestWebKitAPI/Tests/WTF/HashMap.cpp
r237419 r237476 1023 1023 unsigned twos = 0; 1024 1024 1025 for (unsigned i = 0; i < 100 ; ++i) {1025 for (unsigned i = 0; i < 1000; ++i) { 1026 1026 auto it = map.random(); 1027 1027 if (it->value == 1) … … 1033 1033 } 1034 1034 1035 ASSERT_EQ(ones + twos, 100 u);1036 ASSERT_LE(ones, 99u);1037 ASSERT_LE(twos, 99u);1035 ASSERT_EQ(ones + twos, 1000u); 1036 ASSERT_LE(ones, 600u); 1037 ASSERT_LE(twos, 600u); 1038 1038 } 1039 1039
Note: See TracChangeset
for help on using the changeset viewer.