Add dbiIndexSetFilter and dbiIndexSetFilterSet methods
They will be used to resolve "with" rich dependencies.
This commit is contained in:
parent
8d54160ece
commit
8a06ede513
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue