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

14
LINES

< > BotCompany Repo | #1030183 // stringTrie_longestPrefix_loose - longest common prefix of string and trie elements

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

Libraryless. Click here for Pure Java version (3178L/20K).

1  
static <A> S stringTrie_longestPrefix_loose(StringTrie<A> trie, S string) {
2  
  int n = 0;
3  
  S s = string;
4  
  while licensed {
5  
    if (trie == null) break;
6  
    if (empty(string)) break;
7  
    S prefix = trie.longestLocalPrefix(s);
8  
    if (empty(prefix)) break;
9  
    n += l(prefix);
10  
    trie = trie.getChild(prefix);
11  
    s = dropFirst(s, l(prefix));
12  
  }
13  
  ret takeFirst(n, string);
14  
}

Author comment

Began life as a copy of #1030182

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1030183
Snippet name: stringTrie_longestPrefix_loose - longest common prefix of string and trie elements
Eternal ID of this version: #1030183/1
Text MD5: 46f6d425cdc885c217d96fdb342cf636
Transpilation MD5: 70a612b366402e5c192c6830053a9fdc
Author: stefan
Category: javax / tries
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-11-12 14:25:30
Source code size: 389 bytes / 14 lines
Pitched / IR pitched: No / No
Views / Downloads: 181 / 260
Referenced in: [show references]