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

Side by Side Diff: sdk/lib/collection/hash_set.dart

Issue 13913005: Implement JS version of LinkedHashSet and move the various HashTable implementations to the VM coll… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Map -> set. Created 7 years, 8 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 | « sdk/lib/collection/hash_map.dart ('k') | sdk/lib/collection/hash_table.dart » ('j') | 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) 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 part of dart.collection; 5 part of dart.collection;
6 6
7 /** Common parts of [HashSet] and [LinkedHashSet] implementations. */ 7 /** Common parts of [HashSet] and [LinkedHashSet] implementations. */
8 abstract class _HashSetBase<E> extends Collection<E> implements Set<E> { 8 abstract class _HashSetBase<E> extends Collection<E> implements Set<E> {
9 // Set. 9 // Set.
10 bool isSubsetOf(Collection<E> other) { 10 bool isSubsetOf(Collection<E> other) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 } 44 }
45 45
46 Set<E> difference(Set<E> other) { 46 Set<E> difference(Set<E> other) {
47 HashSet<E> result = _newSet(); 47 HashSet<E> result = _newSet();
48 for (E element in this) { 48 for (E element in this) {
49 if (!other.contains(element)) result.add(element); 49 if (!other.contains(element)) result.add(element);
50 } 50 }
51 return result; 51 return result;
52 } 52 }
53 53
54 void retainAll(Iterable objectsToRetain) {
55 Set retainSet;
56 if (objectsToRetain is Set) {
57 retainSet = objectsToRetain;
58 } else {
59 retainSet = objectsToRetain.toSet();
60 }
61 retainWhere(retainSet.contains);
62 }
63
54 String toString() => Collections.collectionToString(this); 64 String toString() => Collections.collectionToString(this);
55 } 65 }
56 66
57 class HashSet<E> extends _HashSetBase<E> { 67 class HashSet<E> extends _HashSetBase<E> {
58 external HashSet(); 68 external HashSet();
59 69
60 factory HashSet.from(Iterable<E> iterable) { 70 factory HashSet.from(Iterable<E> iterable) {
61 return new HashSet<E>()..addAll(iterable); 71 return new HashSet<E>()..addAll(iterable);
62 } 72 }
63 73
64 // Iterable. 74 // Iterable.
65 external Iterator<E> get iterator; 75 external Iterator<E> get iterator;
66 76
67 external int get length; 77 external int get length;
68 78
69 external bool get isEmpty; 79 external bool get isEmpty;
70 80
71 external bool contains(Object object); 81 external bool contains(Object object);
72 82
73 // Collection. 83 // Collection.
74 external void add(E element); 84 external void add(E element);
75 85
76 external void addAll(Iterable<E> objects); 86 external void addAll(Iterable<E> objects);
77 87
78 external bool remove(Object object); 88 external bool remove(Object object);
79 89
80 external void removeAll(Iterable objectsToRemove); 90 external void removeAll(Iterable objectsToRemove);
81 91
82 void retainAll(Iterable objectsToRetain) {
83 Set retainSet;
84 if (objectsToRetain is Set) {
85 retainSet = objectsToRetain;
86 } else {
87 retainSet = objectsToRetain.toSet();
88 }
89 retainWhere(retainSet.contains);
90 }
91
92 external void removeWhere(bool test(E element)); 92 external void removeWhere(bool test(E element));
93 93
94 external void retainWhere(bool test(E element)); 94 external void retainWhere(bool test(E element));
95 95
96 external void clear(); 96 external void clear();
97 97
98 // Set. 98 // Set.
99 Set<E> _newSet() => new HashSet<E>(); 99 Set<E> _newSet() => new HashSet<E>();
100 } 100 }
OLDNEW
« no previous file with comments | « sdk/lib/collection/hash_map.dart ('k') | sdk/lib/collection/hash_table.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698