| OLD | NEW |
| 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> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "platform/assert.h" | 13 #include "platform/assert.h" |
| 14 #include "vm/unit_test.h" | 14 #include "vm/unit_test.h" |
| 15 #include "vm/hash_table.h" | 15 #include "vm/hash_table.h" |
| 16 | 16 |
| 17 namespace dart { | 17 namespace dart { |
| 18 | 18 |
| 19 // Various ways to look up strings. Uses length as the hash code to make it | 19 // Various ways to look up strings. Uses length as the hash code to make it |
| 20 // easy to engineer collisions. | 20 // easy to engineer collisions. |
| 21 class TestTraits { | 21 class TestTraits { |
| 22 public: | 22 public: |
| 23 static const char* Name() { return "TestTraits"; } | 23 static const char* Name() { return "TestTraits"; } |
| 24 static bool ReportStats() { return false; } |
| 24 | 25 |
| 25 static bool IsMatch(const char* key, const Object& obj) { | 26 static bool IsMatch(const char* key, const Object& obj) { |
| 26 return String::Cast(obj).Equals(key); | 27 return String::Cast(obj).Equals(key); |
| 27 } | 28 } |
| 28 static uword Hash(const char* key) { | 29 static uword Hash(const char* key) { |
| 29 return static_cast<uword>(strlen(key)); | 30 return static_cast<uword>(strlen(key)); |
| 30 } | 31 } |
| 31 static bool IsMatch(const Object& a, const Object& b) { | 32 static bool IsMatch(const Object& a, const Object& b) { |
| 32 return a.IsString() && b.IsString() && | 33 return a.IsString() && b.IsString() && |
| 33 String::Cast(a).Equals(String::Cast(b)); | 34 String::Cast(a).Equals(String::Cast(b)); |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 TEST_CASE(Maps) { | 298 TEST_CASE(Maps) { |
| 298 for (intptr_t initial_capacity = 0; | 299 for (intptr_t initial_capacity = 0; |
| 299 initial_capacity < 32; | 300 initial_capacity < 32; |
| 300 ++initial_capacity) { | 301 ++initial_capacity) { |
| 301 TestMap<UnorderedHashMap<TestTraits> >(initial_capacity, false); | 302 TestMap<UnorderedHashMap<TestTraits> >(initial_capacity, false); |
| 302 TestMap<EnumIndexHashMap<TestTraits> >(initial_capacity, true); | 303 TestMap<EnumIndexHashMap<TestTraits> >(initial_capacity, true); |
| 303 } | 304 } |
| 304 } | 305 } |
| 305 | 306 |
| 306 } // namespace dart | 307 } // namespace dart |
| OLD | NEW |