8#ifndef RUNTIME_PLATFORM_SPLAY_TREE_INL_H_
9#define RUNTIME_PLATFORM_SPLAY_TREE_INL_H_
17template <
typename Config,
class B,
class Allocator>
20 ForEachNode(&deleter);
23template <
typename Config,
class B,
class Allocator>
27 root_ =
new (allocator_)
Node(
key, Config::NoValue());
39 Node* node =
new (allocator_)
Node(
key, Config::NoValue());
40 InsertInternal(cmp, node);
46template <
typename Config,
class B,
class Allocator>
50 node->right_ = root_->right_;
51 root_->right_ =
nullptr;
54 node->left_ = root_->left_;
55 root_->left_ =
nullptr;
60template <
typename Config,
class B,
class Allocator>
67template <
typename Config,
class B,
class Allocator>
69 return FindInternal(
key);
72template <
typename Config,
class B,
class Allocator>
74 if (FindInternal(
key)) {
82template <
typename Config,
class B,
class Allocator>
98 bool result = FindGreatest(locator);
104template <
typename Config,
class B,
class Allocator>
115 locator->
bind(root_);
119 root_ = root_->right_;
120 bool result = FindLeast(locator);
126template <
typename Config,
class B,
class Allocator>
129 Node* current = root_;
130 while (current->right_ !=
nullptr)
131 current = current->right_;
132 locator->
bind(current);
136template <
typename Config,
class B,
class Allocator>
139 Node* current = root_;
140 while (current->left_ !=
nullptr)
141 current = current->left_;
142 locator->
bind(current);
146template <
typename Config,
class B,
class Allocator>
148 const Key& new_key) {
149 if (!FindInternal(old_key))
return false;
150 Node* node_to_move = root_;
151 RemoveRootNode(old_key);
159 node_to_move->key_ = new_key;
160 InsertInternal(cmp, node_to_move);
164template <
typename Config,
class B,
class Allocator>
166 if (!FindInternal(
key))
return false;
167 Node* node_to_remove = root_;
169 delete node_to_remove;
173template <
typename Config,
class B,
class Allocator>
175 if (root_->left_ ==
nullptr) {
177 root_ = root_->right_;
180 Node* right = root_->right_;
182 root_ = root_->left_;
187 root_->right_ = right;
191template <
typename Config,
class B,
class Allocator>
194 Node dummy_node(Config::kNoKey, Config::NoValue());
200 Node* dummy = &dummy_node;
203 Node* current = root_;
207 if (current->left_ ==
nullptr)
break;
210 Node* temp = current->left_;
211 current->left_ = temp->right_;
212 temp->right_ = current;
214 if (current->left_ ==
nullptr)
break;
217 right->left_ = current;
219 current = current->left_;
220 }
else if (cmp > 0) {
221 if (current->right_ ==
nullptr)
break;
224 Node* temp = current->right_;
225 current->right_ = temp->left_;
226 temp->left_ = current;
228 if (current->right_ ==
nullptr)
break;
231 left->right_ = current;
233 current = current->right_;
239 left->right_ = current->left_;
240 right->left_ = current->right_;
241 current->left_ = dummy->right_;
242 current->right_ = dummy->left_;
246template <
typename Config,
class B,
class Allocator>
247template <
class Callback>
249 NodeToPairAdaptor<Callback> callback_adaptor(
callback);
250 ForEachNode(&callback_adaptor);
253template <
typename Config,
class B,
class Allocator>
254template <
class Callback>
256 if (root_ ==
nullptr)
return;
258 std::vector<Node*> nodes_to_visit;
259 nodes_to_visit.push_back(root_);
261 while (
pos < nodes_to_visit.size()) {
262 Node* node = nodes_to_visit[
pos++];
263 if (node->left() !=
nullptr) nodes_to_visit.push_back(node->left());
264 if (node->right() !=
nullptr) nodes_to_visit.push_back(node->right());
static void is_empty(skiatest::Reporter *reporter, const SkPath &p)
void ForEach(Callback *callback)
bool FindLeastGreaterThan(const Key &key, Locator *locator)
bool Insert(const Key &key, Locator *locator)
bool Find(const Key &key, Locator *locator)
void Splay(const Key &key)
bool FindGreatestLessThan(const Key &key, Locator *locator)
bool Move(const Key &old_key, const Key &new_key)
bool FindLeast(Locator *locator)
bool FindGreatest(Locator *locator)
bool Remove(const Key &key)
bool Contains(const Key &key)
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
def Compare(symbols1, symbols2)
std::function< void(MTLRenderPipelineDescriptor *)> Callback