File: hash_table.h

package info (click to toggle)
ifile 1.3.9-10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,124 kB
  • sloc: ansic: 7,409; makefile: 344; sh: 269
file content (31 lines) | stat: -rw-r--r-- 1,188 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* header file for self-resizing hash table */
/* written by Jason Rennie <jr6b+@andrew.cmu.edu> */

#define CROWDED_PCT 0.50

typedef struct _hash_elem {
  void * index;
  void * entry;
} hash_elem;

typedef struct _htable {
  int num_slots;                 /* size of DATA array */
  int num_entries;               /* # of slots in DATA array being used */
  hash_elem * data;              /* array of HASH_ELEMs */
  /* S is pointer to index string.  SIZE is size of htable */
  unsigned long (*hash) (const void * s, long int size);
} htable;

void htable_init(htable * hash_table, long int num_slots,
		 unsigned long (*hash_fun) (const void *, long int));
void htable_free(htable * hash_table, 
	    void (*free_index)(void *), void (*free_entry)(void *));
void htable_put(htable * hash_table, void * index, void * entry);
void * htable_lookup(htable * hash_table, void * index);
hash_elem * htable_init_traversal(htable * hash_table);
hash_elem * htable_next_traversal(htable * hash_table, hash_elem * elem);
void htable_resize(htable * hash_table, long int num_slots);


void htable_free_guts(htable * hash_table, 
		      void (*free_index)(void *), void (*free_entry)(void *));