Safe Haskell | None |
---|---|
Language | Haskell2010 |
- data BinLeafTree v a
- = Leaf !a
- | Node (BinLeafTree v a) !v (BinLeafTree v a)
- class Semigroup v => Measured v a | a -> v where
- node :: Measured v a => BinLeafTree v a -> BinLeafTree v a -> BinLeafTree v a
- asBalancedBinLeafTree :: NonEmpty a -> BinLeafTree Size (Elem a)
- foldUp :: (b -> v -> b -> b) -> (a -> b) -> BinLeafTree v a -> b
- foldUpData :: (w -> v -> w -> w) -> (a -> w) -> BinLeafTree v a -> BinLeafTree w a
- zipExactWith :: (u -> v -> w) -> (a -> b -> c) -> BinLeafTree u a -> BinLeafTree v b -> BinLeafTree w c
- newtype Size = Size Int
- newtype Elem a = Elem {
- _unElem :: a
- data Sized a = Sized !Size a
- data RoseElem v a
- = InternalNode v
- | LeafNode a
- toRoseTree :: BinLeafTree v a -> Tree (RoseElem v a)
- drawTree :: (Show v, Show a) => BinLeafTree v a -> String
- data BinaryTree a
- = Nil
- | Internal (BinaryTree a) !a (BinaryTree a)
- access :: BinaryTree a -> Maybe a
- asBalancedBinTree :: [a] -> BinaryTree a
- foldBinaryUp :: b -> (a -> b -> b -> b) -> BinaryTree a -> BinaryTree (a, b)
- toRoseTree' :: BinaryTree a -> Maybe (Tree a)
- drawTree' :: Show a => BinaryTree a -> String
Documentation
data BinLeafTree v a Source #
Leaf !a | |
Node (BinLeafTree v a) !v (BinLeafTree v a) |
Measured v a => Measured v (BinLeafTree v a) Source # | |
Functor (BinLeafTree v) Source # | |
Foldable (BinLeafTree v) Source # | |
Traversable (BinLeafTree v) Source # | |
Foldable1 (BinLeafTree v) Source # | |
(Eq v, Eq a) => Eq (BinLeafTree v a) Source # | |
(Ord v, Ord a) => Ord (BinLeafTree v a) Source # | |
(Read v, Read a) => Read (BinLeafTree v a) Source # | |
(Show v, Show a) => Show (BinLeafTree v a) Source # | |
Generic (BinLeafTree v a) Source # | |
Measured v a => Semigroup (BinLeafTree v a) Source # | |
(NFData v, NFData a) => NFData (BinLeafTree v a) Source # | |
type Rep (BinLeafTree v a) Source # | |
node :: Measured v a => BinLeafTree v a -> BinLeafTree v a -> BinLeafTree v a Source #
smart constructor
asBalancedBinLeafTree :: NonEmpty a -> BinLeafTree Size (Elem a) Source #
Create a balanced tree, i.e. a tree of height \(O(\log n)\) with the elements in the leaves.
\(O(n)\) time.
foldUp :: (b -> v -> b -> b) -> (a -> b) -> BinLeafTree v a -> b Source #
Given a function to combine internal nodes into b's and leafs into b's, traverse the tree bottom up, and combine everything into one b.
foldUpData :: (w -> v -> w -> w) -> (a -> w) -> BinLeafTree v a -> BinLeafTree w a Source #
Traverses the tree bottom up, recomputing the assocated values.
zipExactWith :: (u -> v -> w) -> (a -> b -> c) -> BinLeafTree u a -> BinLeafTree v b -> BinLeafTree w c Source #
Takes two trees, that have the same structure, and uses the provided functions to "zip" them together
Functor Sized Source # | |
Foldable Sized Source # | |
Traversable Sized Source # | |
Eq a => Eq (Sized a) Source # | |
Ord a => Ord (Sized a) Source # | |
Show a => Show (Sized a) Source # | |
Generic (Sized a) Source # | |
Semigroup a => Semigroup (Sized a) Source # | |
Monoid a => Monoid (Sized a) Source # | |
NFData a => NFData (Sized a) Source # | |
type Rep (Sized a) Source # | |
Converting into a Data.Tree
InternalNode v | |
LeafNode a |
toRoseTree :: BinLeafTree v a -> Tree (RoseElem v a) Source #
Internal Node Tree
data BinaryTree a Source #
Nil | |
Internal (BinaryTree a) !a (BinaryTree a) |
Functor BinaryTree Source # | |
Foldable BinaryTree Source # | |
Traversable BinaryTree Source # | |
Eq a => Eq (BinaryTree a) Source # | |
Ord a => Ord (BinaryTree a) Source # | |
Read a => Read (BinaryTree a) Source # | |
Show a => Show (BinaryTree a) Source # | |
Generic (BinaryTree a) Source # | |
NFData a => NFData (BinaryTree a) Source # | |
type Rep (BinaryTree a) Source # | |
access :: BinaryTree a -> Maybe a Source #
Get the element stored at the root, if it exists
asBalancedBinTree :: [a] -> BinaryTree a Source #
Create a balanced binary tree
\(O(n)\)
foldBinaryUp :: b -> (a -> b -> b -> b) -> BinaryTree a -> BinaryTree (a, b) Source #
toRoseTree' :: BinaryTree a -> Maybe (Tree a) Source #