1 | // tok = CNC |
2 | // returns (index, tree leaf) |
3 | static Pair<Int, O> matchEndUsingWordTree(L<S> tok, Map<S, O> tree) {
|
4 | O best = null; // best leaf |
5 | int bestIndex = 0; // best index |
6 | |
7 | int j = l(tok)-2; |
8 | while (j > 0) {
|
9 | O def = tree.get("<default>");
|
10 | if (def != null) { best = def; bestIndex = j; }
|
11 | |
12 | O t = tree.get(tok.get(j)); |
13 | j -= 2; |
14 | if (t == null) break; |
15 | if (!t instanceof Map) ret pair(j, t); // leaf! |
16 | tree = (Map) t; |
17 | } |
18 | |
19 | ret pair(bestIndex, best); |
20 | } |
Began life as a copy of #1017908
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1018102 |
| Snippet name: | matchEndUsingWordTree [untested] - needs a tree from listToReversedWordTree |
| Eternal ID of this version: | #1018102/3 |
| Text MD5: | 6ae463d9b7750fe16042a5cc2e345e27 |
| Author: | stefan |
| Category: | javax / a.i. |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2018-09-02 13:04:51 |
| Source code size: | 508 bytes / 20 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 584 / 616 |
| Version history: | 2 change(s) |
| Referenced in: | [show references] |