Go to the documentation of this file.
35 HashTable*
HashTableInit(uint32_t size, uint32_t (*Hash)(
struct HashTable_ *,
void *, uint16_t),
char (*Compare)(
void *, uint16_t,
void *, uint16_t),
void (*Free)(
void *)) {
63 if (ht->
array == NULL)
70 if (ht->
array != NULL)
88 while (hashbucket != NULL) {
93 hashbucket = next_hashbucket;
98 if (ht->
array != NULL)
106 if (ht == NULL || data == NULL)
109 uint32_t hash = ht->
Hash(ht, data, datalen);
119 SCLogWarning(
"attempt to insert element out of hash array\n");
123 if (ht->
array[hash] == NULL) {
124 ht->
array[hash] = hb;
127 ht->
array[hash] = hb;
144 uint32_t hash = ht->
Hash(ht, data, datalen);
146 if (ht->
array[hash] == NULL) {
151 if (ht->
Free != NULL)
154 ht->
array[hash] = NULL;
160 if (ht->
Compare(hashbucket->
data,hashbucket->
size,data,datalen) == 1) {
161 if (prev_hashbucket == NULL) {
166 prev_hashbucket->
next = hashbucket->
next;
170 if (ht->
Free != NULL)
176 prev_hashbucket = hashbucket;
177 hashbucket = hashbucket->
next;
178 }
while (hashbucket != NULL);
190 hash = ht->
Hash(ht, data, datalen);
193 SCLogWarning(
"attempt to access element out of hash array\n");
197 if (ht->
array[hash] == NULL)
202 if (ht->
Compare(hashbucket->
data, hashbucket->
size, data, datalen) == 1)
203 return hashbucket->
data;
205 hashbucket = hashbucket->
next;
206 }
while (hashbucket != NULL);
213 uint8_t *d = (uint8_t *)data;
217 for (i = 0; i < datalen; i++) {
218 if (i == 0) hash += (((uint32_t)*d++));
219 else if (i == 1) hash += (((uint32_t)*d++) * datalen);
220 else hash *= (((uint32_t)*d++) * i) + datalen + i;
233 if (
SCMemcmp(data1,data2,len1) != 0)
244 static int HashTableTestInit01 (
void)
255 static int HashTableTestInit02 (
void)
265 static int HashTableTestInit03 (
void)
279 static int HashTableTestInit04 (
void)
289 static int HashTableTestInit05 (
void)
303 static char HashTableDefaultCompareTest(
void *data1, uint16_t len1,
void *data2, uint16_t len2)
308 if (
SCMemcmp(data1,data2,len1) != 0)
314 static int HashTableTestInit06 (
void)
321 if (ht->
Compare == HashTableDefaultCompareTest)
328 static int HashTableTestAdd01 (
void)
346 static int HashTableTestAdd02 (
void)
364 static int HashTableTestFull01 (
void)
390 static int HashTableTestFull02 (
void)
char HashTableDefaultCompare(void *data1, uint16_t len1, void *data2, uint16_t len2)
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
void HashTableFree(HashTable *ht)
char(* Compare)(void *, uint16_t, void *, uint16_t)
void HashTableRegisterTests(void)
void * HashTableLookup(HashTable *ht, void *data, uint16_t datalen)
int HashTableRemove(HashTable *ht, void *data, uint16_t datalen)
#define SCLogWarning(...)
Macro used to log WARNING messages.
int HashTableAdd(HashTable *ht, void *data, uint16_t datalen)
struct HashTableBucket_ * next
HashTable * HashTableInit(uint32_t size, uint32_t(*Hash)(struct HashTable_ *, void *, uint16_t), char(*Compare)(void *, uint16_t, void *, uint16_t), void(*Free)(void *))
uint32_t HashTableGenericHash(HashTable *ht, void *data, uint16_t datalen)
#define SCMemcmp(a, b, c)
uint32_t(* Hash)(struct HashTable_ *, void *, uint16_t)