man rhash_new (Fonctions bibliothèques) - allocate a new rhash

NAME

rhash_new - allocate a new rhash

SYNOPSIS

#include <roy.h>

RHash * rhash_new (RHashHashFunction hash_function, RHashCompareFunction compare_function);

DESCRIPTION

Create a new structure to hold a hash. The functions for hashing the type intended to be used in the table, as well as a function for comparing these types, are provided.

RETURN VALUE

This function will always succeed in returning a newly allocated rhash structure. This structure should later be freed using rhash_free(3).

HASH FUNCTION

The hash function passed in as the hash_function argument to rhash_new(3) is defined as:

typedef unsigned long (*RHashHashFunction) (const void *key);

and should be declared as:

unsigned long rhash_hash_function (const void *key);

This function will then cast key to the appropriate structure used in the hash table, and then perform a hashing algorithm on the key stored within the structure.

This algorithm should attempt to return a unique unsigned long integer corresponding to the key.

Passing in a NULL for this argument will cause rhash_new(3) to use the value of the pointer key passed to insert/lookup as the key.

COMPARE FUNCTION

The compare function passed in as the compare_function argument to rhash_new(3) is defined as:

typedef unsigned int (*RHashCompareFunction) (const void *entry_key, const void *key);

and should be declared as:

unsigned int rhash_compare_function (const void *entry_key, const void *key);

The entry_key should then be cast to the key type being used, as should key. key will be the key as passed into the rhash_lookup(3) function, and entry_key will be the key of the entry being tested. This function should then return TRUE if the two keys are equal, or FALSE if they are not.

Passing in a NULL for this argument will cause RHash to use the value of the pointer passed in as they key as an unsigned long integer, which it will then compare directly as an integer to the entries.

ERRORS

The rhash_new(3) call will never return any failure condition. Any out of memory issues are delt with by rmem(3) functions.

SEE ALSO