Ruby 2.0.0p353(2013-11-22revision43784)

- 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 #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) or sizeof(LONG_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
63 typedef st_data_t st_index_t;
64 typedef int st_compare_func(st_data_t, st_data_t);
65 typedef st_index_t st_hash_func(st_data_t);
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;
79 st_index_t num_bins;
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
93 st_index_t num_entries : ST_INDEX_BITS - 1;
94 union {
95 struct {
96 struct st_table_entry **bins;
97 struct st_table_entry *head, *tail;
98 } big;
99 struct {
100 struct st_packed_entry *entries;
101 st_index_t real_entries;
102 } packed;
103 } as;
104 };
105
106 #define st_is_member(table,key) st_lookup((table),(key),(st_data_t *)0)
107
108 enum st_retval {ST_CONTINUE, ST_STOP, ST_DELETE, ST_CHECK};
109
110 st_table *st_init_table(const struct st_hash_type *);
111 st_table *st_init_table_with_size(const struct st_hash_type *, st_index_t);
112 st_table *st_init_numtable(void);
113 st_table *st_init_numtable_with_size(st_index_t);
114 st_table *st_init_strtable(void);
115 st_table *st_init_strtable_with_size(st_index_t);
116 st_table *st_init_strcasetable(void);
117 st_table *st_init_strcasetable_with_size(st_index_t);
118 int st_delete(st_table *, st_data_t *, st_data_t *); /* returns 0:notfound 1:deleted */
119 int st_delete_safe(st_table *, st_data_t *, st_data_t *, st_data_t);
120 int st_insert(st_table *, st_data_t, st_data_t);
121 int st_insert2(st_table *, st_data_t, st_data_t, st_data_t (*)(st_data_t));
122 int st_lookup(st_table *, st_data_t, st_data_t *);
123 int st_get_key(st_table *, st_data_t, st_data_t *);
124 typedef int st_update_callback_func(st_data_t *key, st_data_t *value, st_data_t arg, int existing);
125 int st_update(st_table *table, st_data_t key, st_update_callback_func *func, st_data_t arg);
126 int st_foreach(st_table *, int (*)(ANYARGS), st_data_t);
127 int st_foreach_check(st_table *, int (*)(ANYARGS), st_data_t, st_data_t);
128 int st_reverse_foreach(st_table *, int (*)(ANYARGS), st_data_t);
129 void st_add_direct(st_table *, st_data_t, st_data_t);
130 void st_free_table(st_table *);
131 void st_cleanup_safe(st_table *, st_data_t);
132 void st_clear(st_table *);
133 st_table *st_copy(st_table *);
134 int st_numcmp(st_data_t, st_data_t);
135 st_index_t st_numhash(st_data_t);
136 int st_strcasecmp(const char *s1, const char *s2);
137 int st_strncasecmp(const char *s1, const char *s2, size_t n);
138 size_t st_memsize(const st_table *);
139 st_index_t st_hash(const void *ptr, size_t len, st_index_t h);
140 st_index_t st_hash_uint32(st_index_t h, uint32_t i);
141 st_index_t st_hash_uint(st_index_t h, st_index_t i);
142 st_index_t st_hash_end(st_index_t h);
143 st_index_t st_hash_start(st_index_t h);
144 #define st_hash_start(h) ((st_index_t)(h))
145
146 #if defined __GNUC__ && __GNUC__ >= 4
147 #pragma GCC visibility pop
148 #endif
149
150 #if defined(__cplusplus)
151 #if 0
152 { /* satisfy cc-mode */
153 #endif
154 } /* extern "C" { */
155 #endif
156
157 #endif /* RUBY_ST_H */
n
ssize_t n
Definition: bigdecimal.c:5655
int
VP_EXPORT int
Definition: bigdecimal.c:5050
st_init_table_with_size
st_table * st_init_table_with_size(const struct st_hash_type *, st_index_t)
Definition: st.c:229
ST_DELETE
Definition: ripper.y:108
st_table
Definition: ripper.y:77
st_hash_start
#define st_hash_start(h)
st_lookup
int st_lookup(st_table *, st_data_t, st_data_t *)
st_add_direct
void st_add_direct(st_table *, st_data_t, st_data_t)
Definition: st.c:624
st_init_numtable
st_table * st_init_numtable(void)
Definition: st.c:272
table
static int VALUE table
Definition: tcltklib.c:10138
func
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:108
i
ssize_t i
Definition: bigdecimal.c:5655
st_table::num_bins
st_index_t num_bins
Definition: ripper.y:79
st_table::entries
struct st_packed_entry * entries
Definition: ripper.y:100
st_update_callback_func
int st_update_callback_func(st_data_t *key, st_data_t *value, st_data_t arg, int existing)
Definition: ripper.y:124
st_hash_type::compare
int(* compare)(ANYARGS)
Definition: ripper.y:71
st_init_strcasetable
st_table * st_init_strcasetable(void)
Definition: st.c:296
st_numcmp
int st_numcmp(st_data_t, st_data_t)
Definition: st.c:1569
st_insert2
int st_insert2(st_table *, st_data_t, st_data_t, st_data_t(*)(st_data_t))
st_table::type
struct st_hash_type * type
Definition: ripper.y:78
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: ripper.y:67
st_memsize
size_t st_memsize(const st_table *)
Definition: st.c:342
st_init_strtable
st_table * st_init_strtable(void)
Definition: st.c:284
st_table::big
struct st_table::@74::@75 big
ST_INDEX_BITS
#define ST_INDEX_BITS
Definition: st.h:75
st_hash
st_index_t st_hash(const void *ptr, size_t len, st_index_t h)
Definition: st.c:1313
st_retval
st_retval
Definition: ripper.y:108
st_table::entries_packed
unsigned int entries_packed
Definition: ripper.y:80
st_strcasecmp
int st_strcasecmp(const char *s1, const char *s2)
Definition: st.c:1500
st_update
int st_update(st_table *table, st_data_t key, st_update_callback_func *func, st_data_t arg)
Definition: st.c:834
st_data_t
unsigned long st_data_t
Definition: ripper.y:35
st_delete
int st_delete(st_table *, st_data_t *, st_data_t *)
st_hash_type
Definition: ripper.y:70
st_hash_func
st_index_t st_hash_func(st_data_t)
Definition: ripper.y:65
st_table_entry
Definition: st.c:20
st_numhash
st_index_t st_numhash(st_data_t)
Definition: st.c:1575
st_strncasecmp
int st_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: st.c:1524
ANYARGS
#define ANYARGS
defines.h
st_table::head
struct st_table_entry * head
Definition: ripper.y:97
st_table::as
union st_table::@74 as
key
static int VALUE key
Definition: tkutil.c:265
st_foreach
int st_foreach(st_table *, int(*)(ANYARGS), st_data_t)
Definition: st.c:1000
value
volatile VALUE value
Definition: tcltklib.c:9442
st_hash_uint
st_index_t st_hash_uint(st_index_t h, st_index_t i)
Definition: st.c:1446
st_packed_entry
Definition: st.c:28
st_get_key
int st_get_key(st_table *, st_data_t, st_data_t *)
st_compare_func
int st_compare_func(st_data_t, st_data_t)
Definition: ripper.y:64
st_init_strcasetable_with_size
st_table * st_init_strcasetable_with_size(st_index_t)
Definition: st.c:302
st_table::bins
struct st_table_entry ** bins
Definition: ripper.y:96
ST_CONTINUE
Definition: ripper.y:108
ptr
return ptr
Definition: tcltklib.c:784
st_reverse_foreach
int st_reverse_foreach(st_table *, int(*)(ANYARGS), st_data_t)
uint32_t
unsigned int uint32_t
Definition: sha2.h:101
arg
arg
Definition: ripper.y:1315
ST_CHECK
Definition: ripper.y:108
st_index_t
st_data_t st_index_t
Definition: ripper.y:63
ST_STOP
Definition: ripper.y:108
st_table::real_entries
st_index_t real_entries
Definition: ripper.y:101
st_insert
int st_insert(st_table *, st_data_t, st_data_t)
st_foreach_check
int st_foreach_check(st_table *, int(*)(ANYARGS), st_data_t, st_data_t)
Definition: st.c:909
st_clear
void st_clear(st_table *)
Definition: st.c:308
st_hash_type::hash
st_index_t(* hash)(ANYARGS)
Definition: ripper.y:72
st_init_table
st_table * st_init_table(const struct st_hash_type *)
Definition: st.c:266
st_hash_uint32
st_index_t st_hash_uint32(st_index_t h, uint32_t i)
Definition: st.c:1440
st_copy
st_table * st_copy(st_table *)
Definition: st.c:658
st_init_strtable_with_size
st_table * st_init_strtable_with_size(st_index_t)
Definition: st.c:290
st_init_numtable_with_size
st_table * st_init_numtable_with_size(st_index_t)
Definition: st.c:278
st_delete_safe
int st_delete_safe(st_table *, st_data_t *, st_data_t *, st_data_t)
st_hash_end
st_index_t st_hash_end(st_index_t h)
Definition: st.c:1477
st_cleanup_safe
void st_cleanup_safe(st_table *, st_data_t)
Definition: st.c:797
st_table::tail
struct st_table_entry * tail
Definition: ripper.y:97
st_table::num_entries
st_index_t num_entries
Definition: ripper.y:93
st_table::packed
struct st_table::@74::@76 packed
st_free_table
void st_free_table(st_table *)
Definition: st.c:334
len
size_t len
Definition: tcltklib.c:3568