Uses 11335K of libraries. Click here for Pure Java version (5385L/33K).
sclass ManagedStringPool { replace Addr with int. ManagedIntObjects_v1 mem; *(ManagedIntObjects_v1 *mem) {} sclass Entry { Addr addr; int references; *(Addr *addr, int *references) {} } new Map<S, Entry> map; // stores a string (creates if necessary and registers a reference) Addr store(S s) { Entry e = map.get(s); if (e == null) e = new Entry(mem.newString(s), 0); e.references++; ret e.addr; } // just queries Addr peek(S s) { Entry e = map.get(s); ret e == null ? 0 : e.addr; } // remove a reference void unstore(S s) { Entry e = map.get(s); if (e == null) fail("ManagedStringPool user error"); if (--e.references == 0) map.remove(s); } }
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
Snippet ID: | #1031664 |
Snippet name: | ManagedStringPool (is itself not persistent) |
Eternal ID of this version: | #1031664/3 |
Text MD5: | 6aac11b847bf90ddce95dfff9ba5de3b |
Transpilation MD5: | 4fd313d5043749c8b048e8ee4be04ffb |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-06-25 09:17:46 |
Source code size: | 797 bytes / 39 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 192 / 270 |
Version history: | 2 change(s) |
Referenced in: | [show references] |