return id;
}
+void
+pool_resize_rels_hash(Pool *pool, int numnew)
+{
+ Hashval h, hh, hashmask;
+ Hashtable hashtbl;
+ int i;
+ Reldep *rd;
+
+ if (numnew <= 0)
+ return;
+ hashmask = mkmask(pool->nrels + numnew);
+ if (hashmask <= pool->relhashmask)
+ return; /* same as before */
+
+ /* realloc hash table */
+ pool->relhashmask = hashmask;
+ solv_free(pool->relhashtbl);
+ pool->relhashtbl = hashtbl = solv_calloc(hashmask + 1, sizeof(Id));
+
+ /* rehash all rels into new hashtable */
+ for (i = 1, rd = pool->rels + i; i < pool->nrels; i++, rd++)
+ {
+ h = relhash(rd->name, rd->evr, rd->flags) & hashmask;
+ hh = HASHCHAIN_START;
+ while (hashtbl[h])
+ h = HASHCHAIN_NEXT(h, hh, hashmask);
+ hashtbl[h] = i;
+ }
+}
+
Id
pool_rel2id(Pool *pool, Id name, Id evr, int flags, int create)
{
Hashval h, hh, hashmask;
- int i;
Id id;
Hashtable hashtbl;
Reldep *ran;
- hashmask = pool->relhashmask;
- hashtbl = pool->relhashtbl;
- ran = pool->rels;
/* extend hashtable if needed */
+ hashmask = pool->relhashmask;
if ((Hashval)pool->nrels * 2 > hashmask)
{
- solv_free(pool->relhashtbl);
- pool->relhashmask = hashmask = mkmask(pool->nrels + REL_BLOCK);
- pool->relhashtbl = hashtbl = solv_calloc(hashmask + 1, sizeof(Id));
- /* rehash all rels into new hashtable */
- for (i = 1; i < pool->nrels; i++)
- {
- h = relhash(ran[i].name, ran[i].evr, ran[i].flags) & hashmask;
- hh = HASHCHAIN_START;
- while (hashtbl[h])
- h = HASHCHAIN_NEXT(h, hh, hashmask);
- hashtbl[h] = i;
- }
+ pool_resize_rels_hash(pool, REL_BLOCK);
+ hashmask = pool->relhashmask;
}
+ hashtbl = pool->relhashtbl;
/* compute hash and check for match */
h = relhash(name, evr, flags) & hashmask;
hh = HASHCHAIN_START;
+ ran = pool->rels;
while ((id = hashtbl[h]) != 0)
{
if (ran[id].name == name && ran[id].evr == evr && ran[id].flags == flags)
return p;
}
+static void
+pool_free_rels_hash(Pool *pool)
+{
+ pool->relhashtbl = solv_free(pool->relhashtbl);
+ pool->relhashmask = 0;
+}
+
void
pool_shrink_strings(Pool *pool)
{
+ /* free excessive big hashes */
+ if (pool->ss.stringhashmask && pool->ss.stringhashmask > mkmask(pool->ss.nstrings + 8192))
+ stringpool_freehash(&pool->ss);
stringpool_shrink(&pool->ss);
}
void
pool_shrink_rels(Pool *pool)
{
+ /* free excessive big hashes */
+ if (pool->relhashmask && pool->relhashmask > mkmask(pool->nrels + 4096))
+ pool_free_rels_hash(pool);
pool->rels = solv_extend_resize(pool->rels, pool->nrels, sizeof(Reldep), REL_BLOCK);
}
pool_freeidhashes(Pool *pool)
{
stringpool_freehash(&pool->ss);
- pool->relhashtbl = solv_free(pool->relhashtbl);
- pool->relhashmask = 0;
+ pool_free_rels_hash(pool);
}
/* EOF */