Ruby  1.9.3p551(2014-11-13revision48407)
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 #if defined STDC_HEADERS
18 #include <stddef.h>
19 #elif defined HAVE_STDLIB_H
20 #include <stdlib.h>
21 #endif
22 
23 #ifdef HAVE_STDINT_H
24 # include <stdint.h>
25 #endif
26 #ifdef HAVE_INTTYPES_H
27 # include <inttypes.h>
28 #endif
29 
30 #if defined __GNUC__ && __GNUC__ >= 4
31 #pragma GCC visibility push(default)
32 #endif
33 
34 #if SIZEOF_LONG == SIZEOF_VOIDP
35 typedef unsigned long st_data_t;
36 #elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
37 typedef unsigned LONG_LONG st_data_t;
38 #else
39 # error ---->> st.c requires sizeof(void*) == sizeof(long) to be compiled. <<----
40 #endif
41 #define ST_DATA_T_DEFINED
42 
43 #ifndef CHAR_BIT
44 # ifdef HAVE_LIMITS_H
45 # include <limits.h>
46 # else
47 # define CHAR_BIT 8
48 # endif
49 #endif
50 #ifndef _
51 # define _(args) args
52 #endif
53 #ifndef ANYARGS
54 # ifdef __cplusplus
55 # define ANYARGS ...
56 # else
57 # define ANYARGS
58 # endif
59 #endif
60 
61 typedef struct st_table st_table;
62 
66 
67 typedef char st_check_for_sizeof_st_index_t[SIZEOF_VOIDP == (int)sizeof(st_index_t) ? 1 : -1];
68 #define SIZEOF_ST_INDEX_T SIZEOF_VOIDP
69 
70 struct st_hash_type {
71  int (*compare)(ANYARGS /*st_data_t, st_data_t*/); /* st_compare_func* */
72  st_index_t (*hash)(ANYARGS /*st_data_t*/); /* st_hash_func* */
73 };
74 
75 #define ST_INDEX_BITS (sizeof(st_index_t) * CHAR_BIT)
76 
77 struct st_table {
78  const struct st_hash_type *type;
80  unsigned int entries_packed : 1;
81 #ifdef __GNUC__
82  /*
83  * C spec says,
84  * A bit-field shall have a type that is a qualified or unqualified
85  * version of _Bool, signed int, unsigned int, or some other
86  * implementation-defined type. It is implementation-defined whether
87  * atomic types are permitted.
88  * In short, long and long long bit-field are implementation-defined
89  * feature. Therefore we want to supress a warning explicitly.
90  */
91  __extension__
92 #endif
94  struct st_table_entry **bins;
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 int st_foreach(st_table *, int (*)(ANYARGS), st_data_t);
118 int st_reverse_foreach(st_table *, int (*)(ANYARGS), st_data_t);
120 void st_free_table(st_table *);
122 void st_clear(st_table *);
126 int st_strcasecmp(const char *s1, const char *s2);
127 int st_strncasecmp(const char *s1, const char *s2, size_t n);
128 size_t st_memsize(const st_table *);
129 st_index_t st_hash(const void *ptr, size_t len, st_index_t h);
134 #define st_hash_start(h) ((st_index_t)(h))
135 
136 #if defined __GNUC__ && __GNUC__ >= 4
137 #pragma GCC visibility pop
138 #endif
139 
140 #if defined(__cplusplus)
141 #if 0
142 { /* satisfy cc-mode */
143 #endif
144 } /* extern "C" { */
145 #endif
146 
147 #endif /* RUBY_ST_H */
Definition: st.h:100
#define st_init_strtable_with_size
Definition: regint.h:145
ssize_t n
Definition: bigdecimal.c:5519
VP_EXPORT int
Definition: bigdecimal.c:4911
#define st_hash_start(h)
Definition: st.h:134
Definition: st.h:77
st_index_t st_hash_uint(st_index_t h, st_index_t i)
Definition: st.c:1246
Definition: st.h:100
#define st_foreach
Definition: regint.h:150
st_index_t st_hash_uint32(st_index_t h, uint32_t i)
Definition: st.c:1240
#define ANYARGS
Definition: st.h:57
int st_numcmp(st_data_t, st_data_t)
Definition: st.c:1369
return ST_CHECK
Definition: tkutil.c:271
st_index_t num_bins
Definition: st.h:79
return ST_CONTINUE
Definition: tkutil.c:1273
int(* compare)(ANYARGS)
Definition: st.h:71
int st_get_key(st_table *, st_data_t, st_data_t *)
#define ST_INDEX_BITS
Definition: st.h:75
st_data_t st_index_t
Definition: st.h:63
#define st_delete
Definition: regint.h:146
#define st_lookup
Definition: regint.h:149
#define st_init_strtable
Definition: regint.h:144
#define st_init_numtable_with_size
Definition: regint.h:143
unsigned int entries_packed
Definition: st.h:80
st_index_t st_hash_func(st_data_t)
Definition: st.h:65
int st_insert2(st_table *, st_data_t, st_data_t, st_data_t(*)(st_data_t))
st_table * st_init_strcasetable(void)
Definition: st.c:229
st_table * st_init_strcasetable_with_size(st_index_t)
Definition: st.c:235
#define st_init_table_with_size
Definition: regint.h:141
Definition: st.c:20
int st_compare_func(st_data_t, st_data_t)
Definition: st.h:64
struct st_table_entry * head
Definition: st.h:95
st_index_t st_hash_end(st_index_t h)
Definition: st.c:1277
#define st_init_table
Definition: regint.h:140
st_retval
Definition: st.h:100
struct st_table_entry ** bins
Definition: st.h:94
register unsigned int len
Definition: name2ctype.h:22210
return ptr
Definition: tcltklib.c:780
long st_data_t
Definition: syck.h:69
unsigned int uint32_t
Definition: sha2.h:101
st_index_t st_hash(const void *ptr, size_t len, st_index_t h)
Definition: st.c:1113
int st_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: st.c:1324
int st_shift(st_table *, st_data_t *, st_data_t *)
char st_check_for_sizeof_st_index_t[SIZEOF_VOIDP==(int) sizeof(st_index_t)?1:-1]
Definition: st.h:67
size_t st_memsize(const st_table *)
Definition: st.c:274
#define st_init_numtable
Definition: regint.h:142
#define st_cleanup_safe
Definition: regint.h:153
int st_reverse_foreach(st_table *, int(*)(ANYARGS), st_data_t)
#define st_add_direct
Definition: regint.h:151
#define st_insert
Definition: regint.h:148
st_index_t(* hash)(ANYARGS)
Definition: st.h:72
#define st_free_table
Definition: regint.h:152
int st_strcasecmp(const char *s1, const char *s2)
Definition: st.c:1300
void st_clear(st_table *)
Definition: st.c:241
ssize_t i
Definition: bigdecimal.c:5519
#define st_copy
Definition: regint.h:154
struct st_table_entry * tail
Definition: st.h:95
st_index_t num_entries
Definition: st.h:93
st_index_t st_numhash(st_data_t)
Definition: st.c:1375
#define st_delete_safe
Definition: regint.h:147
struct st_hash_type * type
Definition: st.h:78