falsify-0.4.0: Property-based testing with internal integrated shrinking
Safe HaskellNone
LanguageHaskell2010

Data.Falsify.Tree

Description

Binary trees

Intended for qualified import.

import Data.Falsify.Tree (Tree(..))
import qualified Data.Falsify.Tree as Tree
Synopsis

Documentation

data Tree a Source #

Binary tree

Each branch caches the size of the subtree, so that size can be O(1).

Constructors

Leaf 

Bundled Patterns

pattern Branch :: a -> Tree a -> Tree a -> Tree a 

Instances

Instances details
Foldable Tree Source # 
Instance details

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 #

toList :: Tree a -> [a] #

null :: Tree a -> Bool #

length :: Tree a -> Int #

elem :: Eq a => a -> Tree a -> Bool #

maximum :: Ord a => Tree a -> a #

minimum :: Ord a => Tree a -> a #

sum :: Num a => Tree a -> a #

product :: Num a => Tree a -> a #

Traversable Tree Source # 
Instance details

Defined in Data.Falsify.Tree

Methods

traverse :: Applicative f => (a -> f b) -> Tree a -> f (Tree b) #

sequenceA :: Applicative f => Tree (f a) -> f (Tree a) #

mapM :: Monad m => (a -> m b) -> Tree a -> m (Tree b) #

sequence :: Monad m => Tree (m a) -> m (Tree a) #

Functor Tree Source # 
Instance details

Defined in Data.Falsify.Tree

Methods

fmap :: (a -> b) -> Tree a -> Tree b #

(<$) :: a -> Tree b -> Tree a #

Show a => Show (Tree a) Source # 
Instance details

Defined in Data.Falsify.Tree

Methods

showsPrec :: Int -> Tree a -> ShowS #

show :: Tree a -> String #

showList :: [Tree a] -> ShowS #

Eq a => Eq (Tree a) Source # 
Instance details

Defined in Data.Falsify.Tree

Methods

(==) :: Tree a -> Tree a -> Bool #

(/=) :: Tree a -> Tree a -> Bool #

Properties

size :: Tree a -> Word Source #

Size of the tree

O(1)

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.

Debugging

render :: Tree String -> String Source #

Render tree

This is intended for debugging only.