func (bv *BitVector) Count() int {
	if bv.count == -1 {
		c := 0
		for _, v := range bv.bits {
			c += util.BitCount(v)  
		}
		bv.count = c
	}
	assert2(bv.count <= bv.size, "count=%v size=%v", bv.count, bv.size)
	return bv.count
}
/*
Returns the total number of bits in this vector. This is efficiently
computed and cached, so that, if the vector is not changed, no
recomputation is done for repeated calls.
package lucene40
import (
	"errors"
	"fmt"
	"github.com/balzaczyy/golucene/core/codec"
	"github.com/balzaczyy/golucene/core/store"
	"github.com/balzaczyy/golucene/core/util"
	"reflect"
)
const (
	CODEC = "BitVector"
	BV_VERSION_DGAPS_CLEARED = 1
	BV_VERSION_CHECKSUM = 2
	BV_VERSION_CURRENT = BV_VERSION_CHECKSUM
)
type BitVector struct {
	bits  []byte
	size  int
	count int
}
func NewBitVector(n int) *BitVector {
	return &BitVector{
		size: n,
		bits: make([]byte, numBytes(n)),
	}
}
func numBytes(size int) int {
	bytesLength := int(uint(size) >> 3)
	if (size & 7) != 0 {
		bytesLength++
	}
	return bytesLength
}
func (bv *BitVector) Clear(bit int) {
	assert2(bit >= 0 && bit < bv.size, "bit %v is out of bounds 0..%v", bit, bv.size-1)
	bv.bits[bit>>3] &= ^(1 << (uint(bit) & 7))
	bv.count = -1
}
func (bv *BitVector) At(bit int) bool {
	assert2(bit >= 0 && bit < bv.size, "bit %v is out of bounds 0..%v", bit, bv.size-1)
	return (bv.bits[bit>>3] & (1 << (uint(bit) & 7))) != 0
}
func assert(ok bool) {
	assert2(ok, "assert fail")
}
func assert2(ok bool, msg string, args ...interface{}) {
	if !ok {
		panic(fmt.Sprintf(msg, args...))
	}
}
func (bv *BitVector) Length() int {
	return bv.size
}