Add dbiIndexSetPruneSet helper

Also make pruning from an empty set non-fatal.
This commit is contained in:
Michael Schroeder 2017-08-03 13:34:59 +02:00 committed by Florian Festi
parent a0e92e8b1f
commit 8d54160ece
2 changed files with 20 additions and 1 deletions

View File

@ -126,7 +126,9 @@ int dbiIndexSetPrune(dbiIndexSet set, dbiIndexItem recs,
unsigned int numCopied = 0;
size_t recsize = sizeof(*recs);
assert(set->count > 0);
if (num == 0 || nrecs == 0)
return 1;
if (nrecs > 1 && !sorted)
qsort(recs, nrecs, recsize, hdrNumCmp);
@ -143,6 +145,13 @@ int dbiIndexSetPrune(dbiIndexSet set, dbiIndexItem recs,
return (numCopied == num);
}
int dbiIndexSetPruneSet(dbiIndexSet set, dbiIndexSet oset, int sortset)
{
if (oset == NULL)
return 1;
return dbiIndexSetPrune(set, oset->recs, oset->count, sortset);
}
unsigned int dbiIndexSetCount(dbiIndexSet set)
{
return (set != NULL) ? set->count : 0;

View File

@ -76,6 +76,16 @@ RPM_GNUC_INTERNAL
int dbiIndexSetPrune(dbiIndexSet set, dbiIndexItem recs,
unsigned int nrecs, int sorted);
/**
* Remove an index set from another.
* @param set set of index database items
* @param oset set of entries that should be removed
* @param sorted oset is already sorted?
* @return 0 success, 1 failure (no items found)
*/
RPM_GNUC_INTERNAL
int dbiIndexSetPruneSet(dbiIndexSet set, dbiIndexSet oset, int sorted);
/* Count items in index database set. */
RPM_GNUC_INTERNAL
unsigned int dbiIndexSetCount(dbiIndexSet set);