public static <T> int getLowerBoundToKey(T[] a, int from, int to, T value) {
        int low = from;
        int high = to;
        int lowerBound = low;

        while (low <= high) {
            int mid = (low + high) >>> 1;
            if (mid == high) {
                return mid;
            }
            Comparable midVal = (Comparable) a[mid];
            int cmp = midVal.compareTo(value);
            if (cmp < 0) {
                low = mid + 1;
                lowerBound = low;
            }
            else if (cmp > 0)
                high = mid - 1;
            else
                return mid; // key found

        }
        return lowerBound;
    }