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).

//packageName wikify
//mainClassName Wikify

sclass Wikify {
  volatile Indexed indexed;
  S indexing;
  Q q = startQ();
  int slowSearches;
  
  sclass Indexed {
    S text;
    LCSearcher_v4_multiFile searcher;
  }
  
  int anyIndexOf(S fullText, S pattern) {
    if (empty(fullText)) ret -1;
    Indexed _indexed = indexed;
    if (_indexed != null && fullText == _indexed.text)
      ret _indexed.searcher.singleFileAnyIndexOf(pattern);
      
    // possibly index, do slow search
    possiblyIndexText(fullText);
    ++slowSearches;
    ret main indexOf(fullText, pattern);
  }
  
  synchronized void possiblyIndexText(S text) {
    if (indexing != null) ret;
    indexing = text;
    q.add(r {
      try {
        print("Indexing " + nChars(text) + ": " + quote(shorten(text)));
        new Indexed i;
        i.text = text;
        i.searcher = wikifyString(text);
        setIndexed(i);
      } finally {
        indexing = null;
      }
    });
  }
  
  synchronized void setIndexed(Indexed i) {
    print("Indexed " + nChars(i.text));
    indexed = i;
  }
}

download  show line numbers  debug dex   

Travelled to 3 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx

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: 33 / 91
Version history: 7 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1030256 & http://1030256.tinybrain.de