Permalink
Browse files

add rb_hash_{start, uint32, uint, end}

  • Loading branch information...
1 parent 83959ed commit 73bdff6e2ffe6e2ee212ca01afb760f4db1fd08a @Watson1978 Watson1978 committed Jan 3, 2012
Showing with 30 additions and 0 deletions.
  1. +7 −0 include/ruby/intern.h
  2. +23 −0 random.c
View
@@ -528,6 +528,13 @@ VALUE rb_str_cat2(VALUE, const char*);
VALUE rb_str_append(VALUE, VALUE);
VALUE rb_str_concat(VALUE, VALUE);
long rb_memhash(const void *ptr, long len);
+st_index_t rb_hash_start(st_index_t);
+st_index_t rb_hash_uint32(st_index_t, uint32_t);
+st_index_t rb_hash_uint(st_index_t, st_index_t);
+st_index_t rb_hash_end(st_index_t);
+#define rb_hash_uint32(h, i) st_hash_uint32(h, i)
+#define rb_hash_uint(h, i) st_hash_uint(h, i)
+#define rb_hash_end(h) st_hash_end(h)
unsigned long rb_str_hash(VALUE);
int rb_str_hash_cmp(VALUE,VALUE);
int rb_str_comparable(VALUE, VALUE);
View
@@ -837,6 +837,8 @@ rb_f_rand(VALUE obj, SEL sel, int argc, VALUE *argv)
return r;
}
+static st_index_t hashseed;
+
static void
Init_RandomSeed(void)
{
@@ -845,8 +847,29 @@ Init_RandomSeed(void)
fill_random_seed(initial);
GC_WB(&get_rnd(random)->seed, make_seed_value(initial));
rb_vm_set_default_random(random);
+
+ hashseed = rb_genrand_int32();
+#if SIZEOF_ST_INDEX_T*CHAR_BIT > 4*8
+ hashseed <<= 32;
+ hashseed |= rb_genrand_int32();
+#endif
+#if SIZEOF_ST_INDEX_T*CHAR_BIT > 8*8
+ hashseed <<= 32;
+ hashseed |= rb_genrand_int32();
+#endif
+#if SIZEOF_ST_INDEX_T*CHAR_BIT > 12*8
+ hashseed <<= 32;
+ hashseed |= rb_genrand_int32();
+#endif
}
+st_index_t
+rb_hash_start(st_index_t h)
+{
+ return st_hash_start(hashseed + h);
+}
+
+
void
rb_reset_random_seed(void)
{

0 comments on commit 73bdff6

Please sign in to comment.