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

65
LINES

< > BotCompany Repo | #1032590 // test_SpecialCharsHierarchicalBitMap

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (6211L/37K).

1  
// set flag SpecialCharsHierarchicalBitMap_debug.
2  
3  
svoid test_SpecialCharsHierarchicalBitMap() {
4  
  new SpecialCharsHierarchicalBitMap bitMap;
5  
  int maskOpen = 0x01, maskClose = 0x02;
6  
  bitMap.specialChar("{(", maskOpen);
7  
  bitMap.specialChar(")}", maskClose);
8  
  bitMap.specialChar(",", 0x04);
9  
  bitMap.specialChar('\\', 0x08);
10  
  bitMap.specialChar('"', 0x10);
11  
  bitMap.analyze([[{"abcdefghijklmnop": "abcdefghijklmnopq", "abcdefghijklmnopq": "abcdefghijklmnop"}]]);
12  
  print(bitMap.stats()); 
13  
  print(sfuWithIndent(bitMap));
14  
  
15  
  int minLevel = bitMap.minLevel();
16  
  byte[] input = bitMap.input;
17  
  byte[] charIndex = bitMap.charIndex;
18  
  
19  
  embedded void descend(int level, int i, int iEnd) {
20  
    int step = 1 << level, iChar = i << level;
21  
    if (level < minLevel) {
22  
      //print("Bottom level reached: " + iChar + " to " + (iChar+step));
23  
      iEnd = min(iEnd, input.length);
24  
      int iCharEnd = iEnd << level;
25  
      for (; iChar < iCharEnd; iChar++) {
26  
        byte c = input[iChar];
27  
        int val = bitMap.maskForChar(c);
28  
        //printVars(+iChar, +c, +val);
29  
        if ((val & maskOpen) != 0)
30  
          print("Opening bracket at " + iChar);
31  
        else if ((val & maskClose) != 0)
32  
          print("Closing bracket at " + iChar);
33  
      }
34  
      ret;
35  
    }
36  
  
37  
    byte[] tbl = bitMap.table(level);
38  
    iEnd = min(iEnd, tbl.length);
39  
    //print("Scanning level " + level + ": " + i + " to " + iEnd + " (tbl length=" + tbl.length + ")");
40  
    for (; i < iEnd; i++) {
41  
      int val = tbl[i];
42  
      int iC = iChar;
43  
      iChar = min(iChar+step, input.length);
44  
      if ((val & maskOpen) != 0)
45  
        if ((val & maskClose) != 0)
46  
          print("Opening and closing brackets in " + iC + " to " + iChar);
47  
        else
48  
          print("Only opening brackets in " + iC + " to " + iChar);
49  
      else
50  
        if ((val & maskClose) != 0)
51  
          print("Only closing brackets in " + iC + " to " + iChar);
52  
        else {
53  
          print("No brackets in " + iC + " to " + iChar);
54  
          continue;
55  
        }
56  
  
57  
      int iNext = i << 1;
58  
      descend(level-1, iNext, iNext+2);
59  
    }
60  
  }
61  
  
62  
  int level = bitMap.reachedLevel();
63  
  descend(level, 0, 1);
64  
  //printStruct(tbl);
65  
}

Author comment

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: 180 / 280
Version history: 2 change(s)
Referenced in: [show references]