]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: use per-map hash seeds
authorDamian Gryski <dgryski@gmail.com>
Tue, 31 Jan 2012 05:37:03 +0000 (00:37 -0500)
committerRuss Cox <rsc@golang.org>
Tue, 31 Jan 2012 05:37:03 +0000 (00:37 -0500)
This patch adds a hash seed to the Hmap struct.  Each seed is
initialized by runtime.fastrand1().  This is the first step of a
solution to issue 2630.  Fastrand1 still needs to be updated to provide
us with actually random bits.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5599046

src/pkg/runtime/hashmap.c

index 642995df897f4eb40270e0f860770522fa0ccf5b..1def96727a7dce8b295da5131a7c8df01d8e5773 100644 (file)
@@ -13,6 +13,7 @@ struct Hmap {    /* a hash table; initialize with hash_init() */
        uint8 indirectval;      /* storing pointers to values */
        uint8 valoff;   /* offset of value in key+value data block */
        int32 changes;        /* inc'ed whenever a subtable is created/grown */
+       uintptr hash0;      /* hash seed */
        struct hash_subtable *st;    /* first-level table */
 };
 
@@ -118,6 +119,7 @@ hash_init (Hmap *h, int32 datasize, int64 hint)
        h->count = 0;
        h->changes = 0;
        h->st = hash_subtable_new (h, init_power, 0);
+       h->hash0 = runtime·fastrand1();
 }
 
 static void
@@ -266,7 +268,7 @@ hash_lookup (MapType *t, Hmap *h, void *data, void **pres)
        struct hash_entry *end_e;
        bool eq;
        
-       hash = 0;
+       hash = h->hash0;
        (*t->key->alg->hash) (&hash, t->key->size, data);
        hash &= ~HASH_MASK;
        hash += HASH_ADJUST (hash);
@@ -311,7 +313,7 @@ hash_remove (MapType *t, Hmap *h, void *data)
        struct hash_entry *end_e;
        bool eq;
 
-       hash = 0;
+       hash = h->hash0;
        (*t->key->alg->hash) (&hash, t->key->size, data);
        hash &= ~HASH_MASK;
        hash += HASH_ADJUST (hash);
@@ -435,7 +437,7 @@ hash_insert (MapType *t, Hmap *h, void *data, void **pres)
        uintptr hash;
        int32 rc;
        
-       hash = 0;
+       hash = h->hash0;
        (*t->key->alg->hash) (&hash, t->key->size, data);
        rc = hash_insert_internal (t, &h->st, 0, hash, h, data, pres);