diff --git a/src/util-hash.c b/src/util-hash.c index da9b6413ed..e4cd341e29 100644 --- a/src/util-hash.c +++ b/src/util-hash.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2007-2010 Open Information Security Foundation +/* Copyright (C) 2007-2026 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -75,6 +75,18 @@ error: return NULL; } +HashTable *HashTableInitWithSeed(uint32_t size, + uint32_t (*Hash)(struct HashTable_ *, void *, uint16_t), + char (*Compare)(void *, uint16_t, void *, uint16_t), void (*Free)(void *), + const uint32_t seed) +{ + HashTable *ht = HashTableInit(size, Hash, Compare, Free); + if (ht != NULL) { + ht->seed = seed; + } + return ht; +} + /** * \brief Free a HashTableBucket and return the next bucket * \param ht Pointer to the HashTable diff --git a/src/util-hash.h b/src/util-hash.h index 40241b3db7..0b55f927a4 100644 --- a/src/util-hash.h +++ b/src/util-hash.h @@ -35,6 +35,7 @@ typedef struct HashTableBucket_ { typedef struct HashTable_ { HashTableBucket **array; uint32_t array_size; + uint32_t seed; /**< optional random seed, to be used by the registered hash function. */ #ifdef UNITTESTS uint32_t count; #endif @@ -47,6 +48,9 @@ typedef struct HashTable_ { /* prototypes */ HashTable* HashTableInit(uint32_t, uint32_t (*Hash)(struct HashTable_ *, void *, uint16_t), char (*Compare)(void *, uint16_t, void *, uint16_t), void (*Free)(void *)); +HashTable *HashTableInitWithSeed(uint32_t, uint32_t (*Hash)(struct HashTable_ *, void *, uint16_t), + char (*Compare)(void *, uint16_t, void *, uint16_t), void (*Free)(void *), + const uint32_t seed); void HashTableFree(HashTable *); int HashTableAdd(HashTable *, void *, uint16_t); int HashTableRemove(HashTable *, void *, uint16_t);