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
6129717f
Commit
6129717f
authored
9 years ago
by
Viktor Kuncak
Browse files
Options
Downloads
Patches
Plain Diff
The most elegant version of simple binary search tree.
parent
6d72a634
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
testcases/verification/datastructures/BinarySearchTreeQuant.scala
+39
-31
39 additions, 31 deletions
...s/verification/datastructures/BinarySearchTreeQuant.scala
with
39 additions
and
31 deletions
testcases/verification/datastructures/BinarySearchTreeQuant.scala
+
39
−
31
View file @
6129717f
...
@@ -2,41 +2,49 @@ import leon.lang._
...
@@ -2,41 +2,49 @@ import leon.lang._
import
leon.collection._
import
leon.collection._
object
BSTSimpler
{
object
BSTSimpler
{
sealed
abstract
clas
s
Tree
case
object
Leaf
extend
s
Tree
case
class
Node
(
left
:
Tree
,
value
:
BigInt
,
right
:
Tree
)
extends
Tree
case
class
Node
(
left
:
Tree
,
value
:
BigInt
,
right
:
Tree
)
extends
Tree
case
class
Leaf
()
extends
Tree
sealed
abstract
class
Tree
{
def
isBST
:
Boolean
=
this
match
{
def
content
(
tree
:
Tree
)
:
Set
[
BigInt
]
=
tree
match
{
case
Leaf
=>
true
case
Leaf
()
=>
Set
.
empty
[
BigInt
]
case
Node
(
left
,
v
,
right
)
=>
{
case
Node
(
l
,
v
,
r
)
=>
content
(
l
)
++
Set
(
v
)
++
content
(
r
)
left
.
isBST
&&
right
.
isBST
&&
}
forall
((
x
:
BigInt
)
=>
(
left
.
content
.
contains
(
x
)
==>
x
<
v
))
&&
forall
((
x
:
BigInt
)
=>
(
right
.
content
.
contains
(
x
)
==>
v
<
x
))
}
}
def
isBST
(
tree
:
Tree
)
:
Boolean
=
tree
match
{
def
content
:
Set
[
BigInt
]
=
this
match
{
case
Leaf
()
=>
true
case
Leaf
=>
Set
.
empty
[
BigInt
]
case
Node
(
left
,
v
,
right
)
=>
{
case
Node
(
l
,
v
,
r
)
=>
l
.
content
++
Set
(
v
)
++
r
.
content
isBST
(
left
)
&&
isBST
(
right
)
&&
forall
((
x
:
BigInt
)
=>
(
content
(
left
).
contains
(
x
)
==>
x
<
v
))
&&
forall
((
x
:
BigInt
)
=>
(
content
(
right
).
contains
(
x
)
==>
v
<
x
))
}
}
}
def
emptySet
()
:
Tree
=
Leaf
()
def
insert
(
value
:
BigInt
)
:
Node
=
{
require
(
isBST
)
this
match
{
case
Leaf
=>
Node
(
Leaf
,
value
,
Leaf
)
case
Node
(
l
,
v
,
r
)
=>
(
if
(
v
<
value
)
{
Node
(
l
,
v
,
r
.
insert
(
value
))
}
else
if
(
v
>
value
)
{
Node
(
l
.
insert
(
value
),
v
,
r
)
}
else
{
Node
(
l
,
v
,
r
)
})
}
}
ensuring
(
res
=>
res
.
isBST
&&
res
.
content
==
content
++
Set
(
value
))
def
insert
(
tree
:
Tree
,
value
:
BigInt
)
:
Node
=
{
def
contains
(
value
:
BigInt
)
:
Boolean
=
{
require
(
isBST
(
tree
))
require
(
isBST
)
tree
match
{
this
match
{
case
Leaf
()
=>
Node
(
Leaf
(),
value
,
Leaf
())
case
Leaf
=>
false
case
Node
(
l
,
v
,
r
)
=>
(
if
(
v
<
value
)
{
case
Node
(
l
,
v
,
r
)
=>
(
if
(
v
<
value
)
{
Node
(
l
,
v
,
insert
(
r
,
value
))
r
.
contains
(
value
)
}
else
if
(
v
>
value
)
{
}
else
if
(
v
>
value
)
{
Node
(
insert
(
l
,
value
),
v
,
r
)
l
.
contains
(
value
)
}
else
{
}
else
true
)
Node
(
l
,
v
,
r
)
}
})
}
ensuring
(
res
=>
(
res
==
content
.
contains
(
value
)))
}
}
ensuring
(
res
=>
isBST
(
res
)
&&
content
(
res
)
==
content
(
tree
)
++
Set
(
value
))
def
createRoot
(
v
:
BigInt
)
:
Node
=
{
}
Node
(
Leaf
(),
v
,
Leaf
())
def
empty
:
Tree
=
Leaf
}
ensuring
(
content
(
_
)
==
Set
(
v
))
}
}
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