Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

39
LINES

< > BotCompany Repo | #1028856 - lcSimplifyToLongerProductions

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (3365L/21K).

ifclass LineCompCompressor
static LCLongerProds lcSimplifyToLongerProductions(LineCompCompressor comp) {
  ret lcSimplifyToLongerProductions(
    map(countIterator_exclusive(0, comp.nLiterals()), i -> comp.itemToString(i)),
    map(countIterator_exclusive(comp.nLiterals(), comp.nItems()), i -> comp.getPair(i)),
    comp.finalEncodings);
}
endif

static LCLongerProds lcSimplifyToLongerProductions(LS literals, L<IntPair> pairs, Map<S, L<Int>> files) {
  new LCLongerProds lc;
  lc.literals = literals;
  int nLiterals = l(literals);
  for i over pairs:
    lc.productions.put(nLiterals+i, intPairToList(pairs.get(i)));
  lc.files = mapValues cloneList(files);
  
  bool change;
  do {
    ping();
    change = false;
    new MultiSet<Int> counts;
    for (L<Int> l : concatLists(values(lc.productions), values(lc.files)))
      for (int i : l)
        if (i >= nLiterals)
          counts.add(i);
    for (int i : cloneList(counts.asSet()))
      if (counts.get(i) == 1) {
        set change;
        L<Int> unrolled = assertNotNull(lc.productions.get(i));
        print("Unrolling " + i + " => " + unrolled);
        lc.productions.remove(i);
        counts.remove(i);
        for (L<Int> l : concatLists(values(lc.productions), values(lc.files)))
          replaceSublist(l, ll(i), unrolled);
      }
  } while (change);
  ret lc;
}

Author comment

Began life as a copy of #1028777

download  show line numbers  debug dex   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, 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: 55 / 92
Version history: 9 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1028856 & http://1028856.tinybrain.de