forked from epfl-lara/stainless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExternField.scala
52 lines (42 loc) · 988 Bytes
/
ExternField.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import stainless.lang._
import stainless.annotation._
import scala.annotation.meta.field
import scala.collection.concurrent.TrieMap
object ExternField {
case class TrieMapWrapper[K, V](
@extern
theMap: TrieMap[K, V]
) {
@extern @pure
def contains(k: K): Boolean = {
theMap contains k
}
@extern
def insert(k: K, v: V): Unit = {
theMap.update(k, v)
}.ensuring {
this.contains(k) &&
this.apply(k) == v
}
@extern @pure
def apply(k: K): V = {
require(contains(k))
theMap(k)
}
}
object TrieMapWrapper {
@extern @pure
def empty[K, V]: TrieMapWrapper[K, V] = {
TrieMapWrapper(TrieMap.empty[K, V])
}.ensuring { res =>
forall((k: K) => !res.contains(k))
}
}
def test = {
val wrapper = TrieMapWrapper.empty[BigInt, String]
assert(!wrapper.contains(42))
wrapper.insert(42, "Hello")
assert(wrapper.contains(42))
assert(wrapper(42) == "Hello")
}
}