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