Copyright | (c) Nicolás Rodríguez 2021 |
---|---|
License | GPL-3 |
Maintainer | Nicolás Rodríguez |
Stability | experimental |
Portability | POSIX |
Safe Haskell | Safe |
Language | Haskell2010 |
Implementation of unsafe BST trees. These trees have no type level information useful for compile time verification of invariants.
Synopsis
- data Node :: Type -> Type where
- data BST :: Type -> Type where
- emptyBST :: BST a
- insertBST :: Show a => Int -> a -> BST a -> BST a
- insertBST' :: Node a -> BST a -> Ordering -> BST a
- lookupBST :: Int -> BST a -> Maybe a
- lookupBST' :: Int -> BST a -> Ordering -> Maybe a
- maxKeyDelete :: BST a -> BST a
- maxNode :: BST a -> Maybe (Node a)
- deleteBST :: Int -> BST a -> BST a
- deleteBST' :: Int -> BST a -> Ordering -> BST a
Documentation
insertBST :: Show a => Int -> a -> BST a -> BST a Source #
Entry point for inserting a new key and value. If the key is already present in the tree, update the value.
insertBST' :: Node a -> BST a -> Ordering -> BST a Source #
Insertion algorithm. It has the additional parameter of type
Ordering
, which guides the recursion.
lookupBST :: Int -> BST a -> Maybe a Source #
Lookup the given key in the tree.
It returns Nothing
if tree is empty or if it doesn't have the key.
lookupBST' :: Int -> BST a -> Ordering -> Maybe a Source #
Lookup algorithm. It has the additional parameter of type
Ordering
, which guides the recursion.
maxKeyDelete :: BST a -> BST a Source #
Delete the node with the maximum key value.
maxNode :: BST a -> Maybe (Node a) Source #
Get the node with maximum key value.
| It returns Nothing
if tree is empty.