zalgo-0.1.0.1: Z-algorithm implemented on haskell's built-in cons-cell-based lists.

Copyright(C) 2015 mniip
Maintainermniip <mniip@mniip.com>
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.List.Zalgo.Internal

Description

License: BSD3 Portability: portable Stability: experimental

Implementation of the Z-function on cons-cells.

Z-function has a simple implementation using arrays, the challenge, however was to implement it on haskell lists (which are cons cells) without losing any complexity. The following code uses a tying-the-know data passing structure, however no complicated laziness mechanisms are used: a ZState only depends on previous ZStates and therefore this algorithm can be safely implemented in a strict language with pointers.

Synopsis

Documentation

data ZState a Source

A state of the Z-function computation. zTail points to the tail of the input at the state's position, zLength is the value of the Z-function, and zPrev is a reference to the list of ZStates starting from position described by zLength.

Constructors

ZState 

Fields

zTail :: [a]
 
zLength :: !Int
 
zPrev :: [ZState a]
 

data GenericZState i a Source

Constructors

GenericZState 

Fields

gzTail :: [a]
 
gzLength :: Maybe i
 
gzPrev :: [GenericZState i a]
 

zTraverse :: Eq a => [a] -> [ZState a] Source

_O(N)._ Compute the list of Z-function states for a given input.

zTraverseBy :: (a -> a -> Bool) -> [a] -> [ZState a] Source

_O(N) and O(N) calls to the predicate._ Compute the list of Z-function states using a given equality predicate. See "Data.List.Zalgo.zFunBy" for a detailed explanation of what predicates are allowed.

gzTraverse :: (Num i, Eq a) => [a] -> [GenericZState i a] Source

_O(N) and O(N) plus-1's._ Compute the list of Z-function states using a given number type.

gzTraverseBy :: Num i => (a -> a -> Bool) -> [a] -> [GenericZState i a] Source

_O(N), O(N) calls to the predicate, and O(N) plus-1's._ Compute the list of Z-function states using a given number type and a given equality predicate.