Ruby  2.5.0dev(2017-10-22revision60238)
st.h
Go to the documentation of this file.
1 /* This is a public domain general purpose hash table package
2  originally written by Peter Moore @ UCB.
3 
4  The hash table data strutures were redesigned and the package was
5  rewritten by Vladimir Makarov <vmakarov@redhat.com>. */
6 
7 #ifndef RUBY_ST_H
8 #define RUBY_ST_H 1
9 
10 #if defined(__cplusplus)
11 extern "C" {
12 #if 0
13 } /* satisfy cc-mode */
14 #endif
15 #endif
16 
17 #include "ruby/defines.h"
18 
20 
21 #if SIZEOF_LONG == SIZEOF_VOIDP
22 typedef unsigned long st_data_t;
23 #elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
24 typedef unsigned LONG_LONG st_data_t;
25 #else
26 # error ---->> st.c requires sizeof(void*) == sizeof(long) or sizeof(LONG_LONG) to be compiled. <<----
27 #endif
28 #define ST_DATA_T_DEFINED
29 
30 #ifndef CHAR_BIT
31 # ifdef HAVE_LIMITS_H
32 # include <limits.h>
33 # else
34 # define CHAR_BIT 8
35 # endif
36 #endif
37 #ifndef _
38 # define _(args) args
39 #endif
40 #ifndef ANYARGS
41 # ifdef __cplusplus
42 # define ANYARGS ...
43 # else
44 # define ANYARGS
45 # endif
46 #endif
47 
48 typedef struct st_table st_table;
49 
51 
52 /* Maximal value of unsigned integer type st_index_t. */
53 #define MAX_ST_INDEX_VAL (~(st_index_t) 0)
54 
57 
58 typedef char st_check_for_sizeof_st_index_t[SIZEOF_VOIDP == (int)sizeof(st_index_t) ? 1 : -1];
59 #define SIZEOF_ST_INDEX_T SIZEOF_VOIDP
60 
61 struct st_hash_type {
62  int (*compare)(ANYARGS /*st_data_t, st_data_t*/); /* st_compare_func* */
63  st_index_t (*hash)(ANYARGS /*st_data_t*/); /* st_hash_func* */
64 };
65 
66 #define ST_INDEX_BITS (SIZEOF_ST_INDEX_T * CHAR_BIT)
67 
68 #if defined(HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR) && defined(HAVE_BUILTIN___BUILTIN_TYPES_COMPATIBLE_P)
69 # define ST_DATA_COMPATIBLE_P(type) \
70  __builtin_choose_expr(__builtin_types_compatible_p(type, st_data_t), 1, 0)
71 #else
72 # define ST_DATA_COMPATIBLE_P(type) 0
73 #endif
74 
76 
77 struct st_table_entry; /* defined in st.c */
78 
79 struct st_table {
80  /* Cached features of the table -- see st.c for more details. */
81  unsigned char entry_power, bin_power, size_ind;
82  /* How many times the table was rebuilt. */
83  unsigned int rebuilds_num;
84  const struct st_hash_type *type;
85  /* Number of entries currently in the table. */
87  /* Array of bins used for access by keys. */
89  /* Start and bound index of entries in array entries.
90  entries_starts and entries_bound are in interval
91  [0,allocated_entries]. */
92  st_index_t entries_start, entries_bound;
93  /* Array of size 2^entry_power. */
95 };
96 
97 #define st_is_member(table,key) st_lookup((table),(key),(st_data_t *)0)
98 
100 
101 st_table *st_init_table(const struct st_hash_type *);
109 int st_delete(st_table *, st_data_t *, st_data_t *); /* returns 0:notfound 1:deleted */
111 int st_shift(st_table *, st_data_t *, st_data_t *); /* returns 0:notfound 1:deleted */
116 typedef int st_update_callback_func(st_data_t *key, st_data_t *value, st_data_t arg, int existing);
117 /* *key may be altered, but must equal to the old key, i.e., the
118  * results of hash() are same and compare() returns 0, otherwise the
119  * behavior is undefined */
121 int st_foreach(st_table *, int (*)(ANYARGS), st_data_t);
128 void st_free_table(st_table *);
130 void st_clear(st_table *);
134 PUREFUNC(int st_locale_insensitive_strcasecmp(const char *s1, const char *s2));
135 PUREFUNC(int st_locale_insensitive_strncasecmp(const char *s1, const char *s2, size_t n));
136 #define st_strcasecmp st_locale_insensitive_strcasecmp
137 #define st_strncasecmp st_locale_insensitive_strncasecmp
138 PUREFUNC(size_t st_memsize(const st_table *));
139 PUREFUNC(st_index_t st_hash(const void *ptr, size_t len, st_index_t h));
144 #define st_hash_start(h) ((st_index_t)(h))
145 
147 
148 #if defined(__cplusplus)
149 #if 0
150 { /* satisfy cc-mode */
151 #endif
152 } /* extern "C" { */
153 #endif
154 
155 #endif /* RUBY_ST_H */
Definition: st.h:99
#define st_hash_start(h)
Definition: st.h:144
int st_locale_insensitive_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: st.c:1931
Definition: st.h:79
Definition: st.h:99
st_index_t st_hash_uint32(st_index_t h, uint32_t i)
Definition: st.c:1867
int st_insert(st_table *, st_data_t, st_data_t)
Definition: st.c:1098
st_index_t st_numhash(st_data_t n)
Definition: st.c:1983
Definition: st.h:99
void st_free_table(st_table *)
Definition: st.c:666
int st_get_key(st_table *, st_data_t, st_data_t *)
Definition: st.c:1062
unsigned char size_ind
Definition: st.h:81
st_table * st_init_strtable(void)
Definition: st.c:625
st_data_t st_index_t
Definition: st.h:50
int st_update(st_table *table, st_data_t key, st_update_callback_func *func, st_data_t arg)
Definition: st.c:1393
st_index_t * bins
Definition: st.h:88
RUBY_SYMBOL_EXPORT_BEGIN typedef unsigned long st_data_t
Definition: st.h:22
st_index_t st_hash_func(st_data_t)
Definition: st.h:56
int st_insert2(st_table *, st_data_t, st_data_t, st_data_t(*)(st_data_t))
Definition: st.c:1185
st_table * st_init_strcasetable(void)
Definition: st.c:640
char st_check_for_sizeof_st_index_t[SIZEOF_VOIDP==(int) sizeof(st_index_t) ? 1 :-1]
Definition: st.h:58
int st_lookup(st_table *, st_data_t, st_data_t *)
Definition: st.c:1038
int st_locale_insensitive_strcasecmp(const char *s1, const char *s2)
Definition: st.c:1907
PUREFUNC(int st_locale_insensitive_strcasecmp(const char *s1, const char *s2))
st_table * st_init_strcasetable_with_size(st_index_t)
Definition: st.c:648
st_index_t st_hash_end(st_index_t h)
Definition: st.c:1886
size_t st_memsize(const st_table *tab)
Definition: st.c:676
Definition: st.c:131
void st_add_direct(st_table *, st_data_t, st_data_t)
Definition: st.c:1173
int st_delete(st_table *, st_data_t *, st_data_t *)
Definition: st.c:1313
int st_compare_func(st_data_t, st_data_t)
Definition: st.h:55
st_index_t(* hash)(ANYARGS)
Definition: st.h:63
st_table * st_init_strtable_with_size(st_index_t)
Definition: st.c:632
unsigned int rebuilds_num
Definition: st.h:83
st_index_t st_hash(const void *ptr, size_t len, st_index_t h)
Definition: st.c:1728
st_index_t st_values(st_table *table, st_data_t *values, st_index_t size)
Definition: st.c:1630
#define RUBY_SYMBOL_EXPORT_END
Definition: missing.h:49
st_retval
Definition: st.h:99
#define RUBY_SYMBOL_EXPORT_BEGIN
Definition: missing.h:48
CONSTFUNC(int st_numcmp(st_data_t, st_data_t))
st_index_t st_values_check(st_table *table, st_data_t *values, st_index_t size, st_data_t never)
Definition: st.c:1637
st_table * st_init_numtable(void)
Definition: st.c:610
unsigned int uint32_t
Definition: sha2.h:101
register unsigned int len
Definition: zonetab.h:51
st_table * st_init_table_with_size(const struct st_hash_type *, st_index_t)
Definition: st.c:555
int size
Definition: encoding.c:57
int st_shift(st_table *, st_data_t *, st_data_t *)
Definition: st.c:1335
#define ANYARGS
Definition: defines.h:173
int st_foreach_check(st_table *, int(*)(ANYARGS), st_data_t, st_data_t)
const struct st_hash_type * type
Definition: st.h:84
st_index_t st_keys(st_table *table, st_data_t *keys, st_index_t size)
Definition: st.c:1592
int(* compare)(ANYARGS)
Definition: st.h:62
Definition: st.h:99
st_index_t st_keys_check(st_table *table, st_data_t *keys, st_index_t size, st_data_t never)
Definition: st.c:1599
int st_numcmp(st_data_t x, st_data_t y)
Definition: st.c:1977
void st_cleanup_safe(st_table *, st_data_t)
st_table * st_copy(st_table *)
Definition: st.c:1237
void st_clear(st_table *)
Definition: st.c:655
st_table * st_init_table(const struct st_hash_type *)
Definition: st.c:602
st_table * st_init_numtable_with_size(st_index_t)
Definition: st.c:617
st_table_entry * entries
Definition: st.h:94
st_index_t st_hash_uint(st_index_t h, st_index_t i)
Definition: st.c:1873
int st_delete_safe(st_table *, st_data_t *, st_data_t *, st_data_t)
st_index_t num_entries
Definition: st.h:86
int st_update_callback_func(st_data_t *key, st_data_t *value, st_data_t arg, int existing)
Definition: st.h:116
int st_foreach(st_table *, int(*)(ANYARGS), st_data_t)
Definition: st.c:1554
st_index_t entries_start
Definition: st.h:92