Skip to content

Instantly share code, notes, and snippets.

@zorgiepoo
Created September 17, 2013 04:25
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/6590062 to your computer and use it in GitHub Desktop.
Save zorgiepoo/6590062 to your computer and use it in GitHub Desktop.
template <typename T, typename P>
void ZGSearchWithFunctionHelperDirect(T *searchValue, bool (*comparisonFunction)(ZGSearchData *, T *, T *), ZGSearchData * __unsafe_unretained searchData, ZGMemorySize dataIndex, ZGMemorySize dataSize, ZGMemorySize dataAlignment, ZGMemorySize endLimit, P pointerSize, NSMutableData * __unsafe_unretained resultSet, ZGMemoryAddress address, void *bytes)
{
ZGMemorySize maxSteps = 4096;
while (dataIndex <= endLimit)
{
ZGMemorySize numberOfVariablesFound = 0;
P memoryAddresses[maxSteps];
for (ZGMemorySize stepIndex = 0; stepIndex < maxSteps && dataIndex <= endLimit; stepIndex++)
{
if (comparisonFunction(searchData, (T *)((int8_t *)bytes + dataIndex), searchValue))
{
memoryAddresses[numberOfVariablesFound] = (P)(address + dataIndex);
numberOfVariablesFound++;
}
dataIndex += dataAlignment;
}
[resultSet appendBytes:memoryAddresses length:pointerSize * numberOfVariablesFound];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment