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

47
LINES

< > BotCompany Repo | #1030256 // Wikify [dev.]

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

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

1  
//packageName wikify
2  
//mainClassName Wikify
3  
4  
sclass Wikify {
5  
  volatile Indexed indexed;
6  
  S indexing;
7  
  Q q = startQ();
8  
  int slowSearches;
9  
  
10  
  sclass Indexed {
11  
    S text;
12  
    LCSearcher_v4_multiFile searcher;
13  
  }
14  
  
15  
  int anyIndexOf(S fullText, S pattern) {
16  
    if (empty(fullText)) ret -1;
17  
    Indexed _indexed = indexed;
18  
    if (_indexed != null && fullText == _indexed.text)
19  
      ret _indexed.searcher.singleFileAnyIndexOf(pattern);
20  
      
21  
    // possibly index, do slow search
22  
    possiblyIndexText(fullText);
23  
    ++slowSearches;
24  
    ret main indexOf(fullText, pattern);
25  
  }
26  
  
27  
  synchronized void possiblyIndexText(S text) {
28  
    if (indexing != null) ret;
29  
    indexing = text;
30  
    q.add(r {
31  
      try {
32  
        print("Indexing " + nChars(text) + ": " + quote(shorten(text)));
33  
        new Indexed i;
34  
        i.text = text;
35  
        i.searcher = wikifyString(text);
36  
        setIndexed(i);
37  
      } finally {
38  
        indexing = null;
39  
      }
40  
    });
41  
  }
42  
  
43  
  synchronized void setIndexed(Indexed i) {
44  
    print("Indexed " + nChars(i.text));
45  
    indexed = i;
46  
  }
47  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1030256
Snippet name: Wikify [dev.]
Eternal ID of this version: #1030256/8
Text MD5: 8d03713e1e31965c6845a0cd3f821eb9
Transpilation MD5: 321171a8d075ad5841e50af29286df54
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-11-21 10:34:37
Source code size: 1114 bytes / 47 lines
Pitched / IR pitched: No / No
Views / Downloads: 207 / 408
Version history: 7 change(s)
Referenced in: [show references]