HORIZON HASKELLDocslts/ghc-10.0.x2b276322026-10-31Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 2b27632 · 2026-10-31

Modulevector-algorithms-0.9.1.0Haskell2010

Data.Vector.Algorithms.Search

This module implements several methods of searching for indicies to insert elements into a sorted vector.

Synopsis
valuebinarySearchBy
  1. :: (PrimMonad m, MVector v e)
  2. => Comparison e
  3. -> v (PrimState m) e
  4. -> e
  5. -> m Int

Finds an index in a given vector, which must be sorted with respect to the given comparison function, at which the given element could be inserted while preserving the vector's sortedness.

valuebinarySearchP
  1. :: (PrimMonad m, MVector v e)
  2. => e -> Bool
  3. -> v (PrimState m) e
  4. -> m Int

Given a predicate that is guaranteed to be monotone on the given vector, finds the first index at which the predicate returns True, or the length of the array if the predicate is false for the entire array.

valuebinarySearchPBounds
  1. :: (PrimMonad m, MVector v e)
  2. => e -> Bool
  3. -> v (PrimState m) e
  4. -> Int
  5. -> Int
  6. -> m Int

Given a predicate that is guaranteed to be monotone on the indices [l,u) in a given vector, finds the index in [l,u] at which the predicate turns from False to True (yielding u if the entire interval is False).

valuegallopingSearchLeftP
  1. :: (PrimMonad m, MVector v e)
  2. => e -> Bool
  3. -> v (PrimState m) e
  4. -> m Int

Given a predicate that is guaranteed to be monotone on the vector elements in order, finds the index at which the predicate turns from False to True. The length of the vector is returned if the predicate is False for the entire vector.

Begins searching at the start of the vector, in increasing steps of size 2^n.

valuegallopingSearchLeftPBounds
  1. :: (PrimMonad m, MVector v e)
  2. => (e -> Bool)
  3. -> v (PrimState m) e
  4. -> Int

    l

  5. -> Int

    u

  6. -> m Int

Given a predicate that is guaranteed to be monotone on the indices [l,u) in a given vector, finds the index in [l,u] at which the predicate turns from False to True (yielding u if the entire interval is False). Begins searching at l, going right in increasing (2^n)-steps.

valuegallopingSearchRightP
  1. :: (PrimMonad m, MVector v e)
  2. => e -> Bool
  3. -> v (PrimState m) e
  4. -> m Int

Given a predicate that is guaranteed to be monotone on the vector elements in order, finds the index at which the predicate turns from False to True. The length of the vector is returned if the predicate is False for the entire vector.

Begins searching at the end of the vector, in increasing steps of size 2^n.

valuegallopingSearchRightPBounds
  1. :: (PrimMonad m, MVector v e)
  2. => (e -> Bool)
  3. -> v (PrimState m) e
  4. -> Int

    l

  5. -> Int

    u

  6. -> m Int

Given a predicate that is guaranteed to be monotone on the indices [l,u) in a given vector, finds the index in [l,u] at which the predicate turns from False to True (yielding u if the entire interval is False). Begins searching at u, going left in increasing (2^n)-steps.