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

14
LINES

< > BotCompany Repo | #1011744 // curlyBracketMap

JavaX fragment (include)

1  
// map: index of opening bracket -> index of closing bracket
2  
static Map<Int> curlyBracketMap(L<S> tok) {
3  
  new TreeMap<Int, Int> map;
4  
  new L<int> stack;
5  
  int n = l(tok);
6  
  for (int i = 1; i < n; i += 2) {
7  
    S t = tok.get(i);
8  
    if (eq(t, "{"))
9  
      stack.add(i);
10  
    else if (eq(t, "}") && nempty(stack))
11  
      map.put(liftLast(stack), i);
12  
  }
13  
  ret map;
14  
}

Author comment

Began life as a copy of #1011742

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1011744
Snippet name: curlyBracketMap
Eternal ID of this version: #1011744/1
Text MD5: db1c13c0d12d6c5f5fcc3cac4c691bb4
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-11-04 23:40:23
Source code size: 375 bytes / 14 lines
Pitched / IR pitched: No / No
Views / Downloads: 472 / 520
Referenced in: [show references]