public int binarySearchPredictable(T[] a,
            int from, int limit, T query, BSTYPE type) {
        if (from >= limit) {
            return from;
        }

        int mid = (from + limit) / 2;
        int compared = comparator == null ?
                query.compareTo(a[mid]) : comparator.compare(query,  a[mid]);

        if (compared == 0 && type == BSTYPE.LEFTMOST || compared < 0) {
            return binarySearchPredictable(a, from, mid, query, type);
        }

        if (compared == 0 && type == BSTYPE.RIGHTMOST || compared > 0) {
            return binarySearchPredictable(a, mid + 1, limit, query, type);
        }

        // compared == 0 && type == BSTYPE.FAST
        return mid;
    }