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