// CountBitsRunes count 1's in b
328682
func CountBitsRunes(b []rune) int {
	c := 0
	for _, x := range b {
		c += CountBitsRune(x)
	}
	return c
}
626363
func (r *Redis) BitCount(key string, start, end int) (int64, error) {
	rp, err := r.ExecuteCommand("BITCOUNT", key, start, end)
	if err != nil {
		return 0, err
	}
	return rp.IntegerValue()
}
796868
func (p *PostingsList) Count() uint64 {
	var n, e uint64
	if p.normBits1Hit != 0 {
		n = 1
		if p.except != nil && p.except.Contains(uint32(p.docNum1Hit)) {
			e = 1
		}
	} else if p.postings != nil {
		n = p.postings.GetCardinality()
		if p.except != nil {
			e = p.postings.AndCardinality(p.except)
		}
	}
	return n - e
}
1053192
func (alac *Alac) readbits(bits int) uint32 {
	var result int32 = 0

	if bits > 16 {
		bits -= 16
		result = int32(alac.readbits_16(16) << uint(bits))
	}

	result |= int32(alac.readbits_16(bits))

	return uint32(result)
}
859175
func (s *Bitset) Bits() []uint {
	res := make([]uint, s.BitCount())
	index := 0
	for i, l := Uint0, s.length; i < l; i++ {
		if s.IsSet(i) {
			res[index] = i
			index++
		}
	}

	return res
}
84851
func (b *Buckets) getBits(offset, length uint) uint32 {
	byteIndex := offset / 8
	byteOffset := offset % 8
	if byteOffset+length > 8 {
		rem := 8 - byteOffset
		return b.getBits(offset, rem) | (b.getBits(offset+rem, length-rem) << rem)
	}
	bitMask := uint32((1 << length) - 1)
	return (uint32(b.data[byteIndex]) & (bitMask << byteOffset)) >> byteOffset
}
245389
func (m *metadataTracker) countsPtr(dev protocol.DeviceID, flags uint32) *Counts {
	// must be called with the mutex held

	key := metaKey{dev, flags}
	idx, ok := m.indexes[key]
	if !ok {
		idx = len(m.counts.Counts)
		m.counts.Counts = append(m.counts.Counts, Counts{DeviceID: dev[:], LocalFlags: flags})
		m.indexes[key] = idx
	}
	return &m.counts.Counts[idx]
}
330172
func (b *BitSet) Count() uint {
	if b != nil && b.set != nil {
		return uint(popcntSlice(b.set))
	}
	return 0
}
392103
func RandomBits(bits int) []byte {
	size := bits / 8
	if bits%8 != 0 {
		size++
	}
	b := make([]byte, size)
	if _, err := rand.Read(b); err != nil {
		panic(err) // rand should never fail
	}
	return b
}
393880
func numBits(b byte) (zeros, ones int) {
	ones = int(oneBitsLUT[b])
	zeros = 8 - ones
	return
}
99353
func (b *BitWriter) WriteBit(bit Bit) error {

	if bit {
		b.b[0] |= 1 << (b.count - 1)
	}

	b.count--

	if b.count == 0 {
		if n, err := b.w.Write(b.b[:]); n != 1 || err != nil {
			return err
		}
		b.b[0] = 0
		b.count = 8
	}

	return nil
}
1123194
func CountBitmap(bitmap, sbit C.MMBitmapRef, args ...float32) int {
	var tolerance C.float = 0.01
	if len(args) > 0 {
		tolerance = C.float(args[0])
	}

	count := C.count_of_bitmap(bitmap, sbit, tolerance)
	return int(count)
}
834079
func (b *bitReader) getBits(n uint8) int {
	if n == 0 /*|| b.bitsRead >= 64 */ {
		return 0
	}
	return b.getBitsFast(n)
}
1039107
func (b *BitReader) ReadBits(nbits int) (uint64, error) {

	var u uint64

	for nbits >= 8 {
		byt, err := b.ReadByte()
		if err != nil {
			return 0, err
		}

		u = (u << 8) | uint64(byt)
		nbits -= 8
	}

	var err error
	for nbits > 0 && err != io.EOF {
		byt, err := b.ReadBit()
		if err != nil {
			return 0, err
		}
		u <<= 1
		if byt {
			u |= 1
		}
		nbits--
	}

	return u, nil
}
294056
func (f *decompressor) getBits(n byte) uint16 {
	if f.nbits < n {
		if !f.feed() {
			f.fail(io.ErrUnexpectedEOF)
		}
	}
	c := uint16(f.c >> (32 - n))
	f.c <<= n
	f.nbits -= n
	return c
}
917819
func CountBytes(b []byte) (int, error) {
	var count int
	for len(b) >= 8 {
		v := binary.BigEndian.Uint64(b[:8])
		b = b[8:]

		sel := v >> 60
		if sel >= 16 {
			return 0, fmt.Errorf("invalid selector value: %v", sel)
		}
		count += selector[sel].n
	}

	if len(b) > 0 {
		return 0, fmt.Errorf("invalid slice len remaining: %v", len(b))
	}
	return count, nil
}
209034
func (m *metadataTracker) Counts(dev protocol.DeviceID, flag uint32) Counts {
	if bits.OnesCount32(flag) > 1 {
		panic("incorrect usage: set at most one bit in flag")
	}

	m.mut.RLock()
	defer m.mut.RUnlock()

	idx, ok := m.indexes[metaKey{dev, flag}]
	if !ok {
		return Counts{}
	}

	return m.counts.Counts[idx]
}