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 (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 case 0: case 2: case 3:
156 #if !defined(DEBIAN) && !defined(MULTI_SEMANTICS)
159 #if !defined(HAIKU) && !defined(MULTI_SEMANTICS)
162 return rels[rd->flags];
163 #if defined(DEBIAN) || defined(MULTI_SEMANTICS)
165 return pool->disttype == DISTTYPE_DEB ? " >> " : rels[rd->flags];
167 return pool->disttype == DISTTYPE_DEB ? " << " : rels[rd->flags];
169 #if defined(HAIKU) || defined(MULTI_SEMANTICS)
171 return pool->disttype == DISTTYPE_HAIKU ? " != " : rels[rd->flags];
180 return " NAMESPACE "; /* actually not used in dep2str */
185 case REL_FILECONFLICT:
186 return " FILECONFLICT ";
190 return " compat >= ";
200 /* get e:v.r for Id */
202 pool_id2evr(const Pool *pool, Id id)
207 rd = GETRELDEP(pool, id);
208 if (ISRELDEP(rd->evr))
210 return pool->ss.stringspace + pool->ss.strings[rd->evr];
214 dep2strlen(const Pool *pool, Id id)
220 Reldep *rd = GETRELDEP(pool, id);
221 /* add 2 for parens */
222 l += 2 + dep2strlen(pool, rd->name) + strlen(pool_id2rel(pool, id));
225 return l + strlen(pool->ss.stringspace + pool->ss.strings[id]);
229 dep2strcpy(const Pool *pool, char *p, Id id, int oldrel)
233 Reldep *rd = GETRELDEP(pool, id);
234 if (oldrel == REL_AND || oldrel == REL_OR || oldrel == REL_WITH)
235 if (rd->flags == REL_AND || rd->flags == REL_OR || rd->flags == REL_WITH)
236 if (oldrel != rd->flags)
239 dep2strcpy(pool, p, rd->name, rd->flags);
241 strcpy(p, pool_id2rel(pool, id));
243 dep2strcpy(pool, p, rd->evr, rd->flags);
247 if (rd->flags == REL_KIND)
249 dep2strcpy(pool, p, rd->evr, rd->flags);
256 dep2strcpy(pool, p, rd->name, rd->flags);
258 if (rd->flags == REL_NAMESPACE)
261 dep2strcpy(pool, p, rd->evr, rd->flags);
265 if (rd->flags == REL_FILECONFLICT)
270 strcpy(p, pool_id2rel(pool, id));
275 strcpy(p, pool->ss.stringspace + pool->ss.strings[id]);
279 pool_dep2str(Pool *pool, Id id)
283 return pool->ss.stringspace + pool->ss.strings[id];
284 p = pool_alloctmpspace(pool, dep2strlen(pool, id) + 1);
285 dep2strcpy(pool, p, id, 0);
290 pool_shrink_strings(Pool *pool)
292 stringpool_shrink(&pool->ss);
296 pool_shrink_rels(Pool *pool)
298 pool->rels = solv_extend_resize(pool->rels, pool->nrels, sizeof(Reldep), REL_BLOCK);
301 /* free all hash tables */
303 pool_freeidhashes(Pool *pool)
305 stringpool_freehash(&pool->ss);
306 pool->relhashtbl = solv_free(pool->relhashtbl);
307 pool->relhashmask = 0;