static class Synonyms { Map<S, L<S>> synMap = new TreeMap<S, L<S>>(); void addSynonym(S a, S b) { L<S> la = synMap.get(a), lb = synMap.get(b); if (la == null && lb == null) { L<S> l = litlist(a, b); synMap.put(a, l); synMap.put(b, l); } else if (la == lb) { // nothing to do, they're already synonyms } else if (lb == null) { la.add(b); synMap.put(b, la); } else if (la == null) { lb.add(a); synMap.put(a, lb); } else mergeLists(la, lb); } void mergeLists(L<S> la, L<S> lb) { for (S b : lb) { la.add(b); synMap.put(b, la); } } // returns null or a list L<S> getSynonyms(S x) { ret synMap.get(x); } }
Began life as a copy of #1001511
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1001512 |
Snippet name: | Synonyms (class) |
Eternal ID of this version: | #1001512/1 |
Text MD5: | b8c64d583a65db814d05b01a5de3c85a |
Author: | stefan |
Category: | |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-10-21 16:34:24 |
Source code size: | 758 bytes / 33 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 618 / 791 |
Referenced in: | [show references] |