Commit 85aeeada authored by Damian Gryski's avatar Damian Gryski Committed by Russ Cox

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
parent 4b2dfd6c
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment