.. default-domain:: chpl

.. module:: Search
   :synopsis: The `Search` module is designed to support standard search routines. The

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.


.. function:: 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.
   
   :arg Data: The sorted array to search
   :arg 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.
   
   

.. function:: 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.
   
   :arg Data: The sorted array to search
   :arg val: The value to find in the array
   :arg lo: The lowest index to consider while searching
   :type lo: `integral`
   :arg hi: The highest index to consider while searching
   :type hi: `integral`
   
   :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.
   
   

