diff options
author | Michael Schroeder <mls@suse.de> | 2017-08-03 13:34:59 +0200 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2018-03-28 13:25:23 +0300 |
commit | 7dc85631109a2e38c7f549949e3f50524d2b77df (patch) | |
tree | cc251746868d51e1028e665471402c2d53c2df6e | |
parent | 29ee3e6110089e5c0fc268cb95e289c7fbdd701b (diff) | |
download | rpm-7dc85631109a2e38c7f549949e3f50524d2b77df.tar.gz |
Add dbiIndexSetPruneSet helper
Also make pruning from an empty set non-fatal.
(cherry picked from commit 8d54160ecea351e5b5ef055ceb1378cb6adaf8e4)
-rw-r--r-- | lib/backend/dbiset.c | 11 | ||||
-rw-r--r-- | lib/backend/dbiset.h | 10 |
2 files changed, 20 insertions, 1 deletions
diff --git a/lib/backend/dbiset.c b/lib/backend/dbiset.c index 9ad143f28..649ea8866 100644 --- a/lib/backend/dbiset.c +++ b/lib/backend/dbiset.c @@ -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; diff --git a/lib/backend/dbiset.h b/lib/backend/dbiset.h index 88182d24a..506375865 100644 --- a/lib/backend/dbiset.h +++ b/lib/backend/dbiset.h @@ -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); |