Created
May 25, 2013 22:03
-
-
Save CodaFi/5650930 to your computer and use it in GitHub Desktop.
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
void DMIndexSetDivide(NSArray **slices, NSIndexSet *inIndexSet, NSUInteger parts) { | |
if (parts == 0 || parts == 1) { | |
*slices = [NSArray arrayWithObject:inIndexSet]; | |
return; | |
} | |
NSMutableArray *indexSets = [NSMutableArray arrayWithCapacity:parts]; | |
for (int i = 0; i < parts; i++) { | |
indexSets[i] = [NSMutableIndexSet indexSet]; | |
} | |
NSUInteger divisor = roundtol(inIndexSet.count / parts); | |
__block NSUInteger idx = 0; | |
__block NSUInteger indexSetIdx = 0; | |
__block NSMutableIndexSet *currentIndexSet = nil; | |
[inIndexSet enumerateIndexesUsingBlock:^(NSUInteger index, BOOL *stop) { | |
if (idx % divisor == 0) { | |
currentIndexSet = indexSets[indexSetIdx]; | |
if (indexSetIdx + 1 < indexSets.count) | |
indexSetIdx++; | |
} | |
[currentIndexSet addIndex:index]; | |
idx++; | |
}]; | |
*slices = indexSets; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment