org.apache.commons.math3.utils
Class RecordSegmentSearchIndex

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

public class RecordSegmentSearchIndex
extends AbstractSearchIndex

Search index algorithm with previous index computation storage. This allows, in case of multiple calls in a close neighborhood (stencil with 4 points) to optimize the search by memorizing the last index found and search around it (+/- 2 points).

Since:
2.3.1
Version:
$Id: RecordSegmentSearchIndex.java 12338 2015-02-12 15:38:38Z maggiorani $
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
RecordSegmentSearchIndex(ISearchIndex searchAlgorithm2)
          Constructor of search index class with memorization of the last found index in order to optimize the search and find the index quickly if it belongs to a close neighborhood of the last one (+/- 2 points).
 
Method Summary
 int getIndex(double x)
          Returns the index of x in a tab depending on the convention used.
 int getIndex(double x, int min, int max)
          Returns the index of x in the extracted tab [tab[iMin], tab[iMax]] depending on the convention used.
 int getIndexClosedOpen(double x)
          Returns the index of x in a tab depending on the convention used.
 int getIndexOpenClosed(double x)
          Returns the index of x in a tab depending on the convention used.
 void updateStencil()
          The search algorithm is based on a four-point stencil.
 
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

RecordSegmentSearchIndex

public RecordSegmentSearchIndex(ISearchIndex searchAlgorithm2)
Constructor of search index class with memorization of the last found index in order to optimize the search and find the index quickly if it belongs to a close neighborhood of the last one (+/- 2 points).

Parameters:
searchAlgorithm2 - : the choice of algorithm is made directly through an instance of a class that implements ISearchIndex
Method Detail

updateStencil

public void updateStencil()
The search algorithm is based on a four-point stencil. To take into account the boundary condition, we have :
- if i = - 1 (point outside domain by lower bound), xi-1 = xi = - inf
- if i = 0 (lower bound), xi-1 = - inf
- if i = nMax - 1, xi+2 = + inf
- if i = nMax, xi+2 = xi+1 = + inf

Since:
2.3.1

getIndexClosedOpen

public int getIndexClosedOpen(double x)
Returns the index of x in a tab depending on the convention used.
Therefore no exception is returned even if x does not belong to [tab[0], tab[numberOfPoints - 1] ]
- if x = tab[i], the integer returned is i - if tab[i] < x < tab[i + 1], the integer returned is i - if x < tab[0], the integer returned is -1 - if x >= tab[numberOfPoints-1], the integer returned is numberOfPoints-1

Parameters:
x - : the value to search.
Returns:
the corresponding index, see the above conditions.

getIndexOpenClosed

public int getIndexOpenClosed(double x)
Returns the index of x in a tab depending on the convention used.
Therefore no exception is returned even if x does not belong to [tab[0], tab[numberOfPoints - 1] ]
- if x = tab[i], the integer returned is i - 1
- if tab[i] < x < tab[i + 1], the integer returned is i
- if x <= tab[0], the integer returned is -1
- if x > tab[numberOfPoints-1], the integer returned is numberOfPoints-1

Parameters:
x - : the value to search.
Returns:
the corresponding index, see the above conditions.

getIndex

public int getIndex(double x)
Returns the index of x in a tab depending on the convention used.
Therefore no exception is returned even if x does not belong to [tab[0], tab[numberOfPoints - 1] ]

Parameters:
x - : the value to search.
Returns:
the corresponding index, see the above conditions.

getIndex

public int getIndex(double x,
                    int min,
                    int max)
Returns the index of x in the extracted tab [tab[iMin], tab[iMax]] depending on the convention used.

Parameters:
x - : the value to search.
min - : defines the lower bound of the tab for the search.
max - : defines the upper bound of the tab for the search.
Returns:
the corresponding index, see the above conditions.


Copyright © 2016 CNES. All Rights Reserved.