diff --git a/save/bitstorage.go b/save/bitstorage.go index a87ca75..d6de313 100644 --- a/save/bitstorage.go +++ b/save/bitstorage.go @@ -5,6 +5,8 @@ import ( "math" ) +// BitStorage implement the compacted data array used in chunk storage. +// https://wiki.vg/Chunk_Format // This implement the format since Minecraft 1.16 type BitStorage struct { data []uint64 @@ -14,7 +16,11 @@ type BitStorage struct { valuesPerLong int } -// NewBitStorage create a new BitStorage, // TODO: document +// NewBitStorage create a new BitStorage. +// bits is the number of bits per value. +// size is the number of values. +// arrl is optional data for initializing. +// It's length must match the bits and size if it's not nil. func NewBitStorage(bits, size int, arrl []uint64) (b *BitStorage) { b = &BitStorage{ mask: 1< b.size-1 || v < 0 || uint64(v) > b.mask { @@ -52,6 +68,7 @@ func (b *BitStorage) Swap(i, v int) (old int) { return } +// Set sets v into [i] func (b *BitStorage) Set(i, v int) { if i < 0 || i > b.size-1 || v < 0 || uint64(v) > b.mask { @@ -63,6 +80,7 @@ func (b *BitStorage) Set(i, v int) { b.data[c] = l&(b.mask< b.size-1 { panic("out of bounds")