Next: Troubleshooting
Up: Modules in deep
Previous: Internal list functions
  Contents
  Index
Hash tables are used internally to access string arrays (which are
used to save attributes that are created in real time, for example),
and may be useful to you. The functions provided are not as flexible
as the linked list ones, but should suffice for most uses. Remember
to include hash.h.
-
- int hash_init ( HashTable *t, int size, int (*hash_func)(char *));
Initialize a hash table, with size entries, using hash_func
as the hash generator func. If t is NULL, the function automatically
mallocs memory for it. If hash_func is NULL, the default
internal hash generator is used. Returns -1 on error, 0 if OK.
-
- int hash_insert ( HashTable *t, char *key, void *data );
Inserts a new entry in table t, with key key, which
will contain data. Returns -1 on error, -2 if the data already
exists, or the hash if everything was OK (although theoretically the
hash should be hidden from the user, etc, it's used internally by
GOCR to store character attributes. You can safely ignore the hash,
and use if (hash_insert()) < 0 { error}).
-
- void *hash_del ( HashTable *t, char *key );
Deletes the entry associated with the key. Returns a pointer
to the data structure, which is not freed.
-
- void *hash_data ( HashTable *t, char *key );
Returns the a pointer to the data associated associated with key.
-
- int hash_free ( HashTable *t, void (*free_func)(void *));
Frees the hash table contents. If free_func is not NULL,
it's called for every data stored in the table. Does not free the
hash table structure itself.
-
- char *hash_key ( HashTable *t, void *data );
Searches the hash table for the first ocurrence of data, and returns
the corresponding key.
Next: Troubleshooting
Up: Modules in deep
Previous: Internal list functions
  Contents
  Index
root
2002-02-17