diff options
author | Florian Festi <ffesti@redhat.com> | 2010-05-05 12:49:16 +0200 |
---|---|---|
committer | Florian Festi <ffesti@redhat.com> | 2010-05-06 16:07:56 +0200 |
commit | 70e9b035ff33d649adb32028258f9676fc12d126 (patch) | |
tree | 29cef3fb0264af8a7c96cd093ca73e8f4c3965fe /lib | |
parent | 9fad36f0eddb5d2d63cba6656978c68d7b5b715d (diff) | |
download | librpm-tizen-70e9b035ff33d649adb32028258f9676fc12d126.tar.gz librpm-tizen-70e9b035ff33d649adb32028258f9676fc12d126.tar.bz2 librpm-tizen-70e9b035ff33d649adb32028258f9676fc12d126.zip |
Convert tsmem->removedPackages to a hash table and remove rpmdbPruneIterator from the API
Diffstat (limited to 'lib')
-rw-r--r-- | lib/depends.c | 33 | ||||
-rw-r--r-- | lib/rpmdb.c | 25 | ||||
-rw-r--r-- | lib/rpmdb.h | 12 | ||||
-rw-r--r-- | lib/rpmdb_internal.h | 19 | ||||
-rw-r--r-- | lib/rpmts.c | 22 | ||||
-rw-r--r-- | lib/rpmts_internal.h | 4 | ||||
-rw-r--r-- | lib/transaction.c | 9 |
7 files changed, 70 insertions, 54 deletions
diff --git a/lib/depends.c b/lib/depends.c index b0692688b..1cfc61096 100644 --- a/lib/depends.c +++ b/lib/depends.c @@ -36,6 +36,16 @@ static rpmds rpmlibP = NULL; #define HTDATATYPE int #include "lib/rpmhash.H" #include "lib/rpmhash.C" +#undef HASHTYPE +#undef HTKEYTYPE +#undef HTDATATYPE + +#define HASHTYPE intHash +#define HTKEYTYPE unsigned int +#include "rpmhash.C" +#undef HASHTYPE +#undef HASHKEYTYPE + /** * Compare removed package instances (qsort/bsearch). @@ -67,26 +77,11 @@ static int removePackage(tsMembers tsmem, Header h, rpmte depends) if (dboffset == 0) return 1; /* Filter out duplicate erasures. */ - if (tsmem->numRemovedPackages > 0 && tsmem->removedPackages != NULL) { - if (bsearch(&dboffset, - tsmem->removedPackages, tsmem->numRemovedPackages, - sizeof(*tsmem->removedPackages), intcmp) != NULL) - return 0; - } - - if (tsmem->numRemovedPackages == tsmem->allocedRemovedPackages) { - tsmem->allocedRemovedPackages += tsmem->delta; - tsmem->removedPackages = xrealloc(tsmem->removedPackages, - sizeof(tsmem->removedPackages) * tsmem->allocedRemovedPackages); + if (intHashHasEntry(tsmem->removedPackages, dboffset)) { + return 0; } - if (tsmem->removedPackages != NULL) { /* XXX can't happen. */ - tsmem->removedPackages[tsmem->numRemovedPackages] = dboffset; - tsmem->numRemovedPackages++; - if (tsmem->numRemovedPackages > 1) - qsort(tsmem->removedPackages, tsmem->numRemovedPackages, - sizeof(*tsmem->removedPackages), intcmp); - } + intHashAddEntry(tsmem->removedPackages, dboffset); if (tsmem->orderCount >= tsmem->orderAlloced) { tsmem->orderAlloced += (tsmem->orderCount - tsmem->orderAlloced) + tsmem->delta; @@ -107,7 +102,7 @@ static rpmdbMatchIterator rpmtsPrunedIterator(rpmts ts, rpmTag tag, const char * { rpmdbMatchIterator mi = rpmtsInitIterator(ts, tag, key, 0); tsMembers tsmem = rpmtsMembers(ts); - rpmdbPruneIterator(mi, tsmem->removedPackages, tsmem->numRemovedPackages,1); + rpmdbPruneIterator(mi, tsmem->removedPackages); return mi; } diff --git a/lib/rpmdb.c b/lib/rpmdb.c index 43f86e9a5..194e47a56 100644 --- a/lib/rpmdb.c +++ b/lib/rpmdb.c @@ -1916,14 +1916,29 @@ static int rpmdbGrowIterator(rpmdbMatchIterator mi) return rc; } -int rpmdbPruneIterator(rpmdbMatchIterator mi, int * hdrNums, - int nHdrNums, int sorted) +int rpmdbPruneIterator(rpmdbMatchIterator mi, intHash hdrNums) { - if (mi == NULL || hdrNums == NULL || nHdrNums <= 0) + if (mi == NULL || hdrNums == NULL || intHashNumKeys(hdrNums) <= 0) return 1; - if (mi->mi_set) - (void) dbiPruneSet(mi->mi_set, hdrNums, nHdrNums, sizeof(*hdrNums), sorted); + if (!mi->mi_set) + return 0; + + unsigned int from; + unsigned int to = 0; + unsigned int num = mi->mi_set->count; + + assert(mi->mi_set->count > 0); + + for (from = 0; from < num; from++) { + if (intHashHasEntry(hdrNums, mi->mi_set->recs[from].hdrNum)) { + mi->mi_set->count--; + continue; + } + if (from != to) + mi->mi_set->recs[to] = mi->mi_set->recs[from]; /* structure assignment */ + to++; + } return 0; } diff --git a/lib/rpmdb.h b/lib/rpmdb.h index dc211842b..a4b61bc17 100644 --- a/lib/rpmdb.h +++ b/lib/rpmdb.h @@ -144,18 +144,6 @@ int rpmdbAppendIterator(rpmdbMatchIterator mi, const int * hdrNums, int nHdrNums); /** \ingroup rpmdb - * Remove items from set of package instances to iterate. - * @note Sorted hdrNums are always passed in rpmlib. - * @param mi rpm database iterator - * @param hdrNums array of package instances - * @param nHdrNums number of elements in array - * @param sorted is the array sorted? (array will be sorted on return) - * @return 0 on success, 1 on failure (bad args) - */ -int rpmdbPruneIterator(rpmdbMatchIterator mi, - int * hdrNums, int nHdrNums, int sorted); - -/** \ingroup rpmdb * Add pattern to iterator selector. * @param mi rpm database iterator * @param tag rpm tag diff --git a/lib/rpmdb_internal.h b/lib/rpmdb_internal.h index 1f7be34fa..c738d68d0 100644 --- a/lib/rpmdb_internal.h +++ b/lib/rpmdb_internal.h @@ -56,6 +56,25 @@ int rpmdbExtendIterator(rpmdbMatchIterator mi, */ void rpmdbSortIterator(rpmdbMatchIterator mi); +/* avoid importing rpmts_internal.h */ +#undef HASHTYPE +#undef HTKEYTYPE +#undef HTDATATYPE +#define HASHTYPE intHash +#define HTKEYTYPE unsigned int +#include "rpmhash.H" +#undef HASHTYPE +#undef HTKEYTYPE + +/** \ingroup rpmdb + * Remove items from set of package instances to iterate. + * @note Sorted hdrNums are always passed in rpmlib. + * @param mi rpm database iterator + * @param hdrNums hash of package instances + * @return 0 on success, 1 on failure (bad args) + */ +int rpmdbPruneIterator(rpmdbMatchIterator mi, intHash hdrNums); + #ifndef __APPLE__ /** * * Mergesort, same arguments as qsort(2). diff --git a/lib/rpmts.c b/lib/rpmts.c index 433160d95..1688889fd 100644 --- a/lib/rpmts.c +++ b/lib/rpmts.c @@ -515,6 +515,18 @@ void rpmtsClean(rpmts ts) rpmtsCleanProblems(ts); } +/* hash comparison function */ +static int uintCmp(unsigned int a, unsigned int b) +{ + return (a != b); +} + +/* "hash"function*/ +static unsigned int uintId(unsigned int a) +{ + return a; +} + void rpmtsEmpty(rpmts ts) { tsMembers tsmem = rpmtsMembers(ts); @@ -528,7 +540,7 @@ void rpmtsEmpty(rpmts ts) } tsmem->orderCount = 0; - tsmem->numRemovedPackages = 0; + intHashEmpty(tsmem->removedPackages); return; } @@ -577,7 +589,7 @@ rpmts rpmtsFree(rpmts ts) (void) rpmtsCloseDB(ts); - tsmem->removedPackages = _free(tsmem->removedPackages); + tsmem->removedPackages = intHashFree(tsmem->removedPackages); tsmem->order = _free(tsmem->order); ts->members = _free(ts->members); @@ -906,13 +918,9 @@ rpmts rpmtsCreate(void) } tsmem = xcalloc(1, sizeof(*ts->members)); - tsmem->delta = 5; tsmem->numAddedPackages = 0; tsmem->addedPackages = NULL; - tsmem->numRemovedPackages = 0; - tsmem->allocedRemovedPackages = tsmem->delta; - tsmem->removedPackages = xcalloc(tsmem->allocedRemovedPackages, - sizeof(*tsmem->removedPackages)); + tsmem->removedPackages = intHashCreate(128, uintId, uintCmp, NULL); tsmem->orderAlloced = 0; tsmem->orderCount = 0; tsmem->order = NULL; diff --git a/lib/rpmts_internal.h b/lib/rpmts_internal.h index 551cdd76b..f70401ae0 100644 --- a/lib/rpmts_internal.h +++ b/lib/rpmts_internal.h @@ -12,9 +12,7 @@ typedef struct diskspaceInfo_s * rpmDiskSpaceInfo; /* Transaction set elements information */ typedef struct tsMembers_s { - int * removedPackages; /*!< Set of packages being removed. */ - int numRemovedPackages; /*!< No. removed package instances. */ - int allocedRemovedPackages; /*!< Size of removed packages array. */ + intHash removedPackages; /*!< Set of packages being removed. */ rpmal addedPackages; /*!< Set of packages being installed. */ int numAddedPackages; /*!< No. added package instances. */ diff --git a/lib/transaction.c b/lib/transaction.c index 93903fb08..e9e1f0cb0 100644 --- a/lib/transaction.c +++ b/lib/transaction.c @@ -954,14 +954,7 @@ void checkInstalledFiles(rpmts ts, uint64_t fileCount, rpmFpHash ht, fingerPrint /* Is this package being removed? */ installedPkg = rpmdbGetIteratorOffset(mi); - beingRemoved = 0; - if (tsmem->removedPackages != NULL) - for (j = 0; j < tsmem->numRemovedPackages; j++) { - if (tsmem->removedPackages[j] != installedPkg) - continue; - beingRemoved = 1; - break; - } + beingRemoved = intHashHasEntry(tsmem->removedPackages, installedPkg); h = headerLink(h); headerGet(h, RPMTAG_BASENAMES, &bnames, hgflags); |