cr8r_hashtbl_ft Struct Reference

Function table for hash table. More...

#include <hash.h>

Data Fields

cr8r_base_ft base
 Base function table values (data and size)
 
uint64_t(* hash )(const cr8r_base_ft *, const void *)
 Function to hash an element. Should only depend on "key" data within the element.
 
int(* cmp )(const cr8r_base_ft *, const void *, const void *)
 Function to compare elements. More...
 
int(* add )(cr8r_base_ft *, void *, void *)
 Function to combine two elements. More...
 
void(* del )(cr8r_base_ft *, void *)
 Function to be called to delete elements. More...
 
double load_factor
 Maximum allowable ratio of entries present to total capacity. More...
 

Detailed Description

Function table for hash table.

Imagine this struct as the class of the hash table. This struct specifies the size of the elements in a hash table in bytes and maximum load factor, as well as how to perform necessary operations (hash, compare).

Definition at line 57 of file hash.h.

Field Documentation

◆ cmp

int(* cr8r_hashtbl_ft::cmp) (const cr8r_base_ft *, const void *, const void *)

Function to compare elements.

Should only depend on "key" data within the elements. Should return 0 for elements that are equal, or any nonzero int for elements that are not equal. Equality according to this function should imply equal hash values. Currently no requirement is placed on return values for unequal operands beyond being nonzero, but if possible <0 should indicate the first operand is smaller, >0 should indicate the first argument is large, and the function should avoid returning INT_MIN

Definition at line 68 of file hash.h.

◆ add

int(* cr8r_hashtbl_ft::add) (cr8r_base_ft *, void *, void *)

Function to combine two elements.

Should only depend on "value" data within the elements. Specifying this function can be used to define behavior when cr8r_hash_append is called and an element with the given key already exists, such as adding the int values in any key->int map to create a counter. The first void* argument is the existing entry, and the second is the entry passed to append. Should return 0 on failure, nonzero on success.

Definition at line 74 of file hash.h.

◆ del

void(* cr8r_hashtbl_ft::del) (cr8r_base_ft *, void *)

Function to be called to delete elements.

Not required. Specifying this function allows cleaning up sensitive data by jumbling the memory of an element when it is deleted (including when the whole hash table is deleted), freeing resources "owned" by elements, and so on. If not specified, deleting elements/the whole hash table will be slightly quicker.

Definition at line 79 of file hash.h.

◆ load_factor

double cr8r_hashtbl_ft::load_factor

Maximum allowable ratio of entries present to total capacity.

According to the birthday paradox, at least one collision is expected even with a perfect hash function and random data once the load facter reaches the square root of the capacity, but nevertheless good performance can be expected even up to 50% load factor or possibly higher. Setting lower than .3 would be extravagant and lower than .1 would probably be absurd.

Definition at line 85 of file hash.h.


The documentation for this struct was generated from the following file: