OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 /** | 5 /** |
6 * This class is the public interface of a set. A set is a collection | 6 * This class is the public interface of a set. A set is a collection |
7 * without duplicates. | 7 * without duplicates. |
8 */ | 8 */ |
9 abstract class Set<E> extends Collection<E> { | 9 abstract class Set<E> extends Collection<E> { |
10 factory Set() => new _HashSetImpl<E>(); | 10 factory Set() => new _HashSetImpl<E>(); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 } | 146 } |
147 | 147 |
148 Set map(f(E element)) { | 148 Set map(f(E element)) { |
149 Set result = new Set(); | 149 Set result = new Set(); |
150 _backingMap.forEach((E key, E value) { | 150 _backingMap.forEach((E key, E value) { |
151 result.add(f(key)); | 151 result.add(f(key)); |
152 }); | 152 }); |
153 return result; | 153 return result; |
154 } | 154 } |
155 | 155 |
156 Dynamic reduce(Dynamic initialValue, | 156 dynamic reduce(dynamic initialValue, |
157 Dynamic combine(Dynamic previousValue, E element)) { | 157 dynamic combine(dynamic previousValue, E element)) { |
158 return Collections.reduce(this, initialValue, combine); | 158 return Collections.reduce(this, initialValue, combine); |
159 } | 159 } |
160 | 160 |
161 Set<E> filter(bool f(E element)) { | 161 Set<E> filter(bool f(E element)) { |
162 Set<E> result = new Set<E>(); | 162 Set<E> result = new Set<E>(); |
163 _backingMap.forEach((E key, E value) { | 163 _backingMap.forEach((E key, E value) { |
164 if (f(key)) result.add(key); | 164 if (f(key)) result.add(key); |
165 }); | 165 }); |
166 return result; | 166 return result; |
167 } | 167 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 } | 238 } |
239 | 239 |
240 // The entries in the set. May contain null or the sentinel value. | 240 // The entries in the set. May contain null or the sentinel value. |
241 List<E> _entries; | 241 List<E> _entries; |
242 | 242 |
243 // The next valid index in [_entries] or the length of [entries_]. | 243 // The next valid index in [_entries] or the length of [entries_]. |
244 // If it is the length of [_entries], calling [hasNext] on the | 244 // If it is the length of [_entries], calling [hasNext] on the |
245 // iterator will return false. | 245 // iterator will return false. |
246 int _nextValidIndex; | 246 int _nextValidIndex; |
247 } | 247 } |
OLD | NEW |