index.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /** Limited-scope, fast implementation of a bi-directional hash table.
  2. *
  3. * This data structure holds an array of key-value pairs. It is append-only.
  4. *
  5. * A key is the result of a hash function applied to the value, and keys are
  6. * unique within an index. Hence, both keys and values are uniqure and lookups
  7. * can be done both ways.
  8. *
  9. * A value is a pointer to a `LSUP_SerTerm` structure. Comparison for
  10. * uniqueness is done by comparing the hashes/keys.
  11. *
  12. * To find a key by its value, it is sufficient to apply the hash function to
  13. * the value without having to look up the table.
  14. */
  15. #include "buffer.h"
  16. #include "term.h"
  17. typedef struct Index LSUP_Index;
  18. LSUP_Index *LSUP_index_new(size_t capacity);
  19. /**
  20. * Add a key/value pair. The key must be calculated in advance.
  21. *
  22. * This function takes ownership of the serialized term.
  23. */
  24. int LSUP_index_add_pair(LSUP_Index *idx, LSUP_Key key, LSUP_SerTerm *sterm);
  25. /**
  26. * Add a term and automatically calculate the key.
  27. *
  28. * This function takes ownership of the serialized term.
  29. */
  30. int LSUP_index_add(LSUP_Index *idx, LSUP_SerTerm *sterm);
  31. LSUP_SerTerm *LSUP_index_lookup(LSUP_Index *idx, LSUP_Key key);
  32. void LSUP_index_free(LSUP_Index *idx);