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

18
LINES

< > BotCompany Repo | #1025694 // positionalTokenIndex_filter

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (2338L/15K).

1  
// use "*" as wildcard
2  
// may return null, and returned list is "volatile" (only valid as long as the index is not changed)
3  
static LLS positionalTokenIndex_filter(PositionalTokenIndex idx, LS tok) {
4  
  int cutOff = 1; // if we find a list shorter than this, we just return it. must be at least 1
5  
  LLS shortestList = null;
6  
  for (int i = 1; i < l(tok); i += 2) {
7  
    S t = tok.get(i);
8  
    if (!eq(t, "*")) {
9  
      LLS list = idx.byToken(i/2, t);
10  
      if (l(list) < cutOff) ret list;
11  
      if (shortestList == null || l(list) < l(shortestList))
12  
        shortestList = list;
13  
    }
14  
  }
15  
  if (shortestList == null) // pattern must be all wildcards - return full list
16  
    ret idx.fullList();
17  
  ret shortestList;
18  
}

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: #1025694
Snippet name: positionalTokenIndex_filter
Eternal ID of this version: #1025694/3
Text MD5: df91f00ebfa3ecd27959c9019b31590a
Transpilation MD5: a6963504a6f8519a0af2746cdc087f22
Author: stefan
Category: javax / agi.blue
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-10-13 23:06:37
Source code size: 725 bytes / 18 lines
Pitched / IR pitched: No / No
Views / Downloads: 226 / 332
Version history: 2 change(s)
Referenced in: [show references]