diff options
author | Michael Schroeder <mls@suse.de> | 2017-08-03 13:41:31 +0200 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2018-03-28 13:25:23 +0300 |
commit | 5dd23a7894d7c9ac49428e27e190db51752f2056 (patch) | |
tree | 62862bf3e2d6b5375064ea89fc0cadee21290105 | |
parent | 7dc85631109a2e38c7f549949e3f50524d2b77df (diff) | |
download | rpm-5dd23a7894d7c9ac49428e27e190db51752f2056.tar.gz |
Add dbiIndexSetFilter and dbiIndexSetFilterSet methods
They will be used to resolve "with" rich dependencies.
(cherry picked from commit 8a06ede5139abd621b7d4734e5206dd97c763d41)
-rw-r--r-- | lib/backend/dbiset.c | 33 | ||||
-rw-r--r-- | lib/backend/dbiset.h | 22 |
2 files changed, 55 insertions, 0 deletions
diff --git a/lib/backend/dbiset.c b/lib/backend/dbiset.c index 649ea8866..0ac514582 100644 --- a/lib/backend/dbiset.c +++ b/lib/backend/dbiset.c @@ -152,6 +152,39 @@ int dbiIndexSetPruneSet(dbiIndexSet set, dbiIndexSet oset, int sortset) return dbiIndexSetPrune(set, oset->recs, oset->count, sortset); } +int dbiIndexSetFilter(dbiIndexSet set, dbiIndexItem recs, + unsigned int nrecs, int sorted) +{ + unsigned int from; + unsigned int to = 0; + unsigned int num = set->count; + unsigned int numCopied = 0; + size_t recsize = sizeof(*recs); + + if (num == 0 || nrecs == 0) { + set->count = 0; + return num ? 0 : 1; + } + if (nrecs > 1 && !sorted) + qsort(recs, nrecs, recsize, hdrNumCmp); + for (from = 0; from < num; from++) { + if (!bsearch(&set->recs[from], recs, nrecs, recsize, hdrNumCmp)) { + set->count--; + continue; + } + if (from != to) + set->recs[to] = set->recs[from]; /* structure assignment */ + to++; + numCopied++; + } + return (numCopied == num); +} + +int dbiIndexSetFilterSet(dbiIndexSet set, dbiIndexSet oset, int sorted) +{ + return dbiIndexSetFilter(set, oset->recs, oset->count, sorted); +} + unsigned int dbiIndexSetCount(dbiIndexSet set) { return (set != NULL) ? set->count : 0; diff --git a/lib/backend/dbiset.h b/lib/backend/dbiset.h index 506375865..da196c865 100644 --- a/lib/backend/dbiset.h +++ b/lib/backend/dbiset.h @@ -86,6 +86,28 @@ int dbiIndexSetPrune(dbiIndexSet set, dbiIndexItem recs, RPM_GNUC_INTERNAL int dbiIndexSetPruneSet(dbiIndexSet set, dbiIndexSet oset, int sorted); +/** + * Filter element(s) from set of index database items. + * @param set set of index database items + * @param recs array of items to remove from set + * @param nrecs number of items + * @param sorted recs array is already sorted? + * @return 0 success, 1 failure (no items removed) + */ +RPM_GNUC_INTERNAL +int dbiIndexSetFilter(dbiIndexSet set, dbiIndexItem recs, + unsigned int nrecs, int sorted); + +/** + * Filter (intersect) an index set with another. + * @param set set of index database items + * @param oset set of entries that should be intersected + * @param sorted oset is already sorted? + * @return 0 success, 1 failure (no items removed) + */ +RPM_GNUC_INTERNAL +int dbiIndexSetFilterSet(dbiIndexSet set, dbiIndexSet oset, int sorted); + /* Count items in index database set. */ RPM_GNUC_INTERNAL unsigned int dbiIndexSetCount(dbiIndexSet set); |