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)*/
| 1450 | /*search the index in the array, that has the largest value smaller than or equal to the given value, |
| 1451 | given array must be sorted (if no value is smaller, it returns the size of the given array)*/ |
| 1452 | static 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 | |
| 1466 | static void addLengthDistance(uivector* values, size_t length, size_t distance) { |
| 1467 | /*values in encoded vector are those used by deflate: |