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

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

Issue 9455051: Add getMinimum, getMaximum, getPreceding and getSucceeding to SplayTree. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 10 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 | « no previous file | no next file » | 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) 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 /** 5 /**
6 * A node in a splay tree. It holds the key, the value and the left 6 * A node in a splay tree. It holds the key, the value and the left
7 * and right children in the tree. 7 * and right children in the tree.
8 */ 8 */
9 class SplayTreeNode<K, V> { 9 class SplayTreeNode<K, V> {
10 SplayTreeNode(K k, V v) { 10 SplayTreeNode(K k, V v) {
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 231
232 Collection<V> getValues() { 232 Collection<V> getValues() {
233 List<V> list = new List<V>(); 233 List<V> list = new List<V>();
234 forEach((K k, V v) { list.add(v); }); 234 forEach((K k, V v) { list.add(v); });
235 return list; 235 return list;
236 } 236 }
237 237
238 String toString() { 238 String toString() {
239 return Maps.mapToString(this); 239 return Maps.mapToString(this);
240 } 240 }
241
242 V getMinimum() {
sra1 2012/02/24 22:21:14 Can we avoid the use of 'get' in the name of metho
Anders Johnsen 2012/02/27 06:22:27 I agree, firstKey/lastKey is way better. The user
243 if (_root === null) return null;
244 SplayTreeNode<K, V> node = _root;
sra1 2012/02/24 22:21:14 Should min and max splay the tree? I.e. do you co
Anders Johnsen 2012/02/27 06:22:27 I'm fine with splaying the tree, makes sense! Adde
245 while (node.left !== null) {
246 node = node.left;
247 }
248 return node.value;
249 }
250
251 V getMaximum() {
252 if (_root === null) return null;
253 SplayTreeNode<K, V> node = _root;
254 while (node.right !== null) {
255 node = node.right;
256 }
257 return node.value;
258 }
259
260 V getPreceding(K key) {
sra1 2012/02/24 22:21:14 It feels slightly wrong that preceding and succeed
Anders Johnsen 2012/02/27 06:22:27 Again, yes, this should be keys. I was using the v
261 splay_(key);
262 if (_root === null) return null;
263 SplayTreeNode<K, V> node = _root;
264 if (node.left === null) return null;
265 node = node.left;
266 while (node.right !== null) {
267 node = node.right;
268 }
269 return node.value;
270 }
271
272 V getSucceeding(K key) {
273 splay_(key);
274 if (_root === null) return null;
275 SplayTreeNode<K, V> node = _root;
276 if (node.right === null) return null;
277 node = node.right;
278 while (node.left !== null) {
279 node = node.left;
280 }
281 return node.value;
282 }
241 } 283 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698