// should be thread-safe by nature // compare efficiently due to md5 caching // tested with A = S static class ImmL<A> extends AbstractList<A> { new L<A> l; int hash; S md5; *() {} *(L<A> _l) { l.addAll(_l); } // List methods public int size() { ret l.size(); } public A get(int i) { ret l.get(i); } public synchronized int hashCode() { if (hash == 0) hash = l.hashCode(); ret hash; } public bool equals(O o) { if (o instanceof ImmL && neq(md5(), ((ImmL) o).md5())) false; ret super.equals(o); } public synchronized S md5() { if (md5 == null) md5 = main.md5(structure(l)); ret md5; } }
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1004213 |
Snippet name: | ImmL - immutable list with efficient comparison |
Eternal ID of this version: | #1004213/1 |
Text MD5: | 4b0d2ff1357905a12f743b2a19299803 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-08-10 16:59:17 |
Source code size: | 733 bytes / 40 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 532 / 1211 |
Referenced in: | [show references] |