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

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

Issue 9616012: Update SplayTreeMap with a work-around for frog. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 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 this.key, V this.value); 10 SplayTreeNode(K this.key, V this.value);
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 splay_(node.key); 267 splay_(node.key);
268 return node.key; 268 return node.key;
269 } 269 }
270 270
271 /** 271 /**
272 * Get the last key in the map that is strictly smaller than [key]. Returns 272 * Get the last key in the map that is strictly smaller than [key]. Returns
273 * [null] if no key was not found. 273 * [null] if no key was not found.
274 */ 274 */
275 K lastKeyBefore(K key) { 275 K lastKeyBefore(K key) {
276 splay_(key); 276 splay_(key);
277 K visit(SplayTreeNode node, [K ifEmpty]) { 277 K visit(SplayTreeNode node, K ifEmpty) {
278 if (node === null) return ifEmpty; 278 if (node === null) return ifEmpty;
279 if (node.key.compareTo(key) >= 0) { 279 if (node.key.compareTo(key) >= 0) {
280 return visit(node.left, ifEmpty); 280 return visit(node.left, ifEmpty);
281 } 281 }
282 if (node.key.compareTo(key) < 0) { 282 if (node.key.compareTo(key) < 0) {
283 return visit(node.right, node.key); 283 return visit(node.right, node.key);
284 } 284 }
285 } 285 }
286 return visit(_root); 286 return visit(_root, null);
287 } 287 }
288 288
289 /** 289 /**
290 * Get the first key in the map that is strictly larger than [key]. Returns 290 * Get the first key in the map that is strictly larger than [key]. Returns
291 * [null] if no key was not found. 291 * [null] if no key was not found.
292 */ 292 */
293 K firstKeyAfter(K key) { 293 K firstKeyAfter(K key) {
294 splay_(key); 294 splay_(key);
295 K visit(SplayTreeNode node, [K ifEmpty]) { 295 K visit(SplayTreeNode node, K ifEmpty) {
296 if (node === null) return ifEmpty; 296 if (node === null) return ifEmpty;
297 if (node.key.compareTo(key) > 0) { 297 if (node.key.compareTo(key) > 0) {
298 return visit(node.left, node.key); 298 return visit(node.left, node.key);
299 } 299 }
300 if (node.key.compareTo(key) <= 0) { 300 if (node.key.compareTo(key) <= 0) {
301 return visit(node.right, ifEmpty); 301 return visit(node.right, ifEmpty);
302 } 302 }
303 } 303 }
304 return visit(_root); 304 return visit(_root, null);
305 } 305 }
306 } 306 }
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