Introduce splaytree.KeyNotFoundError and use it for reporting
issues when removing non-existing nodes from a SplayTree. Review URL: http://codereview.chromium.org/42599 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1609 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
bd8816efb0
commit
fc0af92f60
@ -36,6 +36,13 @@ class Node(object):
|
||||
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 @@ class SplayTree(object):
|
||||
"""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:
|
||||
|
@ -235,14 +235,14 @@ class TickProcessor(object):
|
||||
removed_node = self.js_entries.Remove(from_addr)
|
||||
removed_node.value.SetStartAddress(to_addr);
|
||||
self.js_entries.Insert(to_addr, removed_node.value)
|
||||
except 'KeyNotFound':
|
||||
except splaytree.KeyNotFoundError:
|
||||
print('Code move event for unknown code: 0x%x' % from_addr)
|
||||
|
||||
def ProcessCodeDelete(self, from_addr):
|
||||
try:
|
||||
removed_node = self.js_entries.Remove(from_addr)
|
||||
self.deleted_code.append(removed_node.value)
|
||||
except 'KeyNotFound':
|
||||
except splaytree.KeyNotFoundError:
|
||||
print('Code delete event for unknown code: 0x%x' % from_addr)
|
||||
|
||||
def ProcessBeginCodeRegion(self, id, assm, start, name):
|
||||
|
Loading…
Reference in New Issue
Block a user