hash.h

pdirt/drv/compiler/hash.h · 1.5 KB

From the archive pDirt-1_tar.gz

Download the archive   « Back to the archive contents

#ifndef HASH_H_
#define HASH_H_

/* Nice macro to produce some usefull debugging info if memory allocation
 * failed.
 */
#define memAlloc(T,M,N)		ymalloc(sizeof(T),M,N,__FILE__,__LINE__)

/* To calculate the key of the hashtable
 */
typedef long hashKey;

/* First we need a overall record type to store data in and which we can 
 * place in the hashtable.
 */
typedef struct _hashRecord {
     char        *id;			/* Dynamically allocated id string */
     long	 idnumber;		/* Number related to this id */
     struct      _hashRecord *next;
} hashRecord;

typedef struct _hashTable {
     hashRecord   **hashtable;		/* The actual table */
     size_t       size;			/* The size of the table */

     size_t	  elems_stored;		/* Debugging info */
     size_t	  insertcollisions;	/* Also */
     size_t	  findcollisions;	/* ditto */
} hashTable;

/***************************************************************************
 ** PROTOTYPES
 ****************************************************************************/
void        freeHashRecord(hashRecord *ptr);
hashTable  *createHashTable(size_t size);
hashKey     calcHashKey(char *id, size_t tablesize);
int         addHashRecord(hashRecord *newptr, hashTable *to);
hashRecord *findHashRecord(char *id, hashTable *table);
hashRecord *createHashRecord(char *id,long idnum);
int        deleteHashRecord(char *id, hashTable *from);
int        deleteHashTable(hashTable *thistable);
void       printHashTableStatistics(hashTable *h);

void      *ymalloc(size_t size, size_t nmembers,int typenr, char *file, int line);

#endif

Site Stats

Snippets: 1791
Codebases: 571