Safe Haskell | None |
---|---|
Language | Haskell2010 |
Implementation of Euler tour trees.
import qualified Data.EulerTourTree as ETTree import Data.EulerTourTree(EulerTourTree)
When specified, time complexity refers to the number n of nodes in the input tree.
- data EulerTourTree node
- empty :: Ord node => EulerTourTree node
- singleton :: Ord node => node -> EulerTourTree node
- fromTree :: MonadPlus m => Ord node => Tree node -> m (EulerTourTree node)
- toTree :: MonadPlus m => Ord node => EulerTourTree node -> m (Tree node)
- root :: MonadPlus m => Ord node => EulerTourTree node -> m node
- member :: Ord node => node -> EulerTourTree node -> Bool
- size :: Ord node => EulerTourTree node -> Int
- cutEdge :: MonadPlus m => Ord node => EulerTourTree node -> (node, node) -> m (EulerTourTree node, EulerTourTree node)
- splice :: MonadPlus m => Ord node => EulerTourTree node -> node -> EulerTourTree node -> m (EulerTourTree node)
- reroot :: MonadPlus m => Ord node => node -> EulerTourTree node -> m (EulerTourTree node)
Documentation
data EulerTourTree node Source #
Euler-tour implementation of a tree structure. It is parameterized by a node type node
.
Requirements:
node
is ordered- node values are unique
Foldable EulerTourTree Source # |
|
Eq node => Eq (EulerTourTree node) Source # | |
Ord node => Ord (EulerTourTree node) Source # | |
Show node => Show (EulerTourTree node) Source # | |
Ord node => Measured (Set (node, node), Set node, Sum Int) (EulerTourTree node) Source # | |
Construction
empty :: Ord node => EulerTourTree node Source #
O(1) Construct an empty Euler tour tree.
singleton :: Ord node => node -> EulerTourTree node Source #
O(1) Construct an Euler tour tree with a single element.
fromTree :: MonadPlus m => Ord node => Tree node -> m (EulerTourTree node) Source #
O(n) Construct an Euler tour tree from a Tree
.
Fail if, and only if, node values are not unique.
Deconstruction
toTree :: MonadPlus m => Ord node => EulerTourTree node -> m (Tree node) Source #
O(n) Deconstruct an Euler tour tree into a Tree
.
Query
root :: MonadPlus m => Ord node => EulerTourTree node -> m node Source #
O(1) Return the root of the tree. Fail if it is empty.
member :: Ord node => node -> EulerTourTree node -> Bool Source #
O(log n) Return True
if node is an element of the tree.
size :: Ord node => EulerTourTree node -> Int Source #
O(1) Return the number of elements in the tree.
Transformation
:: MonadPlus m | |
=> Ord node | |
=> EulerTourTree node | Denoted by |
-> (node, node) | Denoted by |
-> m (EulerTourTree node, EulerTourTree node) | Denoted by |
O(log n) Return 2 subtrees of tree
where a
is the subtree of nodes above edge
, and b
is the subtree of nodes below edge
.
Fail if edge
isn't found in tree
:: MonadPlus m | |
=> Ord node | |
=> EulerTourTree node | Denoted by |
-> node | Denoted by |
-> EulerTourTree node | Denoted by |
-> m (EulerTourTree node) |
O(log n) Attach tree1
as a child of node
in tree2
.
Fail if node
isn't found in tree2
, or if tree1
and tree2
have nodes in common.
:: MonadPlus m | |
=> Ord node | |
=> node | Denoted by |
-> EulerTourTree node | Denoted by |
-> m (EulerTourTree node) |
O(log n) Rotate tree
such that node
is the new root.
Return Nothing
if node
isn't found in tree
.