// return longest prefix of s actually contained in set sS longestPrefixInNavigableSet(S s, NavigableSet set) { if (set == null || s == null) null; while licensed { S key = set.floor(s); if (key == null) break; // s is in front of whole set => no prefix in there int n = lCommonPrefix(key, s); if (n == l(key)) ret key; // found! s = takeFirst(s, n); // shorten and try again } null; // not found }