OLD | NEW |
| (Empty) |
1 // Copyright 2013 Google Inc. All Rights Reserved. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 // you may not use this file except in compliance with the License. | |
5 // You may obtain a copy of the License at | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 | |
15 /** | |
16 * Collection classes and related utilities. | |
17 */ | |
18 library quiver.collection; | |
19 | |
20 import 'dart:collection'; | |
21 import 'dart:math'; | |
22 | |
23 import 'package:quiver/core.dart'; | |
24 import 'package:quiver/iterables.dart'; | |
25 | |
26 part 'src/collection/bimap.dart'; | |
27 part 'src/collection/lru_map.dart'; | |
28 part 'src/collection/multimap.dart'; | |
29 part 'src/collection/treeset.dart'; | |
30 part 'src/collection/delegates/iterable.dart'; | |
31 part 'src/collection/delegates/list.dart'; | |
32 part 'src/collection/delegates/map.dart'; | |
33 part 'src/collection/delegates/queue.dart'; | |
34 part 'src/collection/delegates/set.dart'; | |
35 | |
36 /** | |
37 * Checks [List]s [a] and [b] for equality. | |
38 * | |
39 * Returns `true` if [a] and [b] are both null, or they are the same length and | |
40 * every element of [a] is equal to the corresponding element at the same index | |
41 * in [b]. | |
42 */ | |
43 bool listsEqual(List a, List b) { | |
44 if (a == b) return true; | |
45 if (a == null || b == null) return false; | |
46 if (a.length != b.length) return false; | |
47 | |
48 for (int i = 0; i < a.length; i++) { | |
49 if (a[i] != b[i]) return false; | |
50 } | |
51 | |
52 return true; | |
53 } | |
54 | |
55 /** | |
56 * Checks [Map]s [a] and [b] for equality. | |
57 * | |
58 * Returns `true` if [a] and [b] are both null, or they are the same length and | |
59 * every key `k` in [a] exists in [b] and the values `a[k] == b[k]`. | |
60 */ | |
61 bool mapsEqual(Map a, Map b) { | |
62 if (a == b) return true; | |
63 if (a == null || b == null) return false; | |
64 if (a.length != b.length) return false; | |
65 | |
66 for (var k in a.keys) { | |
67 var bValue = b[k]; | |
68 if (bValue == null && !b.containsKey(k)) return false; | |
69 if (bValue != a[k]) return false; | |
70 } | |
71 | |
72 return true; | |
73 } | |
74 | |
75 /** | |
76 * Checks [Set]s [a] and [b] for equality. | |
77 * | |
78 * Returns `true` if [a] and [b] are both null, or they are the same length and | |
79 * every element in [b] exists in [a]. | |
80 */ | |
81 bool setsEqual(Set a, Set b) { | |
82 if (a == b) return true; | |
83 if (a == null || b == null) return false; | |
84 if (a.length != b.length) return false; | |
85 | |
86 return a.containsAll(b); | |
87 } | |
OLD | NEW |