The function may be called by the names: m01fsc, nag_sort_search_vector or nag_search_vector.
3Description
m01fsc searches a sorted vector of arbitrary type data objects, which are stored in the elements of an array at intervals of length stride. vec must have previously been sorted into the specified order.
The function searches for the first or last match depending on the value of final. It returns Nag_TRUE if an exact match is found and match is set to point at that object. If there is no exact match then Nag_FALSE is returned and match is set to point to either the next later element, if , or the next earlier element, if .
4References
None.
5Arguments
1: – Pointer Input
On entry: the object to search for.
2: – const Pointer Input
On entry: the array of objects to be searched.
3: – size_tInput
On entry: the number of objects to be searched.
Constraint:
, where is an implementation-dependent value for the maximum size of an array.
4: – ptrdiff_tInput
On entry: the increment between data items in vec to be searched.
Note: if stride is positive, vec should point at the first data object; otherwise vec should point at the last data object.
Constraint:
, where is an implementation-dependent value for the maximum size_t size on the system, divided by n if n is positive.
5: – function, supplied by the userExternal Function
m01fsc compares two data objects. If its arguments are pointers to a structure, this function must allow for the offset of the data field in the structure (if it is not the first).
The function must return:
if the first data field is less than the second,
if the first data field is equal to the second,
if the first data field is greater than the second.
On entry: specifies whether the array will be sorted into ascending or descending order.
Constraint:
or .
7: – Nag_SearchMatchInput
On entry: specifies whether to search for the first or last match. This also determines the pointer returned if an exact match cannot be found.
Constraint:
or .
8: – Pointer *Output
On exit: if an exact match is found this is a pointer to a pointer to the matching data object. If an exact match is not found this is set to point to the nearest object. If this is the next later element, otherwise the next earlier element.
9: – NagError *Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).
On entry, .
Constraint: , an implementation-dependent size that is printed in the error message.
On entry, .
Constraint: , an implementation-dependent size that is printed in the error message.
NE_INT_ARG_LT
On entry, .
Constraint: .
7Accuracy
Not applicable.
8Parallelism and Performance
m01fsc is not threaded in any implementation.
9Further Comments
The maximum time taken by the function is approximately proportional to .
10Example
The example program reads a key and a list of real numbers, which have been sorted into ascending order. It then searches the list for the first number which matches the key.