gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitbb2ebc67bb2ebc67log: #64 live, #53 mergedmrebb2ebc67/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

  • bb2ebc67log: #64 live, #53 mergedmre
  • 27cde42fMerge hm53-dom: tracker#53 inputs bound to membersmre
  • 2156cc7flog: HM54 reviewmre
  • 9fb82efclog: HM54 gap, fill continuesmre
  • b632eb8dlog: HM53 done, HM54 startedmre
  • ccb1a263tracker#53: bind editor drafts and use key event focus targetmre
  • 3356fcfclog: #52 blocked, HM53 startedmre
  • 833dcfc9Merge hm52-search: report only, tracker#52 blocked by framework gapmre
  • 73010cc0HM52: report replace-navigation search draft regressionmre
  • 1742e92bstatus: DP64 and HM52 runningmre
  • 29ad5b58log: #64 merged, DP64 and HM52 startedmre
  • fafddbf9Merge hm64-catalog: tracker#64 catalog from packed entriesmre
  • b2e2206dlog: #63 livemre
  • 5831e0e0log: HM64 donemre
  • 4042b923Flatten catalog membership rows into paired slotsmre
  • ea8a759elog: #61 #62 live, DP63 and HM64 startedmre
  • 40439456Merge hm63-searchtext: tracker#63 packed search textmre
  • b7e6b48ePack normalized search text behind numeric offsetsmre
  • b35f53e1log: DP62 stale runtime decisionmre
  • f9593602log: Apollo deploy rule correctionmre