Libraryless. Click here for Pure Java version (3361L/21K).
1 | sclass LineComp_PairCounts {
|
2 | new MultiSet<IntPair> counts; |
3 | MultiSetMap<Int, IntPair> byCount = multiSetMap_innerTreeSet_outerRevTreeMap(); |
4 | |
5 | void addAll(Iterable<IntPair> l) { fOr (IntPair p : l) add(p); }
|
6 | void removeAll(Iterable<IntPair> l) { fOr (IntPair p : l) remove(p); }
|
7 | |
8 | void add(int a, int b) { add(IntPair(a, b)); }
|
9 | void remove(int a, int b) { remove(IntPair(a, b)); }
|
10 | |
11 | // increment pair's count |
12 | void add(IntPair p) {
|
13 | int count = counts.get(p); |
14 | byCount.remove(count, p); |
15 | counts.add(p); |
16 | byCount.put(count+1, p); |
17 | } |
18 | |
19 | // decrement pair's count |
20 | void remove(IntPair p) {
|
21 | int count = counts.get(p); |
22 | if (count == 0) fail("Can't remove pair " + p);
|
23 | byCount.remove(count, p); |
24 | counts.remove(p); |
25 | if (count-- > 0) byCount.put(count, p); |
26 | } |
27 | |
28 | IntPair mostPopularDuplicate() {
|
29 | ret toInt(firstKey(byCount)) < 2 ? null : firstValue(byCount); |
30 | } |
31 | |
32 | int numberOfDuplicates() {
|
33 | ret counts.size()-l(byCount.get(1)); |
34 | } |
35 | |
36 | int getCount(IntPair p) {
|
37 | ret counts.get(p); |
38 | } |
39 | } |
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: | 520 / 925 |
| Version history: | 4 change(s) |
| Referenced in: | [show references] |