Loading...
Searching...
No Matches
hashtable.h File Reference
`#include <stdint.h>`
`#include <stddef.h>`

Go to the source code of this file.

## Data Structures

struct | ARC_HashtableNode

## Typedefs

typedef struct ARC_Hashtable | ARC_Hashtable
| the arc hashtable data type
typedef struct ARC_HashtableNode | ARC_HashtableNode
| a node that contains a key-value reference along with a linked list like node
typedef void(* | ARC_Hashtable_Hash) (void *key, size_t *keysize, uint32_t *hashval)
| a hashing function ptr
typedef int8_t(* | ARC_Hashtable_KeyCompare) (void *key1, size_t *key1size, void *key2, size_t *key2size)
| key comparison function ptr
typedef void(* | ARC_HashtableNode_DestroyExternal) (ARC_HashtableNode *node, void *userdata)
| callback to allow memory freeing of nodes

## Functions

void | ARC_Hashtable_Create (ARC_Hashtable **htable, uint32_t bucketsize, ARC_Hashtable_Hash hash, ARC_Hashtable_KeyCompare compare)
| cteates ARC_Hashtable type
void | ARC_Hashtable_Destroy (ARC_Hashtable *htable, ARC_HashtableNode_DestroyExternal external, void *userdata)
| destroys ARC_Hashtable type
void | ARC_Hashtable_Add (ARC_Hashtable *htable, void *key, size_t keysize, void *data)
| adds value to hastable
void | ARC_Hashtable_Get (ARC_Hashtable *htable, void *key, size_t keysize, void **data)
| gets value from hashtable by key
void | ARC_Hashtable_Remove (ARC_Hashtable *htable, void *key, size_t keysize, ARC_HashtableNode_DestroyExternal external, void *userdata)
| removes value from hashtable

## Typedef Documentation

## ARC_Hashtable

typedef struct ARC_Hashtable ARC_Hashtable

the arc hashtable data type

Definition at line 14 of file hashtable.h.

## ARC_Hashtable_Hash

typedef void(* ARC_Hashtable_Hash) (void *key, size_t *keysize, uint32_t *hashval)

a hashing function ptr

Parameters

  key | value to hash
  keysize | should be sizeof(key) before key is a void ptr
  hashval | value of hash, does not need to be within range of buckets

Definition at line 35 of file hashtable.h.

## ARC_Hashtable_KeyCompare

typedef int8_t(* ARC_Hashtable_KeyCompare) (void *key1, size_t *key1size, void *key2, size_t *key2size)

key comparison function ptr

Parameters

  key1 | first key
  key2 | second key

Returns
  0 when keys match

Definition at line 45 of file hashtable.h.

## ARC_HashtableNode

typedef struct ARC_HashtableNode ARC_HashtableNode

a node that contains a key-value reference along with a linked list like node

Definition at line 19 of file hashtable.h.

## ARC_HashtableNode_DestroyExternal

typedef void(* ARC_HashtableNode_DestroyExternal) (ARC_HashtableNode *node, void *userdata)

callback to allow memory freeing of nodes

Parameters

  node | node to be destroyed
  userdata | any data the user wants to access in the callback

Definition at line 53 of file hashtable.h.

## Function Documentation

## ARC_Hashtable_Add()

void ARC_Hashtable_Add | ( | ARC_Hashtable * | htable,
|  | void * | key,
|  | size_t | keysize,
|  | void * | data )

adds value to hastable

Parameters

  htable | ARC_Hashtable to add to
  key | key for node that is being added
  keysize | sizeof key before it is passed into a void *
  data | data for node that is being added

## ARC_Hashtable_Create()

void ARC_Hashtable_Create | ( | ARC_Hashtable ** | htable,
|  | uint32_t | bucketsize,
|  | ARC_Hashtable_Hash | hash,
|  | ARC_Hashtable_KeyCompare | compare )

cteates ARC_Hashtable type

Parameters

  htable | where to store data
  bucketsize | num of nodes to create in inital table
  hash | hashing function to be used, if set to NULL, CRC32 will be used
  compare | comparison functon for checking keys, if set to NULL, addresses will be compared

## ARC_Hashtable_Destroy()

void ARC_Hashtable_Destroy | ( | ARC_Hashtable * | htable,
|  | ARC_HashtableNode_DestroyExternal | external,
|  | void * | userdata )

destroys ARC_Hashtable type

Parameters

  htable | htable that will be destroyed
  external | function to allow external freeing of nodes, can be NULL
  userdata | any data the user wants access to in the callback

## ARC_Hashtable_Get()

void ARC_Hashtable_Get | ( | ARC_Hashtable * | htable,
|  | void * | key,
|  | size_t | keysize,
|  | void ** | data )

gets value from hashtable by key

Parameters

  htable | table to get value from
  key | key to get value from table
  keysize | sizeof key before it is passed into a void *
  data | data retrieved from table

## ARC_Hashtable_Remove()

void ARC_Hashtable_Remove | ( | ARC_Hashtable * | htable,
|  | void * | key,
|  | size_t | keysize,
|  | ARC_HashtableNode_DestroyExternal | external,
|  | void * | userdata )

removes value from hashtable

Parameters

  htable | ARC_Hashtable to remove from
  key | key of data to remove from hash table
  keysize | sizeof key before it is passed into a void *
  external | function to allow external freeing of data, can be NULL
  userdata | any data the user wants access to in the callback