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];
182 return " NAMESPACE "; /* actually not used in dep2str */
187 case REL_FILECONFLICT:
188 return " FILECONFLICT ";
192 return " compat >= ";
202 /* get e:v.r for Id */
204 pool_id2evr(const Pool *pool, Id id)
209 rd = GETRELDEP(pool, id);
210 if (ISRELDEP(rd->evr))
212 return pool->ss.stringspace + pool->ss.strings[rd->evr];
216 dep2strlen(const Pool *pool, Id id)
222 Reldep *rd = GETRELDEP(pool, id);
223 /* add 2 for parens */
224 l += 2 + dep2strlen(pool, rd->name) + strlen(pool_id2rel(pool, id));
227 return l + strlen(pool->ss.stringspace + pool->ss.strings[id]);
231 dep2strcpy(const Pool *pool, char *p, Id id, int oldrel)
235 Reldep *rd = GETRELDEP(pool, id);
236 if (oldrel == REL_AND || oldrel == REL_OR || oldrel == REL_WITH)
237 if (rd->flags == REL_AND || rd->flags == REL_OR || rd->flags == REL_WITH)
238 if (oldrel != rd->flags)
241 dep2strcpy(pool, p, rd->name, rd->flags);
243 strcpy(p, pool_id2rel(pool, id));
245 dep2strcpy(pool, p, rd->evr, rd->flags);
249 if (rd->flags == REL_KIND)
251 dep2strcpy(pool, p, rd->evr, rd->flags);
258 dep2strcpy(pool, p, rd->name, rd->flags);
260 if (rd->flags == REL_NAMESPACE)
263 dep2strcpy(pool, p, rd->evr, rd->flags);
267 if (rd->flags == REL_FILECONFLICT)
272 strcpy(p, pool_id2rel(pool, id));
277 strcpy(p, pool->ss.stringspace + pool->ss.strings[id]);
281 pool_dep2str(Pool *pool, Id id)
285 return pool->ss.stringspace + pool->ss.strings[id];
286 p = pool_alloctmpspace(pool, dep2strlen(pool, id) + 1);
287 dep2strcpy(pool, p, id, 0);
292 pool_shrink_strings(Pool *pool)
294 stringpool_shrink(&pool->ss);
298 pool_shrink_rels(Pool *pool)
300 pool->rels = solv_extend_resize(pool->rels, pool->nrels, sizeof(Reldep), REL_BLOCK);
303 /* free all hash tables */
305 pool_freeidhashes(Pool *pool)
307 stringpool_freehash(&pool->ss);
308 pool->relhashtbl = solv_free(pool->relhashtbl);
309 pool->relhashmask = 0;