toy-lib-0.1.0.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

Algorithm.TwoPointers

Description

\(O(f N)\) Two pointers method.

Stateless two pointer method

The stateless two pointer method assumes you can make up an \(O(1)\) Int -> Int -> Bool predicate. Maybe cumulative sum comes with it.

Statefull two pointer method

See also: https://zenn.dev/osushi0x/articles/e5bd9fe60abee4

Synopsis

Documentation

twoPointers :: Int -> (Int -> Int -> Bool) -> [(Int, Int)] #

\(O(f N)\) Stateless two pointer method over a range. Returns the longest non-null inclusive ranges for each l that satisfy the given check.

twoPointersU :: Int -> (Int -> Int -> Bool) -> Vector (Int, Int) #

\(O(f N)\) Stateless two pointer method over a range. Returns the longest non-null inclusive ranges for each l that satisfy the given check.

twoPtrM :: forall acc m v a. (Monad m, Vector v a) => acc -> (acc -> a -> m Bool) -> (acc -> a -> m acc) -> (acc -> a -> m acc) -> v a -> m [(Int, Int)] #

\(O(f N)\) Stateful two pointer method over a vector. Returns the longest non-null inclusive ranges for each l that satisfy the given check.

twoPtr :: Vector v a => acc -> (acc -> a -> Bool) -> (acc -> a -> acc) -> (acc -> a -> acc) -> v a -> [(Int, Int)] #

\(O(f N)\)