V8 Project
v8::internal::SplayTree< Config, AllocationPolicy > Class Template Reference

#include <splay-tree.h>

+ Inheritance diagram for v8::internal::SplayTree< Config, AllocationPolicy >:
+ Collaboration diagram for v8::internal::SplayTree< Config, AllocationPolicy >:

Classes

class  BASE_EMBEDDED
 
class  Node
 

Public Types

typedef Config::Key Key
 
typedef Config::Value Value
 

Public Member Functions

 SplayTree (AllocationPolicy allocator=AllocationPolicy())
 
 ~SplayTree ()
 
 INLINE (void *operator new(size_t size, AllocationPolicy allocator=AllocationPolicy()))
 
 INLINE (void operator delete(void *p))
 
 INLINE (void operator delete(void *p, AllocationPolicy policy))
 
AllocationPolicy allocator ()
 
bool Contains (const Key &key)
 
bool Insert (const Key &key, Locator *locator)
 
bool Find (const Key &key, Locator *locator)
 
bool FindGreatestLessThan (const Key &key, Locator *locator)
 
bool FindGreatest (Locator *locator)
 
bool FindLeastGreaterThan (const Key &key, Locator *locator)
 
bool FindLeast (Locator *locator)
 
bool Move (const Key &old_key, const Key &new_key)
 
bool Remove (const Key &key)
 
void Clear ()
 
bool is_empty ()
 
void Splay (const Key &key)
 
template<class Callback >
void ForEach (Callback *callback)
 

Protected Member Functions

void ResetRoot ()
 

Private Member Functions

bool FindInternal (const Key &key)
 
void InsertInternal (int cmp, Node *node)
 
void RemoveRootNode (const Key &key)
 
template<class Callback >
void ForEachNode (Callback *callback)
 
 DISALLOW_COPY_AND_ASSIGN (SplayTree)
 

Private Attributes

Noderoot_
 
AllocationPolicy allocator_
 

Detailed Description

template<typename Config, class AllocationPolicy>
class v8::internal::SplayTree< Config, AllocationPolicy >

Definition at line 31 of file splay-tree.h.

Member Typedef Documentation

◆ Key

template<typename Config , class AllocationPolicy >
typedef Config::Key v8::internal::SplayTree< Config, AllocationPolicy >::Key

Definition at line 33 of file splay-tree.h.

◆ Value

template<typename Config , class AllocationPolicy >
typedef Config::Value v8::internal::SplayTree< Config, AllocationPolicy >::Value

Definition at line 34 of file splay-tree.h.

Constructor & Destructor Documentation

◆ SplayTree()

template<typename Config , class AllocationPolicy >
v8::internal::SplayTree< Config, AllocationPolicy >::SplayTree ( AllocationPolicy  allocator = AllocationPolicy())
inlineexplicit

Definition at line 38 of file splay-tree.h.

AllocationPolicy allocator()
Definition: splay-tree.h:54
AllocationPolicy allocator_
Definition: splay-tree.h:195
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL

◆ ~SplayTree()

template<typename Config , class Allocator >
v8::internal::SplayTree< Config, Allocator >::~SplayTree

Definition at line 15 of file splay-tree-inl.h.

15  {
16  NodeDeleter deleter;
17  ForEachNode(&deleter);
18 }
void ForEachNode(Callback *callback)

Member Function Documentation

◆ allocator()

template<typename Config , class AllocationPolicy >
AllocationPolicy v8::internal::SplayTree< Config, AllocationPolicy >::allocator ( )
inline

Definition at line 54 of file splay-tree.h.

54 { return allocator_; }

References v8::internal::SplayTree< Config, AllocationPolicy >::allocator_.

Referenced by v8::internal::SplayTree< Config, AllocationPolicy >::Node::INLINE(), v8::internal::SplayTree< Config, AllocationPolicy >::INLINE(), and v8::internal::EffectsBase< Var, kNoVar >::zone().

+ Here is the caller graph for this function:

◆ Clear()

template<typename Config , class AllocationPolicy >
void v8::internal::SplayTree< Config, AllocationPolicy >::Clear ( )
inline

Definition at line 90 of file splay-tree.h.

90 { ResetRoot(); }

References v8::internal::SplayTree< Config, AllocationPolicy >::ResetRoot().

+ Here is the call graph for this function:

◆ Contains()

template<typename Config , class Allocator >
bool v8::internal::SplayTree< Config, Allocator >::Contains ( const Key key)

Definition at line 71 of file splay-tree-inl.h.

71  {
72  return FindInternal(key);
73 }
bool FindInternal(const Key &key)

Referenced by v8::internal::EffectsBase< Var, kNoVar >::Contains().

+ Here is the caller graph for this function:

◆ DISALLOW_COPY_AND_ASSIGN()

template<typename Config , class AllocationPolicy >
v8::internal::SplayTree< Config, AllocationPolicy >::DISALLOW_COPY_AND_ASSIGN ( SplayTree< Config, AllocationPolicy )
private

◆ Find()

template<typename Config , class Allocator >
bool v8::internal::SplayTree< Config, Allocator >::Find ( const Key key,
Locator *  locator 
)

Definition at line 77 of file splay-tree-inl.h.

77  {
78  if (FindInternal(key)) {
79  locator->bind(root_);
80  return true;
81  } else {
82  return false;
83  }
84 }

Referenced by v8::internal::CodeMap::GetSharedId(), and v8::internal::CodeMap::MoveCode().

+ Here is the caller graph for this function:

◆ FindGreatest()

template<typename Config , class Allocator >
bool v8::internal::SplayTree< Config, Allocator >::FindGreatest ( Locator *  locator)

Definition at line 136 of file splay-tree-inl.h.

136  {
137  if (is_empty())
138  return false;
139  Node* current = root_;
140  while (current->right_ != NULL)
141  current = current->right_;
142  locator->bind(current);
143  return true;
144 }

References NULL, and v8::internal::SplayTree< Config, AllocationPolicy >::Node::right_.

◆ FindGreatestLessThan()

template<typename Config , class Allocator >
bool v8::internal::SplayTree< Config, Allocator >::FindGreatestLessThan ( const Key key,
Locator *  locator 
)

Definition at line 88 of file splay-tree-inl.h.

89  {
90  if (is_empty())
91  return false;
92  // Splay on the key to move the node with the given key or the last
93  // node on the search path to the top of the tree.
94  Splay(key);
95  // Now the result is either the root node or the greatest node in
96  // the left subtree.
97  int cmp = Config::Compare(root_->key_, key);
98  if (cmp <= 0) {
99  locator->bind(root_);
100  return true;
101  } else {
102  Node* temp = root_;
103  root_ = root_->left_;
104  bool result = FindGreatest(locator);
105  root_ = temp;
106  return result;
107  }
108 }
bool FindGreatest(Locator *locator)
void Splay(const Key &key)
int Compare(const T &a, const T &b)
Definition: utils.h:96

References v8::internal::Compare().

Referenced by v8::internal::CodeMap::DeleteAllCoveredCode(), and v8::internal::CodeMap::FindEntry().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FindInternal()

template<typename Config , class Allocator >
bool v8::internal::SplayTree< Config, Allocator >::FindInternal ( const Key key)
private

Definition at line 62 of file splay-tree-inl.h.

62  {
63  if (is_empty())
64  return false;
65  Splay(key);
66  return Config::Compare(key, root_->key_) == 0;
67 }

References v8::internal::Compare().

+ Here is the call graph for this function:

◆ FindLeast()

template<typename Config , class Allocator >
bool v8::internal::SplayTree< Config, Allocator >::FindLeast ( Locator *  locator)

Definition at line 148 of file splay-tree-inl.h.

148  {
149  if (is_empty())
150  return false;
151  Node* current = root_;
152  while (current->left_ != NULL)
153  current = current->left_;
154  locator->bind(current);
155  return true;
156 }

◆ FindLeastGreaterThan()

template<typename Config , class Allocator >
bool v8::internal::SplayTree< Config, Allocator >::FindLeastGreaterThan ( const Key key,
Locator *  locator 
)

Definition at line 112 of file splay-tree-inl.h.

113  {
114  if (is_empty())
115  return false;
116  // Splay on the key to move the node with the given key or the last
117  // node on the search path to the top of the tree.
118  Splay(key);
119  // Now the result is either the root node or the least node in
120  // the right subtree.
121  int cmp = Config::Compare(root_->key_, key);
122  if (cmp >= 0) {
123  locator->bind(root_);
124  return true;
125  } else {
126  Node* temp = root_;
127  root_ = root_->right_;
128  bool result = FindLeast(locator);
129  root_ = temp;
130  return result;
131  }
132 }
bool FindLeast(Locator *locator)

References v8::internal::Compare(), and v8::internal::SplayTree< Config, AllocationPolicy >::Node::right_.

+ Here is the call graph for this function:

◆ ForEach()

template<typename Config , class Allocator >
template<class Callback >
void v8::internal::SplayTree< Config, Allocator >::ForEach ( Callback *  callback)

Definition at line 271 of file splay-tree-inl.h.

271  {
272  NodeToPairAdaptor<Callback> callback_adaptor(callback);
273  ForEachNode(&callback_adaptor);
274 }

Referenced by v8::internal::EffectsBase< Var, kNoVar >::ForEach(), and v8::internal::CodeMap::Print().

+ Here is the caller graph for this function:

◆ ForEachNode()

template<typename Config , class Allocator >
template<class Callback >
void v8::internal::SplayTree< Config, Allocator >::ForEachNode ( Callback *  callback)
private

Definition at line 278 of file splay-tree-inl.h.

278  {
279  if (root_ == NULL) return;
280  // Pre-allocate some space for tiny trees.
281  List<Node*, Allocator> nodes_to_visit(10, allocator_);
282  nodes_to_visit.Add(root_, allocator_);
283  int pos = 0;
284  while (pos < nodes_to_visit.length()) {
285  Node* node = nodes_to_visit[pos++];
286  if (node->left() != NULL) nodes_to_visit.Add(node->left(), allocator_);
287  if (node->right() != NULL) nodes_to_visit.Add(node->right(), allocator_);
288  callback->Call(node);
289  }
290 }

References v8::internal::List< T, AllocationPolicy >::Add(), v8::internal::SplayTree< Config, AllocationPolicy >::Node::left(), NULL, and v8::internal::SplayTree< Config, AllocationPolicy >::Node::right().

+ Here is the call graph for this function:

◆ INLINE() [1/3]

template<typename Config , class AllocationPolicy >
v8::internal::SplayTree< Config, AllocationPolicy >::INLINE ( void *operator   newsize_t size, AllocationPolicy allocator=AllocationPolicy())
inline

Definition at line 42 of file splay-tree.h.

43  {
44  return allocator.New(static_cast<int>(size));
45  }
enable harmony numeric enable harmony object literal extensions Optimize object size

References v8::internal::SplayTree< Config, AllocationPolicy >::allocator(), and size.

+ Here is the call graph for this function:

◆ INLINE() [2/3]

template<typename Config , class AllocationPolicy >
v8::internal::SplayTree< Config, AllocationPolicy >::INLINE ( void operator   deletevoid *p)
inline

Definition at line 46 of file splay-tree.h.

46  {
47  AllocationPolicy::Delete(p);
48  }

◆ INLINE() [3/3]

template<typename Config , class AllocationPolicy >
v8::internal::SplayTree< Config, AllocationPolicy >::INLINE ( void operator   deletevoid *p, AllocationPolicy policy)
inline

Definition at line 50 of file splay-tree.h.

50  {
51  UNREACHABLE();
52  }
#define UNREACHABLE()
Definition: logging.h:30

References UNREACHABLE.

◆ Insert()

template<typename Config , class Allocator >
bool v8::internal::SplayTree< Config, Allocator >::Insert ( const Key key,
Locator *  locator 
)

Definition at line 22 of file splay-tree-inl.h.

23  {
24  if (is_empty()) {
25  // If the tree is empty, insert the new node.
26  root_ = new(allocator_) Node(key, Config::NoValue());
27  } else {
28  // Splay on the key to move the last node on the search path
29  // for the key to the root of the tree.
30  Splay(key);
31  // Ignore repeated insertions with the same key.
32  int cmp = Config::Compare(key, root_->key_);
33  if (cmp == 0) {
34  locator->bind(root_);
35  return false;
36  }
37  // Insert the new node.
38  Node* node = new(allocator_) Node(key, Config::NoValue());
39  InsertInternal(cmp, node);
40  }
41  locator->bind(root_);
42  return true;
43 }
void InsertInternal(int cmp, Node *node)

References v8::internal::Compare().

Referenced by v8::internal::CodeMap::AddCode(), and v8::internal::CodeMap::GetSharedId().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ InsertInternal()

template<typename Config , class Allocator >
void v8::internal::SplayTree< Config, Allocator >::InsertInternal ( int  cmp,
Node node 
)
private

Definition at line 47 of file splay-tree-inl.h.

47  {
48  if (cmp > 0) {
49  node->left_ = root_;
50  node->right_ = root_->right_;
51  root_->right_ = NULL;
52  } else {
53  node->right_ = root_;
54  node->left_ = root_->left_;
55  root_->left_ = NULL;
56  }
57  root_ = node;
58 }

References v8::internal::SplayTree< Config, AllocationPolicy >::Node::left_, NULL, and v8::internal::SplayTree< Config, AllocationPolicy >::Node::right_.

◆ is_empty()

template<typename Config , class AllocationPolicy >
bool v8::internal::SplayTree< Config, AllocationPolicy >::is_empty ( )
inline

Definition at line 92 of file splay-tree.h.

92 { return root_ == NULL; }

References NULL, and v8::internal::SplayTree< Config, AllocationPolicy >::root_.

◆ Move()

template<typename Config , class Allocator >
bool v8::internal::SplayTree< Config, Allocator >::Move ( const Key old_key,
const Key new_key 
)

Definition at line 160 of file splay-tree-inl.h.

161  {
162  if (!FindInternal(old_key))
163  return false;
164  Node* node_to_move = root_;
165  RemoveRootNode(old_key);
166  Splay(new_key);
167  int cmp = Config::Compare(new_key, root_->key_);
168  if (cmp == 0) {
169  // A node with the target key already exists.
170  delete node_to_move;
171  return false;
172  }
173  node_to_move->key_ = new_key;
174  InsertInternal(cmp, node_to_move);
175  return true;
176 }
void RemoveRootNode(const Key &key)

◆ Remove()

template<typename Config , class Allocator >
bool v8::internal::SplayTree< Config, Allocator >::Remove ( const Key key)

Definition at line 180 of file splay-tree-inl.h.

180  {
181  if (!FindInternal(key))
182  return false;
183  Node* node_to_remove = root_;
184  RemoveRootNode(key);
185  delete node_to_remove;
186  return true;
187 }

Referenced by v8::internal::CodeMap::DeleteAllCoveredCode(), and v8::internal::CodeMap::MoveCode().

+ Here is the caller graph for this function:

◆ RemoveRootNode()

template<typename Config , class Allocator >
void v8::internal::SplayTree< Config, Allocator >::RemoveRootNode ( const Key key)
private

Definition at line 191 of file splay-tree-inl.h.

191  {
192  if (root_->left_ == NULL) {
193  // No left child, so the new tree is just the right child.
194  root_ = root_->right_;
195  } else {
196  // Left child exists.
197  Node* right = root_->right_;
198  // Make the original left child the new root.
199  root_ = root_->left_;
200  // Splay to make sure that the new root has an empty right child.
201  Splay(key);
202  // Insert the original right child as the right child of the new
203  // root.
204  root_->right_ = right;
205  }
206 }

◆ ResetRoot()

template<typename Config , class AllocationPolicy >
void v8::internal::SplayTree< Config, AllocationPolicy >::ResetRoot ( )
inlineprotected

Definition at line 154 of file splay-tree.h.

154 { root_ = NULL; }

References NULL, and v8::internal::SplayTree< Config, AllocationPolicy >::root_.

Referenced by v8::internal::SplayTree< Config, AllocationPolicy >::Clear(), and v8::internal::ZoneSplayTree< Config >::~ZoneSplayTree().

+ Here is the caller graph for this function:

◆ Splay()

template<typename Config , class Allocator >
void v8::internal::SplayTree< Config, Allocator >::Splay ( const Key key)

Definition at line 210 of file splay-tree-inl.h.

210  {
211  if (is_empty())
212  return;
213  Node dummy_node(Config::kNoKey, Config::NoValue());
214  // Create a dummy node. The use of the dummy node is a bit
215  // counter-intuitive: The right child of the dummy node will hold
216  // the L tree of the algorithm. The left child of the dummy node
217  // will hold the R tree of the algorithm. Using a dummy node, left
218  // and right will always be nodes and we avoid special cases.
219  Node* dummy = &dummy_node;
220  Node* left = dummy;
221  Node* right = dummy;
222  Node* current = root_;
223  while (true) {
224  int cmp = Config::Compare(key, current->key_);
225  if (cmp < 0) {
226  if (current->left_ == NULL)
227  break;
228  if (Config::Compare(key, current->left_->key_) < 0) {
229  // Rotate right.
230  Node* temp = current->left_;
231  current->left_ = temp->right_;
232  temp->right_ = current;
233  current = temp;
234  if (current->left_ == NULL)
235  break;
236  }
237  // Link right.
238  right->left_ = current;
239  right = current;
240  current = current->left_;
241  } else if (cmp > 0) {
242  if (current->right_ == NULL)
243  break;
244  if (Config::Compare(key, current->right_->key_) > 0) {
245  // Rotate left.
246  Node* temp = current->right_;
247  current->right_ = temp->left_;
248  temp->left_ = current;
249  current = temp;
250  if (current->right_ == NULL)
251  break;
252  }
253  // Link left.
254  left->right_ = current;
255  left = current;
256  current = current->right_;
257  } else {
258  break;
259  }
260  }
261  // Assemble.
262  left->right_ = current->left_;
263  right->left_ = current->right_;
264  current->left_ = dummy->right_;
265  current->right_ = dummy->left_;
266  root_ = current;
267 }

References v8::internal::Compare(), v8::internal::SplayTree< Config, AllocationPolicy >::Node::key_, v8::internal::SplayTree< Config, AllocationPolicy >::Node::left_, NULL, and v8::internal::SplayTree< Config, AllocationPolicy >::Node::right_.

+ Here is the call graph for this function:

Member Data Documentation

◆ allocator_

template<typename Config , class AllocationPolicy >
AllocationPolicy v8::internal::SplayTree< Config, AllocationPolicy >::allocator_
private

◆ root_

template<typename Config , class AllocationPolicy >
Node* v8::internal::SplayTree< Config, AllocationPolicy >::root_
private

The documentation for this class was generated from the following files: