Libraryless. Click here for Pure Java version (595L/5K/15K).
1 | !752 |
2 | |
3 | //static new Set<S> things; |
4 | static new L<S> sentences; |
5 | static Map<S, L<S>> rewrites = new TreeMap; // thing -> cluster |
6 | |
7 | p {
|
8 | addRewrite("john", "johnnie");
|
9 | addRewrite("klaus", "klausi");
|
10 | assertTrue(isThing("john"));
|
11 | assertTrue(isThing("klausi"));
|
12 | assertFalse(isThing("jack"));
|
13 | print("all ok");
|
14 | } |
15 | |
16 | static void addThing(S a) {
|
17 | addRewrite(a, a); |
18 | } |
19 | |
20 | static void addRewrite(S a, S b) {
|
21 | if (eq(a, b)) {
|
22 | L<S> cluster = rewrites.get(a); |
23 | if (cluster == null) |
24 | rewrites.put(a, litlist(a)); |
25 | ret; |
26 | } |
27 | |
28 | L<S> clusterA = rewrites.get(a); |
29 | L<S> clusterB = rewrites.get(b); |
30 | if (clusterA == null && clusterB == null) {
|
31 | L<S> cluster = litlist(a, b); |
32 | rewrites.put(a, cluster); |
33 | rewrites.put(b, cluster); |
34 | } else if (clusterA == null) {
|
35 | clusterB.add(a); |
36 | rewrites.put(a, clusterB); |
37 | } else if (clusterB == null) {
|
38 | clusterA.add(b); |
39 | rewrites.put(b, clusterA); |
40 | } else if (clusterA != clusterB) |
41 | mergeClusters(clusterA, clusterB); |
42 | } |
43 | |
44 | static void mergeClusters(L<S> a, L<S> b) {
|
45 | for (S x : b) {
|
46 | a.add(x); |
47 | rewrites.put(x, a); |
48 | } |
49 | } |
50 | |
51 | static boolean isThing(S a) {
|
52 | ret rewrites.containsKey(a); |
53 | } |
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1002227 |
| Snippet name: | Microtheory Bot (aliases) |
| Eternal ID of this version: | #1002227/1 |
| Text MD5: | 759bc5dcb881103af922d8c013bd4631 |
| Transpilation MD5: | 1ca8d1053316aea24988c27ea468a387 |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX source code |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2015-12-30 01:28:22 |
| Source code size: | 1208 bytes / 53 lines |
| Pitched / IR pitched: | No / Yes |
| Views / Downloads: | 824 / 920 |
| Referenced in: | [show references] |