Permalink
Browse files

While we're at it we might as well improve the known asymptotics for …

…the online level ancestor problem.
  • Loading branch information...
1 parent ae01fc8 commit 53a721c54e3288961004f35b6e885b480a48ebfd @ekmett committed May 8, 2013
Showing with 38 additions and 2 deletions.
  1. +4 −0 CHANGELOG.md
  2. +1 −1 lca.cabal
  3. +12 −1 src/Data/LCA/Online.hs
  4. +21 −0 src/Data/LCA/Online/Monoidal.hs
View
@@ -1,3 +1,7 @@
+0.2.3
+-----
+* Improved documentation to also note that this package also provides an improvement in the online version of the [level ancestor problem](http://en.wikipedia.org/wiki/Level_ancestor_problem).
+
0.2.2
-----
* Added README
View
@@ -1,6 +1,6 @@
name: lca
category: Algorithms, Data Structures
-version: 0.2.2
+version: 0.2.3
license: BSD3
cabal-version: >= 1.6
license-file: LICENSE
View
@@ -16,7 +16,13 @@
--
-- <http://www.slideshare.net/ekmett/skewbinary-online-lowest-common-ancestor-search>
--
--- to improve the known asymptotic bounds on 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.
@@ -155,6 +161,11 @@ view (Cons _ w (Bin k a l r) ts) = Node k a (consT w2 l (consT w2 r ts)) where w
{-# INLINE view #-}
-- | /O(log (h - k))/ to @'keep' k@ elements of 'Path' of 'length' @h@
+--
+-- This solves the online version of the \"level ancestor problem\" with no preprocessing in /O(log h)/ time,
+-- improving known complexity bounds.
+--
+-- <http://en.wikipedia.org/wiki/Level_ancestor_problem>
keep :: Int -> Path a -> Path a
keep = go where
go _ Nil = Nil
@@ -12,9 +12,24 @@
-- 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.
+--
----------------------------------------------------------------------------
module Data.LCA.Online.Monoidal
( Path
@@ -198,6 +213,7 @@ view (Cons _ _ w (Bin _ k a l r) ts) = Node k a (consT w2 l (consT w2 r ts)) whe
{-# INLINE view #-}
-- | /O(log (h - k))/ to keep @k@ elements of 'Path' of 'length' @h@, and provide a monoidal summary of the dropped elements
+--
mkeep :: Monoid a => Int -> Path a -> (a, Path a)
mkeep = go mempty where
go as _ Nil = (as, Nil)
@@ -218,6 +234,11 @@ mkeep = go mempty where
{-# INLINE mkeep #-}
-- | /O(log (h - k))/ to @'keep' k@ elements of 'Path' of 'length' @h@
+--
+-- This solves the online version of the \"level ancestor problem\" with no preprocessing in /O(log h)/ time,
+-- improving known complexity bounds.
+--
+-- <http://en.wikipedia.org/wiki/Level_ancestor_problem>
keep :: Monoid a => Int -> Path a -> Path a
keep k xs = snd (mkeep k xs)
{-# INLINE keep #-}

0 comments on commit 53a721c

Please sign in to comment.