Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Software
CoPaR
Commits
29cebc6c
Commit
29cebc6c
authored
Mar 09, 2019
by
Hans-Peter Deifel
🐢
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SumBag: Add some internal documentation
parent
c15d5adf
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
2 deletions
+27
-2
src/Data/SumBag.hs
src/Data/SumBag.hs
+27
-2
No files found.
src/Data/SumBag.hs
View file @
29cebc6c
...
...
@@ -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
. W
ill compute the meta data from its subtrees
-- | "Smart" constructor for Node
, w
ill 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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment