Libraryless. Click here for Pure Java version (3361L/21K).
sclass LineComp_PairCounts { new MultiSet<IntPair> counts; MultiSetMap<Int, IntPair> byCount = multiSetMap_innerTreeSet_outerRevTreeMap(); void addAll(Iterable<IntPair> l) { fOr (IntPair p : l) add(p); } void removeAll(Iterable<IntPair> l) { fOr (IntPair p : l) remove(p); } void add(int a, int b) { add(IntPair(a, b)); } void remove(int a, int b) { remove(IntPair(a, b)); } // increment pair's count void add(IntPair p) { int count = counts.get(p); byCount.remove(count, p); counts.add(p); byCount.put(count+1, p); } // decrement pair's count void remove(IntPair p) { int count = counts.get(p); if (count == 0) fail("Can't remove pair " + p); byCount.remove(count, p); counts.remove(p); if (count-- > 0) byCount.put(count, p); } IntPair mostPopularDuplicate() { ret toInt(firstKey(byCount)) < 2 ? null : firstValue(byCount); } int numberOfDuplicates() { ret counts.size()-l(byCount.get(1)); } int getCount(IntPair p) { ret counts.get(p); } }
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: | #1028215 |
Snippet name: | LineComp_PairCounts - helper for LineComp compressor |
Eternal ID of this version: | #1028215/5 |
Text MD5: | 83025cde1cc1477887661ef3531e58a4 |
Transpilation MD5: | a1360f95a37904b360e2b74cfa85c625 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-05-27 22:40:22 |
Source code size: | 1085 bytes / 39 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 258 / 603 |
Version history: | 4 change(s) |
Referenced in: | #1028236 - LineComp_PairCounts - helper for LineComp compressor (backup before IntPair) #1028247 - LineComp_PairIndex - helper for LineComp compressor [LIVE] #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674) |