- add key filtering to repo_write
[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 SATSOLVER_STRINGPOOL_H
8 #define SATSOLVER_STRINGPOOL_H
9
10 #include "pooltypes.h"
11 #include "hash.h"
12
13 #define STRID_NULL  0
14 #define STRID_EMPTY 1
15
16 struct _Stringpool
17 {
18   Offset *strings;            // table of offsets into stringspace, indexed by Id: Id -> Offset
19   int nstrings;               // number of unique strings in stringspace
20   char *stringspace;          // space for all unique strings: stringspace + Offset = string
21   Offset sstrings;            // next free pos in stringspace
22
23   Hashtable stringhashtbl;    // hash table: (string ->) Hash -> Id
24   Hashmask stringhashmask;    // modulo value for hash table (size of table - 1)
25 };
26
27 void stringpool_init(Stringpool *ss, const char *strs[]);
28 void stringpool_init_empty(Stringpool *ss);
29 void stringpool_clone(Stringpool *ss, Stringpool *from);
30
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
35
36 static inline const char *
37 stringpool_id2str (Stringpool *ss, Id id)
38 {
39   return ss->stringspace + ss->strings[id];
40 }
41
42 #endif