suricata
util-hash.c File Reference
#include "suricata-common.h"
#include "util-hash.h"
#include "util-unittest.h"
#include "util-memcmp.h"
#include "util-debug.h"
Include dependency graph for util-hash.c:

Go to the source code of this file.

Functions

HashTableHashTableInit (uint32_t size, uint32_t(*Hash)(struct HashTable_ *, void *, uint16_t), char(*Compare)(void *, uint16_t, void *, uint16_t), void(*Free)(void *))
 
void HashTableFree (HashTable *ht)
 Free a HashTable and all its contents. More...
 
int HashTableAdd (HashTable *ht, void *data, uint16_t datalen)
 
int HashTableRemove (HashTable *ht, void *data, uint16_t datalen)
 Remove an item from the hash table. More...
 
void * HashTableLookup (HashTable *ht, void *data, uint16_t datalen)
 
void HashTableIterate (HashTable *ht, void(*CallbackFn)(void *, void *), void *aux)
 
uint32_t HashTableGenericHash (HashTable *ht, void *data, uint16_t datalen)
 
char HashTableDefaultCompare (void *data1, uint16_t len1, void *data2, uint16_t len2)
 
void HashTableRegisterTests (void)
 

Detailed Description

Author
Victor Julien victo.nosp@m.r@in.nosp@m.linia.nosp@m.c.ne.nosp@m.t

Chained hash table implementation

The 'Free' pointer can be used to have the API free your hashed data. If it's NULL it's the callers responsibility

Definition in file util-hash.c.

Function Documentation

◆ HashTableAdd()

int HashTableAdd ( HashTable ht,
void *  data,
uint16_t  datalen 
)

◆ HashTableDefaultCompare()

char HashTableDefaultCompare ( void *  data1,
uint16_t  len1,
void *  data2,
uint16_t  len2 
)

Definition at line 242 of file util-hash.c.

References SCMemcmp.

Referenced by HashTableInit().

Here is the caller graph for this function:

◆ HashTableFree()

void HashTableFree ( HashTable ht)

Free a HashTable and all its contents.

This function will free all the buckets and the array of buckets.

Note
If the Free function is set, it will be called for each data item in the hash table.
Parameters
htPointer to the HashTable to free
Returns
void

Definition at line 100 of file util-hash.c.

References HashTable_::array, and HashTable_::array_size.

Referenced by DetectEngineThreadCtxDeinit(), DetectMetadataHashFree(), LogFileFreeCtx(), SCClassConfDeInitContext(), and SCRConfDeInitContext().

Here is the caller graph for this function:

◆ HashTableGenericHash()

uint32_t HashTableGenericHash ( HashTable ht,
void *  data,
uint16_t  datalen 
)

Definition at line 225 of file util-hash.c.

References HashTable_::array_size.

◆ HashTableInit()

HashTable* HashTableInit ( uint32_t  size,
uint32_t(*)(struct HashTable_ *, void *, uint16_t)  Hash,
char(*)(void *, uint16_t, void *, uint16_t)  Compare,
void(*)(void *)  Free 
)

Definition at line 35 of file util-hash.c.

References HashTable_::array, HashTable_::array_size, HashTable_::Compare, HashTable_::Free, HashTable_::Hash, HashTableDefaultCompare(), SCCalloc, SCFree, and unlikely.

Referenced by DetectMetadataHashInit(), and SCLogOpenThreadedFile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HashTableIterate()

void HashTableIterate ( HashTable ht,
void(*)(void *, void *)  CallbackFn,
void *  aux 
)

◆ HashTableLookup()

void* HashTableLookup ( HashTable ht,
void *  data,
uint16_t  datalen 
)

◆ HashTableRegisterTests()

void HashTableRegisterTests ( void  )

Definition at line 464 of file util-hash.c.

References UtRegisterTest().

Here is the call graph for this function:

◆ HashTableRemove()

int HashTableRemove ( HashTable ht,
void *  data,
uint16_t  datalen 
)

Remove an item from the hash table.

This function will search for the item in the hash table and remove it if found

Note
If the Free function is set, it will be called for the data item being removed.
Parameters
htPointer to the HashTable
dataPointer to the data to remove
datalenLength of the data to remove
Returns
int 0 on success, -1 if the item was not found or an error occurred

Definition at line 166 of file util-hash.c.

References HashTable_::array, HashTable_::Compare, and HashTable_::Hash.