On Fri, 2012-01-06 at 10:05 +1100, Bojan Smojver wrote:
> Any other ideas?
Maybe like this?
--
Bojan
Index: tables/apr_hash.c
===================================================================
--- tables/apr_hash.c (revision 1227896)
+++ tables/apr_hash.c (working copy)
@@ -75,7 +75,7 @@
apr_pool_t *pool;
apr_hash_entry_t **array;
apr_hash_index_t iterator; /* For apr_hash_first(NULL, ...) */
- unsigned int count, max;
+ unsigned int count, max, seed;
apr_hashfunc_t hash_func;
apr_hash_entry_t *free; /* List of recycled entries */
};
@@ -100,8 +100,12 @@
ht->free = NULL;
ht->count = 0;
ht->max = INITIAL_MAX;
+ if (apr_generate_random_bytes(
+ (unsigned char *)&ht->seed, sizeof(ht->seed)) != APR_SUCCESS)
+ return NULL;
ht->array = alloc_array(ht, ht->max);
- ht->hash_func = apr_hashfunc_default;
+ ht->hash_func = NULL;
+
return ht;
}
@@ -201,10 +205,10 @@
ht->max = new_max;
}
-APR_DECLARE_NONSTD(unsigned int) apr_hashfunc_default(const char *char_key,
- apr_ssize_t *klen)
+static unsigned int apr_hashfunc_default_internal(const char *char_key,
+ apr_ssize_t *klen,
+ unsigned int hash)
{
- unsigned int hash = 0;
const unsigned char *key = (const unsigned char *)char_key;
const unsigned char *p;
apr_ssize_t i;
@@ -246,7 +250,7 @@
*
* -- Ralf S. Engelschall <[email protected]>
*/
-
+
if (*klen == APR_HASH_KEY_STRING) {
for (p = key; *p; p++) {
hash = hash * 33 + *p;
@@ -262,6 +266,11 @@
return hash;
}
+APR_DECLARE_NONSTD(unsigned int) apr_hashfunc_default(const char *char_key,
+ apr_ssize_t *klen)
+{
+ return apr_hashfunc_default_internal(char_key, klen, 0);
+}
/*
* This is where we keep the details of the hash function and control
@@ -280,7 +289,10 @@
apr_hash_entry_t **hep, *he;
unsigned int hash;
- hash = ht->hash_func(key, &klen);
+ if (ht->hash_func)
+ hash = ht->hash_func(key, &klen);
+ else
+ hash = apr_hashfunc_default_internal(key, &klen, ht->seed);
/* scan linked list */
for (hep = &ht->array[hash & ht->max], he = *hep;
@@ -322,6 +334,7 @@
ht->free = NULL;
ht->count = orig->count;
ht->max = orig->max;
+ ht->seed = orig->seed;
ht->hash_func = orig->hash_func;
ht->array = (apr_hash_entry_t **)((char *)ht + sizeof(apr_hash_t));