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

21
LINES

< > BotCompany Repo | #1004025 // gLongestPrefixMatchNeqIdx

JavaX fragment (include)

1  
sbool gLongestPrefixMatchNeqIdx_debug;
2  
3  
static int gLongestPrefixMatchNeqIdx(S line) {
4  
  line = line.toLowerCase();
5  
  if (gLongestPrefixMatchNeqIdx_debug)
6  
    print("line=" + line);
7  
  L<S> log = gLog();
8  
  int best = -1, bestIdx = -1;
9  
  for (int i = l(log)-1; i >= 0; i--) {
10  
    S s = log.get(i).toLowerCase();
11  
    continue if eq(s, line);
12  
    int n = l(commonPrefix(s, line));
13  
    if (gLongestPrefixMatchNeqIdx_debug)
14  
      print("i=" + i + ", n=" + n + ", line=" + quote(log.get(i)));
15  
    if (n > best) {
16  
      bestIdx = i;
17  
      best = n;
18  
    }
19  
  }
20  
  ret bestIdx;
21  
}

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: 471 / 463
Referenced in: [show references]