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