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 the necessary proofs to ensure (at compile time) that the balance algorithm defined in Data.Tree.AVL.Extern.Balance respects the key ordering and recovers the height balance.
Synopsis
- class ProofIsBSTBalance (t :: Tree) where
- proofIsBSTBalance :: IsBSTT t -> IsBSTT (Balance t)
- class ProofIsBSTBalance' (t :: Tree) (us :: US) where
- proofIsBSTBalance' :: IsBSTT t -> Proxy us -> IsBSTT (Balance' t us)
- class ProofIsBSTRotate (t :: Tree) (us :: US) (bs :: BS) where
- class ProofLtNBalance (t :: Tree) (n :: Nat) where
- class ProofLtNBalance' (t :: Tree) (n :: Nat) (us :: US) where
- class ProofLtNRotate (t :: Tree) (n :: Nat) (us :: US) (bs :: BS) where
- class ProofGtNBalance (t :: Tree) (n :: Nat) where
- class ProofGtNBalance' (t :: Tree) (n :: Nat) (us :: US) where
- class ProofGtNRotate (t :: Tree) (n :: Nat) (us :: US) (bs :: BS) where
- class ProofIsBalancedBalance (t :: Tree) where
- proofIsBalancedBalance :: IsAlmostBalancedT t -> IsBalancedT (Balance t)
- class ProofIsBalancedBalance' (t :: Tree) (us :: US) where
- proofIsBalancedBalance' :: (t ~ 'ForkTree l (Node n a) r, LtN l n ~ 'True, GtN r n ~ 'True) => IsAlmostBalancedT t -> Proxy us -> IsBalancedT (Balance' t us)
- class ProofIsBalancedRotate (t :: Tree) (us :: US) (bs :: BS) where
- proofIsBalancedRotate :: (t ~ 'ForkTree l (Node n a) r, LtN l n ~ 'True, GtN r n ~ 'True) => IsAlmostBalancedT t -> Proxy us -> Proxy bs -> IsBalancedT (Rotate t us bs)
Documentation
class ProofIsBSTBalance (t :: Tree) where Source #
Prove that applying a rebalancing (a composition of rotations)
to a BST
tree preserves BST
condition.
The BST
invariant was already checked since this proof is called after proofs for insert
or delete
.
Instances
ProofIsBSTBalance 'EmptyTree Source # | |
Defined in Data.Tree.AVL.Extern.BalanceProofs | |
(us ~ UnbalancedState (Height l) (Height r), ProofIsBSTBalance' ('ForkTree l (Node n a) r) us) => ProofIsBSTBalance ('ForkTree l (Node n a) r) Source # | |
class ProofIsBSTBalance' (t :: Tree) (us :: US) where Source #
Prove that applying a rebalancing (a composition of rotations)
to a BST
tree preserves BST
condition, given the comparison us
of the heights of the left and right sub trees.
This is called only from ProofIsBSTBalance
.
The BST
invariant was already checked since this proof is called after proofs for insert
or delete
.
class ProofIsBSTRotate (t :: Tree) (us :: US) (bs :: BS) where Source #
class ProofLtNBalance (t :: Tree) (n :: Nat) where Source #
Prove that rebalancing a tree t
which verifies LtN t n ~ 'True
preserves the LtN
invariant.
Instances
ProofLtNBalance 'EmptyTree n Source # | |
(us ~ UnbalancedState (Height l) (Height r), ProofLtNBalance' ('ForkTree l (Node n1 a) r) n us) => ProofLtNBalance ('ForkTree l (Node n1 a) r) n Source # | |
class ProofLtNBalance' (t :: Tree) (n :: Nat) (us :: US) where Source #
Prove that rebalancing a tree t
which verifies LtN t n ~ 'True
preserves the LtN
invariant,
given the unbalanced state us
of the tree.
class ProofLtNRotate (t :: Tree) (n :: Nat) (us :: US) (bs :: BS) where Source #
Prove that applying a rotation to a tree t
which verifies LtN t n ~ 'True
preserves the LtN
invariant.
class ProofGtNBalance (t :: Tree) (n :: Nat) where Source #
Prove that rebalancing a tree t
which verifies GtN t n ~ 'True
preserves the GtN
invariant.
Instances
ProofGtNBalance 'EmptyTree n Source # | |
(us ~ UnbalancedState (Height l) (Height r), ProofGtNBalance' ('ForkTree l (Node n1 a) r) n us) => ProofGtNBalance ('ForkTree l (Node n1 a) r) n Source # | |
class ProofGtNBalance' (t :: Tree) (n :: Nat) (us :: US) where Source #
Prove that rebalancing a tree t
which verifies GtN t n ~ 'True
preserves the GtN
invariant,
given the unbalanced state us
of the tree.
class ProofGtNRotate (t :: Tree) (n :: Nat) (us :: US) (bs :: BS) where Source #
Prove that applying a rotation to a tree t
which verifies GtN t n ~ 'True
preserves the GtN
invariant.
class ProofIsBalancedBalance (t :: Tree) where Source #
Prove that applying a rebalancing (composition of rotations) to an `Almost Balanced` tree returns a `Balanced Tree`.
An `Almost Balanced` tree is a tree t ~ 'ForkTree l (Node n a) r
which verifies all the following conditions:
IsBalanced l ~ 'True
IsBalanced r ~ 'True
In other words, it's a tree with left and right AVL
sub trees that may not be balanced at the root.
proofIsBalancedBalance :: IsAlmostBalancedT t -> IsBalancedT (Balance t) Source #
Instances
ProofIsBalancedBalance 'EmptyTree Source # | |
Defined in Data.Tree.AVL.Extern.BalanceProofs | |
(us ~ UnbalancedState (Height l) (Height r), LtN l n ~ 'True, GtN r n ~ 'True, ProofIsBalancedBalance' ('ForkTree l (Node n a) r) us) => ProofIsBalancedBalance ('ForkTree l (Node n a) r) Source # | |
Defined in Data.Tree.AVL.Extern.BalanceProofs proofIsBalancedBalance :: IsAlmostBalancedT ('ForkTree l (Node n a) r) -> IsBalancedT (Balance ('ForkTree l (Node n a) r)) Source # |
class ProofIsBalancedBalance' (t :: Tree) (us :: US) where Source #
Prove that applying a rebalancing (a composition of rotations)
to an `Almost AVL` tree returns an AVL
, given the comparison us
of the heights of the left and right sub trees.
This is called only from ProofIsBalancedBalance
.
proofIsBalancedBalance' :: (t ~ 'ForkTree l (Node n a) r, LtN l n ~ 'True, GtN r n ~ 'True) => IsAlmostBalancedT t -> Proxy us -> IsBalancedT (Balance' t us) Source #
class ProofIsBalancedRotate (t :: Tree) (us :: US) (bs :: BS) where Source #
Prove that applying a rotation
to an `Almost AVL` tree returns an AVL
tree.
proofIsBalancedRotate :: (t ~ 'ForkTree l (Node n a) r, LtN l n ~ 'True, GtN r n ~ 'True) => IsAlmostBalancedT t -> Proxy us -> Proxy bs -> IsBalancedT (Rotate t us bs) Source #