| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 // Find the mapping with the greatest key in this tree. | 81 // Find the mapping with the greatest key in this tree. |
| 82 bool FindGreatest(Locator* locator); | 82 bool FindGreatest(Locator* locator); |
| 83 | 83 |
| 84 // Finds the mapping with the least key greater than or equal to the | 84 // Finds the mapping with the least key greater than or equal to the |
| 85 // given key. | 85 // given key. |
| 86 bool FindLeastGreaterThan(const Key& key, Locator* locator); | 86 bool FindLeastGreaterThan(const Key& key, Locator* locator); |
| 87 | 87 |
| 88 // Find the mapping with the least key in this tree. | 88 // Find the mapping with the least key in this tree. |
| 89 bool FindLeast(Locator* locator); | 89 bool FindLeast(Locator* locator); |
| 90 | 90 |
| 91 // Move the node from one key to another. |
| 92 bool Move(const Key& old_key, const Key& new_key); |
| 93 |
| 91 // Remove the node with the given key from the tree. | 94 // Remove the node with the given key from the tree. |
| 92 bool Remove(const Key& key); | 95 bool Remove(const Key& key); |
| 93 | 96 |
| 94 bool is_empty() { return root_ == NULL; } | 97 bool is_empty() { return root_ == NULL; } |
| 95 | 98 |
| 96 // Perform the splay operation for the given key. Moves the node with | 99 // Perform the splay operation for the given key. Moves the node with |
| 97 // the given key to the top of the tree. If no node has the given | 100 // the given key to the top of the tree. If no node has the given |
| 98 // key, the last node on the search path is moved to the top of the | 101 // key, the last node on the search path is moved to the top of the |
| 99 // tree. | 102 // tree. |
| 100 void Splay(const Key& key); | 103 void Splay(const Key& key); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 | 147 |
| 145 template <class Callback> | 148 template <class Callback> |
| 146 void ForEach(Callback* callback); | 149 void ForEach(Callback* callback); |
| 147 | 150 |
| 148 protected: | 151 protected: |
| 149 | 152 |
| 150 // Resets tree root. Existing nodes become unreachable. | 153 // Resets tree root. Existing nodes become unreachable. |
| 151 void ResetRoot() { root_ = NULL; } | 154 void ResetRoot() { root_ = NULL; } |
| 152 | 155 |
| 153 private: | 156 private: |
| 157 // Search for a node with a given key. If found, root_ points |
| 158 // to the node. |
| 159 bool FindInternal(const Key& key); |
| 160 |
| 161 // Inserts a node assuming that root_ is already set up. |
| 162 void InsertInternal(int cmp, Node* node); |
| 163 |
| 164 // Removes root_ node. |
| 165 void RemoveRootNode(const Key& key); |
| 154 | 166 |
| 155 template<class Callback> | 167 template<class Callback> |
| 156 class NodeToPairAdaptor BASE_EMBEDDED { | 168 class NodeToPairAdaptor BASE_EMBEDDED { |
| 157 public: | 169 public: |
| 158 explicit NodeToPairAdaptor(Callback* callback) | 170 explicit NodeToPairAdaptor(Callback* callback) |
| 159 : callback_(callback) { } | 171 : callback_(callback) { } |
| 160 void Call(Node* node) { | 172 void Call(Node* node) { |
| 161 callback_->Call(node->key(), node->value()); | 173 callback_->Call(node->key(), node->value()); |
| 162 } | 174 } |
| 163 | 175 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 182 | 194 |
| 183 Node* root_; | 195 Node* root_; |
| 184 | 196 |
| 185 DISALLOW_COPY_AND_ASSIGN(SplayTree); | 197 DISALLOW_COPY_AND_ASSIGN(SplayTree); |
| 186 }; | 198 }; |
| 187 | 199 |
| 188 | 200 |
| 189 } } // namespace v8::internal | 201 } } // namespace v8::internal |
| 190 | 202 |
| 191 #endif // V8_SPLAY_TREE_H_ | 203 #endif // V8_SPLAY_TREE_H_ |
| OLD | NEW |