man rbhash (Fonctions bibliothèques) - Roy hash table

NAME

rbhash - Roy hash table

SYNOPSIS

#include <roy.h>

DESCRIPTION

A memory and speed efficent hash table implementation designed for small as well as a large number of entries. The entries are defined by the programmer, as well as allocated by the programmer prior to insertion into the hash table.

RBHash is identical to RHash except that it is optimized for RBuf keys. This yeilds an additional 30% or so speed increase to RHash. The speed increase is due to special casing and not having to check the compare and hash functions.

The User Defined Entry
In order to use this hash table, you must create your own structure to be used as the entries in the hash table. This structure *MUST* start with the first entry as 'RBHASH_HEADER;'.
        struct FooEntry {
                RBHASH_HEADER;
                char *foodata;
                /* ... */
        };
You can create the toplevel RBHash structure by using rbhash_new(3) (free with rbhash_free(3)), or you can allocate the hash structure yourself, and call RBHASH_INIT(hash) on it. This initializes hash to be totally empty.
RBHASH_INIT (hash)
Initialize a newly created hash table. The 'hash' argument needs to be an RBHash struct.
        {
                RBHash hash;
                RBHASH_INIT (&hash);
                /* ... rbhash functions ... */
        }
RBHASH_DESTRUCT (hash)
Free up the table pointing to the entries and reset the hash table completely empty.
        {
                RBHash hash;
                RBHASH_INIT (&hash);
                /* ... */
                RBHASH_DESTRUCT (&hash);
        }
RBHASH_FOREACH (hash, entry)
This macro walks through a hash, assigning 'entry' to a hash entry through each iteration. Caution while the programmer can use CWbreak, CWcontinue, or CWgoto safely, the order of the entries is not defined. All rbhash functions except rbhash_free(3) can be called safely inside the RBHASH_FOREACH macro.
        RBHASH_FOREACH (hash, entry) {
                if (entry->foodata == NULL)
                        break;
                printf ("Data: %s.\n", entry->foodata);
        } RFOREACH_CLOSE;

SEE ALSO