@@ -1,6 +1,6 @@ -// Package bits provides a bit vector backed with uints +// Package bits provides a bit vector interface and several implementations package bits import ( "strconv" ) @@ -15,10 +15,11 @@ Flip(uint) // Returns the total number of elements supported by the vector Len() uint } +// A Vector type that simply stores booleans in a slice type boolvector []bool // Retrieves the bit at the designated position func (v boolvector) Peek(pos uint) bool { return v[pos] @@ -36,10 +37,15 @@ // Returns the total number of elements supported by the vector func (v boolvector) Len() uint { return uint(len(v)) } + +func NewBool(size uint) Vector { + var slice []bool = make([]bool, size) + return boolvector(slice) +} type vector []uint // Retrieves the bit at the designated position func (v vector) Peek(pos uint) bool { @@ -71,11 +77,11 @@ func at(pos uint) (uint, uint) { return pos / strconv.IntSize, pos % strconv.IntSize } // Create a new bit vector sized up to the desired number of elements -func New(size uint) Vector { +func NewBit(size uint) Vector { var length uint = size / strconv.IntSize if size%strconv.IntSize > 0 { // Allocate one additional slot if the desired // size is does not divide by 32/64 @@ -83,10 +89,5 @@ } var slice []uint = make([]uint, length) return vector(slice) } - -func NewBool(size uint) Vector { - var slice []bool = make([]bool, size) - return boolvector(slice) -}