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

Unified Diff: tools/splaytree.py

Issue 42599: Introduce splaytree.KeyNotFoundError and use it for reporting... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/tickprocessor.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/splaytree.py
===================================================================
--- tools/splaytree.py (revision 1606)
+++ tools/splaytree.py (working copy)
@@ -36,6 +36,13 @@
self.right = None
+class KeyNotFoundError(Exception):
+ """KeyNotFoundError is raised when removing a non-existing node."""
+
+ def __init__(self, key):
+ self.key = key
+
+
class SplayTree(object):
"""The splay tree itself is just a reference to the root of the tree."""
@@ -75,12 +82,12 @@
"""Remove the node with the given key from the SplayTree."""
# Raise exception for key that is not found if the tree is empty.
if self.IsEmpty():
- raise Exception('KeyNotFound')
+ raise KeyNotFoundError(key)
# Splay on the key to move the node with the given key to the top.
self.Splay(key)
# Raise exception for key that is not found.
if self.root.key != key:
- raise Exception('KeyNotFound')
+ raise KeyNotFoundError(key)
removed = self.root
# Link out the root node.
if not self.root.left:
« no previous file with comments | « no previous file | tools/tickprocessor.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698