GRPC C++  1.26.0
avl.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPC_CORE_LIB_AVL_AVL_H
20 #define GRPC_CORE_LIB_AVL_AVL_H
21 
23 
24 #include <grpc/support/sync.h>
25 
27 typedef struct grpc_avl_node {
29  void* key;
30  void* value;
33  long height;
35 
41 typedef struct grpc_avl_vtable {
43  void (*destroy_key)(void* key, void* user_data);
45  void* (*copy_key)(void* key, void* user_data);
48  long (*compare_keys)(void* key1, void* key2, void* user_data);
50  void (*destroy_value)(void* value, void* user_data);
52  void* (*copy_value)(void* value, void* user_data);
54 
58 typedef struct grpc_avl {
61 } grpc_avl;
62 
68 grpc_avl grpc_avl_ref(grpc_avl avl, void* user_data);
72 void grpc_avl_unref(grpc_avl avl, void* user_data);
78 grpc_avl grpc_avl_add(grpc_avl avl, void* key, void* value, void* user_data);
82 grpc_avl grpc_avl_remove(grpc_avl avl, void* key, void* user_data);
87 void* grpc_avl_get(grpc_avl avl, void* key, void* user_data);
90 int grpc_avl_maybe_get(grpc_avl avl, void* key, void** value, void* user_data);
93 
94 #endif /* GRPC_CORE_LIB_AVL_AVL_H */
void * grpc_avl_get(grpc_avl avl, void *key, void *user_data)
Lookup key, and return the associated value.
struct grpc_avl_node grpc_avl_node
internal node of an AVL tree
void grpc_avl_unref(grpc_avl avl, void *user_data)
Remove a reference to a tree - destroying it if there are no references left.
Definition: sync_generic.h:36
long height
Definition: avl.h:33
void(* destroy_key)(void *key, void *user_data)
destroy a key
Definition: avl.h:43
void(* destroy_value)(void *value, void *user_data)
destroy a value
Definition: avl.h:50
grpc_avl grpc_avl_add(grpc_avl avl, void *key, void *value, void *user_data)
Return a new tree with (key, value) added to avl.
int grpc_avl_maybe_get(grpc_avl avl, void *key, void **value, void *user_data)
Return 1 if avl contains key, 0 otherwise; if it has the key, sets *value to its value.
void * value
Definition: avl.h:30
grpc_avl grpc_avl_ref(grpc_avl avl, void *user_data)
Add a reference to an existing tree - returns the tree as a convenience.
struct grpc_avl grpc_avl
"pointer" to an AVL tree - this is a reference counted object - use grpc_avl_ref to add a reference...
grpc_avl grpc_avl_create(const grpc_avl_vtable *vtable)
Create an immutable AVL tree.
const grpc_avl_vtable * vtable
Definition: avl.h:59
grpc_avl grpc_avl_remove(grpc_avl avl, void *key, void *user_data)
Return a new tree with key deleted implicitly unrefs avl to allow easy chaining.
internal node of an AVL tree
Definition: avl.h:27
long(* compare_keys)(void *key1, void *key2, void *user_data)
compare key1, key2; return <0 if key1 < key2, >0 if key1 > key2, 0 if key1 == key2 ...
Definition: avl.h:48
gpr_refcount refs
Definition: avl.h:28
vtable for the AVL tree The optional user_data is propagated from the top level grpc_avl_XXX API...
Definition: avl.h:41
struct grpc_avl_node * right
Definition: avl.h:32
"pointer" to an AVL tree - this is a reference counted object - use grpc_avl_ref to add a reference...
Definition: avl.h:58
struct grpc_avl_vtable grpc_avl_vtable
vtable for the AVL tree The optional user_data is propagated from the top level grpc_avl_XXX API...
struct grpc_avl_node * left
Definition: avl.h:31
grpc_avl_node * root
Definition: avl.h:60
int grpc_avl_is_empty(grpc_avl avl)
Return 1 if avl is empty, 0 otherwise.
void * key
Definition: avl.h:29