Uses 11335K of libraries. Click here for Pure Java version (15914L/109K).
1 | // Ukkonen tree must contain an end symbol as last symbol |
2 | static IntSuffixTree_managed ukkonenToIntSuffixTree_managed(UkkonenIntSuffixTree uTree) { |
3 | new IntSuffixTree_managed tree; |
4 | tree.mem.onMemorySizeChanged = r { tree.mem.printStats(); }; |
5 | int lText = l(uTree.text)-1; |
6 | int endSymbol = uTree.text[lText]; |
7 | printVars_str(+lText, +endSymbol); |
8 | tree.fullText = wrapIntArrayAsImmutableList(uTree.text); |
9 | new HashMap<Int, IntSuffixTree_managed.Node> nodeMap; |
10 | |
11 | // First round: copy all nodes |
12 | |
13 | for (int uNodeIdx : recursiveIterator(uTree.root, n -> values(uTree.nodes[n].next))) { |
14 | UkkonenIntSuffixTree.Node uNode = uTree.nodes[uNodeIdx]; |
15 | IntSuffixTree_managed.Node node = tree.newNode(uNode.start, min(lText, uNode.end)); |
16 | nodeMap.put(uNodeIdx, node); |
17 | if (tree.root == null) tree.root = node; |
18 | } |
19 | |
20 | // Second round: Add edges |
21 | |
22 | for (int idx, IntSuffixTree_managed.Node node : nodeMap) { |
23 | //if (idx == endSymbol) continue; |
24 | UkkonenIntSuffixTree.Node uNode = uTree.nodes[idx]; |
25 | //print("Node " + idx + " children: " + uNode.next); |
26 | node.setChildren(tree, mapValuesToList(uNode.next, iChild -> nodeMap.get(iChild))); |
27 | } |
28 | |
29 | ret tree; |
30 | } |
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: | #1029282 |
Snippet name: | ukkonenToIntSuffixTree_managed |
Eternal ID of this version: | #1029282/18 |
Text MD5: | a0af33f02efb1ec2bc685fb9a9102533 |
Transpilation MD5: | d9e5f31a567bec6a20dc644d81581a6a |
Author: | stefan |
Category: | javax / suffix trees |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-07-29 21:42:49 |
Source code size: | 1208 bytes / 30 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 252 / 380 |
Version history: | 17 change(s) |
Referenced in: | [show references] |