diff options
| author | Damian Gryski <dgryski@gmail.com> | 2012-01-31 00:37:03 -0500 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2012-01-31 00:37:03 -0500 |
| commit | 85aeeadaecbe48ecf0be44f030c06feb85e71eab (patch) | |
| tree | 227fdc5f0c6760b607787d45ef01882429d4a845 | |
| parent | 4b2dfd6c2cf9caade6702cede4a9424f4d308fc8 (diff) | |
| download | go-85aeeadaecbe48ecf0be44f030c06feb85e71eab.tar.xz | |
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
| -rw-r--r-- | src/pkg/runtime/hashmap.c | 8 |
1 files changed, 5 insertions, 3 deletions
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); |
