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