⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 doubleintindex.java

📁 hsql是很有名的嵌入式数据库
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        sortOnValues = false;    }    /**     * @param value the value     * @return the index     */    public synchronized int findFirstGreaterEqualKeyIndex(int value) {        int index = findFirstGreaterEqualSlotIndex(value);        return index == count ? -1                              : index;    }    /**     * @param value the value     * @return the index     */    public synchronized int findFirstEqualKeyIndex(int value) {        if (!sorted) {            fastQuickSort();        }        targetSearchValue = value;        return binaryFirstSearch();    }    /**     * This method is similar to findFirstGreaterEqualKeyIndex(int) but     * returns the index of the empty row past the end of the array if     * the search value is larger than all the values / keys in the searched     * column.     * @param value the value     * @return the index     */    public synchronized int findFirstGreaterEqualSlotIndex(int value) {        if (!sorted) {            fastQuickSort();        }        targetSearchValue = value;        return binarySlotSearch();    }    /**     * Returns the index of the lowest element == the given search target,     * or -1     * @return index or -1 if not found     */    private int binaryFirstSearch() {        int low     = 0;        int high    = count;        int mid     = 0;        int compare = 0;        int found   = count;        while (low < high) {            mid     = (low + high) / 2;            compare = compare(mid);            if (compare < 0) {                high = mid;            } else if (compare > 0) {                low = mid + 1;            } else {                high  = mid;                found = mid;            }        }        return found == count ? -1                              : found;    }    /**     * Returns the index of the lowest element > the given search target     *     @return the index     */    private int binaryGreaterSearch() {        int low     = 0;        int high    = count;        int mid     = 0;        int compare = 0;        while (low < high) {            mid     = (low + high) / 2;            compare = compare(mid);            if (compare < 0) {                high = mid;            } else {                low = mid + 1;            }        }        return low == count ? -1                            : low;    }    /**     * Returns the index of the lowest element >= the given search target,     * or count     *     @return the index     */    private int binarySlotSearch() {        int low     = 0;        int high    = count;        int mid     = 0;        int compare = 0;        while (low < high) {            mid     = (low + high) / 2;            compare = compare(mid);            if (compare <= 0) {                high = mid;            } else {                low = mid + 1;            }        }        return low;    }    /**     * Returns the index of the lowest element > the given search target     * or count or -1 if target is found     * @return the index     */    private int binaryEmptySlotSearch() {        int low     = 0;        int high    = count;        int mid     = 0;        int compare = 0;        while (low < high) {            mid     = (low + high) / 2;            compare = compare(mid);            if (compare < 0) {                high = mid;            } else if (compare > 0) {                low = mid + 1;            } else {                return -1;            }        }        return low;    }    private synchronized void fastQuickSort() {        quickSort(0, count - 1);        insertionSort(0, count - 1);        sorted = true;    }    private void quickSort(int l, int r) {        int M = 4;        int i;        int j;        int v;        if ((r - l) > M) {            i = (r + l) / 2;            if (lessThan(i, l)) {                swap(l, i);    // Tri-Median Methode!            }            if (lessThan(r, l)) {                swap(l, r);            }            if (lessThan(r, i)) {                swap(i, r);            }            j = r - 1;            swap(i, j);            i = l;            v = j;            for (;;) {                while (lessThan(++i, v)) {}                while (lessThan(v, --j)) {}                if (j < i) {                    break;                }                swap(i, j);            }            swap(i, r - 1);            quickSort(l, j);            quickSort(i + 1, r);        }    }    private void insertionSort(int lo0, int hi0) {        int i;        int j;        for (i = lo0 + 1; i <= hi0; i++) {            j = i;            while ((j > lo0) && lessThan(i, j - 1)) {                j--;            }            if (i != j) {                moveAndInsertRow(i, j);            }        }    }    private void moveAndInsertRow(int i, int j) {        int col1 = keys[i];        int col2 = values[i];        moveRows(j, j + 1, i - j);        keys[j]   = col1;        values[j] = col2;    }    private void doubleCapacity() {        keys     = (int[]) ArrayUtil.resizeArray(keys, capacity * 2);        values   = (int[]) ArrayUtil.resizeArray(values, capacity * 2);        capacity *= 2;    }    private void swap(int i1, int i2) {        int col1 = keys[i1];        int col2 = values[i1];        keys[i1]   = keys[i2];        values[i1] = values[i2];        keys[i2]   = col1;        values[i2] = col2;    }    private void moveRows(int fromIndex, int toIndex, int rows) {        System.arraycopy(keys, fromIndex, keys, toIndex, rows);        System.arraycopy(values, fromIndex, values, toIndex, rows);    }    public void removeRange(int start, int limit) {        moveRows(limit, start, count - limit);        count -= (limit - start);    }    public void removeAll() {        hasChanged = true;        ArrayUtil.clearArray(ArrayUtil.CLASS_CODE_INT, keys, 0, count);        ArrayUtil.clearArray(ArrayUtil.CLASS_CODE_INT, values, 0, count);        count = 0;    }    /**     * Check if targeted column value in the row indexed i is less than the     * search target object.     * @param i the index     * @return -1, 0 or +1     */    private int compare(int i) {        if (sortOnValues) {            if (targetSearchValue > values[i]) {                return 1;            } else if (targetSearchValue < values[i]) {                return -1;            }        } else {            if (targetSearchValue > keys[i]) {                return 1;            } else if (targetSearchValue < keys[i]) {                return -1;            }        }        return 0;    }    public final synchronized void remove(int position) {        hasChanged = true;        moveRows(position + 1, position, count - position - 1);        count--;        keys[count]   = 0;        values[count] = 0;    }    /**     * Check if row indexed i is less than row indexed j     * @param i the first index     * @param j the second index     * @return true or false     */    private boolean lessThan(int i, int j) {        if (sortOnValues) {            if (values[i] < values[j]) {                return true;            }        } else {            if (keys[i] < keys[j]) {                return true;            }        }        return false;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -