1 | // map: index of opening bracket -> index of closing bracket |
2 | static Map<Int> getBracketMapC(L tok) {
|
3 | new TreeMap<Int, Int> map; |
4 | new L<int> stack; |
5 | int n = l(tok); |
6 | for i to n: {
|
7 | if (getBracketMapC_opening.contains(tok.get(i))) |
8 | stack.add(i); |
9 | else if (getBracketMapC_closing.contains(tok.get(i))) {
|
10 | if (!empty(stack)) |
11 | map.put(liftLast(stack), i); |
12 | } |
13 | } |
14 | ret map; |
15 | } |
16 | |
17 | static L<S> getBracketMapC_opening = ll("{", "(");
|
18 | static L<S> getBracketMapC_closing = ll("}", ")"); |
Began life as a copy of #1002118
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: | #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: | 673 / 707 |
| Version history: | 1 change(s) |
| Referenced in: | [show references] |