strpool.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (c) 2007, Novell Inc.
  3. *
  4. * This program is licensed under the BSD license, read LICENSE.BSD
  5. * for further information
  6. */
  7. #ifndef LIBSOLV_STRINGPOOL_H
  8. #define LIBSOLV_STRINGPOOL_H
  9. #include "pooltypes.h"
  10. #include "hash.h"
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. #define STRID_NULL 0
  15. #define STRID_EMPTY 1
  16. struct s_Stringpool
  17. {
  18. Offset *strings; /* table of offsets into stringspace, indexed by Id: Id -> Offset */
  19. int nstrings; /* number of ids in strings table */
  20. char *stringspace; /* space for all unique strings: stringspace + Offset = string */
  21. Offset sstrings; /* size of used stringspace */
  22. Hashtable stringhashtbl; /* hash table: (string ->) Hash -> Id */
  23. Hashval stringhashmask; /* modulo value for hash table (size of table - 1) */
  24. };
  25. void stringpool_init(Stringpool *ss, const char *strs[]);
  26. void stringpool_init_empty(Stringpool *ss);
  27. void stringpool_clone(Stringpool *ss, Stringpool *from);
  28. void stringpool_free(Stringpool *ss);
  29. void stringpool_freehash(Stringpool *ss);
  30. void stringpool_resize_hash(Stringpool *ss, int numnew);
  31. Id stringpool_str2id(Stringpool *ss, const char *str, int create);
  32. Id stringpool_strn2id(Stringpool *ss, const char *str, unsigned int len, int create);
  33. void stringpool_shrink(Stringpool *ss);
  34. static inline const char *
  35. stringpool_id2str(Stringpool *ss, Id id)
  36. {
  37. return ss->stringspace + ss->strings[id];
  38. }
  39. #ifdef __cplusplus
  40. }
  41. #endif
  42. #endif