00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef CUCON_RBSET_H
00019 #define CUCON_RBSET_H
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <cucon/fwd.h>
00029 #include <cu/inherit.h>
00030 #include <cucon/rbtree.h>
00031
00032 CU_BEGIN_DECLARATIONS
00033
00034
00035 struct cucon_rbset
00036 {
00037 cu_inherit (cucon_rbtree);
00038 cu_clop(cmp, int, void *, void *);
00039 };
00040
00041
00042
00043
00044 void cucon_rbset_init(cucon_rbset_t rbset, cu_clop(cmp, int, void *, void *));
00045
00046
00047
00048 cucon_rbset_t cucon_rbset_new(cu_clop(cmp, int, void *, void *));
00049
00050
00051 CU_SINLINE cu_bool_t cucon_rbset_is_empty(cucon_rbset_t set)
00052 { return cucon_rbtree_is_empty(cu_to(cucon_rbtree, set)); }
00053
00054
00055 void cucon_rbset_init_str_cmp(cucon_rbset_t rbset);
00056
00057
00058 cucon_rbset_t cucon_rbset_new_str_cmp(void);
00059
00060
00061
00062 CU_SINLINE cu_bool_t
00063 cucon_rbset_insert(cucon_rbset_t rbset, void *key)
00064 {
00065 return cucon_rbtree_insert2p_ptr(cu_to(cucon_rbtree, rbset),
00066 rbset->cmp, &key);
00067 }
00068
00069
00070 CU_SINLINE cu_bool_t
00071 cucon_rbset_erase(cucon_rbset_t rbset, void *key)
00072 {
00073 return cucon_rbtree_erase2p(cu_to(cucon_rbtree, rbset),
00074 rbset->cmp, key) != NULL;
00075 }
00076
00077
00078 CU_SINLINE void *
00079 cucon_rbset_find(cucon_rbset_t rbset, void *key)
00080 {
00081 return cucon_rbtree_find2p_ptr(cu_to(cucon_rbtree, rbset), rbset->cmp, key);
00082 }
00083
00084
00085
00086
00087 void cucon_rbset_nearest(cucon_rbset_t set, void *key,
00088 cu_ptr_ptr_t below_out,
00089 cu_ptr_ptr_t equal_out,
00090 cu_ptr_ptr_t above_out);
00091
00092
00093 CU_SINLINE void
00094 cucon_rbset_iter(cucon_rbset_t set, cu_clop(cb, void, void *))
00095 { cucon_rbtree_iter_ptr(cu_to(cucon_rbtree, set), cb); }
00096
00097
00098 CU_SINLINE void
00099 cucon_rbset_rev_iter(cucon_rbset_t set, cu_clop(cb, void, void *))
00100 { cucon_rbtree_rev_iter_ptr(cu_to(cucon_rbtree, set), cb); }
00101
00102
00103
00104 CU_SINLINE cu_bool_t
00105 cucon_rbset_conj(cucon_rbset_t set, cu_clop(cb, cu_bool_t, void *key))
00106 { return cucon_rbtree_conj_ptr(cu_to(cucon_rbtree, set), cb); }
00107
00108
00109
00110 CU_SINLINE cu_bool_t
00111 cucon_rbset_rev_conj(cucon_rbset_t set, cu_clop(cb, cu_bool_t, void *))
00112 { return cucon_rbtree_rev_conj_ptr(cu_to(cucon_rbtree, set), cb); }
00113
00114
00115 CU_END_DECLARATIONS
00116
00117 #endif