Ruby 2.1.5p273(2014-11-13revision48405)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

st.h
Go to the documentation of this file.
1 /* This is a public domain general purpose hash table package written by Peter Moore @ UCB. */
2
3 /* @(#) st.h 5.1 89/12/14 */
4
5 #ifndef RUBY_ST_H
6 #define RUBY_ST_H 1
7
8 #if defined(__cplusplus)
9 extern "C" {
10 #if 0
11 } /* satisfy cc-mode */
12 #endif
13 #endif
14
15 #include "ruby/defines.h"
16
17 RUBY_SYMBOL_EXPORT_BEGIN
18
19 #if SIZEOF_LONG == SIZEOF_VOIDP
20 typedef unsigned long st_data_t;
21 #elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
22 typedef unsigned LONG_LONG st_data_t;
23 #else
24 # error ---->> st.c requires sizeof(void*) == sizeof(long) or sizeof(LONG_LONG) to be compiled. <<----
25 #endif
26 #define ST_DATA_T_DEFINED
27
28 #ifndef CHAR_BIT
29 # ifdef HAVE_LIMITS_H
30 # include <limits.h>
31 # else
32 # define CHAR_BIT 8
33 # endif
34 #endif
35 #ifndef _
36 # define _(args) args
37 #endif
38 #ifndef ANYARGS
39 # ifdef __cplusplus
40 # define ANYARGS ...
41 # else
42 # define ANYARGS
43 # endif
44 #endif
45
46 typedef struct st_table st_table;
47
48 typedef st_data_t st_index_t;
49 typedef int st_compare_func(st_data_t, st_data_t);
50 typedef st_index_t st_hash_func(st_data_t);
51
52 typedef char st_check_for_sizeof_st_index_t[SIZEOF_VOIDP == (int)sizeof(st_index_t) ? 1 : -1];
53 #define SIZEOF_ST_INDEX_T SIZEOF_VOIDP
54
55 struct st_hash_type {
56 int (*compare)(ANYARGS /*st_data_t, st_data_t*/); /* st_compare_func* */
57 st_index_t (*hash)(ANYARGS /*st_data_t*/); /* st_hash_func* */
58 };
59
60 #define ST_INDEX_BITS (sizeof(st_index_t) * CHAR_BIT)
61
62 #if defined(HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR) && defined(HAVE_BUILTIN___BUILTIN_TYPES_COMPATIBLE_P)
63 # define ST_DATA_COMPATIBLE_P(type) \
64 __builtin_choose_expr(__builtin_types_compatible_p(type, st_data_t), 1, 0)
65 #else
66 # define ST_DATA_COMPATIBLE_P(type) 0
67 #endif
68
69 struct st_table {
70 const struct st_hash_type *type;
71 st_index_t num_bins;
72 unsigned int entries_packed : 1;
73 #ifdef __GNUC__
74 /*
75 * C spec says,
76 * A bit-field shall have a type that is a qualified or unqualified
77 * version of _Bool, signed int, unsigned int, or some other
78 * implementation-defined type. It is implementation-defined whether
79 * atomic types are permitted.
80 * In short, long and long long bit-field are implementation-defined
81 * feature. Therefore we want to supress a warning explicitly.
82 */
83 __extension__
84 #endif
85 st_index_t num_entries : ST_INDEX_BITS - 1;
86 union {
87 struct {
88 struct st_table_entry **bins;
89 struct st_table_entry *head, *tail;
90 } big;
91 struct {
92 struct st_packed_entry *entries;
93 st_index_t real_entries;
94 } packed;
95 } as;
96 };
97
98 #define st_is_member(table,key) st_lookup((table),(key),(st_data_t *)0)
99
100 enum st_retval {ST_CONTINUE, ST_STOP, ST_DELETE, ST_CHECK};
101
102 st_table *st_init_table(const struct st_hash_type *);
103 st_table *st_init_table_with_size(const struct st_hash_type *, st_index_t);
104 st_table *st_init_numtable(void);
105 st_table *st_init_numtable_with_size(st_index_t);
106 st_table *st_init_strtable(void);
107 st_table *st_init_strtable_with_size(st_index_t);
108 st_table *st_init_strcasetable(void);
109 st_table *st_init_strcasetable_with_size(st_index_t);
110 int st_delete(st_table *, st_data_t *, st_data_t *); /* returns 0:notfound 1:deleted */
111 int st_delete_safe(st_table *, st_data_t *, st_data_t *, st_data_t);
112 int st_shift(st_table *, st_data_t *, st_data_t *); /* returns 0:notfound 1:deleted */
113 int st_insert(st_table *, st_data_t, st_data_t);
114 int st_insert2(st_table *, st_data_t, st_data_t, st_data_t (*)(st_data_t));
115 int st_lookup(st_table *, st_data_t, st_data_t *);
116 int st_get_key(st_table *, st_data_t, st_data_t *);
117 typedef int st_update_callback_func(st_data_t *key, st_data_t *value, st_data_t arg, int existing);
118 int st_update(st_table *table, st_data_t key, st_update_callback_func *func, st_data_t arg);
119 int st_foreach(st_table *, int (*)(ANYARGS), st_data_t);
120 int st_foreach_check(st_table *, int (*)(ANYARGS), st_data_t, st_data_t);
121 int st_reverse_foreach(st_table *, int (*)(ANYARGS), st_data_t);
122 st_index_t st_keys(st_table *table, st_data_t *keys, st_index_t size);
123 st_index_t st_keys_check(st_table *table, st_data_t *keys, st_index_t size, st_data_t never);
124 st_index_t st_values(st_table *table, st_data_t *values, st_index_t size);
125 st_index_t st_values_check(st_table *table, st_data_t *values, st_index_t size, st_data_t never);
126 void st_add_direct(st_table *, st_data_t, st_data_t);
127 void st_free_table(st_table *);
128 void st_cleanup_safe(st_table *, st_data_t);
129 void st_clear(st_table *);
130 st_table *st_copy(st_table *);
131 int st_numcmp(st_data_t, st_data_t);
132 st_index_t st_numhash(st_data_t);
133 int st_locale_insensitive_strcasecmp(const char *s1, const char *s2);
134 int st_locale_insensitive_strncasecmp(const char *s1, const char *s2, size_t n);
135 #define st_strcasecmp st_locale_insensitive_strcasecmp
136 #define st_strncasecmp st_locale_insensitive_strncasecmp
137 size_t st_memsize(const st_table *);
138 st_index_t st_hash(const void *ptr, size_t len, st_index_t h);
139 st_index_t st_hash_uint32(st_index_t h, uint32_t i);
140 st_index_t st_hash_uint(st_index_t h, st_index_t i);
141 st_index_t st_hash_end(st_index_t h);
142 st_index_t st_hash_start(st_index_t h);
143 #define st_hash_start(h) ((st_index_t)(h))
144
145 RUBY_SYMBOL_EXPORT_END
146
147 #if defined(__cplusplus)
148 #if 0
149 { /* satisfy cc-mode */
150 #endif
151 } /* extern "C" { */
152 #endif
153
154 #endif /* RUBY_ST_H */
ST_DELETE
Definition: st.h:100
st_hash_start
#define st_hash_start(h)
Definition: st.h:143
st_table
Definition: st.h:69
st_hash_uint
st_index_t st_hash_uint(st_index_t h, st_index_t i)
Definition: st.c:1562
ST_STOP
Definition: st.h:100
st_insert
int st_insert(st_table *, st_data_t, st_data_t)
st_hash_uint32
st_index_t st_hash_uint32(st_index_t h, uint32_t i)
Definition: st.c:1556
st_locale_insensitive_strcasecmp
int st_locale_insensitive_strcasecmp(const char *s1, const char *s2)
Definition: st.c:1616
ST_CONTINUE
Definition: st.h:100
st_numcmp
int st_numcmp(st_data_t, st_data_t)
Definition: st.c:1685
st_table::num_bins
st_index_t num_bins
Definition: st.h:71
st_table::entries
struct st_packed_entry * entries
Definition: st.h:92
st_hash_type::compare
int(* compare)(ANYARGS)
Definition: st.h:56
st_free_table
void st_free_table(st_table *)
Definition: st.c:334
st_get_key
int st_get_key(st_table *, st_data_t, st_data_t *)
st_init_strtable
st_table * st_init_strtable(void)
Definition: st.c:284
ST_INDEX_BITS
#define ST_INDEX_BITS
Definition: st.h:60
st_index_t
st_data_t st_index_t
Definition: st.h:48
st_update
int st_update(st_table *table, st_data_t key, st_update_callback_func *func, st_data_t arg)
Definition: st.c:867
st_table::entries_packed
unsigned int entries_packed
Definition: st.h:72
st_data_t
RUBY_SYMBOL_EXPORT_BEGIN typedef unsigned long st_data_t
Definition: st.h:20
st_hash_func
st_index_t st_hash_func(st_data_t)
Definition: st.h:50
st_insert2
int st_insert2(st_table *, st_data_t, st_data_t, st_data_t(*)(st_data_t))
st_init_strcasetable
st_table * st_init_strcasetable(void)
Definition: st.c:296
st_hash_type
Definition: st.h:55
st_lookup
int st_lookup(st_table *, st_data_t, st_data_t *)
st_init_strcasetable_with_size
st_table * st_init_strcasetable_with_size(st_index_t)
Definition: st.c:302
st_table_entry
Definition: st.c:20
st_table::packed
struct st_table::@120::@122 packed
st_add_direct
void st_add_direct(st_table *, st_data_t, st_data_t)
Definition: st.c:629
st_delete
int st_delete(st_table *, st_data_t *, st_data_t *)
defines.h
st_compare_func
int st_compare_func(st_data_t, st_data_t)
Definition: st.h:49
st_table::head
struct st_table_entry * head
Definition: st.h:89
st_table::as
union st_table::@120 as
st_init_strtable_with_size
st_table * st_init_strtable_with_size(st_index_t)
Definition: st.c:290
st_hash_end
st_index_t st_hash_end(st_index_t h)
Definition: st.c:1593
func
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:113
st_values
st_index_t st_values(st_table *table, st_data_t *values, st_index_t size)
Definition: st.c:1171
RUBY_SYMBOL_EXPORT_END
#define RUBY_SYMBOL_EXPORT_END
Definition: missing.h:39
st_packed_entry
Definition: st.c:28
st_retval
st_retval
Definition: st.h:100
st_table::bins
struct st_table_entry ** bins
Definition: st.h:88
RUBY_SYMBOL_EXPORT_BEGIN
#define RUBY_SYMBOL_EXPORT_BEGIN
Definition: missing.h:38
st_values_check
st_index_t st_values_check(st_table *table, st_data_t *values, st_index_t size, st_data_t never)
Definition: st.c:1177
st_init_numtable
st_table * st_init_numtable(void)
Definition: st.c:272
uint32_t
unsigned int uint32_t
Definition: sha2.h:101
st_hash
st_index_t st_hash(const void *ptr, size_t len, st_index_t h)
Definition: st.c:1429
st_init_table_with_size
st_table * st_init_table_with_size(const struct st_hash_type *, st_index_t)
Definition: st.c:229
size
int size
Definition: encoding.c:49
st_shift
int st_shift(st_table *, st_data_t *, st_data_t *)
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:52
st_memsize
size_t st_memsize(const st_table *)
Definition: st.c:342
ANYARGS
#define ANYARGS
Definition: defines.h:98
key
uint8_t key[16]
Definition: random.c:1250
st_reverse_foreach
int st_reverse_foreach(st_table *, int(*)(ANYARGS), st_data_t)
st_foreach_check
int st_foreach_check(st_table *, int(*)(ANYARGS), st_data_t, st_data_t)
Definition: st.c:942
st_table::real_entries
st_index_t real_entries
Definition: st.h:93
st_table::type
const struct st_hash_type * type
Definition: st.h:70
st_keys
st_index_t st_keys(st_table *table, st_data_t *keys, st_index_t size)
Definition: st.c:1130
ST_CHECK
Definition: st.h:100
st_keys_check
st_index_t st_keys_check(st_table *table, st_data_t *keys, st_index_t size, st_data_t never)
Definition: st.c:1136
st_cleanup_safe
void st_cleanup_safe(st_table *, st_data_t)
Definition: st.c:830
st_hash_type::hash
st_index_t(* hash)(ANYARGS)
Definition: st.h:57
st_copy
st_table * st_copy(st_table *)
Definition: st.c:663
st_clear
void st_clear(st_table *)
Definition: st.c:308
st_init_table
st_table * st_init_table(const struct st_hash_type *)
Definition: st.c:266
st_init_numtable_with_size
st_table * st_init_numtable_with_size(st_index_t)
Definition: st.c:278
st_table::tail
struct st_table_entry * tail
Definition: st.h:89
st_delete_safe
int st_delete_safe(st_table *, st_data_t *, st_data_t *, st_data_t)
st_table::num_entries
st_index_t num_entries
Definition: st.h:85
st_numhash
st_index_t st_numhash(st_data_t)
Definition: st.c:1691
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:117
st_foreach
int st_foreach(st_table *, int(*)(ANYARGS), st_data_t)
Definition: st.c:1034
st_locale_insensitive_strncasecmp
int st_locale_insensitive_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: st.c:1640
st_table::big
struct st_table::@120::@121 big