Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

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
19 RUBY_SYMBOL_EXPORT_BEGIN
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
50 typedef st_data_t st_index_t;
51
52 /* Maximal value of unsigned integer type st_index_t. */
53 #define MAX_ST_INDEX_VAL (~(st_index_t) 0)
54
55 typedef int st_compare_func(st_data_t, st_data_t);
56 typedef st_index_t st_hash_func(st_data_t);
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)(st_data_t, st_data_t); /* st_compare_func* */
63 st_index_t (*hash)(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
75 typedef struct st_table_entry st_table_entry;
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. */
86 st_index_t num_entries;
87 /* Array of bins used for access by keys. */
88 st_index_t *bins;
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. */
94 st_table_entry *entries;
95 };
96
97 #define st_is_member(table,key) st_lookup((table),(key),(st_data_t *)0)
98
99 enum st_retval {ST_CONTINUE, ST_STOP, ST_DELETE, ST_CHECK, ST_REPLACE};
100
101 st_table *rb_st_init_table(const struct st_hash_type *);
102 #define st_init_table rb_st_init_table
103 st_table *rb_st_init_table_with_size(const struct st_hash_type *, st_index_t);
104 #define st_init_table_with_size rb_st_init_table_with_size
105 st_table *rb_st_init_numtable(void);
106 #define st_init_numtable rb_st_init_numtable
107 st_table *rb_st_init_numtable_with_size(st_index_t);
108 #define st_init_numtable_with_size rb_st_init_numtable_with_size
109 st_table *rb_st_init_strtable(void);
110 #define st_init_strtable rb_st_init_strtable
111 st_table *rb_st_init_strtable_with_size(st_index_t);
112 #define st_init_strtable_with_size rb_st_init_strtable_with_size
113 st_table *rb_st_init_strcasetable(void);
114 #define st_init_strcasetable rb_st_init_strcasetable
115 st_table *rb_st_init_strcasetable_with_size(st_index_t);
116 #define st_init_strcasetable_with_size rb_st_init_strcasetable_with_size
117 int rb_st_delete(st_table *, st_data_t *, st_data_t *); /* returns 0:notfound 1:deleted */
118 #define st_delete rb_st_delete
119 int rb_st_delete_safe(st_table *, st_data_t *, st_data_t *, st_data_t);
120 #define st_delete_safe rb_st_delete_safe
121 int rb_st_shift(st_table *, st_data_t *, st_data_t *); /* returns 0:notfound 1:deleted */
122 #define st_shift rb_st_shift
123 int rb_st_insert(st_table *, st_data_t, st_data_t);
124 #define st_insert rb_st_insert
125 int rb_st_insert2(st_table *, st_data_t, st_data_t, st_data_t (*)(st_data_t));
126 #define st_insert2 rb_st_insert2
127 int rb_st_lookup(st_table *, st_data_t, st_data_t *);
128 #define st_lookup rb_st_lookup
129 int rb_st_get_key(st_table *, st_data_t, st_data_t *);
130 #define st_get_key rb_st_get_key
131 typedef int st_update_callback_func(st_data_t *key, st_data_t *value, st_data_t arg, int existing);
132 /* *key may be altered, but must equal to the old key, i.e., the
133 * results of hash() are same and compare() returns 0, otherwise the
134 * behavior is undefined */
135 int rb_st_update(st_table *table, st_data_t key, st_update_callback_func *func, st_data_t arg);
136 #define st_update rb_st_update
137 typedef int st_foreach_callback_func(st_data_t, st_data_t, st_data_t);
138 typedef int st_foreach_check_callback_func(st_data_t, st_data_t, st_data_t, int);
139 int rb_st_foreach_with_replace(st_table *tab, st_foreach_check_callback_func *func, st_update_callback_func *replace, st_data_t arg);
140 #define st_foreach_with_replace rb_st_foreach_with_replace
141 int rb_st_foreach(st_table *, st_foreach_callback_func *, st_data_t);
142 #define st_foreach rb_st_foreach
143 int rb_st_foreach_check(st_table *, st_foreach_check_callback_func *, st_data_t, st_data_t);
144 #define st_foreach_check rb_st_foreach_check
145 st_index_t rb_st_keys(st_table *table, st_data_t *keys, st_index_t size);
146 #define st_keys rb_st_keys
147 st_index_t rb_st_keys_check(st_table *table, st_data_t *keys, st_index_t size, st_data_t never);
148 #define st_keys_check rb_st_keys_check
149 st_index_t rb_st_values(st_table *table, st_data_t *values, st_index_t size);
150 #define st_values rb_st_values
151 st_index_t rb_st_values_check(st_table *table, st_data_t *values, st_index_t size, st_data_t never);
152 #define st_values_check rb_st_values_check
153 void rb_st_add_direct(st_table *, st_data_t, st_data_t);
154 #define st_add_direct rb_st_add_direct
155 void rb_st_free_table(st_table *);
156 #define st_free_table rb_st_free_table
157 void rb_st_cleanup_safe(st_table *, st_data_t);
158 #define st_cleanup_safe rb_st_cleanup_safe
159 void rb_st_clear(st_table *);
160 #define st_clear rb_st_clear
161 st_table *rb_st_copy(st_table *);
162 #define st_copy rb_st_copy
163 CONSTFUNC(int rb_st_numcmp(st_data_t, st_data_t));
164 #define st_numcmp rb_st_numcmp
165 CONSTFUNC(st_index_t rb_st_numhash(st_data_t));
166 #define st_numhash rb_st_numhash
167 PUREFUNC(int rb_st_locale_insensitive_strcasecmp(const char *s1, const char *s2));
168 #define st_locale_insensitive_strcasecmp rb_st_locale_insensitive_strcasecmp
169 PUREFUNC(int rb_st_locale_insensitive_strncasecmp(const char *s1, const char *s2, size_t n));
170 #define st_locale_insensitive_strncasecmp rb_st_locale_insensitive_strncasecmp
171 #define st_strcasecmp rb_st_locale_insensitive_strcasecmp
172 #define st_strncasecmp rb_st_locale_insensitive_strncasecmp
173 PUREFUNC(size_t rb_st_memsize(const st_table *));
174 #define st_memsize rb_st_memsize
175 PUREFUNC(st_index_t rb_st_hash(const void *ptr, size_t len, st_index_t h));
176 #define st_hash rb_st_hash
177 CONSTFUNC(st_index_t rb_st_hash_uint32(st_index_t h, uint32_t i));
178 #define st_hash_uint32 rb_st_hash_uint32
179 CONSTFUNC(st_index_t rb_st_hash_uint(st_index_t h, st_index_t i));
180 #define st_hash_uint rb_st_hash_uint
181 CONSTFUNC(st_index_t rb_st_hash_end(st_index_t h));
182 #define st_hash_end rb_st_hash_end
183 CONSTFUNC(st_index_t rb_st_hash_start(st_index_t h));
184 #define st_hash_start(h) ((st_index_t)(h))
185
186 void rb_hash_bulk_insert_into_st_table(long, const VALUE *, VALUE);
187
188 RUBY_SYMBOL_EXPORT_END
189
190 #if defined(__cplusplus)
191 #if 0
192 { /* satisfy cc-mode */
193 #endif
194 } /* extern "C" { */
195 #endif
196
197 #endif /* RUBY_ST_H */
RUBY_SYMBOL_EXPORT_END
#define RUBY_SYMBOL_EXPORT_END
Definition: missing.h:49
rb_st_clear
void rb_st_clear(st_table *)
rb_st_cleanup_safe
void rb_st_cleanup_safe(st_table *, st_data_t)
st_update_callback_func
int st_update_callback_func(st_data_t *key, st_data_t *value, st_data_t arg, int existing)
Definition: st.h:131
st_table::entry_power
unsigned char entry_power
Definition: st.h:81
st_table::num_entries
st_index_t num_entries
Definition: st.h:86
rb_st_keys_check
st_index_t rb_st_keys_check(st_table *table, st_data_t *keys, st_index_t size, st_data_t never)
st_table::size_ind
unsigned char size_ind
Definition: st.h:81
ST_CHECK
@ ST_CHECK
Definition: st.h:99
rb_st_init_table_with_size
st_table * rb_st_init_table_with_size(const struct st_hash_type *, st_index_t)
ST_STOP
@ ST_STOP
Definition: st.h:99
rb_st_init_strcasetable
st_table * rb_st_init_strcasetable(void)
rb_st_free_table
void rb_st_free_table(st_table *)
LONG_LONG
#define LONG_LONG
Definition: rb_mjit_min_header-2.7.0.h:3939
rb_st_delete
int rb_st_delete(st_table *, st_data_t *, st_data_t *)
rb_st_locale_insensitive_strncasecmp
int rb_st_locale_insensitive_strncasecmp(const char *s1, const char *s2, size_t n)
VALUE
unsigned long VALUE
Definition: ruby.h:102
rb_st_init_numtable_with_size
st_table * rb_st_init_numtable_with_size(st_index_t)
rb_st_values
st_index_t rb_st_values(st_table *table, st_data_t *values, st_index_t size)
st_retval
st_retval
Definition: st.h:99
int
__inline__ int
Definition: rb_mjit_min_header-2.7.0.h:2839
rb_st_add_direct
void rb_st_add_direct(st_table *, st_data_t, st_data_t)
ptr
struct RIMemo * ptr
Definition: debug.c:74
CONSTFUNC
CONSTFUNC(int rb_st_numcmp(st_data_t, st_data_t))
st_compare_func
int st_compare_func(st_data_t, st_data_t)
Definition: st.h:55
ST_DELETE
@ ST_DELETE
Definition: st.h:99
uint32_t
unsigned int uint32_t
Definition: sha2.h:101
st_table::entries
st_table_entry * entries
Definition: st.h:94
rb_st_hash_start
st_index_t rb_st_hash_start(st_index_t h)
Definition: st.c:2070
rb_hash_bulk_insert_into_st_table
void rb_hash_bulk_insert_into_st_table(long, const VALUE *, VALUE)
Definition: st.c:2380
rb_st_init_strtable_with_size
st_table * rb_st_init_strtable_with_size(st_index_t)
st_table::bin_power
unsigned char bin_power
Definition: st.h:81
defines.h
st_table_entry
Definition: st.c:136
rb_st_foreach_check
int rb_st_foreach_check(st_table *, st_foreach_check_callback_func *, st_data_t, st_data_t)
st_foreach_check_callback_func
int st_foreach_check_callback_func(st_data_t, st_data_t, st_data_t, int)
Definition: st.h:138
ST_REPLACE
@ ST_REPLACE
Definition: st.h:99
rb_st_update
int rb_st_update(st_table *table, st_data_t key, st_update_callback_func *func, st_data_t arg)
rb_st_init_table
st_table * rb_st_init_table(const struct st_hash_type *)
st_foreach_callback_func
int st_foreach_callback_func(st_data_t, st_data_t, st_data_t)
Definition: st.h:137
i
uint32_t i
Definition: rb_mjit_min_header-2.7.0.h:5464
st_data_t
RUBY_SYMBOL_EXPORT_BEGIN typedef unsigned long st_data_t
Definition: st.h:22
st_hash_func
st_index_t st_hash_func(st_data_t)
Definition: st.h:56
rb_st_foreach_with_replace
int rb_st_foreach_with_replace(st_table *tab, st_foreach_check_callback_func *func, st_update_callback_func *replace, st_data_t arg)
st_index_t
st_data_t st_index_t
Definition: st.h:50
st_hash_type
Definition: st.h:61
st_hash_type::compare
int(* compare)(st_data_t, st_data_t)
Definition: st.h:62
rb_st_insert
int rb_st_insert(st_table *, st_data_t, st_data_t)
rb_st_keys
st_index_t rb_st_keys(st_table *table, st_data_t *keys, st_index_t size)
size
int size
Definition: encoding.c:58
rb_st_init_strcasetable_with_size
st_table * rb_st_init_strcasetable_with_size(st_index_t)
key
key
Definition: openssl_missing.h:181
rb_st_delete_safe
int rb_st_delete_safe(st_table *, st_data_t *, st_data_t *, st_data_t)
n
const char size_t n
Definition: rb_mjit_min_header-2.7.0.h:5456
arg
VALUE arg
Definition: rb_mjit_min_header-2.7.0.h:5601
ST_CONTINUE
@ ST_CONTINUE
Definition: st.h:99
RUBY_SYMBOL_EXPORT_BEGIN
#define RUBY_SYMBOL_EXPORT_BEGIN
Definition: missing.h:48
st_table::entries_start
st_index_t entries_start
Definition: st.h:92
st_data_t
unsigned long st_data_t
Definition: rb_mjit_min_header-2.7.0.h:5363
keys
const rb_iseq_t const char const VALUE keys
Definition: rb_mjit_min_header-2.7.0.h:13506
st_table::type
const struct st_hash_type * type
Definition: st.h:84
SIZEOF_VOIDP
#define SIZEOF_VOIDP
Definition: rb_mjit_min_header-2.7.0.h:90
PUREFUNC
PUREFUNC(int rb_st_locale_insensitive_strcasecmp(const char *s1, const char *s2))
st_table::bins
st_index_t * bins
Definition: st.h:88
s2
const char * s2
Definition: rb_mjit_min_header-2.7.0.h:5454
st_table::rebuilds_num
unsigned int rebuilds_num
Definition: st.h:83
rb_st_shift
int rb_st_shift(st_table *, st_data_t *, st_data_t *)
len
uint8_t len
Definition: escape.c:17
rb_st_values_check
st_index_t rb_st_values_check(st_table *table, st_data_t *values, st_index_t size, st_data_t never)
st_table::entries_bound
st_index_t entries_bound
Definition: st.h:92
rb_st_get_key
int rb_st_get_key(st_table *, st_data_t, st_data_t *)
rb_st_insert2
int rb_st_insert2(st_table *, st_data_t, st_data_t, st_data_t(*)(st_data_t))
rb_st_copy
st_table * rb_st_copy(st_table *)
rb_st_lookup
int rb_st_lookup(st_table *, st_data_t, st_data_t *)
rb_st_locale_insensitive_strcasecmp
int rb_st_locale_insensitive_strcasecmp(const char *s1, const char *s2)
h
size_t st_index_t h
Definition: rb_mjit_min_header-2.7.0.h:5462
st_check_for_sizeof_st_index_t
char st_check_for_sizeof_st_index_t[SIZEOF_VOIDP==(int) sizeof(st_index_t) ? 1 :-1]
Definition: st.h:58
rb_st_init_strtable
st_table * rb_st_init_strtable(void)
st_table
Definition: st.h:79
rb_st_init_numtable
st_table * rb_st_init_numtable(void)
rb_st_foreach
int rb_st_foreach(st_table *, st_foreach_callback_func *, st_data_t)
st_hash_type::hash
st_index_t(* hash)(st_data_t)
Definition: st.h:63