Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LARA
inox
Commits
9b77b63e
Commit
9b77b63e
authored
14 years ago
by
Ali Sinan Köksal
Browse files
Options
Downloads
Patches
Plain Diff
Buggy balancing method in RBT, a precondition in insertion sort.
parent
ea682699
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
demo/InsertionSort.scala
+18
-18
18 additions, 18 deletions
demo/InsertionSort.scala
demo/RedBlackTree.scala
+15
-1
15 additions, 1 deletion
demo/RedBlackTree.scala
with
33 additions
and
19 deletions
demo/InsertionSort.scala
+
18
−
18
View file @
9b77b63e
...
@@ -29,24 +29,24 @@ object InsertionSort {
...
@@ -29,24 +29,24 @@ object InsertionSort {
}
}
}
}
def
minProp0
(
l
:
List
)
:
Boolean
=
(
l
match
{
//
def minProp0(l : List) : Boolean = (l match {
case
Nil
()
=>
true
//
case Nil() => true
case
c
@
Cons
(
x
,
xs
)
=>
min
(
c
)
match
{
//
case c @ Cons(x, xs) => min(c) match {
case
None
()
=>
false
//
case None() => false
case
Some
(
m
)
=>
x
>=
m
//
case Some(m) => x >= m
}
//
}
})
holds
//
}) holds
def
minProp1
(
l
:
List
)
:
Boolean
=
{
//
def minProp1(l : List) : Boolean = {
require
(
isSorted
(
l
)
&&
size
(
l
)
<=
5
)
//
require(isSorted(l) && size(l) <= 5)
l
match
{
//
l match {
case
Nil
()
=>
true
//
case Nil() => true
case
c
@
Cons
(
x
,
xs
)
=>
min
(
c
)
match
{
//
case c @ Cons(x, xs) => min(c) match {
case
None
()
=>
false
//
case None() => false
case
Some
(
m
)
=>
x
==
m
//
case Some(m) => x == m
}
//
}
}
//
}
}
holds
//
} holds
def
isSorted
(
l
:
List
)
:
Boolean
=
l
match
{
def
isSorted
(
l
:
List
)
:
Boolean
=
l
match
{
case
Nil
()
=>
true
case
Nil
()
=>
true
...
@@ -70,7 +70,7 @@ object InsertionSort {
...
@@ -70,7 +70,7 @@ object InsertionSort {
/* Inserting element 'e' into a sorted list 'l' produces a sorted list with
/* Inserting element 'e' into a sorted list 'l' produces a sorted list with
* the expected content and size */
* the expected content and size */
def
buggySortedIns
(
e
:
Int
,
l
:
List
)
:
List
=
{
def
buggySortedIns
(
e
:
Int
,
l
:
List
)
:
List
=
{
//
require(isSorted(l))
require
(
isSorted
(
l
))
l
match
{
l
match
{
case
Nil
()
=>
Cons
(
e
,
Nil
())
case
Nil
()
=>
Cons
(
e
,
Nil
())
case
Cons
(
x
,
xs
)
=>
if
(
x
<=
e
)
Cons
(
x
,
buggySortedIns
(
e
,
xs
))
else
Cons
(
e
,
l
)
case
Cons
(
x
,
xs
)
=>
if
(
x
<=
e
)
Cons
(
x
,
buggySortedIns
(
e
,
xs
))
else
Cons
(
e
,
l
)
...
...
This diff is collapsed.
Click to expand it.
demo/RedBlackTree.scala
+
15
−
1
View file @
9b77b63e
...
@@ -84,7 +84,7 @@ object RedBlackTree {
...
@@ -84,7 +84,7 @@ object RedBlackTree {
def
buggyAdd
(
x
:
Int
,
t
:
Tree
)
:
Tree
=
{
def
buggyAdd
(
x
:
Int
,
t
:
Tree
)
:
Tree
=
{
require
(
redNodesHaveBlackChildren
(
t
))
require
(
redNodesHaveBlackChildren
(
t
))
makeBlack
(
ins
(
x
,
t
)
)
ins
(
x
,
t
)
}
ensuring
(
res
=>
content
(
res
)
==
content
(
t
)
++
Set
(
x
)
&&
redNodesHaveBlackChildren
(
res
))
}
ensuring
(
res
=>
content
(
res
)
==
content
(
t
)
++
Set
(
x
)
&&
redNodesHaveBlackChildren
(
res
))
def
balance
(
c
:
Color
,
a
:
Tree
,
x
:
Int
,
b
:
Tree
)
:
Tree
=
{
def
balance
(
c
:
Color
,
a
:
Tree
,
x
:
Int
,
b
:
Tree
)
:
Tree
=
{
...
@@ -100,4 +100,18 @@ object RedBlackTree {
...
@@ -100,4 +100,18 @@ object RedBlackTree {
case
Node
(
c
,
a
,
xV
,
b
)
=>
Node
(
c
,
a
,
xV
,
b
)
case
Node
(
c
,
a
,
xV
,
b
)
=>
Node
(
c
,
a
,
xV
,
b
)
}
}
}
ensuring
(
res
=>
content
(
res
)
==
content
(
Node
(
c
,
a
,
x
,
b
)))
// && redDescHaveBlackChildren(res))
}
ensuring
(
res
=>
content
(
res
)
==
content
(
Node
(
c
,
a
,
x
,
b
)))
// && redDescHaveBlackChildren(res))
def
buggyBalance
(
c
:
Color
,
a
:
Tree
,
x
:
Int
,
b
:
Tree
)
:
Tree
=
{
Node
(
c
,
a
,
x
,
b
)
match
{
case
Node
(
Black
(),
Node
(
Red
(),
Node
(
Red
(),
a
,
xV
,
b
),
yV
,
c
),
zV
,
d
)
=>
Node
(
Red
(),
Node
(
Black
(),
a
,
xV
,
b
),
yV
,
Node
(
Black
(),
c
,
zV
,
d
))
case
Node
(
Black
(),
Node
(
Red
(),
a
,
xV
,
Node
(
Red
(),
b
,
yV
,
c
)),
zV
,
d
)
=>
Node
(
Red
(),
Node
(
Black
(),
a
,
xV
,
b
),
yV
,
Node
(
Black
(),
c
,
zV
,
d
))
case
Node
(
Black
(),
a
,
xV
,
Node
(
Red
(),
Node
(
Red
(),
b
,
yV
,
c
),
zV
,
d
))
=>
Node
(
Red
(),
Node
(
Black
(),
a
,
xV
,
b
),
yV
,
Node
(
Black
(),
c
,
zV
,
d
))
case
Node
(
Black
(),
a
,
xV
,
Node
(
Red
(),
b
,
yV
,
Node
(
Red
(),
c
,
zV
,
d
)))
=>
Node
(
Red
(),
Node
(
Black
(),
a
,
xV
,
b
),
yV
,
Node
(
Black
(),
c
,
zV
,
d
))
// case Node(c,a,xV,b) => Node(c,a,xV,b)
}
}
ensuring
(
res
=>
content
(
res
)
==
content
(
Node
(
c
,
a
,
x
,
b
)))
// && redDescHaveBlackChildren(res))
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment