| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library map_test; | 5 library map_test; |
| 6 import 'dart:collection'; | 6 import 'dart:collection'; |
| 7 | 7 |
| 8 // Test that length/isEmpty opertions are constant time on | 8 // Test that length/isEmpty opertions are constant time on |
| 9 // maps, strings and collections. | 9 // maps, strings and collections. |
| 10 | 10 |
| 11 void testString(int n) { | 11 void testString(int n) { |
| 12 String s = "x"; | 12 String s = "x"; |
| 13 String string = ""; | 13 String string = ""; |
| 14 int length = n; | 14 int length = n; |
| 15 while (true) { | 15 while (true) { |
| 16 if ((length & 1) == 1) { | 16 if ((length & 1) == 1) { |
| 17 string = string.concat(s); | 17 string += s; |
| 18 } | 18 } |
| 19 length >>= 1; | 19 length >>= 1; |
| 20 if (length == 0) break; | 20 if (length == 0) break; |
| 21 s = s.concat(s); | 21 s += s; |
| 22 } | 22 } |
| 23 testLength(string, n); | 23 testLength(string, n); |
| 24 testLength(string.codeUnits, n); | 24 testLength(string.codeUnits, n); |
| 25 } | 25 } |
| 26 | 26 |
| 27 void testMap(Map map, int n) { | 27 void testMap(Map map, int n) { |
| 28 for (int i = 0; i < n; i++) { | 28 for (int i = 0; i < n; i++) { |
| 29 map[i] = i; | 29 map[i] = i; |
| 30 } | 30 } |
| 31 testLength(map, n); | 31 testLength(map, n); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 testMap(new LinkedHashMap(), N); | 66 testMap(new LinkedHashMap(), N); |
| 67 testMap(new SplayTreeMap(), N); | 67 testMap(new SplayTreeMap(), N); |
| 68 testCollection(new HashSet(), N); | 68 testCollection(new HashSet(), N); |
| 69 testCollection(new LinkedHashSet(), N); | 69 testCollection(new LinkedHashSet(), N); |
| 70 testCollection(new ListQueue(), N); | 70 testCollection(new ListQueue(), N); |
| 71 testList(new List()..length = N, N); | 71 testList(new List()..length = N, N); |
| 72 testList(new List(N), N); | 72 testList(new List(N), N); |
| 73 testString(N); | 73 testString(N); |
| 74 // DoubleLinkedQueue has linear length, but fast isEmpty. | 74 // DoubleLinkedQueue has linear length, but fast isEmpty. |
| 75 } | 75 } |
| OLD | NEW |