| 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 25 matching lines...) Expand all Loading... |
| 36 static bool DefaultMatchFun(void* a, void* b) { | 36 static bool DefaultMatchFun(void* a, void* b) { |
| 37 return a == b; | 37 return a == b; |
| 38 } | 38 } |
| 39 | 39 |
| 40 | 40 |
| 41 class IntSet { | 41 class IntSet { |
| 42 public: | 42 public: |
| 43 IntSet() : map_(DefaultMatchFun) {} | 43 IntSet() : map_(DefaultMatchFun) {} |
| 44 | 44 |
| 45 void Insert(int x) { | 45 void Insert(int x) { |
| 46 ASSERT(x != 0); // 0 corresponds to (void*)NULL - illegal key value | 46 CHECK(x != 0); // 0 corresponds to (void*)NULL - illegal key value |
| 47 HashMap::Entry* p = map_.Lookup(reinterpret_cast<void*>(x), Hash(x), true); | 47 HashMap::Entry* p = map_.Lookup(reinterpret_cast<void*>(x), Hash(x), true); |
| 48 CHECK(p != NULL); // insert is set! | 48 CHECK(p != NULL); // insert is set! |
| 49 CHECK_EQ(reinterpret_cast<void*>(x), p->key); | 49 CHECK_EQ(reinterpret_cast<void*>(x), p->key); |
| 50 // we don't care about p->value | 50 // we don't care about p->value |
| 51 } | 51 } |
| 52 | 52 |
| 53 bool Present(int x) { | 53 bool Present(int x) { |
| 54 HashMap::Entry* p = map_.Lookup(reinterpret_cast<void*>(x), Hash(x), false); | 54 HashMap::Entry* p = map_.Lookup(reinterpret_cast<void*>(x), Hash(x), false); |
| 55 if (p != NULL) { | 55 if (p != NULL) { |
| 56 CHECK_EQ(reinterpret_cast<void*>(x), p->key); | 56 CHECK_EQ(reinterpret_cast<void*>(x), p->key); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 | 114 |
| 115 // Verify the same sequence of values. | 115 // Verify the same sequence of values. |
| 116 x = start; | 116 x = start; |
| 117 for (uint32_t i = 0; i < n; i++) { | 117 for (uint32_t i = 0; i < n; i++) { |
| 118 CHECK(set.Present(x)); | 118 CHECK(set.Present(x)); |
| 119 x = x*factor + offset; | 119 x = x*factor + offset; |
| 120 } | 120 } |
| 121 | 121 |
| 122 CHECK_EQ(n, static_cast<double>(set.occupancy())); | 122 CHECK_EQ(n, static_cast<double>(set.occupancy())); |
| 123 } | 123 } |
| OLD | NEW |