37 char (*Compare)(
void *, uint16_t,
void *, uint16_t),
void (*Free)(
void *))
69 if (ht->
array == NULL) {
80 if (ht->
array != NULL)
98 while (hashbucket != NULL) {
100 if (ht->
Free != NULL)
103 hashbucket = next_hashbucket;
108 if (ht->
array != NULL)
116 if (ht == NULL || data == NULL)
119 uint32_t hash = ht->
Hash(ht, data, datalen);
132 if (ht->
array[hash] == NULL) {
133 ht->
array[hash] = hb;
136 ht->
array[hash] = hb;
156 uint32_t hash = ht->
Hash(ht, data, datalen);
160 if (ht->
array[hash] == NULL) {
182 if (ht->
Free != NULL)
186 ht->
array[hash] = NULL;
197 if (ht->
Compare(hashbucket->
data,hashbucket->
size,data,datalen) == 1) {
211 if (prev_hashbucket == NULL) {
220 if (ht->
Free != NULL)
226 prev_hashbucket = hashbucket;
228 }
while (hashbucket != NULL);
239 if (
SCMemcmp(data1,data2,len1) != 0)
253 uint32_t hash = ht->
Hash(ht, data, datalen);
255 if (ht->
array[hash] == NULL) {
262 return hashbucket->
data;
265 }
while (hashbucket != NULL);
272 uint8_t *d = (uint8_t *)data;
276 for (i = 0; i < datalen; i++) {
277 if (i == 0) hash += (((uint32_t)*d++));
278 else if (i == 1) hash += (((uint32_t)*d++) * datalen);
279 else hash *= (((uint32_t)*d++) * i) + datalen + i;
297static int HashListTableTestInit01 (
void)
308static int HashListTableTestInit02 (
void)
318static int HashListTableTestInit03 (
void)
332static int HashListTableTestInit04 (
void)
342static int HashListTableTestAdd01 (
void)
360static int HashListTableTestAdd02 (
void)
378static int HashListTableTestAdd03 (
void)
390 printf(
"ht->listhead == NULL: ");
395 printf(
"ht->listtail == NULL: ");
406static int HashListTableTestAdd04 (
void)
423 printf(
"htb == NULL: ");
429 printf(
"rp2 == NULL: ");
434 printf(
"rp != rp2: ");
445static int HashListTableTestFull01 (
void)
471static int HashListTableTestFull02 (
void)
501 UtRegisterTest(
"HashListTableTestInit01", HashListTableTestInit01);
502 UtRegisterTest(
"HashListTableTestInit02", HashListTableTestInit02);
503 UtRegisterTest(
"HashListTableTestInit03", HashListTableTestInit03);
504 UtRegisterTest(
"HashListTableTestInit04", HashListTableTestInit04);
511 UtRegisterTest(
"HashListTableTestFull01", HashListTableTestFull01);
512 UtRegisterTest(
"HashListTableTestFull02", HashListTableTestFull02);
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
struct HashListTableBucket_ * listnext
struct HashListTableBucket_ * listprev
struct HashListTableBucket_ * bucknext
HashListTableBucket * listhead
HashListTableBucket * listtail
HashListTableBucket ** array
uint32_t(* Hash)(struct HashListTable_ *, void *, uint16_t)
char(* Compare)(void *, uint16_t, void *, uint16_t)
thread_local SCError sc_errno
char HashListTableDefaultCompare(void *data1, uint16_t len1, void *data2, uint16_t len2)
void * HashListTableLookup(HashListTable *ht, void *data, uint16_t datalen)
int HashListTableAdd(HashListTable *ht, void *data, uint16_t datalen)
HashListTableBucket * HashListTableGetListHead(HashListTable *ht)
void HashListTableRegisterTests(void)
uint32_t HashListTableGenericHash(HashListTable *ht, void *data, uint16_t datalen)
int HashListTableRemove(HashListTable *ht, void *data, uint16_t datalen)
HashListTable * HashListTableInit(uint32_t size, uint32_t(*Hash)(struct HashListTable_ *, void *, uint16_t), char(*Compare)(void *, uint16_t, void *, uint16_t), void(*Free)(void *))
void HashListTableFree(HashListTable *ht)
#define HashListTableGetListData(hb)
#define SCMemcmp(a, b, c)