Sht
include collections
ยค
Specification of delegation map
module delegation_map(key,id) = {
action set(lo:key.iter.t,hi:key.iter.t,dst:id)
action get(k:key.t) returns (val:id)
relation map(K:key.t, X:id)
object spec = {
init map(K,X) <-> X = 0
before set {
map(K,X) := (X = dst) & key.iter.between(lo,K,hi)
| map(K,X) & ~key.iter.between(lo,K,hi)
}
after get {
assert map(k,val)
}
conjecture map(K,V) & map(K,W) -> V = W
}
object impl = {
instance imap : ordered_map(key,id)
after init {
call imap.set(0,0)
}
implement set(lo:key.iter.t,hi:key.iter.t,dst:id) {
if lo < hi {
if ~key.iter.is_end(hi) {
local nid:id {
nid := imap.get(key.iter.val(imap.glb(hi)),0);
call imap.set(key.iter.val(hi),nid)
}
};
call imap.erase(lo,hi);
call imap.set(key.iter.val(lo),dst)
}
}
implement get(k:key.t) returns (val:id) {
val := imap.get(key.iter.val(imap.glb(key.iter.create(k))),0)
}
conjecture imap.maps(key.iter.val(I),V) & imap.gap(I,J) & key.iter.between(I,K,J) -> map(K,V)
conjecture imap.contains(0)
}
}