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

46
LINES

< > BotCompany Repo | #1029201 // Suffix Tree Spike v2.1 [dev.]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (4405L/23K).

1  
!7
2  
3  
// adapted from https://github.com/eugenp/tutorials/tree/master/algorithms-searching/src/main/java/com/baeldung/algorithms/suffixtree
4  
5  
cmodule SuffixTreeSpike > DynPrintLog {
6  
  // text is by default persistent and can be made non-persistent
7  
  switchable S text = "hello world what is up in the world";
8  
  switchable S testPattern;
9  
  transient SuffixTree tree;
10  
  
11  
  void makeTree {
12  
    time "makeTree" {
13  
      print("Text length: " + n2(l(text)));
14  
      tree = new SuffixTree(text);
15  
    }
16  
    print("Estimated tree size: " + nBytes(guessObjectSize(tree)));
17  
  }
18  
19  
  start-thread {
20  
    makeTree();
21  
    //print(tree.printTree());
22  
    /*print(+text);
23  
    print(+pattern);
24  
    pnl(tree.markText(pattern));*/
25  
  }
26  
  
27  
  // API
28  
  
29  
  L<SuffixTree.Node> search(CharSequence pattern) {
30  
    ret tree.getAllNodesInTraversePath(pattern, tree.root, false);
31  
  }
32  
  
33  
  void dontPersistText {
34  
    dontPersist("text");
35  
  }
36  
  
37  
  void setText(S text) {
38  
    if (setField(+text))
39  
      makeTree();
40  
  }
41  
  
42  
  void setTransientText(S text) {
43  
    dontPersistText();
44  
    setText(text);
45  
  }
46  
}

Author comment

Began life as a copy of #1028130

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: #1029201
Snippet name: Suffix Tree Spike v2.1 [dev.]
Eternal ID of this version: #1029201/11
Text MD5: e4fd06ee345c9b9675e32ec475159202
Transpilation MD5: 6a92413a9123576ea58a2b352981f04a
Author: stefan
Category: javax / text searching
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-07-25 01:05:02
Source code size: 1109 bytes / 46 lines
Pitched / IR pitched: No / No
Views / Downloads: 169 / 1935
Version history: 10 change(s)
Referenced in: [show references]