Ruby  2.1.3p242(2014-09-19revision47630)
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 
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 
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;
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
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;
94  } packed;
95  } as;
96 };
97 
98 #define st_is_member(table,key) st_lookup((table),(key),(st_data_t *)0)
99 
101 
102 st_table *st_init_table(const struct st_hash_type *);
110 int st_delete(st_table *, st_data_t *, st_data_t *); /* returns 0:notfound 1:deleted */
112 int st_shift(st_table *, st_data_t *, st_data_t *); /* returns 0:notfound 1:deleted */
117 typedef int st_update_callback_func(st_data_t *key, st_data_t *value, st_data_t arg, int existing);
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);
127 void st_free_table(st_table *);
129 void st_clear(st_table *);
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);
143 #define st_hash_start(h) ((st_index_t)(h))
144 
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 */
155