- move dep2str buffer into pool so that the memory gets released
[platform/upstream/libsolv.git] / src / pool.h
1 /*
2  * pool.h
3  * 
4  */
5
6 #ifndef POOL_H
7 #define POOL_H
8
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12
13 #include "pooltypes.h"
14 #include "poolid.h"
15 #include "repo.h"
16 #include "solvable.h"
17 #include "queue.h"
18
19 // bool
20 #ifndef __cplusplus
21 #ifndef SWIG
22  typedef _Bool bool;
23 #endif
24 #endif
25 // see initpool_data[] in pool.c
26
27 /* well known ids */
28 #define ID_NULL                 0
29 #define ID_EMPTY                1
30 #define SOLVABLE_NAME           2
31 #define SOLVABLE_ARCH           3
32 #define SOLVABLE_EVR            4
33 #define SOLVABLE_PROVIDES       5
34 #define SOLVABLE_OBSOLETES      6
35 #define SOLVABLE_CONFLICTS      7
36 #define SOLVABLE_REQUIRES       8
37 #define SOLVABLE_RECOMMENDS     9
38 #define SOLVABLE_SUGGESTS       10
39 #define SOLVABLE_SUPPLEMENTS    11
40 #define SOLVABLE_ENHANCES       12
41 #define SOLVABLE_FRESHENS       13
42 #define RPM_RPMDBID             14
43 #define SOLVABLE_PREREQMARKER   15              // normal requires before this, prereqs after this
44 #define SOLVABLE_FILEMARKER     16              // normal provides before this, generated file provides after this
45 #define NAMESPACE_INSTALLED     17
46 #define NAMESPACE_MODALIAS      18
47 #define SYSTEM_SYSTEM           19
48 #define ARCH_SRC                20
49 #define ARCH_NOSRC              21
50 #define ARCH_NOARCH             22
51
52 /* well known solvable */
53 #define SYSTEMSOLVABLE          1
54
55
56 /* how many strings to maintain (round robin) */
57 #define DEP2STRBUF 16
58
59
60 //-----------------------------------------------
61
62 struct _Pool {
63   int verbose;          // pool is used everywhere, so put the verbose flag here
64
65   Offset *strings;            // table of offsets into stringspace, indexed by Id: Id -> Offset
66   int nstrings;               // number of unique strings in stringspace
67   char *stringspace;          // space for all unique strings: stringspace + Offset = string
68   Offset sstrings;            // next free pos in stringspace
69
70   Hashtable stringhashtbl;    // hash table: (string ->) Hash -> Id
71   Hashmask stringhashmask;    // modulo value for hash table (size of table - 1)
72
73   Reldep *rels;               // table of rels: Id -> Reldep
74   int nrels;                  // number of unique rels
75   Hashtable relhashtbl;       // hash table: (name,evr,op ->) Hash -> Id
76   Hashmask relhashmask;
77
78   Repo **repos;
79   int nrepos;
80
81   Solvable *solvables;
82   int nsolvables;
83
84   bool promoteepoch;
85
86   Id *id2arch;                  /* map arch ids to scores */
87   Id lastarch;                  /* last valid entry in id2arch */
88
89   /* providers data, as two-step indirect list
90    * whatprovides[Id] -> Offset into whatprovidesdata for name
91    * whatprovidesdata[Offset] -> ID_NULL-terminated list of solvables providing Id
92    */
93   Offset *whatprovides;         /* Offset to providers of a specific name, Id -> Offset  */
94   Id *whatprovidesdata;         /* Ids of solvable providing Id */
95   Offset whatprovidesdataoff;   /* next free slot within whatprovidesdata */
96   int whatprovidesdataleft;     /* number of 'free slots' within whatprovidesdata */
97
98   Id (*nscallback)(struct _Pool *, void *data, Id name, Id evr);
99   void *nscallbackdata;
100
101   /* our dep2str string space */
102   char *dep2strbuf[DEP2STRBUF];
103   int   dep2strlen[DEP2STRBUF];
104   int   dep2strn;
105 };
106
107 #define TYPE_ID                 1
108 #define TYPE_IDARRAY            2
109 #define TYPE_STR                3
110 #define TYPE_U32                4
111 #define TYPE_BITMAP             128
112
113
114 //-----------------------------------------------
115
116 // whatprovides
117 //  "foo" -> Id -> lookup in table, returns offset into whatprovidesdata where array of Ids providing 'foo' are located, 0-terminated
118
119
120 #define GET_PROVIDESP(d, v) (ISRELDEP(d) ?                              \
121              (v = GETRELID(pool, d), pool->whatprovides[v] ?            \
122                pool->whatprovidesdata + pool->whatprovides[v] :         \
123                pool_addrelproviders(pool, d)                            \
124              ) :                                                        \
125              (pool->whatprovidesdata + pool->whatprovides[d]))
126
127 /* loop over all providers of d */
128 #define FOR_PROVIDES(v, vp, d)                                          \
129   for (vp = GET_PROVIDESP(d, v) ; (v = *vp++) != ID_NULL; )
130
131 /* mark dependencies with relation by setting bit31 */
132
133 #define MAKERELDEP(id) ((id) | 0x80000000)
134 #define ISRELDEP(id) (((id) & 0x80000000) != 0)
135 #define GETRELID(pool, id) ((pool)->nstrings + ((id) ^ 0x80000000))     /* returns Id  */
136 #define GETRELDEP(pool, id) ((pool)->rels + ((id) ^ 0x80000000))        /* returns Reldep* */
137
138 #define REL_GT          1
139 #define REL_EQ          2
140 #define REL_LT          4
141
142 #define REL_AND         16
143 #define REL_OR          17
144 #define REL_WITH        18
145 #define REL_NAMESPACE   19
146
147 /**
148  * Creates a new pool
149  */
150 extern Pool *pool_create(void);
151 /**
152  * Delete a pool
153  */
154 extern void pool_free(Pool *pool);
155 /**
156  * ????
157  */
158 extern void pool_freerepo(Pool *pool, Repo *repo);
159 /**
160  * Prepares a pool for solving
161  */
162 extern void pool_prepare(Pool *pool);
163 extern void pool_freewhatprovides(Pool *pool);
164 extern Id pool_queuetowhatprovides(Pool *pool, Queue *q);
165
166 extern Id *pool_addrelproviders(Pool *pool, Id d);
167
168 static inline int pool_installable(Pool *pool, Solvable *s)
169 {
170   if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
171     return 0;
172   if (pool->id2arch && (s->arch > pool->lastarch || !pool->id2arch[s->arch]))
173     return 0;
174   return 1;
175 }
176
177 #ifdef __cplusplus
178 }
179 #endif
180
181 #endif /* POOL_H */