|
Ruby 1.9.2p290(2011-07-09revision32553)
|
00001 /* This is a public domain general purpose hash table package written by Peter Moore @ UCB. */ 00002 00003 /* @(#) st.h 5.1 89/12/14 */ 00004 00005 #ifndef RUBY_ST_H 00006 #define RUBY_ST_H 1 00007 00008 #if defined(__cplusplus) 00009 extern "C" { 00010 #if 0 00011 } /* satisfy cc-mode */ 00012 #endif 00013 #endif 00014 00015 #ifndef RUBY_LIB_PREFIX 00016 #include "ruby/config.h" 00017 #include "ruby/defines.h" 00018 #ifdef RUBY_EXTCONF_H 00019 #include RUBY_EXTCONF_H 00020 #endif 00021 #endif 00022 00023 #if defined STDC_HEADERS 00024 #include <stddef.h> 00025 #elif defined HAVE_STDLIB_H 00026 #include <stdlib.h> 00027 #endif 00028 00029 #ifdef HAVE_STDINT_H 00030 # include <stdint.h> 00031 #endif 00032 #ifdef HAVE_INTTYPES_H 00033 # include <inttypes.h> 00034 #endif 00035 00036 #if SIZEOF_LONG == SIZEOF_VOIDP 00037 typedef unsigned long st_data_t; 00038 #elif SIZEOF_LONG_LONG == SIZEOF_VOIDP 00039 typedef unsigned LONG_LONG st_data_t; 00040 #else 00041 # error ---->> st.c requires sizeof(void*) == sizeof(long) to be compiled. <<---- 00042 #endif 00043 #define ST_DATA_T_DEFINED 00044 00045 #ifndef CHAR_BIT 00046 # ifdef HAVE_LIMITS_H 00047 # include <limits.h> 00048 # else 00049 # define CHAR_BIT 8 00050 # endif 00051 #endif 00052 #ifndef _ 00053 # define _(args) args 00054 #endif 00055 #ifndef ANYARGS 00056 # ifdef __cplusplus 00057 # define ANYARGS ... 00058 # else 00059 # define ANYARGS 00060 # endif 00061 #endif 00062 00063 typedef struct st_table st_table; 00064 00065 typedef st_data_t st_index_t; 00066 typedef int st_compare_func(st_data_t, st_data_t); 00067 typedef st_index_t st_hash_func(st_data_t); 00068 00069 typedef char st_check_for_sizeof_st_index_t[SIZEOF_VOIDP == (int)sizeof(st_index_t) ? 1 : -1]; 00070 #define SIZEOF_ST_INDEX_T SIZEOF_VOIDP 00071 00072 struct st_hash_type { 00073 int (*compare)(ANYARGS /*st_data_t, st_data_t*/); /* st_compare_func* */ 00074 st_index_t (*hash)(ANYARGS /*st_data_t*/); /* st_hash_func* */ 00075 }; 00076 00077 #define ST_INDEX_BITS (sizeof(st_index_t) * CHAR_BIT) 00078 00079 struct st_table { 00080 const struct st_hash_type *type; 00081 st_index_t num_bins; 00082 unsigned int entries_packed : 1; 00083 #ifdef __GNUC__ 00084 __extension__ 00085 #endif 00086 st_index_t num_entries : ST_INDEX_BITS - 1; 00087 struct st_table_entry **bins; 00088 struct st_table_entry *head, *tail; 00089 }; 00090 00091 #define st_is_member(table,key) st_lookup(table,key,(st_data_t *)0) 00092 00093 enum st_retval {ST_CONTINUE, ST_STOP, ST_DELETE, ST_CHECK}; 00094 00095 st_table *st_init_table(const struct st_hash_type *); 00096 st_table *st_init_table_with_size(const struct st_hash_type *, st_index_t); 00097 st_table *st_init_numtable(void); 00098 st_table *st_init_numtable_with_size(st_index_t); 00099 st_table *st_init_strtable(void); 00100 st_table *st_init_strtable_with_size(st_index_t); 00101 st_table *st_init_strcasetable(void); 00102 st_table *st_init_strcasetable_with_size(st_index_t); 00103 int st_delete(st_table *, st_data_t *, st_data_t *); /* returns 0:notfound 1:deleted */ 00104 int st_delete_safe(st_table *, st_data_t *, st_data_t *, st_data_t); 00105 int st_insert(st_table *, st_data_t, st_data_t); 00106 int st_insert2(st_table *, st_data_t, st_data_t, st_data_t (*)(st_data_t)); 00107 int st_lookup(st_table *, st_data_t, st_data_t *); 00108 int st_get_key(st_table *, st_data_t, st_data_t *); 00109 int st_foreach(st_table *, int (*)(ANYARGS), st_data_t); 00110 int st_reverse_foreach(st_table *, int (*)(ANYARGS), st_data_t); 00111 void st_add_direct(st_table *, st_data_t, st_data_t); 00112 void st_free_table(st_table *); 00113 void st_cleanup_safe(st_table *, st_data_t); 00114 void st_clear(st_table *); 00115 st_table *st_copy(st_table *); 00116 int st_numcmp(st_data_t, st_data_t); 00117 st_index_t st_numhash(st_data_t); 00118 int st_strcasecmp(const char *s1, const char *s2); 00119 int st_strncasecmp(const char *s1, const char *s2, size_t n); 00120 size_t st_memsize(const st_table *); 00121 st_index_t st_hash(const void *ptr, size_t len, st_index_t h); 00122 st_index_t st_hash_uint32(st_index_t h, uint32_t i); 00123 st_index_t st_hash_uint(st_index_t h, st_index_t i); 00124 st_index_t st_hash_end(st_index_t h); 00125 st_index_t st_hash_start(st_index_t h); 00126 #define st_hash_start(h) ((st_index_t)(h)) 00127 00128 #if defined(__cplusplus) 00129 #if 0 00130 { /* satisfy cc-mode */ 00131 #endif 00132 } /* extern "C" { */ 00133 #endif 00134 00135 #endif /* RUBY_ST_H */ 00136
1.7.3