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

Side by Side Diff: src/splay-tree.h

Issue 10443114: Progress towards making Zones independent of Isolates and Threads. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix nits and rebase on current bleeding_edge Created 8 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/safepoint-table.h ('k') | src/splay-tree-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 // static const kNoValue: the dummy value used to initialize nodes 43 // static const kNoValue: the dummy value used to initialize nodes
44 // int (Compare)(Key& a, Key& b) -> {-1, 0, 1}: comparison function 44 // int (Compare)(Key& a, Key& b) -> {-1, 0, 1}: comparison function
45 // 45 //
46 // The tree is also parameterized by an allocation policy 46 // The tree is also parameterized by an allocation policy
47 // (Allocator). The policy is used for allocating lists in the C free 47 // (Allocator). The policy is used for allocating lists in the C free
48 // store or the zone; see zone.h. 48 // store or the zone; see zone.h.
49 49
50 // Forward defined as 50 // Forward defined as
51 // template <typename Config, class Allocator = FreeStoreAllocationPolicy> 51 // template <typename Config, class Allocator = FreeStoreAllocationPolicy>
52 // class SplayTree; 52 // class SplayTree;
53 template <typename Config, class Allocator> 53 template <typename Config, class AllocationPolicy>
54 class SplayTree { 54 class SplayTree {
55 public: 55 public:
56 typedef typename Config::Key Key; 56 typedef typename Config::Key Key;
57 typedef typename Config::Value Value; 57 typedef typename Config::Value Value;
58 58
59 class Locator; 59 class Locator;
60 60
61 SplayTree() : root_(NULL) { } 61 SplayTree() : root_(NULL) { }
62 ~SplayTree(); 62 ~SplayTree();
63 63
64 INLINE(void* operator new(size_t size)) { 64 INLINE(void* operator new(size_t size,
65 return Allocator::New(static_cast<int>(size)); 65 AllocationPolicy allocator = AllocationPolicy())) {
66 return allocator.New(static_cast<int>(size));
66 } 67 }
67 INLINE(void operator delete(void* p, size_t)) { return Allocator::Delete(p); } 68 INLINE(void operator delete(void* p, size_t)) {
69 AllocationPolicy::Delete(p);
70 }
68 71
69 // Inserts the given key in this tree with the given value. Returns 72 // Inserts the given key in this tree with the given value. Returns
70 // true if a node was inserted, otherwise false. If found the locator 73 // true if a node was inserted, otherwise false. If found the locator
71 // is enabled and provides access to the mapping for the key. 74 // is enabled and provides access to the mapping for the key.
72 bool Insert(const Key& key, Locator* locator); 75 bool Insert(const Key& key, Locator* locator,
76 AllocationPolicy allocator = AllocationPolicy());
73 77
74 // Looks up the key in this tree and returns true if it was found, 78 // Looks up the key in this tree and returns true if it was found,
75 // otherwise false. If the node is found the locator is enabled and 79 // otherwise false. If the node is found the locator is enabled and
76 // provides access to the mapping for the key. 80 // provides access to the mapping for the key.
77 bool Find(const Key& key, Locator* locator); 81 bool Find(const Key& key, Locator* locator);
78 82
79 // Finds the mapping with the greatest key less than or equal to the 83 // Finds the mapping with the greatest key less than or equal to the
80 // given key. 84 // given key.
81 bool FindGreatestLessThan(const Key& key, Locator* locator); 85 bool FindGreatestLessThan(const Key& key, Locator* locator);
82 86
(...skipping 22 matching lines...) Expand all
105 void Splay(const Key& key); 109 void Splay(const Key& key);
106 110
107 class Node { 111 class Node {
108 public: 112 public:
109 Node(const Key& key, const Value& value) 113 Node(const Key& key, const Value& value)
110 : key_(key), 114 : key_(key),
111 value_(value), 115 value_(value),
112 left_(NULL), 116 left_(NULL),
113 right_(NULL) { } 117 right_(NULL) { }
114 118
115 INLINE(void* operator new(size_t size)) { 119 INLINE(void* operator new(size_t size, AllocationPolicy allocator)) {
116 return Allocator::New(static_cast<int>(size)); 120 return allocator.New(static_cast<int>(size));
117 } 121 }
118 INLINE(void operator delete(void* p, size_t)) { 122 INLINE(void operator delete(void* p, size_t)) {
119 return Allocator::Delete(p); 123 return AllocationPolicy::Delete(p);
120 } 124 }
121 125
122 Key key() { return key_; } 126 Key key() { return key_; }
123 Value value() { return value_; } 127 Value value() { return value_; }
124 Node* left() { return left_; } 128 Node* left() { return left_; }
125 Node* right() { return right_; } 129 Node* right() { return right_; }
126 130
127 private: 131 private:
128 friend class SplayTree; 132 friend class SplayTree;
129 friend class Locator; 133 friend class Locator;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 181
178 private: 182 private:
179 Callback* callback_; 183 Callback* callback_;
180 184
181 DISALLOW_COPY_AND_ASSIGN(NodeToPairAdaptor); 185 DISALLOW_COPY_AND_ASSIGN(NodeToPairAdaptor);
182 }; 186 };
183 187
184 class NodeDeleter BASE_EMBEDDED { 188 class NodeDeleter BASE_EMBEDDED {
185 public: 189 public:
186 NodeDeleter() { } 190 NodeDeleter() { }
187 void Call(Node* node) { delete node; } 191 void Call(Node* node) { AllocationPolicy::Delete(node); }
188 192
189 private: 193 private:
190 DISALLOW_COPY_AND_ASSIGN(NodeDeleter); 194 DISALLOW_COPY_AND_ASSIGN(NodeDeleter);
191 }; 195 };
192 196
193 template <class Callback> 197 template <class Callback>
194 void ForEachNode(Callback* callback); 198 void ForEachNode(Callback* callback,
199 AllocationPolicy allocator = AllocationPolicy());
195 200
196 Node* root_; 201 Node* root_;
197 202
198 DISALLOW_COPY_AND_ASSIGN(SplayTree); 203 DISALLOW_COPY_AND_ASSIGN(SplayTree);
199 }; 204 };
200 205
201 206
202 } } // namespace v8::internal 207 } } // namespace v8::internal
203 208
204 #endif // V8_SPLAY_TREE_H_ 209 #endif // V8_SPLAY_TREE_H_
OLDNEW
« no previous file with comments | « src/safepoint-table.h ('k') | src/splay-tree-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698