1 | static Pair<IntRange, O> findUsingWordTree(L<S> tok, Map<S, O> tree) { |
2 | ret findUsingWordTree(tok, tree, 0); |
3 | } |
4 | |
5 | // tok = CNC |
6 | // returns (index range C to N, tree leaf) |
7 | static Pair<IntRange, O> findUsingWordTree(L<S> tok, Map<S, O> tree, int i) { |
8 | if (tree == null) null; |
9 | O best = null; // best leaf |
10 | int bestIndex = 0; // best index |
11 | int n = l(tok); |
12 | |
13 | i |= 1; // Proceed to C token |
14 | while (i <= n) { |
15 | int j = i; |
16 | while true { |
17 | O def = tree.get("<default>"); |
18 | if (def != null) { best = def; bestIndex = j; } |
19 | |
20 | if (j >= n) break; |
21 | O t = tree.get(tok.get(j)); |
22 | j += 2; |
23 | if (t == null) break; |
24 | if (!t instanceof Map) ret pair(intRange(i, j-1), t); // leaf! |
25 | tree = (Map) t; |
26 | } |
27 | if (best != null) ret pair(intRange(i, bestIndex), best); |
28 | i += 2; |
29 | } |
30 | |
31 | null; |
32 | } |
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: | #1017956 |
Snippet name: | findUsingWordTree |
Eternal ID of this version: | #1017956/4 |
Text MD5: | b5d0ef72ebba8f9f51f3a531147384b1 |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-08-23 01:43:08 |
Source code size: | 859 bytes / 32 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 341 / 357 |
Version history: | 3 change(s) |
Referenced in: | [show references] |