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

Reduce functions

Open srdja opened this issue 8 years ago • 6 comments

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

srdja avatar Mar 26 '16 13:03 srdja

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?

aeltawela avatar May 24 '18 21:05 aeltawela

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

srdja avatar May 25 '18 00:05 srdja

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

aeltawela avatar May 25 '18 10:05 aeltawela

@ahmedabt That would be awesome!

srdja avatar May 26 '18 13:05 srdja

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

qequ avatar Jan 11 '22 16:01 qequ

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

srdja avatar Jan 13 '22 10:01 srdja