// addBits16Clean will add up to 16 bits. value may not contain more set bits than indicated.
// It will not check if there is space for them, so the caller must ensure that it has flushed recently.
431383
func (b *bitWriter) addBits16Clean(value uint16, bits uint8) {
	b.bitContainer |= uint64(value) << (b.nBits & 63)
	b.nBits += bits
}
1268502
func swap16(i uint16) uint16 {
	if Native == binary.BigEndian {
		return i
	}
	return (i&0xff00)>>8 | (i&0xff)<<8
}
938502
func (e Encoder) AppendInt16(dst []byte, val int16) []byte {
	return e.AppendInt(dst, int(val))
}
94239
func (vb *keyWriter) WriteUint16(num uint16) (int, error) {
	binary.BigEndian.PutUint16(vb.buffer[:2], num)
	vb.hash.Write(vb.buffer[:2])
	return 2, nil
}
281344
func Swap16(i uint16) uint16 {
	if NativeEndian() == binary.BigEndian {
		return i
	}
	return (i&0xff00)>>8 | (i&0xff)<<8
}
1274320
func (s *Subnet) Bits() (ones int, zeros int) {
	for _, b := range []byte(s.mask) {
		for i := uint(0); i < 8; i++ {
			if b&(1<<i) == 0 {
				zeros++
			} else {
				ones++
			}
		}
	}
	return
}
584090
func (s *rowSegment) SetBit(i uint64) (changed bool) {
	s.ensureWritable()
	changed, _ = s.data.Add(i)
	if changed {
		s.n++
	}
	return changed
}
522571
func (c Context) Ints16(key string, i []int16) Context {
	c.l.context = enc.AppendInts16(enc.AppendKey(c.l.context, key), i)
	return c
}
1286407
func (b *PCMBuffer) AsInt16s() (out []int16) {
	if b == nil {
		return nil
	}
	switch b.DataType {
	case Integer, Float:
		out = make([]int16, len(b.Ints))
		for i := 0; i < len(b.Ints); i++ {
			out[i] = int16(b.Ints[i])
		}
	case Byte:
		// if the format isn't defined, we can't read the byte data
		if b.Format == nil || b.Format.Endianness == nil || b.Format.BitDepth == 0 {
			return out
		}
		bytesPerSample := int((b.Format.BitDepth-1)/8 + 1)
		buf := bytes.NewBuffer(b.Bytes)
		out := make([]int16, len(b.Bytes)/bytesPerSample)
		binary.Read(buf, b.Format.Endianness, &out)
	}
	return out
}
1143629
func CountBitsUint64s(b []uint64) int {
	c := 0
	for _, x := range b {
		c += CountBitsUint64(x)
	}
	return c
}
1011503
func (b *BitSet) DumpAsBits() string {
	if b.set == nil {
		return "."
	}
	buffer := bytes.NewBufferString("")
	i := len(b.set) - 1
	for ; i >= 0; i-- {
		fmt.Fprintf(buffer, "%064b.", b.set[i])
	}
	return buffer.String()
}
605496
func setbits(h *HashSet, b []byte, i int, k int) {
	h.addB(b)
	if k == 0 {
		return
	}
	for j := i; j < len(b)*8; j++ {
		b[j/8] |= byte(1 << uint(j&7))
		setbits(h, b, j+1, k-1)
		b[j/8] &= byte(^(1 << uint(j&7)))
	}
}
575732
func (e Encoder) AppendInts16(dst []byte, vals []int16) []byte {
	major := majorTypeArray
	l := len(vals)
	if l == 0 {
		return e.AppendArrayEnd(e.AppendArrayStart(dst))
	}
	if l <= additionalMax {
		lb := byte(l)
		dst = append(dst, byte(major|lb))
	} else {
		dst = appendCborTypePrefix(dst, major, uint64(l))
	}
	for _, v := range vals {
		dst = e.AppendInt(dst, int(v))
	}
	return dst
}
1259585
func (b *BitWriter) WriteBits(u uint64, nbits int) error {
	u <<= (64 - uint(nbits))
	for nbits >= 8 {
		byt := byte(u >> 56)
		err := b.WriteByte(byt)
		if err != nil {
			return err
		}
		u <<= 8
		nbits -= 8
	}

	for nbits > 0 {
		err := b.WriteBit((u >> 63) == 1)
		if err != nil {
			return err
		}
		u <<= 1
		nbits--
	}

	return nil
}
446023
func (u *ubiTweak) addBytesProcessed(value int) {
    const len = 3
    carry := uint64(value)

    var words [len]uint64

    words[0] = u.tweak[0] & 0xffffffff
    words[1] = (u.tweak[0] >> 32) & 0xffffffff
    words[2] = u.tweak[1] & 0xffffffff

    for i := 0; i < len; i++ {
        carry += words[i]
        words[i] = carry
        carry >>= 32
    }
    u.tweak[0] = words[0] & 0xffffffff
    u.tweak[0] |= (words[1] & 0xffffffff) << 32
    u.tweak[1] |= words[2] & 0xffffffff
}
275107
func (a addressType) AddrLen() uint16 {
	switch a {
	case noAddr:
		return 0
	case tcp4Addr:
		return 6
	case tcp6Addr:
		return 18
	case v2OnionAddr:
		return 12
	case v3OnionAddr:
		return 37
	default:
		return 0
	}
}
212478
func Len16(x uint16) (n int) {
	if x >= 1<<8 {
		x >>= 8
		n = 8
	}
	return n + int(len8tab[x])
}