Skip to content

Commit

Permalink
Made merge sort verify using better specified splitAtIndex.
Browse files Browse the repository at this point in the history
  • Loading branch information
vkuncak committed Sep 23, 2015
1 parent 2c0436d commit 6dea823
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions library/par/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import leon.lang.synthesis.choose
package object par {

// @library
@inline
def parallel[A,B](x: => A, y: => B) : (A,B) = {
(x,y)
}
Expand Down
3 changes: 2 additions & 1 deletion testcases/verification/list-algorithms/BasicMergeSort.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ object MergeSort {
def msort[T](less: (T, T) => Boolean)(l: List[T]): List[T] = {
if (l.size <= 1) l
else {
val (first, second) = l.evenSplit
val c = l.length/2
val (first, second) = l.splitAtIndex(c) // evenSplit
merge(less)(msort(less)(first), msort(less)(second))
}
} ensuring { res => res.content == l.content && res.size == l.size }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ object MergeSortPar {
def msort[T](less: (T, T) => Boolean)(l: List[T]): List[T] = {
if (l.size <= 1) l
else {
val (first, second) = l.evenSplit
val c = l.length/2
val (first, second) = l.splitAtIndex(c) // evenSplit
val (s1, s2) = parallel(msort(less)(first), msort(less)(second))
merge(less)(s1, s2)
}
} ensuring { res => res.content == l.content && res.size == l.size }
} ensuring { res => res.content == l.content &&
res.size == l.size }
}

0 comments on commit 6dea823

Please sign in to comment.