Chromium Code Reviews| Index: src/splay-tree-inl.h |
| diff --git a/src/splay-tree-inl.h b/src/splay-tree-inl.h |
| index 4640ed5b08bdda8509f01ba34ac1e2d788970b04..739bd3169b87f0a59408e5f55e68ff6528f991f8 100644 |
| --- a/src/splay-tree-inl.h |
| +++ b/src/splay-tree-inl.h |
| @@ -34,18 +34,19 @@ namespace v8 { |
| namespace internal { |
| -template<typename Config, class Allocator> |
| -SplayTree<Config, Allocator>::~SplayTree() { |
| - NodeDeleter deleter; |
| +template<typename Config, class P> |
|
danno
2012/05/25 11:03:37
AllocatorPolicy, or Policy (P is not very descript
|
| +SplayTree<Config, P>::~SplayTree() { |
| + NodeDeleter deleter(deallocator_); |
| ForEachNode(&deleter); |
| } |
| -template<typename Config, class Allocator> |
| -bool SplayTree<Config, Allocator>::Insert(const Key& key, Locator* locator) { |
| +template<typename Config, class P> |
| +bool SplayTree<Config, P>::Insert(const Key& key, Locator* locator, |
| + Allocator allocator) { |
| if (is_empty()) { |
| // If the tree is empty, insert the new node. |
| - root_ = new Node(key, Config::NoValue()); |
| + root_ = new(allocator) Node(key, Config::NoValue()); |
| } else { |
| // Splay on the key to move the last node on the search path |
| // for the key to the root of the tree. |
| @@ -57,7 +58,7 @@ bool SplayTree<Config, Allocator>::Insert(const Key& key, Locator* locator) { |
| return false; |
| } |
| // Insert the new node. |
| - Node* node = new Node(key, Config::NoValue()); |
| + Node* node = new(allocator) Node(key, Config::NoValue()); |
| InsertInternal(cmp, node); |
| } |
| locator->bind(root_); |
| @@ -65,8 +66,8 @@ bool SplayTree<Config, Allocator>::Insert(const Key& key, Locator* locator) { |
| } |
| -template<typename Config, class Allocator> |
| -void SplayTree<Config, Allocator>::InsertInternal(int cmp, Node* node) { |
| +template<typename Config, class P> |
| +void SplayTree<Config, P>::InsertInternal(int cmp, Node* node) { |
| if (cmp > 0) { |
| node->left_ = root_; |
| node->right_ = root_->right_; |
| @@ -80,8 +81,8 @@ void SplayTree<Config, Allocator>::InsertInternal(int cmp, Node* node) { |
| } |
| -template<typename Config, class Allocator> |
| -bool SplayTree<Config, Allocator>::FindInternal(const Key& key) { |
| +template<typename Config, class P> |
| +bool SplayTree<Config, P>::FindInternal(const Key& key) { |
| if (is_empty()) |
| return false; |
| Splay(key); |
| @@ -89,8 +90,8 @@ bool SplayTree<Config, Allocator>::FindInternal(const Key& key) { |
| } |
| -template<typename Config, class Allocator> |
| -bool SplayTree<Config, Allocator>::Find(const Key& key, Locator* locator) { |
| +template<typename Config, class P> |
| +bool SplayTree<Config, P>::Find(const Key& key, Locator* locator) { |
| if (FindInternal(key)) { |
| locator->bind(root_); |
| return true; |
| @@ -100,9 +101,9 @@ bool SplayTree<Config, Allocator>::Find(const Key& key, Locator* locator) { |
| } |
| -template<typename Config, class Allocator> |
| -bool SplayTree<Config, Allocator>::FindGreatestLessThan(const Key& key, |
| - Locator* locator) { |
| +template<typename Config, class P> |
| +bool SplayTree<Config, P>::FindGreatestLessThan(const Key& key, |
| + Locator* locator) { |
| if (is_empty()) |
| return false; |
| // Splay on the key to move the node with the given key or the last |
| @@ -124,9 +125,9 @@ bool SplayTree<Config, Allocator>::FindGreatestLessThan(const Key& key, |
| } |
| -template<typename Config, class Allocator> |
| -bool SplayTree<Config, Allocator>::FindLeastGreaterThan(const Key& key, |
| - Locator* locator) { |
| +template<typename Config, class P> |
| +bool SplayTree<Config, P>::FindLeastGreaterThan(const Key& key, |
| + Locator* locator) { |
| if (is_empty()) |
| return false; |
| // Splay on the key to move the node with the given key or the last |
| @@ -148,8 +149,8 @@ bool SplayTree<Config, Allocator>::FindLeastGreaterThan(const Key& key, |
| } |
| -template<typename Config, class Allocator> |
| -bool SplayTree<Config, Allocator>::FindGreatest(Locator* locator) { |
| +template<typename Config, class P> |
| +bool SplayTree<Config, P>::FindGreatest(Locator* locator) { |
| if (is_empty()) |
| return false; |
| Node* current = root_; |
| @@ -160,8 +161,8 @@ bool SplayTree<Config, Allocator>::FindGreatest(Locator* locator) { |
| } |
| -template<typename Config, class Allocator> |
| -bool SplayTree<Config, Allocator>::FindLeast(Locator* locator) { |
| +template<typename Config, class P> |
| +bool SplayTree<Config, P>::FindLeast(Locator* locator) { |
| if (is_empty()) |
| return false; |
| Node* current = root_; |
| @@ -172,9 +173,8 @@ bool SplayTree<Config, Allocator>::FindLeast(Locator* locator) { |
| } |
| -template<typename Config, class Allocator> |
| -bool SplayTree<Config, Allocator>::Move(const Key& old_key, |
| - const Key& new_key) { |
| +template<typename Config, class P> |
| +bool SplayTree<Config, P>::Move(const Key& old_key, const Key& new_key) { |
| if (!FindInternal(old_key)) |
| return false; |
| Node* node_to_move = root_; |
| @@ -183,7 +183,7 @@ bool SplayTree<Config, Allocator>::Move(const Key& old_key, |
| int cmp = Config::Compare(new_key, root_->key_); |
| if (cmp == 0) { |
| // A node with the target key already exists. |
| - delete node_to_move; |
| + deallocator_.Delete(node_to_move); |
| return false; |
| } |
| node_to_move->key_ = new_key; |
| @@ -192,8 +192,8 @@ bool SplayTree<Config, Allocator>::Move(const Key& old_key, |
| } |
| -template<typename Config, class Allocator> |
| -bool SplayTree<Config, Allocator>::Remove(const Key& key) { |
| +template<typename Config, class P> |
| +bool SplayTree<Config, P>::Remove(const Key& key) { |
| if (!FindInternal(key)) |
| return false; |
| Node* node_to_remove = root_; |
| @@ -203,8 +203,8 @@ bool SplayTree<Config, Allocator>::Remove(const Key& key) { |
| } |
| -template<typename Config, class Allocator> |
| -void SplayTree<Config, Allocator>::RemoveRootNode(const Key& key) { |
| +template<typename Config, class P> |
| +void SplayTree<Config, P>::RemoveRootNode(const Key& key) { |
| if (root_->left_ == NULL) { |
| // No left child, so the new tree is just the right child. |
| root_ = root_->right_; |
| @@ -222,8 +222,8 @@ void SplayTree<Config, Allocator>::RemoveRootNode(const Key& key) { |
| } |
| -template<typename Config, class Allocator> |
| -void SplayTree<Config, Allocator>::Splay(const Key& key) { |
| +template<typename Config, class P> |
| +void SplayTree<Config, P>::Splay(const Key& key) { |
| if (is_empty()) |
| return; |
| Node dummy_node(Config::kNoKey, Config::NoValue()); |
| @@ -283,23 +283,24 @@ void SplayTree<Config, Allocator>::Splay(const Key& key) { |
| } |
| -template <typename Config, class Allocator> template <class Callback> |
| -void SplayTree<Config, Allocator>::ForEach(Callback* callback) { |
| +template <typename Config, class P> template <class Callback> |
| +void SplayTree<Config, P>::ForEach(Callback* callback) { |
| NodeToPairAdaptor<Callback> callback_adaptor(callback); |
| ForEachNode(&callback_adaptor); |
| } |
| -template <typename Config, class Allocator> template <class Callback> |
| -void SplayTree<Config, Allocator>::ForEachNode(Callback* callback) { |
| +template <typename Config, class P> template <class Callback> |
| +void SplayTree<Config, P>::ForEachNode(Callback* callback, |
| + Allocator allocator) { |
| // Pre-allocate some space for tiny trees. |
| - List<Node*, Allocator> nodes_to_visit(10); |
| - if (root_ != NULL) nodes_to_visit.Add(root_); |
| + List<Node*, P> nodes_to_visit(10); |
| + if (root_ != NULL) nodes_to_visit.Add(root_, allocator); |
| int pos = 0; |
| while (pos < nodes_to_visit.length()) { |
| Node* node = nodes_to_visit[pos++]; |
| - if (node->left() != NULL) nodes_to_visit.Add(node->left()); |
| - if (node->right() != NULL) nodes_to_visit.Add(node->right()); |
| + if (node->left() != NULL) nodes_to_visit.Add(node->left(), allocator); |
| + if (node->right() != NULL) nodes_to_visit.Add(node->right(), allocator); |
| callback->Call(node); |
| } |
| } |