hgeometry-combinatorial
Copyright(C) Frank Staals
Licensesee the LICENSE file
MaintainerFrank Staals
Safe HaskellNone
LanguageGHC2021

HGeometry.Tree.Binary.Static

Description

Several types of Binary trees.

Synopsis

Documentation

data BinLeafTree v a Source #

Binary tree that stores its values (of type a) in the leaves. Internal nodes store something of type v.

Constructors

Leaf !a 
Node (BinLeafTree v a) !v (BinLeafTree v a) 

Instances

Instances details
Bifunctor BinLeafTree Source # 
Instance details

Defined in HGeometry.Tree.Binary.Static

Methods

bimap :: (a -> b) -> (c -> d) -> BinLeafTree a c -> BinLeafTree b d Source #

first :: (a -> b) -> BinLeafTree a c -> BinLeafTree b c Source #

second :: (b -> c) -> BinLeafTree a b -> BinLeafTree a c Source #

Foldable1 (BinLeafTree v) Source # 
Instance details

Defined in HGeometry.Tree.Binary.Static

Methods

fold1 :: Semigroup m => BinLeafTree v m -> m Source #

foldMap1 :: Semigroup m => (a -> m) -> BinLeafTree v a -> m Source #

foldMap1' :: Semigroup m => (a -> m) -> BinLeafTree v a -> m Source #

toNonEmpty :: BinLeafTree v a -> NonEmpty a Source #

maximum :: Ord a => BinLeafTree v a -> a Source #

minimum :: Ord a => BinLeafTree v a -> a Source #

head :: BinLeafTree v a -> a Source #

last :: BinLeafTree v a -> a Source #

foldrMap1 :: (a -> b) -> (a -> b -> b) -> BinLeafTree v a -> b Source #

foldlMap1' :: (a -> b) -> (b -> a -> b) -> BinLeafTree v a -> b Source #

foldlMap1 :: (a -> b) -> (b -> a -> b) -> BinLeafTree v a -> b Source #

foldrMap1' :: (a -> b) -> (a -> b -> b) -> BinLeafTree v a -> b Source #

Functor (BinLeafTree v) Source # 
Instance details

Defined in HGeometry.Tree.Binary.Static

Methods

fmap :: (a -> b) -> BinLeafTree v a -> BinLeafTree v b Source #

(<$) :: a -> BinLeafTree v b -> BinLeafTree v a Source #

Foldable (BinLeafTree v) Source # 
Instance details

Defined in HGeometry.Tree.Binary.Static

Methods

fold :: Monoid m => BinLeafTree v m -> m Source #

foldMap :: Monoid m => (a -> m) -> BinLeafTree v a -> m Source #

foldMap' :: Monoid m => (a -> m) -> BinLeafTree v a -> m Source #

foldr :: (a -> b -> b) -> b -> BinLeafTree v a -> b Source #

foldr' :: (a -> b -> b) -> b -> BinLeafTree v a -> b Source #

foldl :: (b -> a -> b) -> b -> BinLeafTree v a -> b Source #

foldl' :: (b -> a -> b) -> b -> BinLeafTree v a -> b Source #

foldr1 :: (a -> a -> a) -> BinLeafTree v a -> a Source #

foldl1 :: (a -> a -> a) -> BinLeafTree v a -> a Source #

toList :: BinLeafTree v a -> [a] Source #

null :: BinLeafTree v a -> Bool Source #

length :: BinLeafTree v a -> Int Source #

elem :: Eq a => a -> BinLeafTree v a -> Bool Source #

maximum :: Ord a => BinLeafTree v a -> a Source #

minimum :: Ord a => BinLeafTree v a -> a Source #

sum :: Num a => BinLeafTree v a -> a Source #

product :: Num a => BinLeafTree v a -> a Source #

Traversable (BinLeafTree v) Source # 
Instance details

Defined in HGeometry.Tree.Binary.Static

Methods

traverse :: Applicative f => (a -> f b) -> BinLeafTree v a -> f (BinLeafTree v b) Source #

sequenceA :: Applicative f => BinLeafTree v (f a) -> f (BinLeafTree v a) Source #

mapM :: Monad m => (a -> m b) -> BinLeafTree v a -> m (BinLeafTree v b) Source #

sequence :: Monad m => BinLeafTree v (m a) -> m (BinLeafTree v a) Source #

Traversable1 (BinLeafTree v) Source # 
Instance details

Defined in HGeometry.Tree.Binary.Static

Methods

traverse1 :: Apply f => (a -> f b) -> BinLeafTree v a -> f (BinLeafTree v b) Source #

sequence1 :: Apply f => BinLeafTree v (f b) -> f (BinLeafTree v b) Source #

(NFData v, NFData a) => NFData (BinLeafTree v a) Source # 
Instance details

Defined in HGeometry.Tree.Binary.Static

Methods

rnf :: BinLeafTree v a -> () Source #

(Measured f a, Semigroup (f a)) => Semigroup (BinLeafTree (f a) a) Source # 
Instance details

Defined in HGeometry.Tree.Binary.Static

Methods

(<>) :: BinLeafTree (f a) a -> BinLeafTree (f a) a -> BinLeafTree (f a) a Source #

sconcat :: NonEmpty (BinLeafTree (f a) a) -> BinLeafTree (f a) a Source #

stimes :: Integral b => b -> BinLeafTree (f a) a -> BinLeafTree (f a) a Source #

Generic (BinLeafTree v a) Source # 
Instance details

Defined in HGeometry.Tree.Binary.Static

Associated Types

type Rep (BinLeafTree v a) 
Instance details

Defined in HGeometry.Tree.Binary.Static

Methods

from :: BinLeafTree v a -> Rep (BinLeafTree v a) x Source #

to :: Rep (BinLeafTree v a) x -> BinLeafTree v a Source #

(Read a, Read v) => Read (BinLeafTree v a) Source # 
Instance details

Defined in HGeometry.Tree.Binary.Static

(Show a, Show v) => Show (BinLeafTree v a) Source # 
Instance details

Defined in HGeometry.Tree.Binary.Static

(Eq a, Eq v) => Eq (BinLeafTree v a) Source # 
Instance details

Defined in HGeometry.Tree.Binary.Static

Methods

(==) :: BinLeafTree v a -> BinLeafTree v a -> Bool Source #

(/=) :: BinLeafTree v a -> BinLeafTree v a -> Bool Source #

(Ord a, Ord v) => Ord (BinLeafTree v a) Source # 
Instance details

Defined in HGeometry.Tree.Binary.Static

type Rep (BinLeafTree v a) Source # 
Instance details

Defined in HGeometry.Tree.Binary.Static

node :: (Measured f a, Semigroup (f a)) => BinLeafTree (f a) a -> BinLeafTree (f a) a -> BinLeafTree (f a) a Source #

smart constructor

asBalancedBinLeafTree :: Foldable1 f => f a -> BinLeafTree (Count a) 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

toRoseTree :: BinLeafTree v a -> Tree (TreeNode v a) Source #

\( O(n) \) Convert binary tree to a rose tree, aka Tree.

drawTree :: (Show v, Show a) => BinLeafTree v a -> String Source #

2-dimensional ASCII drawing of a tree.

data BinaryTree a Source #

Binary tree in which we store the values of type a in internal nodes.

Constructors

Nil 
Internal (BinaryTree a) !a (BinaryTree a) 

Instances

Instances details
Functor BinaryTree Source # 
Instance details

Defined in HGeometry.Tree.Binary.Static

Methods

fmap :: (a -> b) -> BinaryTree a -> BinaryTree b Source #

(<$) :: a -> BinaryTree b -> BinaryTree a Source #

Foldable BinaryTree Source # 
Instance details

Defined in HGeometry.Tree.Binary.Static

Methods

fold :: Monoid m => BinaryTree m -> m Source #

foldMap :: Monoid m => (a -> m) -> BinaryTree a -> m Source #

foldMap' :: Monoid m => (a -> m) -> BinaryTree a -> m Source #

foldr :: (a -> b -> b) -> b -> BinaryTree a -> b Source #

foldr' :: (a -> b -> b) -> b -> BinaryTree a -> b Source #

foldl :: (b -> a -> b) -> b -> BinaryTree a -> b Source #

foldl' :: (b -> a -> b) -> b -> BinaryTree a -> b Source #

foldr1 :: (a -> a -> a) -> BinaryTree a -> a Source #

foldl1 :: (a -> a -> a) -> BinaryTree a -> a Source #

toList :: BinaryTree a -> [a] Source #

null :: BinaryTree a -> Bool Source #

length :: BinaryTree a -> Int Source #

elem :: Eq a => a -> BinaryTree a -> Bool Source #

maximum :: Ord a => BinaryTree a -> a Source #

minimum :: Ord a => BinaryTree a -> a Source #

sum :: Num a => BinaryTree a -> a Source #

product :: Num a => BinaryTree a -> a Source #

Traversable BinaryTree Source # 
Instance details

Defined in HGeometry.Tree.Binary.Static

Methods

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

sequenceA :: Applicative f => BinaryTree (f a) -> f (BinaryTree a) Source #

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

sequence :: Monad m => BinaryTree (m a) -> m (BinaryTree a) Source #

NFData a => NFData (BinaryTree a) Source # 
Instance details

Defined in HGeometry.Tree.Binary.Static

Methods

rnf :: BinaryTree a -> () Source #

Generic (BinaryTree a) Source # 
Instance details

Defined in HGeometry.Tree.Binary.Static

Associated Types

type Rep (BinaryTree a) 
Instance details

Defined in HGeometry.Tree.Binary.Static

type Rep (BinaryTree a) = D1 ('MetaData "BinaryTree" "HGeometry.Tree.Binary.Static" "hgeometry-combinatorial-1.0.0.0-inplace" 'False) (C1 ('MetaCons "Nil" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Internal" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (BinaryTree a)) :*: (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (BinaryTree a)))))

Methods

from :: BinaryTree a -> Rep (BinaryTree a) x Source #

to :: Rep (BinaryTree a) x -> BinaryTree a Source #

Read a => Read (BinaryTree a) Source # 
Instance details

Defined in HGeometry.Tree.Binary.Static

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

Defined in HGeometry.Tree.Binary.Static

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

Defined in HGeometry.Tree.Binary.Static

Ord a => Ord (BinaryTree a) Source # 
Instance details

Defined in HGeometry.Tree.Binary.Static

type Rep (BinaryTree a) Source # 
Instance details

Defined in HGeometry.Tree.Binary.Static

type Rep (BinaryTree a) = D1 ('MetaData "BinaryTree" "HGeometry.Tree.Binary.Static" "hgeometry-combinatorial-1.0.0.0-inplace" 'False) (C1 ('MetaCons "Nil" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Internal" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (BinaryTree a)) :*: (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (BinaryTree a)))))

asBalancedBinTree :: Foldable f => f a -> BinaryTree a Source #

Create a balanced binary tree.

running time: \(O(n)\)

access :: BinaryTree a -> Maybe a Source #

Get the element stored at the root, if it exists

foldBinaryUp :: b -> (a -> b -> b -> b) -> BinaryTree a -> BinaryTree (a, b) Source #

Fold function for folding over a binary tree.

toRoseTree' :: BinaryTree a -> Maybe (Tree a) Source #

Convert a BinaryTree into a RoseTree

fromRoseTree' :: Tree a -> Maybe (BinaryTree a) Source #

Tries to convert a rose Tree into a binary tree.

drawTree' :: Show a => BinaryTree a -> String Source #

Draw a binary tree.