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