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