mirror of
https://github.com/OISF/suricata.git
synced 2026-10-11 22:09:53 +00:00
hash: allow registing with a seed value
Seed value will have to be used by the caller's hash function.
This commit is contained in:
+13
-1
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user