Libraryless. Click here for Pure Java version (104L/1K).
1 | sclass HashedByteArray is Comparable<HashedByteArray> {
|
2 | byte[] data; |
3 | int hashCode; |
4 | |
5 | *() {}
|
6 | *(byte[] *data) {}
|
7 | |
8 | public int hashCode() {
|
9 | if (hashCode == 0) |
10 | hashCode = oneIfZero(arrayHashCode(data)); |
11 | ret hashCode; |
12 | } |
13 | |
14 | public bool equals(O o) {
|
15 | if (o cast HashedByteArray) |
16 | ret this == o || hashCode() == o.hashCode() && byteArraysEqual(data, o.data); |
17 | false; |
18 | } |
19 | |
20 | // we interpret the bytes as ubytes |
21 | public int compareTo(HashedByteArray a) {
|
22 | ret Arrays.compareUnsigned(data, a.data); |
23 | } |
24 | |
25 | toString {
|
26 | ret bytesToHex(data); |
27 | } |
28 | } |
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: | 550 / 1028 |
| Version history: | 7 change(s) |
| Referenced in: | [show references] |