---
name: "rbhash"
section: "3"
platform: "linux"
package: "libroy-dev"
version: "1.0.8-1"
release: "Debian 3.1 (Sarge)"
platforms: ["linux"]
url: "https://new.carta.tech/rbhash"
---

# rbhash(3)

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)](/rbhash_new/3.md) (free with [*rbhash\_free*(3)](/rbhash_free/3.md)), 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 `"break"`, `"continue"`, or `"goto"` safely, the order of the entries is not defined. All rbhash functions except [*rbhash\_free*(3)](/rbhash_free/3.md) 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

[*rbhash\_entry\_getkey*(3)](/rbhash_entry_getkey/3.md), [*rbhash\_entry\_setkey*(3)](/rbhash_entry_setkey/3.md),  [*rbhash\_free*(3)](/rbhash_free/3.md), [*rbhash\_insert*(3)](/rbhash_insert/3.md),  [*rbhash\_len*(3)](/rbhash_len/3.md), [*rbhash\_lookup*(3)](/rbhash_lookup/3.md),  [*rbhash\_lookup\_next*(3)](/rbhash_lookup_next/3.md), [*rbhash\_new*(3)](/rbhash_new/3.md),  [*rbhash\_remove*(3)](/rbhash_remove/3.md), [*rbhash\_remove\_entry*(3)](/rbhash_remove_entry/3.md),  [*roy*(3)](/roy/3.md)
