trie.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* This file is part of nit.
  2. *
  3. * Nit is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU Lesser General Public License as published by
  5. * the Free Software Foundation, either version 3 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * Nit is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU Lesser General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Lesser General Public License
  14. * along with nit. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef TRIE_H
  17. #define TRIE_H
  18. #include "map.h"
  19. typedef struct Trie_entry {
  20. Map map;
  21. struct Trie_entry *prev;
  22. void *dat;
  23. } Trie_entry;
  24. typedef struct Trie {
  25. Trie_entry *root;
  26. Disposer disposer;
  27. } Trie;
  28. Nit_error
  29. trie_init(Trie *trie, Disposer *disposer, const void *root_dat);
  30. void
  31. trie_dispose(Trie *trie);
  32. /* For single values */
  33. Trie_entry *
  34. trie_add(Trie *trie, Trie_entry *entry, uint32_t key_len,
  35. const void *key, const void *val);
  36. Nit_error
  37. trie_remove(Trie *trie, Trie_entry *entry, uint32_t key_len,
  38. const void *key, void **val);
  39. Trie_entry *
  40. trie_get(Trie_entry *entry, uint32_t key_len, const void *key);
  41. /* For lists of keys */
  42. Trie_entry *
  43. trie_list_add(Trie *trie, Trie_entry *entry, List *key_list, const void *val);
  44. Nit_error
  45. trie_list_remove(Trie *trie, Trie_entry *entry, List *key_list, void **val);
  46. Trie_entry *
  47. trie_list_get(Trie_entry *entry, List *key_list);
  48. #endif