This HTML automatically generated with rman for NEMO
Table of Contents

Name

init_Hash_Table, get_hash, put_hash, next_hash - hash functions

Synopsis


struct Hash_Table* init_Hash_Table();
void* get_hash(Hash_Table, key);
bool  put_hash(Hash_Table, key, object);
void* next_hash(Hash_Table, firstp);
struct Hash_Table *Hash_Table;
string key;
void *object;
bool firstp; 

Description

hash implements a general hashing technique of storing and retrieving keyword based information in a hashed database. Each database must be initialized with a call to init_Hash_Table, which returns a handle that is subsequently used to store and retrieve information.

put_hash stores the information: it uses the pointers to the key and object you supply, which must hence be in safe memory, not local variables. It returns FALSE if for some reason the key could not be stored (a common cause would be if the key had already been entered).

get_hash returns a pointer to the object requested by name key. It returns NULL if no data found.

next_hash iterated over all objects, in the order as stored in the hash table. It MUST be called the first time with firstp set to TRUE. It can be iterated until NULL is returned.

Limitations

The largest prime number stored is 524287.

Example


    typedef struct keyval {
        char *key;
        char *val;
    } keyval;
    keyval x[] = {
        "in",  "???",
        "out", "???",
        "n",   "10",
        "k",   "2",
        "x",   "2.342",
        "pi",  "PI",
        NULL,  NULL,
    };
    struct Hash_Table  *h;
    keyval *xp;
    int i;
    h = init_Hash_Table();                                  /* init */
    for (xp=x; xp->key; xp++) {                             /* store */
        if (!put_hash(h,xp->key, xp->val))
            printf("### error put_hash0);
    }
    for (i=1; i<ac; i++)                                    /* retrieve
*/
        printf("%s -> %s0,av[i],(char *)get_hash(h,av[i]));

See Also

getparam(3NEMO) , bsearch(3) , hsearch(3) , lsearch(3) , tsearch(3)

Author

LGO

Files

$NEMO/usr/lib/misc

Copyright

Copyright (C) 1990 Texas Instruments Incorporated.

Permission is granted to any individual or institution to use, copy, modify, and distribute this software, provided that this complete copyright and permission notice is maintained, intact, in all copies and supporting documentation.

Texas Instruments Incorporated provides this software "as is" without express or implied warranty.

Implementation

The following is an extract from hash.h and shows the implementation of the hash tables.
#define BUCKET_SIZE 8
struct hash_pair {
  char* key;
  void* value;
};
struct bucket {
  struct hash_pair data[BUCKET_SIZE];
};
struct Hash_Table {
  struct bucket* table;
  unsigned char* items_in_buckets;
  int entry_count;
  int bucket_index;
  int current_bucket;
  int current_index;
}

Update History


30-mar-89    Initial design and implementation.    LGO
28-apr-92    Adapted from the TI cpp for NEMO          PJT


Table of Contents