From 2a817e5ea2c58e86bc897bc4a80a945ba8b3a9cc Mon Sep 17 00:00:00 2001 From: Michael Schroeder Date: Fri, 5 Apr 2013 17:00:30 +0200 Subject: [PATCH] cleanup hash code, it makes no sense to have an extra type for the mask --- ext/pool_fileconflicts.c | 36 ++++++++++++++++++------------------ ext/repo_arch.c | 8 ++++---- ext/repo_mdk.c | 8 ++++---- ext/repo_susetags.c | 8 ++++---- src/hash.h | 5 +---- src/pool.h | 2 +- src/poolid.c | 4 +--- src/repo.h | 2 +- src/repo_solv.c | 5 ++--- src/strpool.c | 4 +--- src/strpool.h | 2 +- 11 files changed, 38 insertions(+), 46 deletions(-) diff --git a/ext/pool_fileconflicts.c b/ext/pool_fileconflicts.c index 806cdb14..bfc76614 100644 --- a/ext/pool_fileconflicts.c +++ b/ext/pool_fileconflicts.c @@ -21,12 +21,12 @@ struct cbdata { Queue lookat; Queue lookat_dir; - Hashval *cflmap; - Hashmask cflmapn; + Hashtable cflmap; + Hashval cflmapn; unsigned int cflmapused; - Hashval *dirmap; - Hashmask dirmapn; + Hashtable dirmap; + Hashval dirmapn; unsigned int dirmapused; int dirconflicts; @@ -42,13 +42,13 @@ struct cbdata { #define FILESSPACE_BLOCK 255 -static Hashval * -doublehash(Hashval *map, Hashmask *mapnp) +static Hashtable +growhash(Hashtable map, Hashval *mapnp) { - Hashmask mapn = *mapnp; - Hashmask i, hx, qx, h, hh; - Hashmask nn = (mapn + 1) * 2 - 1; - Hashmask *m; + Hashval mapn = *mapnp; + Hashval i, hx, qx, h, hh; + Hashval nn = (mapn + 1) * 2 - 1; + Hashtable m; m = solv_calloc(nn + 1, 2 * sizeof(Id)); for (i = 0; i <= mapn; i++) @@ -77,7 +77,7 @@ static void finddirs_cb(void *cbdatav, const char *fn, int fmode, const char *md5) { struct cbdata *cbdata = cbdatav; - Hashmask h, hh, hx, qx; + Hashval h, hh, hx, qx; Hashval idx = cbdata->idx; hx = strhash(fn); @@ -103,7 +103,7 @@ finddirs_cb(void *cbdatav, const char *fn, int fmode, const char *md5) cbdata->dirmap[2 * h + 1] = idx; cbdata->dirmapused++; if (cbdata->dirmapused * 2 > cbdata->dirmapn) - cbdata->dirmap = doublehash(cbdata->dirmap, &cbdata->dirmapn); + cbdata->dirmap = growhash(cbdata->dirmap, &cbdata->dirmapn); return; } if (cbdata->dirmap[2 * h + 1] == idx) @@ -119,9 +119,9 @@ finddirs_cb(void *cbdatav, const char *fn, int fmode, const char *md5) } static inline int -isindirmap(struct cbdata *cbdata, Hashmask hx) +isindirmap(struct cbdata *cbdata, Hashval hx) { - Hashmask h, hh, qx; + Hashval h, hh, qx; h = hx & cbdata->dirmapn; hh = HASHCHAIN_START; @@ -143,7 +143,7 @@ findfileconflicts_cb(void *cbdatav, const char *fn, int fmode, const char *md5) int isdir = S_ISDIR(fmode); char *dp; Hashval idx, qidx; - Hashmask qx, h, hx, hh, dhx; + Hashval qx, h, hx, hh, dhx; idx = cbdata->idx; @@ -182,7 +182,7 @@ findfileconflicts_cb(void *cbdatav, const char *fn, int fmode, const char *md5) cbdata->cflmap[2 * h + 1] = (isdir ? ~idx : idx); cbdata->cflmapused++; if (cbdata->cflmapused * 2 > cbdata->cflmapn) - cbdata->cflmap = doublehash(cbdata->cflmap, &cbdata->cflmapn); + cbdata->cflmap = growhash(cbdata->cflmap, &cbdata->cflmapn); return; } qidx = cbdata->cflmap[2 * h + 1]; @@ -317,7 +317,7 @@ pool_findfileconflicts(Pool *pool, Queue *pkgs, int cutoff, Queue *conflicts, vo idxmapset++; } - POOL_DEBUG(SOLV_DEBUG_STATS, "dirmap size: %d used %d\n", cbdata.dirmapn + 1, cbdata.dirmapused); + POOL_DEBUG(SOLV_DEBUG_STATS, "dirmap size: %d, used %d\n", cbdata.dirmapn + 1, cbdata.dirmapused); POOL_DEBUG(SOLV_DEBUG_STATS, "dirmap memory usage: %d K\n", (cbdata.dirmapn + 1) * 2 * (int)sizeof(Id) / 1024); POOL_DEBUG(SOLV_DEBUG_STATS, "dirmap creation took %d ms\n", solv_timems(now)); POOL_DEBUG(SOLV_DEBUG_STATS, "dir conflicts found: %d, idxmap %d of %d\n", cbdata.dirconflicts, idxmapset, pkgs->count); @@ -343,7 +343,7 @@ pool_findfileconflicts(Pool *pool, Queue *pkgs, int cutoff, Queue *conflicts, vo rpm_iterate_filelist(handle, RPM_ITERATE_FILELIST_NOGHOSTS, findfileconflicts_cb, &cbdata); } - POOL_DEBUG(SOLV_DEBUG_STATS, "filemap size: %d used %d\n", cbdata.cflmapn + 1, cbdata.cflmapused); + POOL_DEBUG(SOLV_DEBUG_STATS, "filemap size: %d, used %d\n", cbdata.cflmapn + 1, cbdata.cflmapused); POOL_DEBUG(SOLV_DEBUG_STATS, "filemap memory usage: %d K\n", (cbdata.cflmapn + 1) * 2 * (int)sizeof(Id) / 1024); POOL_DEBUG(SOLV_DEBUG_STATS, "filemap creation took %d ms\n", solv_timems(now)); diff --git a/ext/repo_arch.c b/ext/repo_arch.c index 835899ee..e9d12a74 100644 --- a/ext/repo_arch.c +++ b/ext/repo_arch.c @@ -500,9 +500,9 @@ static char *getsentrynl(struct tarhead *th, char *s, int size) } static Hashtable -joinhash_init(Repo *repo, Hashmask *hmp) +joinhash_init(Repo *repo, Hashval *hmp) { - Hashmask hm = mkmask(repo->nsolvables); + Hashval hm = mkmask(repo->nsolvables); Hashtable ht = solv_calloc(hm + 1, sizeof(*ht)); Hashval h, hh; Solvable *s; @@ -521,7 +521,7 @@ joinhash_init(Repo *repo, Hashmask *hmp) } static Solvable * -joinhash_lookup(Repo *repo, Hashtable ht, Hashmask hm, const char *fn) +joinhash_lookup(Repo *repo, Hashtable ht, Hashval hm, const char *fn) { const char *p; Id name, evr; @@ -748,7 +748,7 @@ repo_add_arch_repo(Repo *repo, FILE *fp, int flags) int lastdnlen = 0; Solvable *s = 0; Hashtable joinhash = 0; - Hashmask joinhashmask = 0; + Hashval joinhashmask = 0; data = repo_add_repodata(repo, flags); diff --git a/ext/repo_mdk.c b/ext/repo_mdk.c index 82d32654..bdd7f402 100644 --- a/ext/repo_mdk.c +++ b/ext/repo_mdk.c @@ -287,7 +287,7 @@ struct parsedata { enum state sbtab[NUMSTATES]; Solvable *solvable; Hashtable joinhash; - Hashmask joinhashmask; + Hashval joinhashmask; }; static inline const char * @@ -302,9 +302,9 @@ find_attr(const char *txt, const char **atts) } static Hashtable -joinhash_init(Repo *repo, Hashmask *hmp) +joinhash_init(Repo *repo, Hashval *hmp) { - Hashmask hm = mkmask(repo->nsolvables); + Hashval hm = mkmask(repo->nsolvables); Hashtable ht = solv_calloc(hm + 1, sizeof(*ht)); Hashval h, hh; Solvable *s; @@ -323,7 +323,7 @@ joinhash_init(Repo *repo, Hashmask *hmp) } static Solvable * -joinhash_lookup(Repo *repo, Hashtable ht, Hashmask hm, const char *fn, const char *distepoch) +joinhash_lookup(Repo *repo, Hashtable ht, Hashval hm, const char *fn, const char *distepoch) { Hashval h, hh; const char *p, *vrstart, *vrend; diff --git a/ext/repo_susetags.c b/ext/repo_susetags.c index c4272009..4f0232a3 100644 --- a/ext/repo_susetags.c +++ b/ext/repo_susetags.c @@ -385,9 +385,9 @@ finish_solvable(struct parsedata *pd, Solvable *s, Offset freshens) } static Hashtable -joinhash_init(Repo *repo, Hashmask *hmp) +joinhash_init(Repo *repo, Hashval *hmp) { - Hashmask hm = mkmask(repo->nsolvables); + Hashval hm = mkmask(repo->nsolvables); Hashtable ht = solv_calloc(hm + 1, sizeof(*ht)); Hashval h, hh; Solvable *s; @@ -406,7 +406,7 @@ joinhash_init(Repo *repo, Hashmask *hmp) } static Solvable * -joinhash_lookup(Repo *repo, Hashtable ht, Hashmask hm, Id name, Id evr, Id arch, Id start) +joinhash_lookup(Repo *repo, Hashtable ht, Hashval hm, Id name, Id evr, Id arch, Id start) { Hashval h, hh; @@ -478,7 +478,7 @@ repo_add_susetags(Repo *repo, FILE *fp, Id defvendor, const char *language, int Repodata *data = 0; Id handle = 0; Hashtable joinhash = 0; - Hashmask joinhashm = 0; + Hashval joinhashm = 0; int createdpkgs = 0; if ((flags & (SUSETAGS_EXTEND|REPO_EXTEND_SOLVABLES)) != 0 && repo->nrepodata) diff --git a/src/hash.h b/src/hash.h index b3cfbde4..1d3222bc 100644 --- a/src/hash.h +++ b/src/hash.h @@ -21,9 +21,6 @@ extern "C" { /* value of a hash */ typedef unsigned int Hashval; -/* mask for hash, used as modulo operator to ensure 'wrapping' of hash - values -> hash table */ -typedef unsigned int Hashmask; /* inside the hash table, Ids are stored. Hash maps: string -> hash -> Id */ typedef Id *Hashtable; @@ -80,7 +77,7 @@ relhash(Id name, Id evr, int flags) * * used for Hashtable 'modulo' operation */ -static inline Hashmask +static inline Hashval mkmask(unsigned int num) { num *= 2; diff --git a/src/pool.h b/src/pool.h index 77808bd3..bed20528 100644 --- a/src/pool.h +++ b/src/pool.h @@ -135,7 +135,7 @@ struct _Pool { /* hash for rel unification */ Hashtable relhashtbl; /* hashtable: (name,evr,op)Hash -> Id */ - Hashmask relhashmask; + Hashval relhashmask; Id *languagecache; int languagecacheother; diff --git a/src/poolid.c b/src/poolid.c index 1b198728..6dc2c1b8 100644 --- a/src/poolid.c +++ b/src/poolid.c @@ -54,9 +54,7 @@ pool_strn2id(Pool *pool, const char *str, unsigned int len, int create) Id pool_rel2id(Pool *pool, Id name, Id evr, int flags, int create) { - Hashval h; - unsigned int hh; - Hashmask hashmask; + Hashval h, hh, hashmask; int i; Id id; Hashtable hashtbl; diff --git a/src/repo.h b/src/repo.h index 130afb00..06848278 100644 --- a/src/repo.h +++ b/src/repo.h @@ -50,7 +50,7 @@ typedef struct _Repo { Offset lastoff; /* start of last array in idarraydata */ Hashtable lastidhash; /* hash to speed up repo_addid_dep */ - Hashmask lastidhash_mask; + Hashval lastidhash_mask; int lastidhash_idarraysize; int lastmarker; Offset lastmarkerpos; diff --git a/src/repo_solv.c b/src/repo_solv.c index 62e399fe..2835c30f 100644 --- a/src/repo_solv.c +++ b/src/repo_solv.c @@ -453,9 +453,8 @@ repo_add_solv(Repo *repo, FILE *fp, int flags) char *sp; /* pointer into string space */ Id *idmap; /* map of repo Ids to pool Ids */ Id id, type; - unsigned int hashmask, h; - int hh; - Id *hashtbl; + Hashval hashmask, h, hh; + Hashtable hashtbl; Id name, evr, did; int relflags; Reldep *ran; diff --git a/src/strpool.c b/src/strpool.c index 5a9c64a2..364f096f 100644 --- a/src/strpool.c +++ b/src/strpool.c @@ -79,9 +79,7 @@ stringpool_clone(Stringpool *ss, Stringpool *from) Id stringpool_strn2id(Stringpool *ss, const char *str, unsigned int len, int create) { - Hashval h; - unsigned int hh; - Hashmask hashmask, oldhashmask; + Hashval h, hh, hashmask, oldhashmask; int i; Id id; Hashtable hashtbl; diff --git a/src/strpool.h b/src/strpool.h index 6745be8d..c97b8737 100644 --- a/src/strpool.h +++ b/src/strpool.h @@ -25,7 +25,7 @@ struct _Stringpool Offset sstrings; /* size of used stringspace */ Hashtable stringhashtbl; /* hash table: (string ->) Hash -> Id */ - Hashmask stringhashmask; /* modulo value for hash table (size of table - 1) */ + Hashval stringhashmask; /* modulo value for hash table (size of table - 1) */ }; void stringpool_init(Stringpool *ss, const char *strs[]); -- 2.47.2