| OLD | NEW | 
|---|
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. | 
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without | 
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are | 
| 4 // met: | 4 // met: | 
| 5 // | 5 // | 
| 6 //     * Redistributions of source code must retain the above copyright | 6 //     * Redistributions of source code must retain the above copyright | 
| 7 //       notice, this list of conditions and the following disclaimer. | 7 //       notice, this list of conditions and the following disclaimer. | 
| 8 //     * Redistributions in binary form must reproduce the above | 8 //     * Redistributions in binary form must reproduce the above | 
| 9 //       copyright notice, this list of conditions and the following | 9 //       copyright notice, this list of conditions and the following | 
| 10 //       disclaimer in the documentation and/or other materials provided | 10 //       disclaimer in the documentation and/or other materials provided | 
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 86   HashMap map_; | 86   HashMap map_; | 
| 87 }; | 87 }; | 
| 88 | 88 | 
| 89 | 89 | 
| 90 static uint32_t Hash(uint32_t key)  { return 23; } | 90 static uint32_t Hash(uint32_t key)  { return 23; } | 
| 91 static uint32_t CollisionHash(uint32_t key)  { return key & 0x3; } | 91 static uint32_t CollisionHash(uint32_t key)  { return key & 0x3; } | 
| 92 | 92 | 
| 93 | 93 | 
| 94 void TestSet(IntKeyHash hash, int size) { | 94 void TestSet(IntKeyHash hash, int size) { | 
| 95   IntSet set(hash); | 95   IntSet set(hash); | 
| 96   CHECK_EQ(0u, set.occupancy()); | 96   CHECK_EQ(0, set.occupancy()); | 
| 97 | 97 | 
| 98   set.Insert(1); | 98   set.Insert(1); | 
| 99   set.Insert(2); | 99   set.Insert(2); | 
| 100   set.Insert(3); | 100   set.Insert(3); | 
| 101   CHECK_EQ(3u, set.occupancy()); | 101   CHECK_EQ(3, set.occupancy()); | 
| 102 | 102 | 
| 103   set.Insert(2); | 103   set.Insert(2); | 
| 104   set.Insert(3); | 104   set.Insert(3); | 
| 105   CHECK_EQ(3u, set.occupancy()); | 105   CHECK_EQ(3, set.occupancy()); | 
| 106 | 106 | 
| 107   CHECK(set.Present(1)); | 107   CHECK(set.Present(1)); | 
| 108   CHECK(set.Present(2)); | 108   CHECK(set.Present(2)); | 
| 109   CHECK(set.Present(3)); | 109   CHECK(set.Present(3)); | 
| 110   CHECK(!set.Present(4)); | 110   CHECK(!set.Present(4)); | 
| 111   CHECK_EQ(3u, set.occupancy()); | 111   CHECK_EQ(3, set.occupancy()); | 
| 112 | 112 | 
| 113   set.Remove(1); | 113   set.Remove(1); | 
| 114   CHECK(!set.Present(1)); | 114   CHECK(!set.Present(1)); | 
| 115   CHECK(set.Present(2)); | 115   CHECK(set.Present(2)); | 
| 116   CHECK(set.Present(3)); | 116   CHECK(set.Present(3)); | 
| 117   CHECK_EQ(2u, set.occupancy()); | 117   CHECK_EQ(2, set.occupancy()); | 
| 118 | 118 | 
| 119   set.Remove(3); | 119   set.Remove(3); | 
| 120   CHECK(!set.Present(1)); | 120   CHECK(!set.Present(1)); | 
| 121   CHECK(set.Present(2)); | 121   CHECK(set.Present(2)); | 
| 122   CHECK(!set.Present(3)); | 122   CHECK(!set.Present(3)); | 
| 123   CHECK_EQ(1u, set.occupancy()); | 123   CHECK_EQ(1, set.occupancy()); | 
| 124 | 124 | 
| 125   set.Clear(); | 125   set.Clear(); | 
| 126   CHECK_EQ(0u, set.occupancy()); | 126   CHECK_EQ(0, set.occupancy()); | 
| 127 | 127 | 
| 128   // Insert a long series of values. | 128   // Insert a long series of values. | 
| 129   const int start = 453; | 129   const int start = 453; | 
| 130   const int factor = 13; | 130   const int factor = 13; | 
| 131   const int offset = 7; | 131   const int offset = 7; | 
| 132   const uint32_t n = size; | 132   const uint32_t n = size; | 
| 133 | 133 | 
| 134   int x = start; | 134   int x = start; | 
| 135   for (uint32_t i = 0; i < n; i++) { | 135   for (uint32_t i = 0; i < n; i++) { | 
| 136     CHECK_EQ(i, static_cast<double>(set.occupancy())); | 136     CHECK_EQ(i, static_cast<double>(set.occupancy())); | 
| (...skipping 23 matching lines...) Expand all  Loading... | 
| 160     int y = start; | 160     int y = start; | 
| 161     for (uint32_t j = 0; j < n; j++) { | 161     for (uint32_t j = 0; j < n; j++) { | 
| 162       if (j <= i) { | 162       if (j <= i) { | 
| 163         CHECK(!set.Present(y)); | 163         CHECK(!set.Present(y)); | 
| 164       } else { | 164       } else { | 
| 165         CHECK(set.Present(y)); | 165         CHECK(set.Present(y)); | 
| 166       } | 166       } | 
| 167       y = y * factor + offset; | 167       y = y * factor + offset; | 
| 168     } | 168     } | 
| 169   } | 169   } | 
| 170   CHECK_EQ(0u, set.occupancy()); | 170   CHECK_EQ(0, set.occupancy()); | 
| 171 } | 171 } | 
| 172 | 172 | 
| 173 | 173 | 
| 174 TEST(Set) { | 174 TEST(Set) { | 
| 175   TestSet(Hash, 100); | 175   TestSet(Hash, 100); | 
| 176   TestSet(CollisionHash, 50); | 176   TestSet(CollisionHash, 50); | 
| 177 } | 177 } | 
| OLD | NEW | 
|---|