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

Side by Side Diff: pkg/compiler/lib/src/helpers/expensive_set.dart

Issue 2413233002: Change Set.difference API to accept Set<Object>. (Closed)
Patch Set: Also update a few subclasses. Created 4 years, 2 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
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 import 'dart:collection'; 5 import 'dart:collection';
6 6
7 /** 7 /**
8 * The expensive set is a data structure useful for tracking down 8 * The expensive set is a data structure useful for tracking down
9 * excessive memory usage due to large sets. It acts as an ordinary 9 * excessive memory usage due to large sets. It acts as an ordinary
10 * hash set, but it uses 10 times more memory (by default). 10 * hash set, but it uses 10 times more memory (by default).
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 if (other.contains(element)) result.add(element); 94 if (other.contains(element)) result.add(element);
95 } 95 }
96 } 96 }
97 return result; 97 return result;
98 } 98 }
99 99
100 Set<E> union(Set<E> other) { 100 Set<E> union(Set<E> other) {
101 return _newSet()..addAll(this)..addAll(other); 101 return _newSet()..addAll(this)..addAll(other);
102 } 102 }
103 103
104 Set<E> difference(Set<E> other) { 104 Set<E> difference(Set<Object> other) {
105 Set<E> result = _newSet(); 105 Set<E> result = _newSet();
106 for (E element in this) { 106 for (E element in this) {
107 if (!other.contains(element)) result.add(element); 107 if (!other.contains(element)) result.add(element);
108 } 108 }
109 return result; 109 return result;
110 } 110 }
111 111
112 void retainAll(Iterable objectsToRetain) { 112 void retainAll(Iterable objectsToRetain) {
113 Set retainSet; 113 Set retainSet;
114 if (objectsToRetain is Set) { 114 if (objectsToRetain is Set) {
115 retainSet = objectsToRetain; 115 retainSet = objectsToRetain;
116 } else { 116 } else {
117 retainSet = objectsToRetain.toSet(); 117 retainSet = objectsToRetain.toSet();
118 } 118 }
119 retainWhere(retainSet.contains); 119 retainWhere(retainSet.contains);
120 } 120 }
121 121
122 Set<E> toSet() { 122 Set<E> toSet() {
123 var result = new ExpensiveSet<E>(_sets.length); 123 var result = new ExpensiveSet<E>(_sets.length);
124 for (int i = 0; i < _sets.length; i++) { 124 for (int i = 0; i < _sets.length; i++) {
125 result._sets[i] = _sets[i].toSet(); 125 result._sets[i] = _sets[i].toSet();
126 } 126 }
127 return result; 127 return result;
128 } 128 }
129 129
130 String toString() => "expensive(${_sets[0]}x${_sets.length})"; 130 String toString() => "expensive(${_sets[0]}x${_sets.length})";
131 } 131 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/helpers/debug_collection.dart ('k') | pkg/compiler/lib/src/util/emptyset.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698