gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit85cfb4ae85cfb4ae|||PR records: AP61 day61, DP74 liveTracker85cfb4ae/lib/catalog-map.hl

2.5 KB

  1. // String keys and JSON values in UTF-8 Bytes; open-addressed slots contain only u32 words.
  2. import { read32, write32 } from './catalog-bytes.hl'
  3. slots = toBytes(20480)
  4. payload = toBytes(0)
  5. capacity = 1024
  6. count = 0
  7. waste = 0
  8. hashOf(String key) {
  9. bytes = toBytes(key)
  10. let hash = 0
  11. for (let i = 0; i < bytes.length; i = i + 1) { hash = (hash * 31 + bytes[i]) % 4294967291 }
  12. return hash
  13. }
  14. slot(String key, Number hash) {
  15. let i = hash % capacity
  16. while (true) {
  17. at = i * 20
  18. size = read32(&slots, at + 8)
  19. if (size == 0) { return at }
  20. if (read32(&slots, at) == hash) {
  21. start = read32(&slots, at + 4)
  22. if (payload.text(start, start + size - 1) == key) { return at }
  23. }
  24. i = (i + 1) % capacity
  25. }
  26. }
  27. grow() {
  28. old = slots
  29. capacity = capacity * 2
  30. slots = toBytes(capacity * 20)
  31. for (let i = 0; i < old.length; i = i + 20) {
  32. size = read32(&old, i + 8)
  33. if (size != 0) {
  34. hash = read32(&old, i)
  35. start = read32(&old, i + 4)
  36. at = slot(payload.text(start, start + size - 1), hash)
  37. for (let j = 0; j < 20; j = j + 1) { slots[at + j] = old[i + j] }
  38. }
  39. }
  40. return null
  41. }
  42. fetch(String key) {
  43. at = slot(key, hashOf(key))
  44. if (read32(&slots, at + 8) == 0) { return null }
  45. start = read32(&slots, at + 12)
  46. return JSON.parse(payload.text(start, start + read32(&slots, at + 16)))
  47. }
  48. put(String key, &value) {
  49. if ((count + 1) * 2 > capacity) { grow() }
  50. hash = hashOf(key)
  51. at = slot(key, hash)
  52. if (read32(&slots, at + 8) == 0) {
  53. bytes = toBytes(key)
  54. write32(&slots, at, hash)
  55. write32(&slots, at + 4, payload.length)
  56. write32(&slots, at + 8, bytes.length + 1)
  57. payload.append(&bytes)
  58. count = count + 1
  59. } else { waste = waste + read32(&slots, at + 16) }
  60. bytes = toBytes(JSON.stringify(value))
  61. write32(&slots, at + 12, payload.length)
  62. write32(&slots, at + 16, bytes.length)
  63. payload.append(&bytes)
  64. if (waste > 1048576 && waste * 2 > payload.length) { compact() }
  65. return null
  66. }
  67. keys() {
  68. out = []
  69. for (let i = 0; i < slots.length; i = i + 20) {
  70. size = read32(&slots, i + 8)
  71. if (size != 0) {
  72. start = read32(&slots, i + 4)
  73. out.push(payload.text(start, start + size - 1))
  74. }
  75. }
  76. return out
  77. }
  78. compact() {
  79. out = toBytes(0)
  80. for (let i = 0; i < slots.length; i = i + 20) {
  81. size = read32(&slots, i + 8)
  82. if (size != 0) {
  83. keyStart = read32(&slots, i + 4)
  84. valueStart = read32(&slots, i + 12)
  85. key = payload.slice(keyStart, keyStart + size - 1)
  86. value = payload.slice(valueStart, valueStart + read32(&slots, i + 16))
  87. write32(&slots, i + 4, out.length)
  88. out.append(&key)
  89. write32(&slots, i + 12, out.length)
  90. out.append(&value)
  91. }
  92. }
  93. payload = out
  94. waste = 0
  95. return null
  96. }

Branches

Latest commits

  • 85cfb4ae|||PR records: AP61 day61, DP74 liveTracker
  • b1496147Merge branch 'ap61' into mainTracker
  • 2047955bMerge branch 'u12-gateports' into mainTracker
  • c8da40f3|||PR AP61: re-vendor Hybriel set day61 (source a05af47c, bin a11042e5)Tracker
  • 4e018678|||PR deploy.sh: gates use Tracker's ports 8716-8719 and LC_ALL=C; README: 2 backups keptTracker
  • 0b86324aMerge branch 'records-dp73' into mainTracker
  • 9ce5f59b|||PR records: DP73 live 613ae0e; deploy.sh keeps 2 backupsTracker
  • 613ae0ecMerge branch 'bs3' into mainTracker
  • 1383264b|||PR BS3: keep shared synchronous sorting fastTracker
  • 63e5ba1a|||PR BS3: guard boot imports and share resumable sort buffersTracker
  • 310613f1Merge branch 'records-dp72' into mainTracker
  • 6f7b61ba|||PR records: deploy-swap fix live, Kunibert findingsTracker
  • c41587d2Merge branch 'bs2' into mainTracker
  • 0dd538a6|||PR BS2: finish the boot index in slices so a booting instance keeps answeringTracker
  • 019d5cedMerge branch 'records-1110' into mainTracker
  • f88ae8b9|||PR records: day56 toggle live, reviewTracker
  • b6b3bb4dMerge branch 'ap56e' into mainTracker
  • 29a26da9|||PR AP56e: guard hidden show helpers during session syncTracker
  • 7c9ec236|||PR AP56e: re-vendor Hybriel set day56 (source 36ae83a8, bin c1f595a2)Tracker
  • 4b54f6f9Merge branch 'records-audit' into mainTracker