summaryrefslogtreecommitdiff
path: root/include/ruby/st.h
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-09-01 02:14:40 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-09-01 02:14:40 +0000
commitd4cbf950029c99d37ad2f4369d1782f3a9a3dc98 (patch)
tree31f745acb00379cf9de0e6656a9b12da7cf7ef4f /include/ruby/st.h
parentb39e00d39d426ef8a08af0a3627ea7f5bf4cd973 (diff)
* st.c (st_numcmp, st_numhash): use st_data_t instead of long, because
the former may be larger than the latter. * include/ruby/st.h (CHAR_BIT): get rid of magic number. * include/ruby/st.h (struct st_table): num_entries never exceed num_bins. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13326 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'include/ruby/st.h')
-rw-r--r--include/ruby/st.h51
1 files changed, 32 insertions, 19 deletions
diff --git a/include/ruby/st.h b/include/ruby/st.h
index 728159121e..7702c7a8e9 100644
--- a/include/ruby/st.h
+++ b/include/ruby/st.h
@@ -17,23 +17,47 @@ typedef unsigned long st_data_t;
#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
typedef unsigned LONG_LONG st_data_t;
#else
-# error ---->> st.c requires sizeof(void*) == sizeof(long) to be compiled. <<---
--
+# error ---->> st.c requires sizeof(void*) == sizeof(long) to be compiled. <<----
#endif
#define ST_DATA_T_DEFINED
+#ifndef CHAR_BIT
+# ifdef HAVE_LIMITS_H
+# include <limits.h>
+# else
+# define CHAR_BIT 8
+# endif
+#endif
+#ifndef _
+# define _(args) args
+#endif
+#ifndef ANYARGS
+# ifdef __cplusplus
+# define ANYARGS ...
+# else
+# define ANYARGS
+# endif
+#endif
+
typedef struct st_table st_table;
+typedef int st_compare_func(st_data_t, st_data_t);
+typedef int st_hash_func(st_data_t);
+
struct st_hash_type {
- int (*compare)();
- int (*hash)();
+ int (*compare)(ANYARGS /*st_data_t, st_data_t*/); /* st_compare_func* */
+ int (*hash)(ANYARGS /*st_data_t*/); /* st_hash_func* */
};
+typedef unsigned int st_index_t;
+#define ST_INDEX_BITS (sizeof(st_index_t) * CHAR_BIT - 1)
+
struct st_table {
const struct st_hash_type *type;
unsigned int entries_packed : 1;
- int num_bins : sizeof(int) * 8 - 1;
- int num_entries;
+ st_index_t num_bins : ST_INDEX_BITS;
+ unsigned int st_dummy_bit : 1;
+ st_index_t num_entries : ST_INDEX_BITS;
struct st_table_entry **bins;
struct st_table_entry *head;
};
@@ -42,17 +66,6 @@ struct st_table {
enum st_retval {ST_CONTINUE, ST_STOP, ST_DELETE, ST_CHECK};
-#ifndef _
-# define _(args) args
-#endif
-#ifndef ANYARGS
-# ifdef __cplusplus
-# define ANYARGS ...
-# else
-# define ANYARGS
-# endif
-#endif
-
st_table *st_init_table(const struct st_hash_type *);
st_table *st_init_table_with_size(const struct st_hash_type *, int);
st_table *st_init_numtable(void);
@@ -70,8 +83,8 @@ void st_free_table(st_table *);
void st_cleanup_safe(st_table *, st_data_t);
void st_clear(st_table *);
st_table *st_copy(st_table *);
-int st_numcmp(long, long);
-int st_numhash(long);
+int st_numcmp(st_data_t, st_data_t);
+int st_numhash(st_data_t);
#if defined(__cplusplus)
#if 0