From: Damian Gryski Date: Tue, 31 Jan 2012 05:37:03 +0000 (-0500) Subject: runtime: use per-map hash seeds X-Git-Tag: weekly.2012-02-07~188 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=85aeeadaecbe48ecf0be44f030c06feb85e71eab;p=gostls13.git runtime: use per-map hash seeds 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 --- diff --git a/src/pkg/runtime/hashmap.c b/src/pkg/runtime/hashmap.c index 642995df89..1def96727a 100644 --- a/src/pkg/runtime/hashmap.c +++ b/src/pkg/runtime/hashmap.c @@ -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);