Download Jar. Libraryless. Click here for Pure Java version (8006L/54K).
1 | !7 |
2 | |
3 | concept BigEntry { |
4 | S globalID; |
5 | long fileNr, headerStart, start, length; |
6 | } |
7 | |
8 | p { |
9 | dbIndexing(BigEntry, 'globalID); |
10 | |
11 | S s = "Hello world"; |
12 | BigEntry entry = db_newStringEntry(s); |
13 | print("Stored as: " + renderConcept(entry)); |
14 | assertEqualsVerbose(s, db_getText(entry)); |
15 | print("OK"); |
16 | } |
17 | |
18 | static BigEntry db_newStringEntry(S text) { |
19 | lock dbLock(); |
20 | long fileNr = fileNrToAppendTo(); |
21 | S globalID = aGlobalID(); |
22 | File file = db_file(fileNr); |
23 | long length = fileSize(file); |
24 | long l = lUtf8(text); |
25 | S header = globalID + " " + l + "\n"; |
26 | long start = length + lUtf8(header); |
27 | appendToTextFile(file, header + text + "\n"); |
28 | ret cnew(BigEntry, +globalID, +fileNr, headerStart := length, +start, length := l); |
29 | } |
30 | |
31 | static long fileNrToAppendTo() { |
32 | ret 1; |
33 | } |
34 | |
35 | static File db_file(long nr) { |
36 | ret getProgramFile("db." + nr); |
37 | } |
38 | |
39 | static S db_getText(BigEntry entry) { |
40 | File f = db_file(entry.fileNr); |
41 | ret fromUtf8(loadBinaryFilePart(f, entry.start, entry.start+entry.length)); |
42 | } |
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: | #1010406 |
Snippet name: | Bigger-Than-RAM DB v1 [OK] |
Eternal ID of this version: | #1010406/4 |
Text MD5: | 0586623e50acbf1012ef5be8c52d8050 |
Transpilation MD5: | 6bdccc3df973fd99b781a104cfe1e8d3 |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX source code (desktop) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-09-15 18:35:53 |
Source code size: | 1032 bytes / 42 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 549 / 1136 |
Version history: | 3 change(s) |
Referenced in: | [show references] |