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

18
LINES

< > BotCompany Repo | #1028772 // lcRenumberTopLevelEncodings_simplify - simplify pairs of items appearing only once to a single item

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

Libraryless. Click here for Pure Java version (3016L/19K).

1  
// the result indices are kind of nonsensical; we should make new pairs instead
2  
static Map<S, L<Int>> lcRenumberTopLevelEncodings_simplify(Map<S, L<Int>> encodings) {
3  
  new MultiSet<Int> ms;
4  
  for (L<Int> l : values(encodings))
5  
    ms.addAll(l);
6  
  
7  
  new LinkedHashMap<S, L<Int>> out;
8  
  for (S file, L<Int> l : encodings) {
9  
    new L<Int> l2;
10  
    for i over l: {
11  
      if (i > 0 && ms.get(l.get(i-1)) == 1
12  
        && ms.get(l.get(i)) == 1) continue;
13  
      l2.add(l.get(i));
14  
    }
15  
    out.put(file, l2);
16  
  }
17  
  ret out;
18  
}

Author comment

Began life as a copy of #1028771

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: #1028772
Snippet name: lcRenumberTopLevelEncodings_simplify - simplify pairs of items appearing only once to a single item
Eternal ID of this version: #1028772/4
Text MD5: 0e75603099c911c332161ce2bb927687
Transpilation MD5: 84c67f35555c9c3c197b687af6fc4bcb
Author: stefan
Category: javax / parsing
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-07-08 01:21:22
Source code size: 536 bytes / 18 lines
Pitched / IR pitched: No / No
Views / Downloads: 183 / 282
Version history: 3 change(s)
Referenced in: [show references]