org.apache.commons.math3.utils
Class BinarySearchIndexOpenClosed

java.lang.Object
  extended by org.apache.commons.math3.utils.AbstractSearchIndex
      extended by org.apache.commons.math3.utils.BinarySearchIndexOpenClosed
All Implemented Interfaces:
ISearchIndex

public class BinarySearchIndexOpenClosed
extends AbstractSearchIndex

Searches index in a double[] with a coupled dichotomy-BinarySearch algorithms.

IMPORTANT: the tab passed in the constructor has to be sorted by increasing order. Duplicates are allowed. If this tab is not sorted, no exception will be thrown, but the results can be totally wrong.

The interval convention is set to ISearchIndex.SearchIndexIntervalConvention.OPEN_CLOSED.

Since:
2.3.1
Version:
$Id: BinarySearchIndexOpenClosed.java 17583 2017-05-10 13:05:10Z bignon $
Author:
Sophie Laurens
Concurrency :
immutable

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.commons.math3.utils.ISearchIndex
ISearchIndex.SearchIndexIntervalConvention
 
Field Summary
 
Fields inherited from class org.apache.commons.math3.utils.AbstractSearchIndex
convention, iMax, iMin, tab
 
Constructor Summary
BinarySearchIndexOpenClosed(double[] tab2)
          Constructor.
 
Method Summary
 int getIndex(double x)
          Returns the index of x in a tab with a dichotomy / BinarySearch algorithm under the convention ISearchIndex.SearchIndexIntervalConvention.OPEN_CLOSED.
 int getIndex(double x, int iMin2, int iMax2)
          Returns the index of x in a tab with a dichotomy / BinarySearch algorithm under the convention ISearchIndex.SearchIndexIntervalConvention.OPEN_CLOSED.
 
Methods inherited from class org.apache.commons.math3.utils.AbstractSearchIndex
getConvention, getTab
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BinarySearchIndexOpenClosed

public BinarySearchIndexOpenClosed(double[] tab2)
Constructor.

Parameters:
tab2 - : a double[] array sorted by increasing order. Duplicates are allowed.
Method Detail

getIndex

public int getIndex(double x)
Returns the index of x in a tab with a dichotomy / BinarySearch algorithm under the convention ISearchIndex.SearchIndexIntervalConvention.OPEN_CLOSED.

Parameters:
x - : the value to search.
Returns:
index of value that belongs to [0, numberOfPoints-1] that fits the above conditions.

getIndex

public int getIndex(double x,
                    int iMin2,
                    int iMax2)
Returns the index of x in a tab with a dichotomy / BinarySearch algorithm under the convention ISearchIndex.SearchIndexIntervalConvention.OPEN_CLOSED.

Parameters:
x - : the value to search.
iMin2 - : defines the lower index bound of the tab for the search.
iMax2 - : defines the upper index bound of the tab for the search.
Returns:
index of value that belongs to [iMin2, iMax2] that fits the above conditions.


Copyright © 2017 CNES. All Rights Reserved.