hash.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * addr_hash.h:
  3. *
  4. */
  5. #ifndef __HASH_H_ /* include guard */
  6. #define __HASH_H_
  7. /* implementation independent declarations */
  8. typedef enum {
  9. HASH_STATUS_OK,
  10. HASH_STATUS_MEM_EXHAUSTED,
  11. HASH_STATUS_KEY_NOT_FOUND
  12. } hash_status_enum;
  13. typedef struct node_tag {
  14. struct node_tag *next; /* next node */
  15. void* key; /* key */
  16. void* rec; /* user data */
  17. } hash_node_type;
  18. typedef struct {
  19. int (*compare) (void*, void*);
  20. int (*hash) (void*);
  21. void* (*copy_key) (void*);
  22. void (*delete_key) (void*);
  23. hash_node_type** table;
  24. int size;
  25. } hash_type;
  26. hash_status_enum hash_initialise(hash_type*);
  27. hash_status_enum hash_destroy(hash_type*);
  28. hash_status_enum hash_insert(hash_type*, void* key, void *rec);
  29. hash_status_enum hash_delete(hash_type* hash_table, void* key);
  30. hash_status_enum hash_find(hash_type* hash_table, void* key, void** rec);
  31. hash_status_enum hash_next_item(hash_type* hash_table, hash_node_type** ppnode);
  32. void hash_delete_all(hash_type* hash_table);
  33. #endif /* __HASH_H_ */