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 16 matching lines...) Expand all Loading... | |
27 | 27 |
28 #include <stdlib.h> | 28 #include <stdlib.h> |
29 | 29 |
30 #include "src/v8.h" | 30 #include "src/v8.h" |
31 #include "test/cctest/cctest.h" | 31 #include "test/cctest/cctest.h" |
32 | 32 |
33 #include "src/base/hashmap.h" | 33 #include "src/base/hashmap.h" |
34 | 34 |
35 using namespace v8::internal; | 35 using namespace v8::internal; |
36 | 36 |
37 static bool DefaultMatchFun(void* a, void* b) { | |
38 return a == b; | |
39 } | |
40 | |
41 | 37 |
42 typedef uint32_t (*IntKeyHash)(uint32_t key); | 38 typedef uint32_t (*IntKeyHash)(uint32_t key); |
43 | 39 |
44 | 40 |
45 class IntSet { | 41 class IntSet { |
46 public: | 42 public: |
47 explicit IntSet(IntKeyHash hash) : hash_(hash), map_(DefaultMatchFun) {} | 43 explicit IntSet(IntKeyHash hash) : hash_(hash), map_() {} |
marja
2016/09/30 10:27:33
Ditto
Leszek Swirski
2016/09/30 10:44:28
Done.
| |
48 | 44 |
49 void Insert(int x) { | 45 void Insert(int x) { |
50 CHECK_NE(0, x); // 0 corresponds to (void*)NULL - illegal key value | 46 CHECK_NE(0, x); // 0 corresponds to (void*)NULL - illegal key value |
51 v8::base::HashMap::Entry* p = | 47 v8::base::HashMap::Entry* p = |
52 map_.LookupOrInsert(reinterpret_cast<void*>(x), hash_(x)); | 48 map_.LookupOrInsert(reinterpret_cast<void*>(x), hash_(x)); |
53 CHECK(p != NULL); // insert is set! | 49 CHECK(p != NULL); // insert is set! |
54 CHECK_EQ(reinterpret_cast<void*>(x), p->key); | 50 CHECK_EQ(reinterpret_cast<void*>(x), p->key); |
55 // we don't care about p->value | 51 // we don't care about p->value |
56 } | 52 } |
57 | 53 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 } | 166 } |
171 } | 167 } |
172 CHECK_EQ(0u, set.occupancy()); | 168 CHECK_EQ(0u, set.occupancy()); |
173 } | 169 } |
174 | 170 |
175 | 171 |
176 TEST(HashSet) { | 172 TEST(HashSet) { |
177 TestSet(Hash, 100); | 173 TestSet(Hash, 100); |
178 TestSet(CollisionHash, 50); | 174 TestSet(CollisionHash, 50); |
179 } | 175 } |
OLD | NEW |