GRPC Core  4.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 
25 typedef struct gpr_avl_node {
27  void *key;
28  void *value;
29  struct gpr_avl_node *left;
31  long height;
32 } gpr_avl_node;
33 
39 typedef struct gpr_avl_vtable {
41  void (*destroy_key)(void *key, void *user_data);
43  void *(*copy_key)(void *key, void *user_data);
46  long (*compare_keys)(void *key1, void *key2, void *user_data);
48  void (*destroy_value)(void *value, void *user_data);
50  void *(*copy_value)(void *value, void *user_data);
52 
56 typedef struct gpr_avl {
59 } gpr_avl;
60 
66 GPRAPI gpr_avl gpr_avl_ref(gpr_avl avl, void *user_data);
70 GPRAPI void gpr_avl_unref(gpr_avl avl, void *user_data);
76 GPRAPI gpr_avl gpr_avl_add(gpr_avl avl, void *key, void *value,
77  void *user_data);
81 GPRAPI gpr_avl gpr_avl_remove(gpr_avl avl, void *key, void *user_data);
86 GPRAPI void *gpr_avl_get(gpr_avl avl, void *key, void *user_data);
89 GPRAPI int gpr_avl_maybe_get(gpr_avl avl, void *key, void **value,
90  void *user_data);
93 
94 #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:39
struct gpr_avl_node * right
Definition: avl.h:30
void(* destroy_key)(void *key, void *user_data)
destroy a key
Definition: avl.h:41
Definition: sync_generic.h:32
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:56
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:46
void * value
Definition: avl.h:28
#define GPRAPI
Definition: port_platform.h:401
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:26
gpr_avl_node * root
Definition: avl.h:58
long height
Definition: avl.h:31
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:48
const gpr_avl_vtable * vtable
Definition: avl.h:57
struct gpr_avl_node gpr_avl_node
internal node of an AVL tree
void * key
Definition: avl.h:27
internal node of an AVL tree
Definition: avl.h:25
struct gpr_avl_node * left
Definition: avl.h:29
GPRAPI void * gpr_avl_get(gpr_avl avl, void *key, void *user_data)
Lookup key, and return the associated value.