tracker
All repositories: gitoria
2.5 KB
// String keys and JSON values in UTF-8 Bytes; open-addressed slots contain only u32 words.import { read32, write32 } from './catalog-bytes.hl'slots = toBytes(20480)payload = toBytes(0)capacity = 1024count = 0waste = 0hashOf(String key) {bytes = toBytes(key)let hash = 0for (let i = 0; i < bytes.length; i = i + 1) { hash = (hash * 31 + bytes[i]) % 4294967291 }return hash}slot(String key, Number hash) {let i = hash % capacitywhile (true) {at = i * 20size = read32(&slots, at + 8)if (size == 0) { return at }if (read32(&slots, at) == hash) {start = read32(&slots, at + 4)if (payload.text(start, start + size - 1) == key) { return at }}i = (i + 1) % capacity}}grow() {old = slotscapacity = capacity * 2slots = toBytes(capacity * 20)for (let i = 0; i < old.length; i = i + 20) {size = read32(&old, i + 8)if (size != 0) {hash = read32(&old, i)start = read32(&old, i + 4)at = slot(payload.text(start, start + size - 1), hash)for (let j = 0; j < 20; j = j + 1) { slots[at + j] = old[i + j] }}}return null}fetch(String key) {at = slot(key, hashOf(key))if (read32(&slots, at + 8) == 0) { return null }start = read32(&slots, at + 12)return JSON.parse(payload.text(start, start + read32(&slots, at + 16)))}put(String key, &value) {if ((count + 1) * 2 > capacity) { grow() }hash = hashOf(key)at = slot(key, hash)if (read32(&slots, at + 8) == 0) {bytes = toBytes(key)write32(&slots, at, hash)write32(&slots, at + 4, payload.length)write32(&slots, at + 8, bytes.length + 1)payload.append(&bytes)count = count + 1} else { waste = waste + read32(&slots, at + 16) }bytes = toBytes(JSON.stringify(value))write32(&slots, at + 12, payload.length)write32(&slots, at + 16, bytes.length)payload.append(&bytes)if (waste > 1048576 && waste * 2 > payload.length) { compact() }return null}keys() {out = []for (let i = 0; i < slots.length; i = i + 20) {size = read32(&slots, i + 8)if (size != 0) {start = read32(&slots, i + 4)out.push(payload.text(start, start + size - 1))}}return out}compact() {out = toBytes(0)for (let i = 0; i < slots.length; i = i + 20) {size = read32(&slots, i + 8)if (size != 0) {keyStart = read32(&slots, i + 4)valueStart = read32(&slots, i + 12)key = payload.slice(keyStart, keyStart + size - 1)value = payload.slice(valueStart, valueStart + read32(&slots, i + 16))write32(&slots, i + 4, out.length)out.append(&key)write32(&slots, i + 12, out.length)out.append(&value)}}payload = outwaste = 0return null}
Branches
Latest commits
- c7cdef62Log: Apollo STOP, workers pausedmre
- d0c083fbLog: usage stopmre
- c6d464e5Log: Apollo GO backlog, AP56 and BS1 startedmre
- 1eb6f1a1Missions AP56, BS1mre
- 4871f8adLog: AP52 live on day52, browser gate greenmre
- d9bf2988Merge ap52: day52, tracker#58 server argument, #51 modal close rule, #56 keyed season rowsmre
- c4a60ef2Log: RT52 retest passed, AP52 startedmre
- 83760a55Browser gate: search results belong to the address form of the typed text (tracker#52 navigate replace)mre
- 6e951d91AP52: show-page rows are keyed records; closing a season is one upsert and removes (tracker#56, hybriel#331)mre
- 3bb4ccddAP52: modal close button refers to its nested rule with Style.buttonModalX (tracker#51, hybriel#333)mre
- ba16933fAP52: login callback and title route are static handlers taking the server as third argument (tracker#58, hybriel#332)mre
- 85153900AP52: re-vendor Hybriel set day52 (source 77cfca31, bin 0a8ed496)mre
- 7c051eddLog: hybriel#338 answermre
- d049b8b8Log: HM50 live, #52 donemre
- 6d05fa37Log: HM50 Part A mergedmre
- 1c7dab74HM50: the shell reads the framework's online state, netProbe removed (tracker#55)mre
- e8b91697HM50: search address follows the text via navigate(path, replace = true) (tracker#52)mre
- 6fe1896cHM50: re-vendor Hybriel set day50 (source 0ae38232, bin d3ef9d16)mre
- 2f391aa9Log: HM50 startedmre
- 4b59c03dHM50 mission: doc pathmre