1 | // a map of assignments that can be rolled back to some state |
2 | static class SNLMatches { |
3 | new HashMap<S, Lisp> map; |
4 | new L<S> log; |
5 | |
6 | boolean put(S key, Lisp val) { |
7 | if (map.containsKey(key)) |
8 | // existing |
9 | ret eq(map.get(key), val); |
10 | |
11 | // new |
12 | map.put(key, val); |
13 | log.add(key); |
14 | ret true; |
15 | } |
16 | |
17 | Lisp get(S key) { |
18 | ret map.get(key); |
19 | } |
20 | |
21 | S raw(S key) { |
22 | Lisp x = get(key); |
23 | if (x == null) fail("var not set: " + key); |
24 | ret x.raw(); |
25 | } |
26 | |
27 | boolean containsKey(S key) { |
28 | ret map.containsKey(key); |
29 | } |
30 | |
31 | int save() { |
32 | ret l(log); |
33 | } |
34 | |
35 | void restore(int i) { |
36 | while (l(log) > i) { |
37 | S key = log.get(l(log)-1); |
38 | map.remove(key); |
39 | log.remove(l(log)-1); |
40 | } |
41 | } |
42 | |
43 | boolean addAll(SNLMatches m) { |
44 | for (S var : m.keySet()) |
45 | if (!put(var, m.get(var))) |
46 | ret false; |
47 | ret true; |
48 | } |
49 | |
50 | Set<S> keySet() { |
51 | ret map.keySet(); |
52 | } |
53 | } |
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1002748 |
Snippet name: | class SNLMatches |
Eternal ID of this version: | #1002748/1 |
Text MD5: | 10b4588d4ea13249689a55a58425efda |
Author: | stefan |
Category: | eleu / nl |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-02-25 01:31:58 |
Source code size: | 974 bytes / 53 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 724 / 1989 |
Referenced in: | [show references] |