lca-0.2: O(log n) persistent on-line lowest common ancestor calculation without preprocessing with optional monoidal annotations

Portabilityportable
Stabilityexperimental
MaintainerEdward Kmett <ekmett@gmail.com>
Safe HaskellSafe-Infered

Data.LCA.Online.Naive

Description

Naive online calculation of the the lowest common ancestor in O(h)

Synopsis

Documentation

data Path a Source

Instances

empty :: Path aSource

The empty path

cons :: Int -> a -> Path a -> Path aSource

O(1) Invariant: most operations assume that the keys k are globally unique

uncons :: Path a -> Maybe (Int, a, Path a)Source

null :: Path a -> BoolSource

O(1)

length :: Path a -> IntSource

O(1)

lca :: Path a -> Path b -> Path aSource

O(h) Compute the lowest common ancestor

keep :: Int -> Path a -> Path aSource

O(h - k) to keep k elements of path of height h

drop :: Int -> Path a -> Path aSource

O(k) to drop k elements from a path

traverseWithKey :: Applicative f => (Int -> a -> f b) -> Path a -> f (Path b)Source

toList :: Path a -> [(Int, a)]Source

fromList :: [(Int, a)] -> Path aSource

(~=) :: Path a -> Path b -> BoolSource

O(1) Compare to see if two trees have the same leaf key