Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(288)

Side by Side Diff: runtime/vm/hash_table_test.cc

Issue 583443003: Add 'Clear' method to HashMap/HashSet templates. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/hash_table.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 #include <cstring> 6 #include <cstring>
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 for (int i = 0; i < 2; ++i) { 238 for (int i = 0; i < 2; ++i) {
239 for (char ch = 'a'; ch <= 'z'; ++ch) { 239 for (char ch = 'a'; ch <= 'z'; ++ch) {
240 std::string key('z' - ch + 1, ch); 240 std::string key('z' - ch + 1, ch);
241 expected.insert(key); 241 expected.insert(key);
242 bool present = actual.Insert(String::Handle(String::New(key.c_str()))); 242 bool present = actual.Insert(String::Handle(String::New(key.c_str())));
243 EXPECT_EQ((i != 0), present); 243 EXPECT_EQ((i != 0), present);
244 Validate(actual); 244 Validate(actual);
245 VerifyStringSetsEqual(expected, actual, ordered); 245 VerifyStringSetsEqual(expected, actual, ordered);
246 } 246 }
247 } 247 }
248 // TODO(koda): Delete all entries. 248 actual.Clear();
249 EXPECT_EQ(0, actual.NumOccupied());
249 actual.Release(); 250 actual.Release();
250 } 251 }
251 252
252 253
253 template<typename Map> 254 template<typename Map>
254 void TestMap(intptr_t initial_capacity, bool ordered) { 255 void TestMap(intptr_t initial_capacity, bool ordered) {
255 std::map<std::string, int> expected; 256 std::map<std::string, int> expected;
256 Map actual(HashTables::New<Map>(initial_capacity)); 257 Map actual(HashTables::New<Map>(initial_capacity));
257 // Insert the following (strings, int) mapping: 258 // Insert the following (strings, int) mapping:
258 // aaa...aaa -> 26 259 // aaa...aaa -> 26
259 // bbb..bbb -> 25 260 // bbb..bbb -> 25
260 // ... 261 // ...
261 // yy -> 2 262 // yy -> 2
262 // z -> 1 263 // z -> 1
263 for (int i = 0; i < 2; ++i) { 264 for (int i = 0; i < 2; ++i) {
264 for (char ch = 'a'; ch <= 'z'; ++ch) { 265 for (char ch = 'a'; ch <= 'z'; ++ch) {
265 int length = 'z' - ch + 1; 266 int length = 'z' - ch + 1;
266 std::string key(length, ch); 267 std::string key(length, ch);
267 // Map everything to zero initially, then update to their final values. 268 // Map everything to zero initially, then update to their final values.
268 int value = length * i; 269 int value = length * i;
269 expected[key] = value; 270 expected[key] = value;
270 bool present = 271 bool present =
271 actual.UpdateOrInsert(String::Handle(String::New(key.c_str())), 272 actual.UpdateOrInsert(String::Handle(String::New(key.c_str())),
272 Smi::Handle(Smi::New(value))); 273 Smi::Handle(Smi::New(value)));
273 EXPECT_EQ((i != 0), present); 274 EXPECT_EQ((i != 0), present);
274 Validate(actual); 275 Validate(actual);
275 VerifyStringMapsEqual(expected, actual, ordered); 276 VerifyStringMapsEqual(expected, actual, ordered);
276 } 277 }
277 } 278 }
278 // TODO(koda): Delete all entries. 279 actual.Clear();
280 EXPECT_EQ(0, actual.NumOccupied());
279 actual.Release(); 281 actual.Release();
280 } 282 }
281 283
282 284
283 TEST_CASE(Sets) { 285 TEST_CASE(Sets) {
284 for (intptr_t initial_capacity = 0; 286 for (intptr_t initial_capacity = 0;
285 initial_capacity < 32; 287 initial_capacity < 32;
286 ++initial_capacity) { 288 ++initial_capacity) {
287 TestSet<UnorderedHashSet<TestTraits> >(initial_capacity, false); 289 TestSet<UnorderedHashSet<TestTraits> >(initial_capacity, false);
288 TestSet<EnumIndexHashSet<TestTraits> >(initial_capacity, true); 290 TestSet<EnumIndexHashSet<TestTraits> >(initial_capacity, true);
289 } 291 }
290 } 292 }
291 293
292 294
293 TEST_CASE(Maps) { 295 TEST_CASE(Maps) {
294 for (intptr_t initial_capacity = 0; 296 for (intptr_t initial_capacity = 0;
295 initial_capacity < 32; 297 initial_capacity < 32;
296 ++initial_capacity) { 298 ++initial_capacity) {
297 TestMap<UnorderedHashMap<TestTraits> >(initial_capacity, false); 299 TestMap<UnorderedHashMap<TestTraits> >(initial_capacity, false);
298 TestMap<EnumIndexHashMap<TestTraits> >(initial_capacity, true); 300 TestMap<EnumIndexHashMap<TestTraits> >(initial_capacity, true);
299 } 301 }
300 } 302 }
301 303
302 } // namespace dart 304 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/hash_table.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698