Collections-C icon indicating copy to clipboard operation
Collections-C copied to clipboard

Filter functions

Open srdja opened this issue 8 years ago • 8 comments

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)
    ...

srdja avatar Mar 26 '16 12:03 srdja

  • [x] Array
  • [ ] Deque
  • [x] List
  • [x] SList
  • [ ] HashTable
  • [ ] TreeTable
  • [ ] HashSet
  • [ ] TreeSet

srdja avatar Apr 12 '16 08:04 srdja

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.

argonlaser avatar Feb 19 '17 09:02 argonlaser

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. :-)

srdja avatar Feb 19 '17 11:02 srdja

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.

argonlaser avatar Feb 19 '17 17:02 argonlaser

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.

srdja avatar Feb 19 '17 19:02 srdja

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.

argonlaser avatar Feb 20 '17 14:02 argonlaser

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:

argonlaser avatar Feb 20 '17 18:02 argonlaser

Raised https://github.com/srdja/Collections-C/pull/82 for deque filter functions as per the currently written tests.

argonlaser avatar Feb 21 '17 19:02 argonlaser