MCPcopy Create free account
hub / github.com/DFHack/dfhack / searchCodeIndex

Function searchCodeIndex

depends/lodepng/lodepng.cpp:1452–1464  ·  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

1450/*search the index in the array, that has the largest value smaller than or equal to the given value,
1451given array must be sorted (if no value is smaller, it returns the size of the given array)*/
1452static size_t searchCodeIndex(const unsigned* array, size_t array_size, size_t value) {
1453 /*binary search (only small gain over linear). TODO: use CPU log2 instruction for getting symbols instead*/
1454 size_t left = 1;
1455 size_t right = array_size - 1;
1456
1457 while(left <= right) {
1458 size_t mid = (left + right) >> 1;
1459 if(array[mid] >= value) right = mid - 1;
1460 else left = mid + 1;
1461 }
1462 if(left >= array_size || array[left] > value) left--;
1463 return left;
1464}
1465
1466static void addLengthDistance(uivector* values, size_t length, size_t distance) {
1467 /*values in encoded vector are those used by deflate:

Callers 1

addLengthDistanceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected