Go to the documentation of this file.
15 #ifndef GRPC_CORE_LIB_AVL_AVL_H
16 #define GRPC_CORE_LIB_AVL_AVL_H
29 template <
class K,
class V =
void>
37 template <
typename SomethingLikeK>
41 template <
typename SomethingLikeK>
44 return n ? &
n->kv.second :
nullptr;
49 return n ? &
n->kv :
nullptr;
65 Node* p =
a.current();
66 Node* q =
b.current();
67 if (p ==
nullptr)
return q ==
nullptr;
68 if (q ==
nullptr)
return false;
69 if (p->kv != q->kv)
return false;
79 Node* p =
a.current();
80 Node* q =
b.current();
81 if (p ==
nullptr)
return q !=
nullptr;
82 if (q ==
nullptr)
return false;
83 if (p->kv < q->kv)
return true;
84 if (p->kv != q->kv)
return false;
93 typedef std::shared_ptr<Node>
NodePtr;
94 struct Node :
public std::enable_shared_from_this<Node> {
100 const std::pair<K, V>
kv;
111 while (
n !=
nullptr) {
120 if (
n->right !=
nullptr) {
122 while (
n !=
nullptr) {
137 if (
n ==
nullptr)
return;
139 f(
const_cast<const K&
>(
n->kv.first),
const_cast<const V&
>(
n->kv.second));
151 template <
typename SomethingLikeK>
153 if (node ==
nullptr) {
157 if (node->kv.first >
key) {
158 return Get(node->left,
key);
159 }
else if (node->kv.first <
key) {
160 return Get(node->right,
key);
167 if (!node)
return nullptr;
168 if (node->kv.first >
key) {
170 }
else if (node->kv.first <
key) {
172 if (
n ==
nullptr)
n = node;
182 right->kv.first, right->kv.second,
190 left->kv.first, left->kv.second, left->left,
198 left->right->kv.first, left->right->kv.second,
199 MakeNode(left->kv.first, left->kv.second, left->left,
208 right->left->kv.first, right->left->kv.second,
210 MakeNode(right->kv.first, right->kv.second, right->left->right,
238 if (node->kv.first <
key) {
239 return Rebalance(node->kv.first, node->kv.second, node->left,
242 if (key < node->kv.first) {
243 return Rebalance(node->kv.first, node->kv.second,
251 while (node->left !=
nullptr) {
258 while (node->right !=
nullptr) {
264 template <
typename SomethingLikeK>
266 if (node ==
nullptr) {
269 if (key < node->kv.first) {
270 return Rebalance(node->kv.first, node->kv.second,
272 }
else if (node->kv.first <
key) {
273 return Rebalance(node->kv.first, node->kv.second, node->left,
276 if (node->left ==
nullptr) {
278 }
else if (node->right ==
nullptr) {
280 }
else if (node->left->height < node->right->height) {
282 return Rebalance(h->kv.first, h->kv.second, node->left,
286 return Rebalance(h->kv.first, h->kv.second,
287 RemoveKey(node->left, h->kv.first), node->right);
314 typedef std::shared_ptr<Node>
NodePtr;
315 struct Node :
public std::enable_shared_from_this<Node> {
332 if (
n ==
nullptr)
return;
334 f(
const_cast<const K&
>(
n->key));
341 return std::make_shared<Node>(
std::move(
key), left, right,
346 if (node ==
nullptr) {
350 if (node->key >
key) {
351 return Get(node->left,
key);
352 }
else if (node->key <
key) {
353 return Get(node->right,
key);
365 return MakeNode(left->key, left->left,
373 MakeNode(left->key, left->left, left->right->left),
382 MakeNode(right->key, right->left->right, right->right));
408 if (node->key <
key) {
412 if (key < node->
key) {
420 while (node->left !=
nullptr) {
427 while (node->right !=
nullptr) {
434 if (node ==
nullptr) {
437 if (key < node->
key) {
439 }
else if (node->key <
key) {
442 if (node->left ==
nullptr) {
444 }
else if (node->right ==
nullptr) {
446 }
else if (node->left->height < node->right->height) {
460 #endif // GRPC_CORE_LIB_AVL_AVL_H
static NodePtr Get(const NodePtr &node, const K &key)
static NodePtr Rebalance(K key, V value, const NodePtr &left, const NodePtr &right)
static long Height(const NodePtr &n)
static NodePtr Rebalance(K key, const NodePtr &left, const NodePtr &right)
static long Height(const NodePtr &n)
const V * Lookup(const SomethingLikeK &key) const
static NodePtr InOrderTail(NodePtr node)
static NodePtr AddKey(const NodePtr &node, K key, V value)
static NodePtr MakeNode(K key, const NodePtr &left, const NodePtr &right)
bool Lookup(const K &key) const
static NodePtr RotateRight(K key, V value, const NodePtr &left, const NodePtr &right)
std::shared_ptr< Node > NodePtr
static NodePtr RotateLeft(K key, const NodePtr &left, const NodePtr &right)
bool SameIdentity(const AVL &avl) const
AVL Remove(const SomethingLikeK &key) const
static NodePtr RotateLeftRight(K key, const NodePtr &left, const NodePtr &right)
static void ForEachImpl(const Node *n, F &&f)
AVL Remove(const K &key) const
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Node(K k, V v, NodePtr l, NodePtr r, long h)
RefCountedPtr< grpc_tls_certificate_provider > root
bool operator==(const AVL &other) const
std::vector< Node * > stack_
AVL Add(K key, V value) const
Node(K k, NodePtr l, NodePtr r, long h)
static NodePtr InOrderTail(NodePtr node)
bool SameIdentity(AVL avl) const
static NodePtr RotateLeftRight(K key, V value, const NodePtr &left, const NodePtr &right)
std::shared_ptr< Node > NodePtr
const std::pair< K, V > kv
static NodePtr RotateLeft(K key, V value, const NodePtr &left, const NodePtr &right)
void ForEach(F &&f) const
bool operator<(const AVL &other) const
static NodePtr InOrderHead(NodePtr node)
Iterator(const NodePtr &root)
static NodePtr InOrderHead(NodePtr node)
void ForEach(F &&f) const
const std::pair< K, V > * LookupBelow(const K &key) const
static NodePtr AddKey(const NodePtr &node, K key)
static NodePtr RotateRightLeft(K key, const NodePtr &left, const NodePtr &right)
static NodePtr RemoveKey(const NodePtr &node, const K &key)
static NodePtr RotateRightLeft(K key, V value, const NodePtr &left, const NodePtr &right)
static NodePtr MakeNode(K key, V value, const NodePtr &left, const NodePtr &right)
static NodePtr Get(const NodePtr &node, const SomethingLikeK &key)
static NodePtr GetBelow(const NodePtr &node, const K &key)
static NodePtr RotateRight(K key, const NodePtr &left, const NodePtr &right)
static void ForEachImpl(const Node *n, F &&f)
static NodePtr RemoveKey(const NodePtr &node, const SomethingLikeK &key)
grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:35