2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
20 #include "poolid_private.h"
24 /* intern string into pool, return id */
27 pool_str2id(Pool *pool, const char *str, int create)
29 int oldnstrings = pool->ss.nstrings;
30 Id id = stringpool_str2id(&pool->ss, str, create);
31 if (create && pool->whatprovides && oldnstrings != pool->ss.nstrings && (id & WHATPROVIDES_BLOCK) == 0)
33 /* grow whatprovides array */
34 pool->whatprovides = solv_realloc(pool->whatprovides, (id + (WHATPROVIDES_BLOCK + 1)) * sizeof(Offset));
35 memset(pool->whatprovides + id, 0, (WHATPROVIDES_BLOCK + 1) * sizeof(Offset));
41 pool_strn2id(Pool *pool, const char *str, unsigned int len, int create)
43 int oldnstrings = pool->ss.nstrings;
44 Id id = stringpool_strn2id(&pool->ss, str, len, create);
45 if (create && pool->whatprovides && oldnstrings != pool->ss.nstrings && (id & WHATPROVIDES_BLOCK) == 0)
47 /* grow whatprovides array */
48 pool->whatprovides = solv_realloc(pool->whatprovides, (id + (WHATPROVIDES_BLOCK + 1)) * sizeof(Offset));
49 memset(pool->whatprovides + id, 0, (WHATPROVIDES_BLOCK + 1) * sizeof(Offset));
55 pool_rel2id(Pool *pool, Id name, Id evr, int flags, int create)
57 Hashval h, hh, hashmask;
63 hashmask = pool->relhashmask;
64 hashtbl = pool->relhashtbl;
67 /* extend hashtable if needed */
68 if ((Hashval)pool->nrels * 2 > hashmask)
70 solv_free(pool->relhashtbl);
71 pool->relhashmask = hashmask = mkmask(pool->nrels + REL_BLOCK);
72 pool->relhashtbl = hashtbl = solv_calloc(hashmask + 1, sizeof(Id));
73 /* rehash all rels into new hashtable */
74 for (i = 1; i < pool->nrels; i++)
76 h = relhash(ran[i].name, ran[i].evr, ran[i].flags) & hashmask;
79 h = HASHCHAIN_NEXT(h, hh, hashmask);
84 /* compute hash and check for match */
85 h = relhash(name, evr, flags) & hashmask;
87 while ((id = hashtbl[h]) != 0)
89 if (ran[id].name == name && ran[id].evr == evr && ran[id].flags == flags)
91 h = HASHCHAIN_NEXT(h, hh, hashmask);
94 return MAKERELDEP(id);
100 /* extend rel space if needed */
101 pool->rels = solv_extend(pool->rels, id, 1, sizeof(Reldep), REL_BLOCK);
103 ran = pool->rels + id;
108 /* extend whatprovides_rel if needed */
109 if (pool->whatprovides_rel && (id & WHATPROVIDES_BLOCK) == 0)
111 pool->whatprovides_rel = solv_realloc2(pool->whatprovides_rel, id + (WHATPROVIDES_BLOCK + 1), sizeof(Offset));
112 memset(pool->whatprovides_rel + id, 0, (WHATPROVIDES_BLOCK + 1) * sizeof(Offset));
114 return MAKERELDEP(id);
119 * for rels (returns name only) and strings
122 pool_id2str(const Pool *pool, Id id)
126 Reldep *rd = GETRELDEP(pool, id);
129 return pool->ss.stringspace + pool->ss.strings[id];
132 static const char *rels[] = {
144 /* get operator for RelId */
146 pool_id2rel(const Pool *pool, Id id)
151 rd = GETRELDEP(pool, id);
154 /* debian special cases < and > */
155 /* haiku special cases <> (maybe we should use != for the others as well */
156 case 0: case REL_EQ: case REL_GT | REL_EQ:
157 case REL_LT | REL_EQ: case REL_LT | REL_EQ | REL_GT:
158 #if !defined(DEBIAN) && !defined(MULTI_SEMANTICS)
159 case REL_LT: case REL_GT:
161 #if !defined(HAIKU) && !defined(MULTI_SEMANTICS)
162 case REL_LT | REL_GT:
164 return rels[rd->flags];
165 #if defined(DEBIAN) || defined(MULTI_SEMANTICS)
167 return pool->disttype == DISTTYPE_DEB ? " >> " : rels[rd->flags];
169 return pool->disttype == DISTTYPE_DEB ? " << " : rels[rd->flags];
171 #if defined(HAIKU) || defined(MULTI_SEMANTICS)
172 case REL_LT | REL_GT:
173 return pool->disttype == DISTTYPE_HAIKU ? " != " : rels[rd->flags];
176 return pool->disttype == DISTTYPE_RPM ? " and " : " & ";
178 return pool->disttype == DISTTYPE_RPM ? " or " : " | ";
180 return pool->disttype == DISTTYPE_RPM ? " with " : " + ";
182 return " NAMESPACE "; /* actually not used in dep2str */
187 case REL_FILECONFLICT:
188 return " FILECONFLICT ";
190 return pool->disttype == DISTTYPE_RPM ? " if " : " IF ";
192 return " compat >= ";
196 return pool->disttype == DISTTYPE_RPM ? " else " : " ELSE ";
204 /* get e:v.r for Id */
206 pool_id2evr(const Pool *pool, Id id)
211 rd = GETRELDEP(pool, id);
212 if (ISRELDEP(rd->evr))
214 return pool->ss.stringspace + pool->ss.strings[rd->evr];
218 dep2strlen(const Pool *pool, Id id)
224 Reldep *rd = GETRELDEP(pool, id);
225 /* add 2 for parens */
226 l += 2 + dep2strlen(pool, rd->name) + strlen(pool_id2rel(pool, id));
229 return l + strlen(pool->ss.stringspace + pool->ss.strings[id]);
233 dep2strcpy(const Pool *pool, char *p, Id id, int oldrel)
237 Reldep *rd = GETRELDEP(pool, id);
239 if (oldrel == REL_AND || oldrel == REL_OR || oldrel == REL_WITH || oldrel == REL_COND || oldrel == REL_ELSE || oldrel == -1)
240 if (rel == REL_AND || rel == REL_OR || rel == REL_WITH || rel == REL_COND || rel == REL_ELSE)
241 if ((oldrel != rel || rel == REL_COND || rel == REL_ELSE) && !(oldrel == REL_COND && rel == REL_ELSE))
244 dep2strcpy(pool, p, rd->name, rd->flags);
246 strcpy(p, pool_id2rel(pool, id));
248 dep2strcpy(pool, p, rd->evr, rd->flags);
252 if (rd->flags == REL_KIND)
254 dep2strcpy(pool, p, rd->evr, rd->flags);
261 dep2strcpy(pool, p, rd->name, rd->flags);
263 if (rd->flags == REL_NAMESPACE)
266 dep2strcpy(pool, p, rd->evr, rd->flags);
270 if (rd->flags == REL_FILECONFLICT)
275 strcpy(p, pool_id2rel(pool, id));
280 strcpy(p, pool->ss.stringspace + pool->ss.strings[id]);
284 pool_dep2str(Pool *pool, Id id)
288 return pool->ss.stringspace + pool->ss.strings[id];
289 p = pool_alloctmpspace(pool, dep2strlen(pool, id) + 1);
290 dep2strcpy(pool, p, id, pool->disttype == DISTTYPE_RPM ? -1 : 0);
295 pool_shrink_strings(Pool *pool)
297 stringpool_shrink(&pool->ss);
301 pool_shrink_rels(Pool *pool)
303 pool->rels = solv_extend_resize(pool->rels, pool->nrels, sizeof(Reldep), REL_BLOCK);
306 /* free all hash tables */
308 pool_freeidhashes(Pool *pool)
310 stringpool_freehash(&pool->ss);
311 pool->relhashtbl = solv_free(pool->relhashtbl);
312 pool->relhashmask = 0;