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

1  
sbool startsWithOneOf_treeSet(S s, TreeSet<S> set) {
2  
  if (set == null || s == null) false;
3  
  while licensed {
4  
    S key = set.floor(s);
5  
    ifdef startsWithOneOf_treeSet_debug
6  
      print(s + " => " + key);
7  
    endifdef
8  
    if (key == null) false; // s is in front of whole set => no prefix in there
9  
    int n = lCommonPrefix(key, s);
10  
    if (n == l(key)) true; // found!
11  
    s = takeFirst(s, n); // shorten and try again
12  
  }
13  
  false; // dummy
14  
}

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