HT(3X)

NAME
ht_create, ht_destroy, ht_insert, ht_insert_uniq, ht_delete, ht_search, ht_minimum, ht_maximum, ht_successor, ht_predecessor, ht_iterate, ht_nextobj - hash table management functions

SYNOPSIS

#include "dict.h"
#include "ht.h"

dict_h ht_create( oo_compare, ko_compare, flags, errnop, argsp )
int (*oo_compare)( dict_obj, dict_obj ) ;
int (*ko_compare)( dict_key, dict_obj ) ;
int flags ;
int *errnop ;
struct ht_args *argsp ;

void ht_destroy( handle )
dict_h handle ;

int ht_insert( handle, object )
dict_h handle ;
dict_obj object ;

int ht_insert_uniq( handle, object, objectp )
dict_h handle ;
dict_obj object ;
dict_obj *objectp ;

int ht_delete( handle, object )
dict_h handle ;
dict_obj object ;

dict_obj ht_search( handle, key )
dict_h handle ;
dict_key key ;

dict_obj ht_minimum( handle )
dict_h handle ;

dict_obj ht_maximum( handle )
dict_h handle ;

dict_obj ht_successor( handle, object )
dict_h handle ;
dict_obj object ;

dict_obj ht_predecessor( handle, object )
dict_h handle ;
dict_obj object ;

void ht_iterate( handle, direction )
dict_h handle ;
enum dict_direction direction ;

dict_obj ht_nextobj( handle )
dict_h handle ;

DESCRIPTION
This library supports dictionary functions using hash tables. A hash table is an array of linked lists which contain objects with the same hash value.

ht_create() supports the following flags:

    DICT_RETURN_ERROR

    DICT_UNIQUE_KEYS

    DICT_UNORDERED

The argsp argument points to this structure:

    struct ht_args
    {
        unsigned ht_table_entries ;
        unsigned ht_bucket_entries ;
        ht_func ht_objvalue ;
        ht_func ht_keyvalue ;
    } ;

where ht_func is defined as:

    typedef ht_val (*ht_func)() ;

The ht_table_entries field determines the number of entries in the hash table. The hash function used is a modulo function, so in order to make sure that a proper number is used, the ht_table_entries is treated as a hint about the order of the number of entries of the table. If it is 0 then a default number of entries will be used. Every entry in the table points to a linked list of buckets where the objects are kept. The ht_bucket_entries field determines the number of objects in each bucket. If it is 0 a default number will be used. Otherwise, it is treated as a hint for the number of entries in each bucket. The fields ht_table_entries and ht_bucket_entries are treated as value-result parameters. On return from this function they will contain the actual values that will be used for this hash table.

A hash table does not order the objects stored in it; therefore the direction argument in the ht_iterate() call is ignored. Furthermore, the ht_minimum(), ht_maxumim(), ht_successor(), and ht_predecessor() operations can be used to enumerate the objects in a hash table but the enumeration order is arbitrary.

SEE ALSO
dict(3)

RETURN VALUES
Check dict(3) for function return values and error codes.