All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.xxdb.route.AbstractRangePartitionedTableRouter Maven / Gradle / Ivy

Go to download

The messaging and data conversion protocol between Java and DolphinDB server

There is a newer version: 1.0.27
Show newest version
package com.xxdb.route;

abstract class AbstractRangePartitionedTableRouter implements TableRouter {
    /**
     * java equivalent of c++ lower_bound.
     * @param A list to be searched on
     * @param x element for which is being searched
     * @param  types that implements Comparable interface
     * @return index of the first element that is no less than x, or -1 if:
     *           1) list is empty
     *           2) list has only one element
     *           3) x < list.get(0) or x >= list[list.size() - 1]
     *
     */
    protected   > int lowerBound(T[] A, T x) {
        if (A.length == 0 || A.length == 1 || x.compareTo(A[0]) < 0 || x.compareTo(A[A.length - 1]) >= 0)
            return -1;
        int l = 0, h = A.length;
        while (l < h) {
            int m = l + ((h - l) >> 1);
            if (A[m].compareTo(x) < 0) { // A[m] < x
                l = m + 1;
            } else { // A[m] >= x
                h = m;
            }
        }
        return l;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy