Created
August 1, 2015 11:38
-
-
Save AdamBrouwersHarries/6df0d5134a7cffe1fcb5 to your computer and use it in GitHub Desktop.
Zipping two sparse arrays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef struct Tuple2 | |
{ | |
int a; | |
int b; | |
} Tuple2; | |
// array lengths | |
int sparseLength; | |
int denseLength; | |
// arrays | |
Tuple2* sparseArray; | |
int* denseArray; | |
// pointers into arrays | |
int sparsePointer = 0; | |
int densePointer = 0 | |
int acc; | |
while(sparsePointer < sparseLength) | |
Tuple2 tSpElem = sparseArray[i]; | |
while(!(matchPredicate(sparsePointer, densePointer)) && densePointer<denseLength){ | |
densePointer++; | |
if(denseFinished(densePointer)) | |
{ | |
goto finished; | |
} | |
} | |
acc += accFunction(sparsePointer, densePointer); | |
sparsePointer++; | |
if(sparseFinished(sparsePointer)){ | |
goto finished; | |
} | |
} | |
finished: | |
return acc; |
michel-steuwer
commented
Aug 1, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment