/* Hash table structures and constants */ #ifndef __HASH_H #define __HASH_H /* Hash table entry */ struct hash_entry{ /* Key used for hashing */ void* key; /* Additional data */ void* data; /* Flag to show state of entry (VALID, EMPTY, DELETED) */ int state; /* If this is entry with collisions where is next value, or if this is empty spot where is the next spot. This is hash index. */ int next; /* If this is empty slot, what is its predecessor in list of empty slots */ int prev; }; /* Hash table This is really an attempt to make classfull, reusable structure in C */ struct hash_table{ /* Contents */ struct hash_entry* entries; /* Number of entries */ unsigned long size; unsigned long min_size; unsigned long max_size; /* Number of filled entries */ unsigned long filled; /* Size of key */ int key_size; /* Size of data */ int data_size; /* Load factors for rehashing */ double rehash_lf_high; double rehash_lf_low; /* Flag indicating that hash is dangerously full and can not grow anymore. Then drastic cleaning has to be done */ int FULL_ALERT; /* Points to the first empty spot, all empty spots are linked together */ int empty; /* Function to check if entry can be deleted depending on urgency of deletion */ int (*clean)(void*); /* Function to compare keys if they are same it returns 1 if they are same, and 0 otherwise */ int (*compare)(void*, void*); /* First hash function, for double hashing */ unsigned long (*hash1)(void*,unsigned long); /* Sometimes it is useful to forbid rehashing */ int no_rehash; }; struct subnet { unsigned int ip; char checklist[256]; int count; struct subnet *next; }; /* Function prototypes, refer to implementation in hash.c for descriptions */ int test_prime(long); void create_hash(struct hash_table**, unsigned long, unsigned long, unsigned long, double, double, int, int, int (*)(void*), int (*)(void*,void*), unsigned long (*)(void*,unsigned long)); void clean_table(struct hash_table*); void rehash(int, struct hash_table*); long insert(void*, struct hash_table*, int*); long find(void*, struct hash_table*); long delete(void*, struct hash_table*); void check_rehash(struct hash_table*); #define NEW 1 #define FAILED -1 #define EXISTING 2 #endif