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

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

Issue 18072004: Add fromIterable(s) constructors in SplayTreeMap and LinkedHashMap. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments. Created 7 years, 5 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 part of dart.collection; 5 part of dart.collection;
6 6
7 /** 7 /**
8 * A node in a splay tree. It holds the sorting key and the left 8 * A node in a splay tree. It holds the sorting key and the left
9 * and right children in the tree. 9 * and right children in the tree.
10 */ 10 */
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 // TODO(ngeoffray): Restore type when feature is implemented in dart2js 244 // TODO(ngeoffray): Restore type when feature is implemented in dart2js
245 // checked mode. http://dartbug.com/7733 245 // checked mode. http://dartbug.com/7733
246 Function /* Comparator<K> */_comparator; 246 Function /* Comparator<K> */_comparator;
247 247
248 SplayTreeMap([int compare(K key1, K key2)]) 248 SplayTreeMap([int compare(K key1, K key2)])
249 : _comparator = (compare == null) ? Comparable.compare : compare; 249 : _comparator = (compare == null) ? Comparable.compare : compare;
250 250
251 factory SplayTreeMap.from(Map<K, V> other, [int compare(K key1, K key2)]) => 251 factory SplayTreeMap.from(Map<K, V> other, [int compare(K key1, K key2)]) =>
252 new SplayTreeMap(compare)..addAll(other); 252 new SplayTreeMap(compare)..addAll(other);
253 253
254 factory SplayTreeMap.fromIterable(Iterable iterable,
255 {K key(element), V value(element), int compare(K key1, K key2)}) {
256 SplayTreeMap<K, V> map = new SplayTreeMap<K, V>(compare);
257 Maps._fillMapWithMappedIterable(map, iterable, key: key, value: value);
258 return map;
259 }
260
261 factory SplayTreeMap.fromIterables(Iterable<K> keys, Iterable<V> values,
262 [int compare(K key1, K key2)]) {
263 SplayTreeMap<K, V> map = new SplayTreeMap<K, V>(compare);
264 Maps._fillMapWithIterables(map, keys, values);
265 return map;
266 }
267
254 int _compare(K key1, K key2) => _comparator(key1, key2); 268 int _compare(K key1, K key2) => _comparator(key1, key2);
255 269
256 SplayTreeMap._internal(); 270 SplayTreeMap._internal();
257 271
258 V operator [](Object key) { 272 V operator [](Object key) {
259 if (key == null) throw new ArgumentError(key); 273 if (key == null) throw new ArgumentError(key);
260 if (key is! K) return null; 274 if (key is! K) return null;
261 if (_root != null) { 275 if (_root != null) {
262 int comp = _splay(key); 276 int comp = _splay(key);
263 if (comp == 0) { 277 if (comp == 0) {
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 class _SplayTreeValueIterator<K, V> extends _SplayTreeIterator<V> { 551 class _SplayTreeValueIterator<K, V> extends _SplayTreeIterator<V> {
538 _SplayTreeValueIterator(SplayTreeMap<K, V> map): super(map); 552 _SplayTreeValueIterator(SplayTreeMap<K, V> map): super(map);
539 V _getValue(_SplayTreeMapNode node) => node.value; 553 V _getValue(_SplayTreeMapNode node) => node.value;
540 } 554 }
541 555
542 class _SplayTreeNodeIterator<K> 556 class _SplayTreeNodeIterator<K>
543 extends _SplayTreeIterator<_SplayTreeNode<K>> { 557 extends _SplayTreeIterator<_SplayTreeNode<K>> {
544 _SplayTreeNodeIterator(_SplayTree<K> map): super(map); 558 _SplayTreeNodeIterator(_SplayTree<K> map): super(map);
545 _SplayTreeNode<K> _getValue(_SplayTreeNode node) => node; 559 _SplayTreeNode<K> _getValue(_SplayTreeNode node) => node;
546 } 560 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698