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

Side by Side Diff: corelib/src/implementation/hash_map_set.dart

Issue 10832060: Add reduce to Collection. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 // Hash map implementation with open addressing and quadratic probing. 5 // Hash map implementation with open addressing and quadratic probing.
6 class HashMapImplementation<K extends Hashable, V> implements HashMap<K, V> { 6 class HashMapImplementation<K extends Hashable, V> implements HashMap<K, V> {
7 7
8 // The [_keys] list contains the keys inserted in the map. 8 // The [_keys] list contains the keys inserted in the map.
9 // The [_keys] list must be a raw list because it 9 // The [_keys] list must be a raw list because it
10 // will contain both elements of type K, and the [_DELETED_KEY] of type 10 // will contain both elements of type K, and the [_DELETED_KEY] of type
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 } 343 }
344 344
345 Set map(f(E element)) { 345 Set map(f(E element)) {
346 Set result = new Set(); 346 Set result = new Set();
347 _backingMap.forEach(void _(E key, E value) { 347 _backingMap.forEach(void _(E key, E value) {
348 result.add(f(key)); 348 result.add(f(key));
349 }); 349 });
350 return result; 350 return result;
351 } 351 }
352 352
353 reduce(var init, f(var prev, E element)) {
Lasse Reichstein Nielsen 2012/08/08 07:19:14 Return type, variable names unabbreviated.
Anders Johnsen 2012/08/08 07:56:14 Done / see other comments.
354 return Collections.reduce(this, init, f);
355 }
356
353 Set<E> filter(bool f(E element)) { 357 Set<E> filter(bool f(E element)) {
354 Set<E> result = new Set<E>(); 358 Set<E> result = new Set<E>();
355 _backingMap.forEach(void _(E key, E value) { 359 _backingMap.forEach(void _(E key, E value) {
356 if (f(key)) result.add(key); 360 if (f(key)) result.add(key);
357 }); 361 });
358 return result; 362 return result;
359 } 363 }
360 364
361 bool every(bool f(E element)) { 365 bool every(bool f(E element)) {
362 Collection<E> keys = _backingMap.getKeys(); 366 Collection<E> keys = _backingMap.getKeys();
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 444
441 /** 445 /**
442 * A singleton sentinel used to represent when a key is deleted from the map. 446 * A singleton sentinel used to represent when a key is deleted from the map.
443 * We can't use [: const Object() :] as a sentinel because it would end up 447 * We can't use [: const Object() :] as a sentinel because it would end up
444 * canonicalized and then we cannot distinguish the deleted key from the 448 * canonicalized and then we cannot distinguish the deleted key from the
445 * canonicalized [: Object() :]. 449 * canonicalized [: Object() :].
446 */ 450 */
447 class _DeletedKeySentinel { 451 class _DeletedKeySentinel {
448 const _DeletedKeySentinel(); 452 const _DeletedKeySentinel();
449 } 453 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698