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)

// immutable object
sclass Bits {
  BitSet bs;
  int n; // length
  
  *() { bs = new BitSet; }
  *(BitSet *bs, int *n) {}
  *(S s) {
    byte[] data = toUtf8(s);
    bs = bytesToBitSet(data);
    n = data.length*8;
  }
  
  byte[] toByteArray() {
    ret bitSetToBytes(bs, n); 
  }
  
  public int hashCode() {
    ret main.hashCode(bs) + n;
  }
  
  public bool equals(O o) {
    if (!o instanceof Bits) false;
    ret n == o/Bits.n && eq(bs, o/Bits.bs);
  }
  
  S getString() {
    ret fromUtf8(toByteArray());
  }
}

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: 485 / 1068
Referenced in: [show references]