use "unsigned long" for indexing
[rrq/rrqmisc.git] / pvector / hashvector.h
1 #ifndef hashvector_H
2 #define hashvector_H
3
4 #ifdef USE_PTHREAD
5 #define __USE_GNU 1
6 #include <pthread.h>
7 #endif
8
9 #include "pvector.h"
10
11 typedef struct _hashvector {
12     pvector table;
13     unsigned int fill;    // number of added elements
14     unsigned int holes;   // number of deleted
15     int (*keyhashcode)(void *key);
16     void *(*itemkey)(void *item);
17     int (*haskey)(void *item,void *key);
18 #ifdef USE_PTHREAD
19     pthread_mutex_t lock;
20 #endif
21 } hashvector;
22
23 #define HV_HOLE ((void*) 1)
24
25 // Find the keyed element, and assign the x pointer, or assign 0.
26 // Returns 1 if element is found and 0 otherwise.
27 int hashvector_find(hashvector *hv,void *key,void **x);
28
29 // Add the given element.
30 void hashvector_add(hashvector *hv,void *p);
31
32 // Return the next element starting at i, or 0 if there are no more.
33 // Also increment the index to be of the element + 1, or -1 if there
34 // are no more elements.
35 //unsigned char *htnext(htable *table,int *i);
36
37 // Delete the given element.
38 void hashvector_delete(hashvector *hv,void *p);
39
40 // Copy content items into pvector, which must be empty.
41 int hashvector_pack(hashvector *hv,pvector *pv);
42
43 #endif