srdja / Collections-C

A library of generic data structures for the C language.
http://srdja.github.io/Collections-C
GNU Lesser General Public License v3.0
2.8k stars 328 forks source link

Reduce functions #19

Open srdja opened 8 years ago

srdja commented 8 years ago

It might be convinient for collections to have a fold/reduce function so that you may do something like this:

void fn(void *e1, void *e2, void *result)
{
    int el1 = *((int*)e1);
    int el2 = *((int*)e2);
    *((int*) reslut) = el1 + el2;
}

...

// accumulate values of array into result
int reslut;
array_reduce(array, fn, &result);
aeltawela commented 6 years ago

do you mean a separate generic function which doesn't belong to any data structure? or a function for the dynamic array data structure only?

srdja commented 6 years ago

@ahmedabt No, not a separate generic function. What I meant to say is that every sequential data structure should have a reduce function that is specific to it. Array already has it implemented, but the Deque, List and SList doesn't.

aeltawela commented 6 years ago

@srdja I can work on it as my first contribution to this project but it will take some time until I get familiar with the guidelines and code.

srdja commented 6 years ago

@ahmedabt That would be awesome!

qequ commented 2 years ago

Is this issue still up? I'd like to contribute with this

srdja commented 2 years ago

Hey @qequ, the issue is still up, and of course, you're welcome to contribute :)