package core import ( "encoding/binary" "math/bits" ) // PageDiff tracks which nodes in a page have changed, using a 128-bit // bitfield stored as two uint64 words. // // Bit 63 of the second word is the "cleared" flag, indicating the page // was cleared entirely. Bit 62 of the second word is reserved. type PageDiff struct { words [2]uint64 } const clearBit = uint64(1) << 63 // SetChanged marks the node at the given index (0-125) as changed. // Also clears the "cleared" flag if set. func (d *PageDiff) SetChanged(index int) { // Always clear the "cleared" flag when setting a changed node. d.words[1] &= ^clearBit if index < 64 { d.words[0] |= 1 << index } else { d.words[1] |= 1 << (index - 64) } } // IsChanged reports whether the node at the given index is marked changed. func (d *PageDiff) IsChanged(index int) bool { if index < 64 { return d.words[0]&(1<