Skip to content

Instantly share code, notes, and snippets.

@zorgiepoo
Created September 18, 2013 00:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zorgiepoo/6602809 to your computer and use it in GitHub Desktop.
Save zorgiepoo/6602809 to your computer and use it in GitHub Desktop.
template <typename T, typename P>
void ZGSearchWithFunctionHelperRegular(T *searchValue, bool (*comparisonFunction)(ZGSearchData *, T *, T *), ZGSearchData * __unsafe_unretained searchData, ZGMemorySize dataIndex, ZGMemorySize dataAlignment, ZGMemorySize endLimit, P pointerSize, NSMutableData * __unsafe_unretained resultSet, ZGMemoryAddress address, void *bytes)
{
const ZGMemorySize maxSteps = 4096;
while (dataIndex <= endLimit)
{
ZGMemorySize numberOfVariablesFound = 0;
P memoryAddresses[maxSteps];
ZGMemorySize numberOfStepsToTake = MIN(maxSteps, (endLimit + dataAlignment - dataIndex) / dataAlignment);
for (ZGMemorySize stepIndex = 0; stepIndex < numberOfStepsToTake; stepIndex++)
{
if (comparisonFunction(searchData, (T *)((int8_t *)bytes + dataIndex), searchValue))
{
memoryAddresses[numberOfVariablesFound] = (P)(address + dataIndex);
numberOfVariablesFound++;
}
dataIndex += dataAlignment;
}
[resultSet appendBytes:memoryAddresses length:sizeof(P) * numberOfVariablesFound];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment