Skip to content

Commit 45a3108

Browse files
committed
updated HashMap with new xform.
1 parent 876066c commit 45a3108

File tree

2 files changed

+66
-59
lines changed

2 files changed

+66
-59
lines changed

axioms/HashMap.sk

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
adt HMap {
2+
Map { }
3+
Obj { Object o; }
4+
Get { HMap h; HMap k; }
5+
Put { HMap h; HMap k; HMap v; }
6+
Error { int code; }
7+
}
8+
Object hashmap() {
9+
return new Object(__cid = HashMap(), hmap=new Map());
10+
}
11+
Object put(HMap h, Object k, Object v) {
12+
return new Object(__cid = HashMap(), hmap=new Put(h=h, k=new Obj(o=k), v=new Obj(o=v)));
13+
}
14+
Object get(HMap h, Object k) {
15+
return new Object(__cid = HashMap(), hmap=new Get(h=h, k=new Obj(o=k)));
16+
}
17+
Object object(Object o) {
18+
return new Object(__cid = O(), hmap=new Obj(o=o));
19+
}
20+
21+
HMap get_xform(HMap h, HMap key) {
22+
HMap hmap = null;
23+
switch (h) {
24+
case Map: { return new Error(code=ERR_M()); }
25+
case Obj: { return new Error(code=ERR_O()); }
26+
case Get: { hmap = h.h; }
27+
case Put: {
28+
if (h.k == key) { return h.v; }
29+
else { hmap = h.h; }
30+
}
31+
case Error: { return new Error(code=ERR_E()); }
32+
}
33+
return xform(new Get(h=hmap, k=key));
34+
}
35+
36+
HMap xform(HMap h) {
37+
switch (h) {
38+
case Map: return h;
39+
case Obj: return h;
40+
case Get: return get_xform(h.h, h.k);
41+
case Put: return h;
42+
case Error: return h;
43+
}
44+
}
45+
46+
struct Object {
47+
int __cid;
48+
int v;
49+
HMap hmap;
50+
Object o;
51+
}
52+
53+
harness void mn() {
54+
HMap h = new Map();
55+
Object one = new Object(__cid=O(), v=1);
56+
Object two = new Object(__cid=O(), v=2);
57+
h = put(h, one, two).hmap;
58+
assert xform(get(h, one).hmap) == new Obj(o=two);
59+
}
60+
61+
int O() { return 1; }
62+
int HashMap() { return 2; }
63+
int ERR_M() { return -1; }
64+
int ERR_O() { return -2; }
65+
int ERR_E() { return -3; }
66+

axioms/HashMap_Ax.sk

-59
This file was deleted.

0 commit comments

Comments
 (0)