Libraryless. Click here for Pure Java version (2739L/17K).
1 | // return longest prefix of s actually contained in set |
2 | sS longestPrefixInNavigableSet(S s, NavigableSet<S> set) {
|
3 | if (set == null || s == null) null; |
4 | while licensed {
|
5 | S key = set.floor(s); |
6 | if (key == null) break; // s is in front of whole set => no prefix in there |
7 | int n = lCommonPrefix(key, s); |
8 | if (n == l(key)) ret key; // found! |
9 | s = takeFirst(s, n); // shorten and try again |
10 | } |
11 | null; // not found |
12 | } |
Began life as a copy of #1029746
download show line numbers debug dex old transpilations
Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1029748 |
| Snippet name: | longestPrefixInNavigableSet [case sensitive] |
| Eternal ID of this version: | #1029748/5 |
| Text MD5: | 9fc4abddc0fbaffd8b328ff5481059ed |
| Transpilation MD5: | 838049dec64579a67fed83bcc7594045 |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2020-11-11 22:15:24 |
| Source code size: | 440 bytes / 12 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 406 / 539 |
| Version history: | 4 change(s) |
| Referenced in: | [show references] |