gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit9c4397c99c4397c9mission HM63mre9c4397c9/lib/shortid-owners.hl

1.8 KB

  1. // Packed short-ID owners. Twelve bytes per hash slot: key+1, payload offset, byte length.
  2. // The payload holds the existing prefixed owner strings as UTF-8, without a String per row.
  3. // Empty slots have key zero; no owner is removed, including failed-write reservations.
  4. static alphabet = 'abcdefghijklmnopqrstuvwxyz0123456789'
  5. static read32 = (&bytes, Number pos) => {
  6. return bytes[pos] + bytes[pos + 1] * 256 + bytes[pos + 2] * 65536 + bytes[pos + 3] * 16777216
  7. }
  8. static write32 = (&bytes, Number pos, Number value) => {
  9. let n = value
  10. let i = 0
  11. while (i < 4) {
  12. bytes[pos + i] = n % 256
  13. n = (n - n % 256) / 256
  14. i = i + 1
  15. }
  16. return true
  17. }
  18. static keyOf = (String sid) => {
  19. let key = 0
  20. let i = 0
  21. while (i < 5) {
  22. key = key * 36 + alphabet.indexOf(sid[i])
  23. i = i + 1
  24. }
  25. return key + 1
  26. }
  27. slots = toBytes(12288)
  28. payload = toBytes(0)
  29. capacity = 1024
  30. count = 0
  31. slot(Number key) {
  32. let pos = key % capacity
  33. while (true) {
  34. stored = read32(&slots, pos * 12)
  35. if (stored == 0 || stored == key) { return pos * 12 }
  36. pos = (pos + 1) % capacity
  37. }
  38. }
  39. grow() {
  40. old = slots
  41. oldCapacity = capacity
  42. capacity = capacity * 2
  43. slots = toBytes(capacity * 12)
  44. let i = 0
  45. while (i < oldCapacity) {
  46. key = read32(&old, i * 12)
  47. if (key != 0) {
  48. pos = slot(key)
  49. let j = 0
  50. while (j < 12) { slots[pos + j] = old[i * 12 + j] j = j + 1 }
  51. }
  52. i = i + 1
  53. }
  54. return true
  55. }
  56. fetch(String sid) {
  57. pos = slot(keyOf(sid))
  58. if (read32(&slots, pos) == 0) { return null }
  59. start = read32(&slots, pos + 4)
  60. return payload.text(start, start + read32(&slots, pos + 8))
  61. }
  62. put(String sid, String owner) {
  63. if ((count + 1) * 2 > capacity) { grow() }
  64. key = keyOf(sid)
  65. pos = slot(key)
  66. if (read32(&slots, pos) == 0) { count = count + 1 }
  67. bytes = toBytes(owner)
  68. write32(&slots, pos, key)
  69. write32(&slots, pos + 4, payload.length)
  70. write32(&slots, pos + 8, bytes.length)
  71. payload.append(&bytes)
  72. return true
  73. }

Branches

Latest commits

  • 9c4397c9mission HM63mre
  • 8dfe42c8mission DP62mre
  • e347fef4Merge rv44: tracker#61 #62 on Hybriel day44mre
  • 8274bcf1log: RV44 done, deploy held for the usage windowmre
  • 1ef7a3b1RV44: report day44 gates and migration/restart proofsmre
  • a5f62f6cRV44: re-vendor Hybriel set day44 (source 222edef7, bin 4f0f263e)mre
  • 6159a248Merge branch 'hm62-personindex' into rv44mre
  • a8923d93log: RV44 startedmre
  • cf28cf77mission RV44mre
  • 585782dfLog: tracker#60 Chrome look, STATUS rewrittenmre
  • 147d0172conductor: caramboleyo is the user, not owner/creatorApollo
  • 21dd0cfblog: #60 live measurement, reviewmre
  • 7793cf94HM62b report: person indexes with fixed mpackdbmre
  • b4c8d3a9Document tracker#62 fixed-index migration and GC proofmre
  • 09d66ed5status: #60 livemre
  • 4171672flog: #60 livemre
  • f52862a2log: HM62b startedmre
  • 88fde2c4mission HM62bmre
  • a722e526log: #62 blocked by hybriel#317mre
  • 074a7418log: #62 assigned to Tracker; pending rulemre