Commit 29cebc6c authored by Hans-Peter Deifel's avatar Hans-Peter Deifel 🐢

SumBag: Add some internal documentation

parent c15d5adf
......@@ -57,7 +57,7 @@ instance Foldable SumBag where
toList = toAscList
{-# INLINE toList #-}
data MetaData a = MetaData
{ nodeSize :: Int
......@@ -160,7 +160,7 @@ fromList = foldr insert empty
-- Internal functions
-- | "Smart" constructor for Node. Will compute the meta data from its subtrees
-- | "Smart" constructor for Node, will compute the meta data from its subtrees.
node :: Monoid a => Element a -> SumBag a -> SumBag a -> SumBag a
node a left right =
let nodeData = MetaData
......@@ -169,23 +169,48 @@ node a left right =
}
in Node nodeData a left right
-- a b
-- / \ / \
-- x b => a z
-- / \ / \
-- y z x y
rotateSingleLeft :: Monoid a => Element a -> SumBag a -> SumBag a -> SumBag a
rotateSingleLeft a x (Node _ b y z) = node b (node a x y) z
rotateSingleLeft _ _ _ = error "rotateSingleLeft called with empty right tree"
-- b a
-- / \ / \
-- a z => x b
-- / \ / \
-- x y y z
rotateSingleRight :: Monoid a => Element a -> SumBag a -> SumBag a -> SumBag a
rotateSingleRight b (Node _ a x y) z = node a x (node b y z)
rotateSingleRight _ _ _ = error "rotateSingleRight called with empty left tree"
-- a b
-- / \ / \
-- x c a c
-- / \ => / \ / \
-- b z x y1 y2 z
-- / \
-- y1 y2
rotateDoubleLeft :: Monoid a => Element a -> SumBag a -> SumBag a -> SumBag a
rotateDoubleLeft a x (Node _ c (Node _ b y1 y2) z) = node b (node a x y1) (node c y2 z)
rotateDoubleLeft _ _ _ = error "rotateDoubleLeft called with too small right tree"
-- c b
-- / \ / \
-- a z a c
-- / \ => / \ / \
-- x b x y1 y2 z
-- / \
-- y1 y2
rotateDoubleRight :: Monoid a => Element a -> SumBag a -> SumBag a -> SumBag a
rotateDoubleRight c (Node _ a x (Node _ b y1 y2)) z = node b (node a x y1) (node c y2 z)
rotateDoubleRight _ _ _ = error "rotateDoubleRight called with too small left tree"
-- | Performs a single balancing act on a node.
balance1 :: Monoid a => Element a -> SumBag a -> SumBag a -> SumBag a
balance1 a left right
-- Subtrees have only one element
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment