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

18
LINES

< > TinyBrain | #1010376 - getBracketMapC (takes code tokens)

JavaX fragment (include)

// map: index of opening bracket -> index of closing bracket
static Map<Int> getBracketMapC(L tok) {
  new TreeMap<Int, Int> map;
  new L<int> stack;
  int n = l(tok);
  for i to n: {
    if (getBracketMapC_opening.contains(tok.get(i)))
      stack.add(i);
    else if (getBracketMapC_closing.contains(tok.get(i))) {
      if (!empty(stack))
        map.put(liftLast(stack), i);
    }
  }
  ret map;
}

static L<S> getBracketMapC_opening = ll("{", "(");
static L<S> getBracketMapC_closing = ll("}", ")");

Author comment

Began life as a copy of #1002118

download  show line numbers  debug dex   

Travelled to 2 computer(s): cfunsshuasjs, tvejysmllsmz

No comments. add comment

Snippet ID: #1010376
Snippet name: getBracketMapC (takes code tokens)
Eternal ID of this version: #1010376/2
Text MD5: a53441cd2bc1c4b85d33ff7b2cfac231
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-09-13 16:52:56
Source code size: 521 bytes / 18 lines
Pitched / IR pitched: No / No
Views / Downloads: 20 / 29
Version history: 1 change(s)
Referenced in: [show]