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

21
LINES

< > BotCompany Repo | #1004025 // gLongestPrefixMatchNeqIdx

JavaX fragment (include)

sbool gLongestPrefixMatchNeqIdx_debug;

static int gLongestPrefixMatchNeqIdx(S line) {
  line = line.toLowerCase();
  if (gLongestPrefixMatchNeqIdx_debug)
    print("line=" + line);
  L<S> log = gLog();
  int best = -1, bestIdx = -1;
  for (int i = l(log)-1; i >= 0; i--) {
    S s = log.get(i).toLowerCase();
    continue if eq(s, line);
    int n = l(commonPrefix(s, line));
    if (gLongestPrefixMatchNeqIdx_debug)
      print("i=" + i + ", n=" + n + ", line=" + quote(log.get(i)));
    if (n > best) {
      bestIdx = i;
      best = n;
    }
  }
  ret bestIdx;
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1004025
Snippet name: gLongestPrefixMatchNeqIdx
Eternal ID of this version: #1004025/1
Text MD5: e46142d38c214ed11c040fef30e30fd4
Author: stefan
Category: javax / talking robots
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-08-03 18:34:50
Source code size: 587 bytes / 21 lines
Pitched / IR pitched: No / No
Views / Downloads: 542 / 541
Referenced in: [show references]