fd13bdb71bc0cd98cce86073f94297e0605f57b0
[platform/upstream/libsolv.git] / src / strpool.h
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
10 #include "pooltypes.h"
11 #include "hash.h"
12
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16
17 #define STRID_NULL  0
18 #define STRID_EMPTY 1
19
20 struct s_Stringpool
21 {
22   Offset *strings;            /* table of offsets into stringspace, indexed by Id: Id -> Offset */
23   int nstrings;               /* number of ids in strings table */
24   char *stringspace;          /* space for all unique strings: stringspace + Offset = string */
25   Offset sstrings;            /* size of used stringspace */
26
27   Hashtable stringhashtbl;    /* hash table: (string ->) Hash -> Id */
28   Hashval stringhashmask;     /* modulo value for hash table (size of table - 1) */
29 };
30
31 void stringpool_init(Stringpool *ss, const char *strs[]);
32 void stringpool_init_empty(Stringpool *ss);
33 void stringpool_clone(Stringpool *ss, Stringpool *from);
34 void stringpool_free(Stringpool *ss);
35 void stringpool_freehash(Stringpool *ss);
36 void stringpool_resize_hash(Stringpool *ss, int numnew);
37
38 Id stringpool_str2id(Stringpool *ss, const char *str, int create);
39 Id stringpool_strn2id(Stringpool *ss, const char *str, unsigned int len, int create);
40
41 void stringpool_shrink(Stringpool *ss);
42
43
44 static inline const char *
45 stringpool_id2str(Stringpool *ss, Id id)
46 {
47   return ss->stringspace + ss->strings[id];
48 }
49
50 #ifdef __cplusplus
51 }
52 #endif
53
54 #endif