[前][次][番号順一覧][スレッド一覧]

ruby-changes:13048

From: nobu <ko1@a...>
Date: Tue, 8 Sep 2009 22:19:13 +0900 (JST)
Subject: [ruby-changes:13048] Ruby:r24794 (trunk): * st.c (st_init_*table_with_size): use st_index_t.

nobu	2009-09-08 22:18:13 +0900 (Tue, 08 Sep 2009)

  New Revision: 24794

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=24794

  Log:
    * st.c (st_init_*table_with_size): use st_index_t.

  Modified files:
    trunk/ChangeLog
    trunk/include/ruby/st.h
    trunk/st.c

Index: include/ruby/st.h
===================================================================
--- include/ruby/st.h	(revision 24793)
+++ include/ruby/st.h	(revision 24794)
@@ -83,13 +83,13 @@
 enum st_retval {ST_CONTINUE, ST_STOP, ST_DELETE, ST_CHECK};
 
 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_table_with_size(const struct st_hash_type *, st_index_t);
 st_table *st_init_numtable(void);
-st_table *st_init_numtable_with_size(int);
+st_table *st_init_numtable_with_size(st_index_t);
 st_table *st_init_strtable(void);
-st_table *st_init_strtable_with_size(int);
+st_table *st_init_strtable_with_size(st_index_t);
 st_table *st_init_strcasetable(void);
-st_table *st_init_strcasetable_with_size(int);
+st_table *st_init_strcasetable_with_size(st_index_t);
 int st_delete(st_table *, st_data_t *, st_data_t *); /* returns 0:notfound 1:deleted */
 int st_delete_safe(st_table *, st_data_t *, st_data_t *, st_data_t);
 int st_insert(st_table *, st_data_t, st_data_t);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 24793)
+++ ChangeLog	(revision 24794)
@@ -1,5 +1,7 @@
-Tue Sep  8 22:10:02 2009  Nobuyoshi Nakada  <nobu@r...>
+Tue Sep  8 22:18:11 2009  Nobuyoshi Nakada  <nobu@r...>
 
+	* st.c (st_init_*table_with_size): use st_index_t.
+
 	* include/ruby/st.h (st_hash_func): use st_index_t.
 
 Tue Sep  8 21:48:15 2009  Nobuyoshi Nakada  <nobu@r...>
Index: st.c
===================================================================
--- st.c	(revision 24793)
+++ st.c	(revision 24794)
@@ -44,13 +44,13 @@
 };
 
 /* extern int strcmp(const char *, const char *); */
-static st_index_t strhash(const char *);
+static st_index_t strhash(st_data_t);
 static const struct st_hash_type type_strhash = {
     strcmp,
     strhash,
 };
 
-static st_index_t strcasehash(const char *);
+static st_index_t strcasehash(st_data_t);
 static const struct st_hash_type type_strcasehash = {
     st_strcasecmp,
     strcasehash,
@@ -64,6 +64,8 @@
 #define free(x) xfree(x)
 #endif
 
+#define numberof(array) (int)(sizeof(array) / sizeof((array)[0]))
+
 #define alloc(type) (type*)malloc((size_t)sizeof(type))
 #define Calloc(n,s) (char*)calloc((n),(s))
 
@@ -81,7 +83,7 @@
 /*
 Table of prime numbers 2^n+a, 2<=n<=30.
 */
-static const long primes[] = {
+static const unsigned int primes[] = {
 	8 + 3,
 	16 + 3,
 	32 + 5,
@@ -113,8 +115,8 @@
 	0
 };
 
-static int
-new_size(int size)
+static st_index_t
+new_size(st_index_t size)
 {
     int i;
 
@@ -124,12 +126,9 @@
     }
     return -1;
 #else
-    int newsize;
+    st_index_t newsize;
 
-    for (i = 0, newsize = MINSIZE;
-	 i < (int )(sizeof(primes)/sizeof(primes[0]));
-	 i++, newsize <<= 1)
-    {
+    for (i = 0, newsize = MINSIZE; i < numberof(primes); i++, newsize <<= 1) {
 	if (newsize > size) return primes[i];
     }
     /* Ran out of polynomials */
@@ -153,10 +152,10 @@
 }
 #endif
 
-#define MAX_PACKED_NUMHASH 5
+#define MAX_PACKED_NUMHASH ((st_index_t)5)
 
 st_table*
-st_init_table_with_size(const struct st_hash_type *type, int size)
+st_init_table_with_size(const struct st_hash_type *type, st_index_t size)
 {
     st_table *tbl;
 
@@ -194,7 +193,7 @@
 }
 
 st_table*
-st_init_numtable_with_size(int size)
+st_init_numtable_with_size(st_index_t size)
 {
     return st_init_table_with_size(&type_numhash, size);
 }
@@ -206,7 +205,7 @@
 }
 
 st_table*
-st_init_strtable_with_size(int size)
+st_init_strtable_with_size(st_index_t size)
 {
     return st_init_table_with_size(&type_strhash, size);
 }
@@ -218,7 +217,7 @@
 }
 
 st_table*
-st_init_strcasetable_with_size(int size)
+st_init_strcasetable_with_size(st_index_t size)
 {
     return st_init_table_with_size(&type_strcasehash, size);
 }
@@ -291,7 +290,7 @@
 int
 st_lookup(st_table *table, register st_data_t key, st_data_t *value)
 {
-    unsigned int hash_val, bin_pos;
+    st_index_t hash_val, bin_pos;
     register st_table_entry *ptr;
 
     if (table->entries_packed) {
@@ -392,7 +391,7 @@
 int
 st_insert(register st_table *table, register st_data_t key, st_data_t value)
 {
-    unsigned int hash_val, bin_pos;
+    st_index_t hash_val, bin_pos;
     register st_table_entry *ptr;
 
     if (table->entries_packed) {
@@ -431,7 +430,7 @@
 st_insert2(register st_table *table, register st_data_t key, st_data_t value,
 	   st_data_t (*func)(st_data_t))
 {
-    unsigned int hash_val, bin_pos;
+    st_index_t hash_val, bin_pos;
     register st_table_entry *ptr;
 
     if (table->entries_packed) {
@@ -470,7 +469,7 @@
 void
 st_add_direct(st_table *table, st_data_t key, st_data_t value)
 {
-    unsigned int hash_val, bin_pos;
+    st_index_t hash_val, bin_pos;
 
     if (table->entries_packed) {
         int i;
@@ -494,8 +493,7 @@
 rehash(register st_table *table)
 {
     register st_table_entry *ptr, **new_bins;
-    int i, new_num_bins;
-    unsigned int hash_val;
+    st_index_t i, new_num_bins, hash_val;
 
     new_num_bins = new_size(table->num_bins+1);
     new_bins = (st_table_entry**)
@@ -518,8 +516,8 @@
 {
     st_table *new_table;
     st_table_entry *ptr, *entry, *prev, **tail;
-    int num_bins = old_table->num_bins;
-    unsigned int hash_val;
+    st_index_t num_bins = old_table->num_bins;
+    st_index_t hash_val;
 
     new_table = alloc(st_table);
     if (new_table == 0) {
@@ -582,7 +580,7 @@
 int
 st_delete(register st_table *table, register st_data_t *key, st_data_t *value)
 {
-    unsigned int hash_val;
+    st_index_t hash_val;
     st_table_entry **prev;
     register st_table_entry *ptr;
 
@@ -621,7 +619,7 @@
 int
 st_delete_safe(register st_table *table, register st_data_t *key, st_data_t *value, st_data_t never)
 {
-    unsigned int hash_val;
+    st_index_t hash_val;
     register st_table_entry *ptr;
 
     if (table->entries_packed) {
@@ -928,8 +926,9 @@
 #define FNV_32_PRIME 0x01000193
 
 static st_index_t
-strhash(register const char *string)
+strhash(st_data_t arg)
 {
+    register const char *string = (const char *)arg;
     register st_index_t hval = FNV1_32A_INIT;
 
     /*
@@ -995,8 +994,9 @@
 }
 
 static st_index_t
-strcasehash(register const char *string)
+strcasehash(st_data_t arg)
 {
+    register const char *string = (const char *)arg;
     register st_index_t hval = FNV1_32A_INIT;
 
     /*

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]