Module: Search¶
The Search module is designed to support standard search routines. The current interface is minimal and should be expected to grow and evolve over time.
- proc LinearSearch(Data: [?Dom], val)¶
Searches through the pre-sorted array Data looking for the value val using a sequential linear search. Returns a tuple indicating (1) whether or not the value was found and (2) the location of the value if it was found, or the location where the value should have been if it was not found.
Arguments: - Data – The sorted array to search
- val – The value to find in the array
Returns: A tuple indicating (1) if the value was found and (2) the location of the value if it was found or the location where the value should have been if it was not found.
- proc BinarySearch(Data: [?Dom], val, in lo = Dom.low, in hi = Dom.high)¶
Searches through the pre-sorted array Data looking for the value val using a sequential binary search. If provided, only the indices lo through hi will be considered, otherwise the whole array will be searched. Returns a tuple indicating (1) whether or not the value was found and (2) the location of the value if it was found, or the location where the value should have been if it was not found.
Arguments: - Data – The sorted array to search
- val – The value to find in the array
- lo : integral – The lowest index to consider while searching
- hi : integral – The highest index to consider while searching
Returns: A tuple indicating (1) if the value was found and (2) the location of the value if it was found or the location where the value should have been if it was not found.