Convert tsmem->removedPackages to a hash table and remove rpmdbPruneIterator from the API

This commit is contained in:
Florian Festi 2010-05-05 12:49:16 +02:00
parent 9fad36f0ed
commit 70e9b035ff
7 changed files with 70 additions and 54 deletions

View File

@ -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 (intHashHasEntry(tsmem->removedPackages, dboffset)) {
return 0;
}
if (tsmem->numRemovedPackages == tsmem->allocedRemovedPackages) {
tsmem->allocedRemovedPackages += tsmem->delta;
tsmem->removedPackages = xrealloc(tsmem->removedPackages,
sizeof(tsmem->removedPackages) * tsmem->allocedRemovedPackages);
}
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;
}

View File

@ -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;
}

View File

@ -143,18 +143,6 @@ unsigned int rpmdbGetIteratorFileNum(rpmdbMatchIterator mi);
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

View File

@ -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).

View File

@ -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;

View File

@ -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. */

View File

@ -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);