rwhashtab.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #ifndef RWHASHTAB_H_
  2. #define RWHASHTAB_H_
  3. #include <stddef.h> /* size_t */
  4. #include <stdint.h> /* uint8_t */
  5. /**
  6. * Structure used to store RW hash table state.
  7. */
  8. typedef struct rwhashtab_internal RWHASHTAB;
  9. /**
  10. * rwhashtab_init(keyoffset, keylength):
  11. * Create an empty hash ${table} for storing records which contain keys of
  12. * length ${keylength} bytes starting at offset ${keyoffset} from the start
  13. * of each record. Return NULL on failure.
  14. */
  15. RWHASHTAB * rwhashtab_init(size_t, size_t);
  16. /**
  17. * rwhashtab_getsize(table):
  18. * Return the number of entries in the ${table}.
  19. */
  20. size_t rwhashtab_getsize(RWHASHTAB *);
  21. /**
  22. * rwhashtab_insert(table, record):
  23. * Insert the provided ${record} into the hash ${table}. Return (-1) on error,
  24. * 0 on success, and 1 if the table already contains a record with the same
  25. * key.
  26. */
  27. int rwhashtab_insert(RWHASHTAB *, void *);
  28. /**
  29. * rwhashtab_read(table, key):
  30. * Return a pointer to the record in the ${table} with the specified ${key}, or
  31. * NULL if no such record exists.
  32. */
  33. void * rwhashtab_read(RWHASHTAB *, const uint8_t *);
  34. /**
  35. * rwhashtab_foreach(table, func, cookie):
  36. * Call ${func(record, cookie)} for each ${record} in the hash ${table}. Stop
  37. * the iteration early if ${func} returns a non-zero value; return 0 or the
  38. * non-zero value returned by ${func}.
  39. */
  40. int rwhashtab_foreach(RWHASHTAB *, int(void *, void *), void *);
  41. /**
  42. * rwhashtab_free(table):
  43. * Free the hash ${table}.
  44. */
  45. void rwhashtab_free(RWHASHTAB *);
  46. #endif /* !RWHASHTAB_H_ */