MCPcopy Create free account
hub / github.com/HiLab-git/SimpleCRF / searchCodeIndex

Function searchCodeIndex

dependency/densecrf/examples/lodepng.cpp:1328–1341  ·  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

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

Callers 1

addLengthDistanceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected