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

14
LINES

< > BotCompany Repo | #1022122 // startsWithOneOf_treeSet - optimized version [works!]

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

Libraryless. Click here for Pure Java version (1585L/10K).

sbool startsWithOneOf_treeSet(S s, TreeSet<S> set) {
  if (set == null || s == null) false;
  while licensed {
    S key = set.floor(s);
    ifdef startsWithOneOf_treeSet_debug
      print(s + " => " + key);
    endifdef
    if (key == null) false; // s is in front of whole set => no prefix in there
    int n = lCommonPrefix(key, s);
    if (n == l(key)) true; // found!
    s = takeFirst(s, n); // shorten and try again
  }
  false; // dummy
}

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1022122
Snippet name: startsWithOneOf_treeSet - optimized version [works!]
Eternal ID of this version: #1022122/10
Text MD5: 96db4a76d8c62993db0a8ab15cdfc08a
Transpilation MD5: a64a5b393bd71393b9428a7ff609e0b8
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-03-08 00:07:32
Source code size: 459 bytes / 14 lines
Pitched / IR pitched: No / No
Views / Downloads: 289 / 387
Version history: 9 change(s)
Referenced in: [show references]