chatty-utils-0.7.3.0: Some utilities every serious chatty-based application may need.

Safe HaskellSafe
LanguageHaskell2010

Data.Chatty.BST

Description

Provides a typeclass for all binary search trees and an unbalanced implementation

Synopsis

Documentation

class Ord o => Indexable i o v | i -> o, i -> v where Source

Only instances of Indexable may be saved in a BST

Methods

indexOf :: i -> o Source

Extract the index

valueOf :: i -> v Source

Extract the value

Instances

Indexable Int Int Int 
Indexable (Node a) NodeId (Node a) 
Ord o => Indexable (o, a) o a 
Ord o => Indexable (o, a, b) o (a, b) 
Ord o => Indexable (o, a, b, c) o (a, b, c) 
Ord o => Indexable (o, a, b, c, d) o (a, b, c, d) 
Ord o => Indexable (o, a, b, c, d, e) o (a, b, c, d, e) 

class Indexable i o v => AnyBST t i o v where Source

Typeclass for all BSTs that store the given Indexable

Methods

anyBstInsert :: i -> t i -> t i Source

Insert into the tree

anyBstRemove :: o -> t i -> t i Source

Remove from the tree

anyBstMax :: t i -> Maybe i Source

Get the greatest element

anyBstMin :: t i -> Maybe i Source

Get the least element

anyBstLookup :: o -> t i -> Maybe v Source

Lookup a given key

anyBstEmpty :: t i Source

An empty tree

anyBstHead :: t i -> Maybe i Source

The root of the tree

anyBstInorder :: t i -> [i] Source

Traverse the tree in order

Instances

Indexable i o v => AnyBST BST i o v 
Indexable i o v => AnyBST Focus i o v 
Indexable i o v => AnyBST AVL i o v 

data BST a Source

An unbalanced binary search tree

Constructors

EmptyBST 
BST a !(BST a) !(BST a) 

Instances

Indexable i o v => AnyBST BST i o v 
None (BST a) 

bstInsert :: Indexable i o v => i -> BST i -> BST i Source

Insert into the BST

bstRemove :: Indexable i o v => o -> BST i -> BST i Source

Remove from the BST

bstMax :: BST i -> Maybe i Source

Get the greatest element

bstMin :: BST i -> Maybe i Source

Get the least element

bstLookup :: Indexable i o v => o -> BST i -> Maybe v Source

Lookup a given key

bstContains :: Indexable i o v => o -> BST i -> Bool Source

Lookup if a given key is contained

bstHead :: Indexable i o v => BST i -> Maybe i Source

Return the tree's root

bstInorder :: Indexable i o v => BST i -> [i] Source

Traverse the tree in order