MCPcopy Create free account
hub / github.com/creatale/node-dv / searchCodeIndex

Function searchCodeIndex

deps/lodepng/lodepng.cpp:1336–1349  ·  view source on GitHub ↗

search the index in the array, that has the largest value smaller than or equal to the given value, given array must be sorted (if no value is smaller, it returns the size of the given array)*/

Source from the content-addressed store, hash-verified

1334/*search the index in the array, that has the largest value smaller than or equal to the given value,
1335given array must be sorted (if no value is smaller, it returns the size of the given array)*/
1336static size_t searchCodeIndex(const unsigned* array, size_t array_size, size_t value)
1337{
1338 /*binary search (only small gain over linear). TODO: use CPU log2 instruction for getting symbols instead*/
1339 size_t left = 1;
1340 size_t right = array_size - 1;
1341
1342 while(left <= right) {
1343 size_t mid = (left + right) >> 1;
1344 if (array[mid] >= value) right = mid - 1;
1345 else left = mid + 1;
1346 }
1347 if(left >= array_size || array[left] > value) left--;
1348 return left;
1349}
1350
1351static void addLengthDistance(uivector* values, size_t length, size_t distance)
1352{

Callers 1

addLengthDistanceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected