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

30
LINES

< > BotCompany Repo | #1006140 // class Bits (a BitSet with a defined size)

JavaX fragment (include)

1  
// immutable object
2  
sclass Bits {
3  
  BitSet bs;
4  
  int n; // length
5  
  
6  
  *() { bs = new BitSet; }
7  
  *(BitSet *bs, int *n) {}
8  
  *(S s) {
9  
    byte[] data = toUtf8(s);
10  
    bs = bytesToBitSet(data);
11  
    n = data.length*8;
12  
  }
13  
  
14  
  byte[] toByteArray() {
15  
    ret bitSetToBytes(bs, n); 
16  
  }
17  
  
18  
  public int hashCode() {
19  
    ret main.hashCode(bs) + n;
20  
  }
21  
  
22  
  public bool equals(O o) {
23  
    if (!o instanceof Bits) false;
24  
    ret n == o/Bits.n && eq(bs, o/Bits.bs);
25  
  }
26  
  
27  
  S getString() {
28  
    ret fromUtf8(toByteArray());
29  
  }
30  
}

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: #1006140
Snippet name: class Bits (a BitSet with a defined size)
Eternal ID of this version: #1006140/1
Text MD5: d087383b4de48bbc9f35183922a955cb
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-12-21 16:09:39
Source code size: 551 bytes / 30 lines
Pitched / IR pitched: No / No
Views / Downloads: 565 / 1156
Referenced in: [show references]