2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
13 #ifndef SATSOLVER_POOL_H
14 #define SATSOLVER_POOL_H
20 #include "pooltypes.h"
26 // see initpool_data[] in pool.c
29 #define ID_NULL STRID_NULL
30 #define ID_EMPTY STRID_EMPTY
31 #define SOLVABLE_NAME 2
32 #define SOLVABLE_ARCH 3
33 #define SOLVABLE_EVR 4
34 #define SOLVABLE_VENDOR 5
35 #define SOLVABLE_PROVIDES 6
36 #define SOLVABLE_OBSOLETES 7
37 #define SOLVABLE_CONFLICTS 8
38 #define SOLVABLE_REQUIRES 9
39 #define SOLVABLE_RECOMMENDS 10
40 #define SOLVABLE_SUGGESTS 11
41 #define SOLVABLE_SUPPLEMENTS 12
42 #define SOLVABLE_ENHANCES 13
43 #define SOLVABLE_FRESHENS 14
44 #define RPM_RPMDBID 15
45 #define SOLVABLE_PREREQMARKER 16 // normal requires before this, prereqs after this
46 #define SOLVABLE_FILEMARKER 17 // normal provides before this, generated file provides after this
47 #define NAMESPACE_INSTALLED 18
48 #define NAMESPACE_MODALIAS 19
49 #define NAMESPACE_SPLITPROVIDES 20
50 #define SYSTEM_SYSTEM 21
53 #define ARCH_NOARCH 24
54 #define REPODATA_EXTERNAL 25
55 #define REPODATA_KEYS 26
56 #define REPODATA_LOCATION 27
58 #define ID_NUM_INTERNAL 28
61 /* well known solvable */
62 #define SYSTEMSOLVABLE 1
65 /* how many strings to maintain (round robin) */
68 //-----------------------------------------------
73 struct _Stringpool ss;
75 Reldep *rels; // table of rels: Id -> Reldep
76 int nrels; // number of unique rels
77 Hashtable relhashtbl; // hash table: (name,evr,op ->) Hash -> Id
86 int promoteepoch; /* 0/1 */
88 Id *id2arch; /* map arch ids to scores */
89 Id lastarch; /* last valid entry in id2arch */
90 Queue vendormap; /* map vendor to vendorclasses mask */
92 /* providers data, as two-step indirect list
93 * whatprovides[Id] -> Offset into whatprovidesdata for name
94 * whatprovidesdata[Offset] -> ID_NULL-terminated list of solvables providing Id
96 Offset *whatprovides; /* Offset to providers of a specific name, Id -> Offset */
97 Offset *whatprovides_rel; /* Offset to providers of a specific relation, Id -> Offset */
99 Id *whatprovidesdata; /* Ids of solvable providing Id */
100 Offset whatprovidesdataoff; /* next free slot within whatprovidesdata */
101 int whatprovidesdataleft; /* number of 'free slots' within whatprovidesdata */
103 Id (*nscallback)(struct _Pool *, void *data, Id name, Id evr);
104 void *nscallbackdata;
106 /* our dep2str string space */
107 char *dep2strbuf[DEP2STRBUF];
108 int dep2strlen[DEP2STRBUF];
111 /* debug mask and callback */
113 void (*debugcallback)(struct _Pool *, void *data, int type, const char *str);
114 void *debugcallbackdata;
117 #define SAT_FATAL (1<<0)
118 #define SAT_ERROR (1<<1)
119 #define SAT_WARN (1<<2)
120 #define SAT_DEBUG_STATS (1<<3)
121 #define SAT_DEBUG_RULE_CREATION (1<<4)
122 #define SAT_DEBUG_PROPAGATE (1<<5)
123 #define SAT_DEBUG_ANALYZE (1<<6)
124 #define SAT_DEBUG_UNSOLVABLE (1<<7)
125 #define SAT_DEBUG_SOLUTIONS (1<<8)
126 #define SAT_DEBUG_POLICY (1<<9)
127 #define SAT_DEBUG_RESULT (1<<10)
128 #define SAT_DEBUG_JOB (1<<11)
129 #define SAT_DEBUG_SCHUBI (1<<12)
133 #define TYPE_IDARRAY 2
136 #define TYPE_REL_IDARRAY 5
138 #define TYPE_ATTR_INT 6
139 #define TYPE_ATTR_CHUNK 7
140 #define TYPE_ATTR_STRING 8
141 #define TYPE_ATTR_INTLIST 9
142 #define TYPE_ATTR_LOCALIDS 10
144 #define TYPE_COUNT_NAMED 11
145 #define TYPE_COUNTED 12
147 #define TYPE_IDVALUEARRAY 13
148 #define TYPE_IDVALUEVALUEARRAY 14
150 /* The special types are usable to encode one-valued attributes, they have
151 no associated data. This is useful to encode values which many solvables
152 have in common, and whose overall set is relatively limited. A prime
153 example would be the media number. Be warned: careless use of this
154 leads to combinatoric explosion of number of schemas. */
155 #define TYPE_ATTR_SPECIAL_START 15
156 #define TYPE_ATTR_SPECIAL_END (TYPE_ATTR_SPECIAL_START + 31)
157 #define TYPE_ATTR_TYPE_MAX TYPE_ATTR_SPECIAL_END
159 //-----------------------------------------------
162 /* mark dependencies with relation by setting bit31 */
164 #define MAKERELDEP(id) ((id) | 0x80000000)
165 #define ISRELDEP(id) (((id) & 0x80000000) != 0)
166 #define GETRELID(id) ((id) ^ 0x80000000) /* returns Id */
167 #define GETRELDEP(pool, id) ((pool)->rels + ((id) ^ 0x80000000)) /* returns Reldep* */
176 #define REL_NAMESPACE 19
178 #if !defined(__GNUC__) && !defined(__attribute__)
179 # define __attribute__(x)
185 extern Pool *pool_create(void);
189 extern void pool_free(Pool *pool);
191 extern void pool_debug(Pool *pool, int type, const char *format, ...) __attribute__((format(printf, 3, 4)));
194 * Solvable management
196 extern Id pool_add_solvable(Pool *pool);
197 extern Id pool_add_solvable_block(Pool *pool, int count);
199 extern void pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids);
200 static inline Solvable *pool_id2solvable(Pool *pool, Id p)
202 return pool->solvables + p;
204 extern const char *solvable2str(Pool *pool, Solvable *s);
208 * Prepares a pool for solving
210 extern void pool_createwhatprovides(Pool *pool);
211 extern void pool_addfileprovides(Pool *pool, struct _Repo *installed);
212 extern void pool_freewhatprovides(Pool *pool);
213 extern Id pool_queuetowhatprovides(Pool *pool, Queue *q);
215 static inline int pool_installable(Pool *pool, Solvable *s)
217 if (!s->arch || s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
219 if (pool->id2arch && (s->arch > pool->lastarch || !pool->id2arch[s->arch]))
224 extern Id *pool_addrelproviders(Pool *pool, Id d);
226 static inline Id *pool_whatprovides(Pool *pool, Id d)
230 return pool->whatprovidesdata + pool->whatprovides[d];
232 if (pool->whatprovides_rel[v])
233 return pool->whatprovidesdata + pool->whatprovides_rel[v];
234 return pool_addrelproviders(pool, d);
237 extern void pool_setdebuglevel(Pool *pool, int level);
239 static inline void pool_setdebugcallback(Pool *pool, void (*debugcallback)(struct _Pool *, void *data, int type, const char *str), void *debugcallbackdata)
241 pool->debugcallback = debugcallback;
242 pool->debugcallbackdata = debugcallbackdata;
245 static inline void pool_setdebugmask(Pool *pool, int mask)
247 pool->debugmask = mask;
250 /* loop over all providers of d */
251 #define FOR_PROVIDES(v, vp, d) \
252 for (vp = pool_whatprovides(pool, d) ; (v = *vp++) != 0; )
254 #define POOL_DEBUG(type, ...) do {if ((pool->debugmask & (type)) != 0) pool_debug(pool, (type), __VA_ARGS__);} while (0)
255 #define IF_POOLDEBUG(type) if ((pool->debugmask & (type)) != 0)
262 #endif /* SATSOLVER_POOL_H */