naginterfaces.library.sort.intvec_search¶
- naginterfaces.library.sort.intvec_search(valid, iv, item, m1=1)[source]¶
intvec_search
searches an ordered vector of integer numbers and returns the index of the first value equal to the sought-after item.For full information please refer to the NAG Library document for m01nb
https://support.nag.com/numeric/nl/nagdoc_30.3/flhtml/m01/m01nbf.html
- Parameters
- validbool
If is set to argument checking will be performed. If is set to
intvec_search
will be called without argument checking (which includes checking that array is sorted in ascending order) and the function will return with no exception or warning is raised. See Further Comments for further details.- ivint, array-like, shape
Elements to contain integer values to be searched.
- itemint
The sought-after item.
- m1int, optional
Note: this argument represents an array index; the value you supply must be base-1 for compatibility with the NAG Engine.
The index of the first element of to be searched.
- Returns
- iivint
Note: this argument represents an array index; the value returned will be base-1.
The index of the first value equal to the sought-after item.
- Raises
- NagValueError
- (errno )
On entry, must be sorted in ascending order: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, , .
Constraint: .
- Notes
intvec_search
is based on Professor Niklaus Wirth’s implementation of the Binary Search algorithm (see Wirth (2004)), but with two modifications. First, if the sought-after item is less than the value of the first element of the array to be searched, is returned. Second, if a value equal to the sought-after item is not found, the index of the immediate lower value is returned.
- References
Wirth, N, 2004, Algorithms and Data Structures, 35–36, Prentice Hall