Portability | portable |
---|---|
Stability | experimental |
Maintainer | Edward Kmett <ekmett@gmail.com> |
Safe Haskell | Safe-Inferred |
Data.LCA.Online.Monoidal
Description
Provides online calculation of the the lowest common ancestor in O(log h) by compressing the spine of the paths using a skew-binary random access list.
This library implements the technique described in my talk
http://www.slideshare.net/ekmett/skewbinary-online-lowest-common-ancestor-search
to improve the known asymptotic bounds on both online lowest common ancestor search
http://en.wikipedia.org/wiki/Lowest_common_ancestor
and the online level ancestor problem:
http://en.wikipedia.org/wiki/Level_ancestor_problem
Algorithms used here assume that the key values chosen for k
are
globally unique.
This version provides access to a monoidal "summary" of the elided path for many operations.
- data Path a
- toList :: Path a -> [(Int, a)]
- fromList :: Monoid a => [(Int, a)] -> Path a
- map :: Monoid b => (a -> b) -> Path a -> Path b
- mapHom :: (a -> b) -> Path a -> Path b
- mapWithKey :: Monoid b => (Int -> a -> b) -> Path a -> Path b
- traverse :: (Applicative f, Monoid b) => (a -> f b) -> Path a -> f (Path b)
- traverseWithKey :: (Applicative f, Monoid b) => (Int -> a -> f b) -> Path a -> f (Path b)
- empty :: Path a
- cons :: Monoid a => Int -> a -> Path a -> Path a
- uncons :: Monoid a => Path a -> Maybe (Int, a, Path a)
- view :: Monoid a => Path a -> View Path a
- null :: Path a -> Bool
- length :: Path a -> Int
- measure :: Monoid a => Path a -> a
- isAncestorOf :: Monoid b => Path a -> Path b -> Bool
- keep :: Monoid a => Int -> Path a -> Path a
- mkeep :: Monoid a => Int -> Path a -> (a, Path a)
- drop :: Monoid a => Int -> Path a -> Path a
- mdrop :: Monoid a => Int -> Path a -> (a, Path a)
- (~=) :: Path a -> Path b -> Bool
- lca :: (Monoid a, Monoid b) => Path a -> Path b -> Path a
- mlca :: (Monoid a, Monoid b) => Path a -> Path b -> (a, Path a, b, Path b)
Documentation
A compressed Path
as a skew binary random access list
mapWithKey :: Monoid b => (Int -> a -> b) -> Path a -> Path bSource
O(n) Re-annotate a Path
full of monoidal values with access to the key.
traverse :: (Applicative f, Monoid b) => (a -> f b) -> Path a -> f (Path b)Source
Traverse a Path
yielding a new monoidal annotation.
traverseWithKey :: (Applicative f, Monoid b) => (Int -> a -> f b) -> Path a -> f (Path b)Source
Traverse a Path
with access to the node IDs.
cons :: Monoid a => Int -> a -> Path a -> Path aSource
O(1) Invariant: most operations assume that the keys k
are globally unique
Extend the Path
with a new node ID and value.
uncons :: Monoid a => Path a -> Maybe (Int, a, Path a)Source
O(1) Extract the node ID and value from the newest node on the Path
.
isAncestorOf :: Monoid b => Path a -> Path b -> BoolSource
O(log h) xs `'isAncestorOf'` ys
holds when xs
is a prefix starting at the root of path ys
.
mdrop :: Monoid a => Int -> Path a -> (a, Path a)Source
O(log k) to drop k
elements from a Path
and provide a monoidal summary of the dropped elements