| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Falsify.Tree
Contents
Description
Binary trees
Intended for qualified import.
import Data.Falsify.Tree (Tree(..)) import qualified Data.Falsify.Tree as Tree
Documentation
Binary tree
Each branch caches the size of the subtree, so that size can be O(1).
Constructors
| Leaf |
Instances
| Foldable Tree Source # | |
Defined in Data.Falsify.Tree Methods fold :: Monoid m => Tree m -> m # foldMap :: Monoid m => (a -> m) -> Tree a -> m # foldMap' :: Monoid m => (a -> m) -> Tree a -> m # foldr :: (a -> b -> b) -> b -> Tree a -> b # foldr' :: (a -> b -> b) -> b -> Tree a -> b # foldl :: (b -> a -> b) -> b -> Tree a -> b # foldl' :: (b -> a -> b) -> b -> Tree a -> b # foldr1 :: (a -> a -> a) -> Tree a -> a # foldl1 :: (a -> a -> a) -> Tree a -> a # elem :: Eq a => a -> Tree a -> Bool # maximum :: Ord a => Tree a -> a # | |
| Traversable Tree Source # | |
| Functor Tree Source # | |
| Show a => Show (Tree a) Source # | |
| Eq a => Eq (Tree a) Source # | |
Properties
weight :: Tree a -> Word Source #
Weight of the tree
The weight of a tree is simply its size plus one.
O(1)
height :: Tree a -> Word Source #
Height of the tree
The height of a tree is the maximum length from the root to any of the leafs.
O(1)
BST
lookup :: Ord a => a -> Tree (a, b) -> Maybe b Source #
Look value up in BST
NOTE: The Tree datatype itself does NOT guarantee that the tree is in
fact a BST. It is the responsibility of the caller to ensure this.
Balancing
isWeightBalanced :: Tree a -> Bool Source #
Check if the tree is weight-balanced
A tree is weight-balanced if the weights of the subtrees does not differ by more than a factor 3.
See "Balancing weight-balanced trees", Hirai and Yamamoto, JFP 21(3), 2011.
isHeightBalanced :: Tree a -> Bool Source #
Check if a tree is height-balanced
A tree is height balanced if the heights of its subtrees do not differ by more than one.