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

14
LINES

< > BotCompany Repo | #1011744 // curlyBracketMap

JavaX fragment (include)

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

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