Skip to content

Instantly share code, notes, and snippets.

@ChadSki
Last active December 23, 2015 05:49
Show Gist options
  • Select an option

  • Save ChadSki/6590170 to your computer and use it in GitHub Desktop.

Select an option

Save ChadSki/6590170 to your computer and use it in GitHub Desktop.
Zorgiepoo
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;
ZGMemorySize numSteps = (endLimit - dataIndex) / dataAlignment;
assert(numSteps < maxSteps);
P memoryAddresses[maxSteps];
ZGMemorySize numberOfVariablesFound = 0;
while (numSteps--)
{
if (comparisonFunction(searchData, (T *)((int8_t *)bytes + dataIndex), searchValue))
{
memoryAddresses[numberOfVariablesFound] = (P)(address + dataIndex);
numberOfVariablesFound++;
}
dataIndex += dataAlignment;
}
[resultSet appendBytes:&memoryAddress length:pointerSize];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment