Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

30
LINES

< > BotCompany Repo | #1029282 // ukkonenToIntSuffixTree_managed

JavaX fragment (include) [tags: use-pretranspiled]

Uses 11335K of libraries. Click here for Pure Java version (15914L/109K).

// Ukkonen tree must contain an end symbol as last symbol
static IntSuffixTree_managed ukkonenToIntSuffixTree_managed(UkkonenIntSuffixTree uTree) {
  new IntSuffixTree_managed tree;
  tree.mem.onMemorySizeChanged = r { tree.mem.printStats(); };
  int lText = l(uTree.text)-1;
  int endSymbol = uTree.text[lText];
  printVars_str(+lText, +endSymbol);
  tree.fullText = wrapIntArrayAsImmutableList(uTree.text);
  new HashMap<Int, IntSuffixTree_managed.Node> nodeMap;
  
  // First round: copy all nodes
  
  for (int uNodeIdx : recursiveIterator(uTree.root, n -> values(uTree.nodes[n].next))) {
    UkkonenIntSuffixTree.Node uNode = uTree.nodes[uNodeIdx];
    IntSuffixTree_managed.Node node = tree.newNode(uNode.start, min(lText, uNode.end));
    nodeMap.put(uNodeIdx, node);
    if (tree.root == null) tree.root = node;
  }
  
  // Second round: Add edges
  
  for (int idx, IntSuffixTree_managed.Node node : nodeMap) {
    //if (idx == endSymbol) continue;
    UkkonenIntSuffixTree.Node uNode = uTree.nodes[idx];
    //print("Node " + idx + " children: " + uNode.next);
    node.setChildren(tree, mapValuesToList(uNode.next, iChild -> nodeMap.get(iChild)));
  }
  
  ret tree;
}

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: 253 / 380
Version history: 17 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)