// formatBits computes the string representation of u in the given base.
// If neg is set, u is treated as negative int64 value.
// Extracted from std package strconv
11212
func formatBits(dst io.Writer, u uint64, neg bool) (int, error) {

	var a = pool_integerBuffer.Get().(*byteSliceBuffer)

	i := integerBufferSize

	if neg {
		u = -u
	}

	// common case: use constants for / because
	// the compiler can optimize it into a multiply+shift

	if ^uintptr(0)>>32 == 0 {
		for u > uint64(^uintptr(0)) {
			q := u / 1e9
			us := uintptr(u - q*1e9) // us % 1e9 fits into a uintptr
			for j := 9; j > 0; j-- {
				i--
				qs := us / 10
				a.bytes[i] = byte(us - qs*10 + '0')
				us = qs
			}
			u = q
		}
	}

	// u guaranteed to fit into a uintptr
	us := uintptr(u)
	for us >= 10 {
		i--
		q := us / 10
		a.bytes[i] = byte(us - q*10 + '0')
		us = q
	}
	// u < 10
	i--
	a.bytes[i] = byte(us + '0')

	// add sign, if any
	if neg {
		i--
		a.bytes[i] = '-'
	}
	counter, err := dst.Write(a.bytes[i:])
	pool_integerBuffer.Put(a)
	return counter, err
}
195432
func CountBitsUint8s(b []uint8) int {
	c := 0
	for _, x := range b {
		c += CountBitsUint8(x)
	}
	return c
}
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)))
	}
}
895536
func (bv *BitVector) writeBits(output store.IndexOutput) error {
	return store.Stream(output).
		WriteInt(int32(bv.size)).
		WriteInt(int32(bv.Count())).
		WriteBytes(bv.bits).
		Close()
}
539822
func formatBytesDec(i int64) (result string) {
	switch {
	case i >= TB:
		result = fmt.Sprintf("%.02f TB", float64(i)/TB)
	case i >= GB:
		result = fmt.Sprintf("%.02f GB", float64(i)/GB)
	case i >= MB:
		result = fmt.Sprintf("%.02f MB", float64(i)/MB)
	case i >= KB:
		result = fmt.Sprintf("%.02f KB", float64(i)/KB)
	default:
		result = fmt.Sprintf("%d B", i)
	}
	return
}
905481
func EncodeBits(dst, src []byte, bits int) int {
	if bits < 0 {
		return 0
	}
	return encode(dst, src, bits)
}
111667
func (b *Bitset) Bits() []bool {
	result := make([]bool, b.numBits)

	var i int
	for i = 0; i < b.numBits; i++ {
		result[i] = (b.bits[i/8] & (0x80 >> byte(i%8))) != 0
	}

	return result
}
1277426
func FormatDMS(l float64) string {
	val := math.Abs(l)
	degrees := int(math.Floor(val))
	minutes := int(math.Floor(60 * (val - float64(degrees))))
	seconds := 3600 * (val - float64(degrees) - (float64(minutes) / 60))
	return fmt.Sprintf("%d\u00B0 %d' %f\"", degrees, minutes, seconds)
}
503341
func (d *dataEncoder) charCountBits(dataMode dataMode) int {
	switch dataMode {
	case dataModeNumeric:
		return d.numNumericCharCountBits
	case dataModeAlphanumeric:
		return d.numAlphanumericCharCountBits
	case dataModeByte:
		return d.numByteCharCountBits
	default:
		log.Panic("Unknown data mode")
	}

	return 0
}
187234
func CountBitsUint16s(b []uint16) int {
	c := 0
	for _, x := range b {
		c += CountBitsUint16(x)
	}
	return c
}
1166551
func StringsToInt64s(strs []string) []int64 {
	ints := make([]int64, len(strs))
	for i := range strs {
		ints[i] = com.StrTo(strs[i]).MustInt64()
	}
	return ints
}
965988
func Int64s(b0, b1 []int64) int {
	d := 0
	for i, x := range b0 {
		d += Int64(x, b1[i])
	}
	return d
}
657874
func FormatUUID(part string) (string, error) {
	if len(part) < 1 {
		return "", fmt.Errorf("Empty UUID")
	}
	if len(part) < 32 {
		part = strings.Repeat(part, 32)
	}
	if len(part) > 32 {
		part = part[:32]
	}
	uuid := part[:8] + "-" + part[8:12] + "-1" + part[13:16] + "-" + part[16:20] + "-" + part[20:32]

	err := IsUUID(uuid)
	if err != nil {
		return "", err
	}

	return uuid, nil
}
933956
func Uint16s(b0, b1 []uint16) int {
	d := 0
	for i, x := range b0 {
		d += Uint16(x, b1[i])
	}
	return d
}
848288
func (r *Reader) ReadBits(n uint) (Block, error) {
	if r.Err != nil {
		return 0, r.Err
	}

	if b, err := r.src.Get(r.position, n); err != nil {
		r.Err = errors.WithMessage(err, fmt.Sprintf("read bits (index=%d, length=%d)", r.position, n))
		return 0, r.Err
	} else {
		r.position += n
		return b, nil
	}
}
811516
func FormatGPS(l float64) string {
	padding := ""
	degrees := math.Floor(math.Abs(l))
	fraction := (math.Abs(l) - degrees) * 60
	if fraction < 10 {
		padding = "0"
	}
	return fmt.Sprintf("%d%s%.4f", int(degrees), padding, fraction)
}
237237
func (r *reader) readBitsAsBytes(n uint32) []byte {
	tmp := make([]byte, 0)
	for n >= 8 {
		tmp = append(tmp, r.readByte())
		n -= 8
	}
	if n > 0 {
		tmp = append(tmp, byte(r.readBits(n)))
	}
	return tmp
}