Libraryless. Click here for Pure Java version (3365L/21K).
1 | ifclass LineCompCompressor |
2 | static LCLongerProds lcSimplifyToLongerProductions(LineCompCompressor comp) { |
3 | ret lcSimplifyToLongerProductions( |
4 | map(countIterator_exclusive(0, comp.nLiterals()), i -> comp.itemToString(i)), |
5 | map(countIterator_exclusive(comp.nLiterals(), comp.nItems()), i -> comp.getPair(i)), |
6 | comp.finalEncodings); |
7 | } |
8 | endif |
9 | |
10 | static LCLongerProds lcSimplifyToLongerProductions(LS literals, L<IntPair> pairs, Map<S, L<Int>> files) { |
11 | new LCLongerProds lc; |
12 | lc.literals = literals; |
13 | int nLiterals = l(literals); |
14 | for i over pairs: |
15 | lc.productions.put(nLiterals+i, intPairToList(pairs.get(i))); |
16 | lc.files = mapValues cloneList(files); |
17 | |
18 | bool change; |
19 | do { |
20 | ping(); |
21 | change = false; |
22 | new MultiSet<Int> counts; |
23 | for (L<Int> l : concatLists(values(lc.productions), values(lc.files))) |
24 | for (int i : l) |
25 | if (i >= nLiterals) |
26 | counts.add(i); |
27 | for (int i : cloneList(counts.asSet())) |
28 | if (counts.get(i) == 1) { |
29 | set change; |
30 | L<Int> unrolled = assertNotNull(lc.productions.get(i)); |
31 | print("Unrolling " + i + " => " + unrolled); |
32 | lc.productions.remove(i); |
33 | counts.remove(i); |
34 | for (L<Int> l : concatLists(values(lc.productions), values(lc.files))) |
35 | replaceSublist(l, ll(i), unrolled); |
36 | } |
37 | } while (change); |
38 | ret lc; |
39 | } |
Began life as a copy of #1028777
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1028856 |
Snippet name: | lcSimplifyToLongerProductions |
Eternal ID of this version: | #1028856/10 |
Text MD5: | ff0d66af34510d95ffc7820dea15bd04 |
Transpilation MD5: | 57dda7a739315b755a3e876c7f192baf |
Author: | stefan |
Category: | javax / linecomp |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-07-10 13:57:23 |
Source code size: | 1374 bytes / 39 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 254 / 352 |
Version history: | 9 change(s) |
Referenced in: | [show references] |