package iskra import "git.smesh.lol/iskradb/lattice" // Stage tags prepended to the key's high byte. const ( StageSRC uint8 = 0x01 StageAST uint8 = 0x02 StageIR uint8 = 0x03 StageASM uint8 = 0x04 StageBIN uint8 = 0x05 ) // MakeKey encodes stage in the high 8 bits and the FNV hash in the lower 56 // bits of Key[0], with Key[1] = 0. This preserves existing stage-based // semantics as a 128-bit lattice.Key (same collision rate as before, but // compatible with the updated iskradb interface). // MakeCodeKey encodes a code-lattice stage+FNV key. // Renamed from MakeKey to make room for MakeKey(domain, coord, word) in coord.mx. func MakeCodeKey(stage uint8, hash uint64) lattice.Key { return lattice.Key{(uint64(stage) << 56) | (hash & 0x00FFFFFFFFFFFFFF), 0} } func KeyStage(key lattice.Key) uint8 { return uint8(key[0] >> 56) } func KeyHash(key lattice.Key) uint64 { return key[0] & 0x00FFFFFFFFFFFFFF } // NameKey builds a lattice.Key from stage and the segment's name. func NameKey(stage uint8, name string) lattice.Key { return MakeCodeKey(stage, HashBytes([]byte(name))) } func StageName(s uint8) string { switch s { case StageSRC: return "SRC" case StageAST: return "AST" case StageIR: return "IR" case StageASM: return "ASM" case StageBIN: return "BIN" } return "?" }