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
76f8611a
Commit
76f8611a
authored
15 years ago
by
Mirco Dotta
Browse files
Options
Downloads
Patches
Plain Diff
Added SplayHeap example.
parent
afa66489
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
forall-tests.sh
+8
-1
8 additions, 1 deletion
forall-tests.sh
tests/plugin/kawaguchi/MapReduce.scala
+86
-0
86 additions, 0 deletions
tests/plugin/kawaguchi/MapReduce.scala
with
94 additions
and
1 deletion
forall-tests.sh
+
8
−
1
View file @
76f8611a
...
...
@@ -78,6 +78,8 @@ scalac plugin/kawaguchi/InsertSort.scala
scalac plugin/kawaguchi/MergeSort.scala
scalac plugin/kawaguchi/MergeSortBug.scala
scalac plugin/kawaguchi/QuickSort.scala
scalac plugin/kawaguchi/MapReduce.scala
scalac plugin/kawaguchi/SplayHeap.scala
cd
..
...
...
@@ -109,6 +111,8 @@ export InsertSort="plugin.kawaguchi.InsertSort"
export
MergeSort
=
"plugin.kawaguchi.MergeSort"
export
MergeSortBug
=
"plugin.kawaguchi.MergeSortBug"
export
QuickSort
=
"plugin.kawaguchi.QuickSort"
export
MapReduce
=
"plugin.kawaguchi.MapReduce"
export
SplayHeap
=
"plugin.kawaguchi.SplayHeap"
echo
" - Testing
${
BST
}
"
scala
${
BST
}
...
...
@@ -143,5 +147,8 @@ scala ${MergeSortBug} 2> /dev/null | head -n 4
echo
" - Testing
${
QuickSort
}
"
scala
${
QuickSort
}
echo
" - Testing
${
MapReduce
}
"
scala
${
MapReduce
}
echo
" - Testing
${
SplayHeap
}
"
scala
${
SplayHeap
}
This diff is collapsed.
Click to expand it.
tests/plugin/kawaguchi/MapReduce.scala
0 → 100644
+
86
−
0
View file @
76f8611a
package
plugin.kawaguchi
/* Example from paper "Type-based Data Structure Verification"
* http://pho.ucsd.edu/liquid/demo/index2.php */
import
funcheck.lib.Specs._
object
MapReduce
{
/* specification */
def
insert
(
map
:
Map
[
Int
,
List
[
Int
]],
entry
:
(
Int
,
Int
))
:
Map
[
Int
,
List
[
Int
]]
=
{
val
(
key
,
value
)
=
entry
map
.
get
(
key
)
match
{
case
None
=>
map
+
((
key
,
List
(
value
)))
case
Some
(
vs
)
=>
map
+
((
key
,
value
::
vs
))
}
}
def
content
(
kvs
:
List
[(
Int
,
List
[
Int
])])
=
Map
.
empty
[
Int
,
List
[
Int
]]
++
(
kvs
)
/*****************************************/
forAll
[(
List
[(
Int
,
List
[
Int
])]
,
(
Int
,
Int
))]{
p
=>
insert
(
content
(
p
.
_1
),
p
.
_2
)
==
content
(
insert
(
p
.
_1
,
p
.
_2
))}
def
insert
(
t
:
List
[(
Int
,
List
[
Int
])],
x
:
(
Int
,
Int
))
:
List
[(
Int
,
List
[
Int
])]
=
{
val
(
key
,
value
)
=
x
t
match
{
case
Nil
=>
List
((
key
,
List
(
value
)))
case
(
k
,
vs
)
::
t
=>
if
(
k
==
key
)
(
k
,
value
::
vs
)
::
t
else
(
k
,
vs
)
::
(
insert
(
t
,
x
))
}
}
def
expand
(
f
:
Int
=>
List
[(
Int
,
Int
)],
xs
:
List
[
Int
])
:
List
[(
Int
,
Int
)]
=
xs
match
{
case
Nil
=>
Nil
case
x
::
xs
=>
f
(
x
)
:::
expand
(
f
,
xs
)
}
def
group
(
kvs
:
List
[(
Int
,
Int
)])
:
List
[(
Int
,
List
[
Int
])]
=
{
val
nil
:
List
[(
Int
,
List
[
Int
])]
=
Nil
(
nil
/:
kvs
)
{
case
(
z
,
a
)
=>
insert
(
z
,
a
)
}
}
def
collapse
(
f
:
(
Int
,
Int
)
=>
Int
,
gs
:
List
[(
Int
,
List
[
Int
])])
:
List
[(
Int
,
Int
)]
=
{
val
collapser
=
{
x
:
(
Int
,
List
[
Int
])
=>
x
match
{
case
(
k
,
Nil
)
=>
assert
(
false
);
null
case
(
k
,
v
::
vs
)
=>
(
k
,
vs
.
foldLeft
(
v
)((
z
:
Int
,
a
:
Int
)
=>
f
(
z
,
a
)))
}
}
gs
.
map
(
collapser
(
_
))
}
def
map_reduce
(
xs
:
List
[
Int
],
mapper
:
Int
=>
List
[(
Int
,
Int
)],
reducer
:
(
Int
,
Int
)
=>
Int
)
:
List
[(
Int
,
Int
)]
=
{
val
kvs
:
List
[(
Int
,
Int
)]
=
expand
(
mapper
,
xs
)
val
gs
:
List
[(
Int
,
List
[
Int
])]
=
group
(
kvs
)
val
rs
=
collapse
(
reducer
,
gs
)
rs
}
def
main
(
args
:
Array
[
String
])
=
{
// val xs = List.range(1,5)
// val mapper: Int => List[(Int,Int)] = {x: Int => List((x,x+2), (x,x+3))}
// val reducer = {(a: Int,b: Int) => a + b}
//
// println(map_reduce(xs,mapper,reducer))
}
}
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