Libraryless. Click here for Pure Java version (104L/1K).
sclass HashedByteArray is Comparable<HashedByteArray> { byte[] data; int hashCode; *() {} *(byte[] *data) {} public int hashCode() { if (hashCode == 0) hashCode = oneIfZero(arrayHashCode(data)); ret hashCode; } public bool equals(O o) { if (o cast HashedByteArray) ret this == o || hashCode() == o.hashCode() && byteArraysEqual(data, o.data); false; } // we interpret the bytes as ubytes public int compareTo(HashedByteArray a) { ret Arrays.compareUnsigned(data, a.data); } toString { ret bytesToHex(data); } }
download show line numbers debug dex old transpilations
Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1024840 |
Snippet name: | HashedByteArray - byte array with content-based hash code/equals |
Eternal ID of this version: | #1024840/8 |
Text MD5: | c9feec59bf04fc03d7a69d4839184afd |
Transpilation MD5: | 61d03b0d29fd4bcc9349478d920f17d6 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-08-05 18:22:58 |
Source code size: | 614 bytes / 28 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 269 / 703 |
Version history: | 7 change(s) |
Referenced in: | [show references] |