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

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

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: 266 / 361
Version history: 3 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1028146 - longestPrefixInCISet_charSequence [dev.]
#1028154 - lengthOfLongestPrefixInCISet
#1029746 - longestPrefixInTreeSet [case sensitive]