Collections-C
Collections-C copied to clipboard
Filter functions
Collections should have *_filter
and *_filter_mut
functions so that one may do something like this:
bool predicate(void *e) {
int el = *((int*) e);
if (el > 5) return true;
return false;
}
...
// filters out all integers greater than 5 by mutating the array
array_filter_mut(array1, predicate);
// filters out all integers greater than 5 and stores the filter results in a new array
Array *new_array;
if (array_filter(array2, predicate, &new_array) != CC_OK)
...
- [x] Array
- [ ] Deque
- [x] List
- [x] SList
- [ ] HashTable
- [ ] TreeTable
- [ ] HashSet
- [ ] TreeSet
Hi @srdja ! Thanks for this awesome library. I was wondering if you are looking for a PR to address this issue. I would like to give a try if so.
Hey @argonlaser, thanks for looking into the library and your interest in contributing. A PR addressing this issue would be most welcome!
However, it would be great if you could say on which specific collection you will be working on, so that we don't end up working on the same thing. Also if ever need any help along the way feel free ask. :-)
As I see it, array.c
already has this function. I think I should be using that as a reference for the other collections as well. Please correct me if I am wrong. I would like to start out with the deque
and list
initially.
Yup, you're right, filter
functions (+ tests) have been implemented for the Array
so you can use that as a reference, at least on some higher level. As far as the actual implementations go, I think that implementing filter
for List
should be pretty straightforward. Deque
on the other hand, might be a little bit tricky, especially filter_mut
, which modifies the actual collection.
Hey @srdja ! As a start, I have raised the PR https://github.com/srdja/Collections-C/pull/80 that adds filter functions for list
and slist
. Please do have a look.
Hi @srdja ! I would like to try the filter functions for deque
and remaining data structures as well when I get some time. I am trying to understand the implementation. Will raise a PR whenever possible. Cheers :+1:
Raised https://github.com/srdja/Collections-C/pull/82 for deque filter functions as per the currently written tests.