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

15
LINES

< > BotCompany Repo | #1030184 // stringTrie_firstNodeStartingWith

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

Libraryless. Click here for Pure Java version (3061L/19K).

static <A> Pair<S, StringTrie<A>> stringTrie_firstNodeStartingWith(StringTrie<A> trie, S string) {
  new StringBuilder buf;
  S s = string;
  while licensed {
    if (trie == null) break;
    if (empty(string)) break;
    S prefix = trie.longestLocalPrefix(s);
    if (empty(prefix)) break;
    Map.Entry<S, StringTrie<A>> e = trie.children.ceilingEntry(prefix);
    buf.append(e.getKey());
    trie = e.getValue();
    s = dropFirst(s, l(e.getKey()));
  }
  ret trie == null ? null : pair(str(buf), trie);
}

Author comment

Began life as a copy of #1030183

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1030184
Snippet name: stringTrie_firstNodeStartingWith
Eternal ID of this version: #1030184/3
Text MD5: 499d975dff89ea0f0b2faed1a4250d1f
Transpilation MD5: 19e06605c8c17752d3cd18a5b5019ab9
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:33:43
Source code size: 522 bytes / 15 lines
Pitched / IR pitched: No / No
Views / Downloads: 199 / 276
Version history: 2 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)