| Copyright | (C) 2011-2015 Edward Kmett |
|---|---|
| License | BSD-style (see the file LICENSE) |
| Maintainer | Edward Kmett <ekmett@gmail.com> |
| Stability | experimental |
| Portability | portable |
| Safe Haskell | Safe |
| Language | Haskell98 |
Data.LCA.Online
Description
Provides online calculation of the the lowest common ancestor in O(log h)
by compressing the spine of a Path 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.
Synopsis
- data Path a
- lca :: Path a -> Path b -> Path a
- empty :: Path a
- cons :: Int -> a -> Path a -> Path a
- uncons :: Path a -> Maybe (Int, a, Path a)
- view :: Path a -> View Path a
- null :: Foldable t => t a -> Bool
- length :: Foldable t => t a -> Int
- isAncestorOf :: Path a -> Path b -> Bool
- keep :: Int -> Path a -> Path a
- drop :: Int -> Path a -> Path a
- traverseWithKey :: Applicative f => (Int -> a -> f b) -> Path a -> f (Path b)
- toList :: Path a -> [(Int, a)]
- fromList :: [(Int, a)] -> Path a
- (~=) :: Path a -> Path b -> Bool
Documentation
Compressed paths using skew binary random access lists
Instances
| Functor Path # | |
| Foldable Path # | |
Defined in Data.LCA.Online Methods fold :: Monoid m => Path m -> m # foldMap :: Monoid m => (a -> m) -> Path a -> m # foldr :: (a -> b -> b) -> b -> Path a -> b # foldr' :: (a -> b -> b) -> b -> Path a -> b # foldl :: (b -> a -> b) -> b -> Path a -> b # foldl' :: (b -> a -> b) -> b -> Path a -> b # foldr1 :: (a -> a -> a) -> Path a -> a # foldl1 :: (a -> a -> a) -> Path a -> a # elem :: Eq a => a -> Path a -> Bool # maximum :: Ord a => Path a -> a # | |
| Traversable Path # | |
| Read a => Read (Path a) # | |
| Show a => Show (Path a) # | |
cons :: Int -> a -> Path a -> Path a #
O(1) Invariant: most operations assume that the keys k are globally unique
Extend the Path with a new node ID and value.
uncons :: Path a -> Maybe (Int, a, Path a) #
O(1) Extract the node ID and value from the newest node on the Path.
null :: Foldable t => t a -> Bool #
Test whether the structure is empty. The default implementation is optimized for structures that are similar to cons-lists, because there is no general way to do better.
length :: Foldable t => t a -> Int #
Returns the size/length of a finite structure as an Int. The
default implementation is optimized for structures that are similar to
cons-lists, because there is no general way to do better.
isAncestorOf :: Path a -> Path b -> Bool #
O(log h) xs holds when isAncestorOf ysxs is a prefix starting at the root of Path ys.
traverseWithKey :: Applicative f => (Int -> a -> f b) -> Path a -> f (Path b) #
Traverse a Path with access to the node IDs.