naginterfaces.library.sort.charvec_search¶
- naginterfaces.library.sort.charvec_search(valid, ch, item, m1=1)[source]¶
charvec_search
examines an ordered vector of strings and returns the index of the first value equal to the sought-after item. Character items are compared according to the ASCII collating sequence.For full information please refer to the NAG Library document for m01nc
https://support.nag.com/numeric/nl/nagdoc_30.3/flhtml/m01/m01ncf.html
- Parameters
- validbool
If is set to argument checking will be performed. If is set to
charvec_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.- chstr, array-like, shape
Elements to contain character data to be searched.
- itemstr
The sought-after item. Trailing space characters are ignored.
- 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
- ichint
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: .
- (errno )
On entry, the length of each element of must be at most : maximum string length .
- Notes
charvec_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