Libraryless. Click here for Pure Java version (6211L/37K).
// set flag SpecialCharsHierarchicalBitMap_debug. svoid test_SpecialCharsHierarchicalBitMap() { new SpecialCharsHierarchicalBitMap bitMap; int maskOpen = 0x01, maskClose = 0x02; bitMap.specialChar("{(", maskOpen); bitMap.specialChar(")}", maskClose); bitMap.specialChar(",", 0x04); bitMap.specialChar('\\', 0x08); bitMap.specialChar('"', 0x10); bitMap.analyze([[{"abcdefghijklmnop": "abcdefghijklmnopq", "abcdefghijklmnopq": "abcdefghijklmnop"}]]); print(bitMap.stats()); print(sfuWithIndent(bitMap)); int minLevel = bitMap.minLevel(); byte[] input = bitMap.input; byte[] charIndex = bitMap.charIndex; embedded void descend(int level, int i, int iEnd) { int step = 1 << level, iChar = i << level; if (level < minLevel) { //print("Bottom level reached: " + iChar + " to " + (iChar+step)); iEnd = min(iEnd, input.length); int iCharEnd = iEnd << level; for (; iChar < iCharEnd; iChar++) { byte c = input[iChar]; int val = bitMap.maskForChar(c); //printVars(+iChar, +c, +val); if ((val & maskOpen) != 0) print("Opening bracket at " + iChar); else if ((val & maskClose) != 0) print("Closing bracket at " + iChar); } ret; } byte[] tbl = bitMap.table(level); iEnd = min(iEnd, tbl.length); //print("Scanning level " + level + ": " + i + " to " + iEnd + " (tbl length=" + tbl.length + ")"); for (; i < iEnd; i++) { int val = tbl[i]; int iC = iChar; iChar = min(iChar+step, input.length); if ((val & maskOpen) != 0) if ((val & maskClose) != 0) print("Opening and closing brackets in " + iC + " to " + iChar); else print("Only opening brackets in " + iC + " to " + iChar); else if ((val & maskClose) != 0) print("Only closing brackets in " + iC + " to " + iChar); else { print("No brackets in " + iC + " to " + iChar); continue; } int iNext = i << 1; descend(level-1, iNext, iNext+2); } } int level = bitMap.reachedLevel(); descend(level, 0, 1); //printStruct(tbl); }
Began life as a copy of #1032583
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1032590 |
Snippet name: | test_SpecialCharsHierarchicalBitMap |
Eternal ID of this version: | #1032590/3 |
Text MD5: | 48afef338fdae62891a08a44163d51a3 |
Transpilation MD5: | 6cd20bc6d477abb44ba5e8d7f14942a6 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-09-23 08:38:21 |
Source code size: | 2233 bytes / 65 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 179 / 277 |
Version history: | 2 change(s) |
Referenced in: | [show references] |