Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 } |
| OLD | NEW |