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

14
LINES

< > BotCompany Repo | #1027971 // longestPrefixInCISet [seems to work]

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

Libraryless. Click here for Pure Java version (2739L/17K).

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

Author comment

Began life as a copy of #1022122

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: #1027971
Snippet name: longestPrefixInCISet [seems to work]
Eternal ID of this version: #1027971/4
Text MD5: ec94cdf7560c00caf763cb4c7de77d26
Transpilation MD5: cd0bfae8bc821bdd2ab890d2c930586d
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-11-11 20:49:47
Source code size: 460 bytes / 14 lines
Pitched / IR pitched: No / No
Views / Downloads: 153 / 216
Version history: 3 change(s)
Referenced in: [show references]