GRPC Core  5.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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_SUPPORT_AVL_H
20 #define GRPC_SUPPORT_AVL_H
21 
22 #include <grpc/support/sync.h>
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
29 typedef struct gpr_avl_node {
31  void* key;
32  void* value;
33  struct gpr_avl_node* left;
35  long height;
36 } gpr_avl_node;
37 
43 typedef struct gpr_avl_vtable {
45  void (*destroy_key)(void* key, void* user_data);
47  void* (*copy_key)(void* key, void* user_data);
50  long (*compare_keys)(void* key1, void* key2, void* user_data);
52  void (*destroy_value)(void* value, void* user_data);
54  void* (*copy_value)(void* value, void* user_data);
56 
60 typedef struct gpr_avl {
63 } gpr_avl;
64 
70 GPRAPI gpr_avl gpr_avl_ref(gpr_avl avl, void* user_data);
74 GPRAPI void gpr_avl_unref(gpr_avl avl, void* user_data);
80 GPRAPI gpr_avl gpr_avl_add(gpr_avl avl, void* key, void* value,
81  void* user_data);
85 GPRAPI gpr_avl gpr_avl_remove(gpr_avl avl, void* key, void* user_data);
90 GPRAPI void* gpr_avl_get(gpr_avl avl, void* key, void* user_data);
93 GPRAPI int gpr_avl_maybe_get(gpr_avl avl, void* key, void** value,
94  void* user_data);
97 
98 #ifdef __cplusplus
99 }
100 #endif
101 
102 #endif /* GRPC_SUPPORT_AVL_H */
vtable for the AVL tree The optional user_data is propagated from the top level gpr_avl_XXX API...
Definition: avl.h:43
struct gpr_avl_node * right
Definition: avl.h:34
void(* destroy_key)(void *key, void *user_data)
destroy a key
Definition: avl.h:45
Definition: sync_generic.h:34
GPRAPI int gpr_avl_is_empty(gpr_avl avl)
Return 1 if avl is empty, 0 otherwise.
GPRAPI gpr_avl gpr_avl_ref(gpr_avl avl, void *user_data)
Add a reference to an existing tree - returns the tree as a convenience.
GPRAPI gpr_avl gpr_avl_remove(gpr_avl avl, void *key, void *user_data)
Return a new tree with key deleted implicitly unrefs avl to allow easy chaining.
"pointer" to an AVL tree - this is a reference counted object - use gpr_avl_ref to add a reference...
Definition: avl.h:60
GPRAPI gpr_avl gpr_avl_add(gpr_avl avl, void *key, void *value, void *user_data)
Return a new tree with (key, value) added to avl.
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:50
void * value
Definition: avl.h:32
#define GPRAPI
Definition: port_platform.h:466
GPRAPI void gpr_avl_unref(gpr_avl avl, void *user_data)
Remove a reference to a tree - destroying it if there are no references left.
GPRAPI gpr_avl gpr_avl_create(const gpr_avl_vtable *vtable)
Create an immutable AVL tree.
struct gpr_avl gpr_avl
"pointer" to an AVL tree - this is a reference counted object - use gpr_avl_ref to add a reference...
struct gpr_avl_vtable gpr_avl_vtable
vtable for the AVL tree The optional user_data is propagated from the top level gpr_avl_XXX API...
gpr_refcount refs
Definition: avl.h:30
gpr_avl_node * root
Definition: avl.h:62
long height
Definition: avl.h:35
GPRAPI int gpr_avl_maybe_get(gpr_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(* destroy_value)(void *value, void *user_data)
destroy a value
Definition: avl.h:52
const gpr_avl_vtable * vtable
Definition: avl.h:61
struct gpr_avl_node gpr_avl_node
internal node of an AVL tree
void * key
Definition: avl.h:31
internal node of an AVL tree
Definition: avl.h:29
struct gpr_avl_node * left
Definition: avl.h:33
GPRAPI void * gpr_avl_get(gpr_avl avl, void *key, void *user_data)
Lookup key, and return the associated value.