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

8
LINES

< > TinyBrain | #1008021 - nicestClosestKey - floorKey or ceilingKey depending on Levenshtein distance

JavaX fragment (include)

static U nicestClosestKey(NavigableMap<U, ?> map, U key) {
  U a = map.floorKey(key), b = map.ceilingKey(key);
  if (b == null) ret a;
  if (a == null) ret b;
  int d1 = leven(str(key), str(a));
  int d2 = leven_limited(str(key), str(b), d1);
  ret d1 <= d2 ? a : b;
}

download  show line numbers  debug dex   

Travelled to 2 computer(s): cfunsshuasjs, tvejysmllsmz

No comments. add comment

Snippet ID: #1008021
Snippet name: nicestClosestKey - floorKey or ceilingKey depending on Levenshtein distance
Eternal ID of this version: #1008021/2
Text MD5: 6f50dca871da08b77864ac0cd730405c
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-04-20 19:14:24
Source code size: 275 bytes / 8 lines
Pitched / IR pitched: No / No
Views / Downloads: 40 / 44
Version history: 1 change(s)
Referenced in: [show]