// getBitsFast requires that at least one bit is requested every time.
// There are no checks if the buffer is filled.
329145
func (b *bitReader) getBitsFast(n uint8) uint16 {
	const regMask = 64 - 1
	v := uint16((b.value << (b.bitsRead & regMask)) >> ((regMask + 1 - n) & regMask))
	b.bitsRead += n
	return v
}
1258560
func (sba *sparseBitArray) GetBit(k uint64) (bool, error) {
	index, position := getIndexAndRemainder(k)
	i := sba.indices.get(index)
	if i == -1 {
		return false, nil
	}

	return sba.blocks[i].get(position), nil
}
320412
func (d *Context) GetBuffer(index int) (rawPtr unsafe.Pointer, outSize uint) {
	rawPtr = C.duk_get_buffer(d.duk_context, C.duk_idx_t(index), (*C.duk_size_t)(unsafe.Pointer(&outSize)))
	return rawPtr, outSize
}
1148838
func (bl *BitList) GetBytes() []byte {
	len := bl.count >> 3
	if (bl.count % 8) != 0 {
		len++
	}
	result := make([]byte, len)
	for i := 0; i < len; i++ {
		shift := (3 - (i % 4)) * 8
		result[i] = (byte)((bl.data[i/4] >> uint(shift)) & 0xFF)
	}
	return result
}
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
}
34992
func getBytes(f *flag.Flag) (int64, error) {
	var res map[string]interface{}
	// Use NATS parser to do the conversion for us.
	res, err := conf.Parse(fmt.Sprintf("bytes: %v", f.Value.String()))
	if err != nil {
		return 0, err
	}
	resVal := res["bytes"]
	if resVal == nil || reflect.TypeOf(resVal).Kind() != reflect.Int64 {
		return 0, fmt.Errorf("%v should be a size, got '%v'", f.Name, resVal)
	}
	return resVal.(int64), nil
}
628952
func (b *BitReader) ReadBit() (Bit, error) {
	if b.count == 0 {
		if n, err := b.r.Read(b.b[:]); n != 1 || (err != nil && err != io.EOF) {
			return Zero, err
		}
		b.count = 8
	}
	b.count--
	d := (b.b[0] & 0x80)
	b.b[0] <<= 1
	return d != 0, nil
}
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
}
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
}
194015
func getIfSocket() (fd int, err error) {
	for _, socket := range []int{
		syscall.AF_INET,
		syscall.AF_PACKET,
		syscall.AF_INET6,
	} {
		if fd, err = syscall.Socket(socket, syscall.SOCK_DGRAM, 0); err == nil {
			break
		}
	}
	if err == nil {
		return fd, nil
	}
	return -1, err
}
1104802
func (c *Contract) GetByte(n uint64) byte {
	if n < uint64(len(c.Code)) {
		return c.Code[n]
	}

	return 0
}
1364180
func (b *BitSet) Get(o int) bool {
	bucketID := o / 8
	oInBucket := uint8(o % 8)
	if o >= b.size {
		return false
	}
	return (b.set[bucketID]&(0x1<<oInBucket))>>oInBucket == 0x1
}
939330
func (this *MBRPartition) GetLBALast() uint32 {
	last := uint64(this.GetLBAStart()) + uint64(this.GetLBALen()) - 1

	// If last > max uint32 - panic
	if last > uint64(0xFFFFFFFF) {
		panic(errors.New("Overflow while calc last sector. Max sector number in mbr must be less or equal 0xFFFFFFFF"))
	}
	return uint32(last)
}
1008436
func CountBitsInts(b []int) int {
	c := 0
	for _, x := range b {
		c += CountBitsInt(x)
	}
	return c
}
1288229
func GetFSTOutput(fst *FST, input []byte) (output interface{}, err error) {
	if fst.inputType != INPUT_TYPE_BYTE1 {
		panic("assert fail")
	}
	fstReader := fst.BytesReader()
	// TODO: would be nice not to alloc this on every lookup
	arc := fst.FirstArc(&Arc{})

	// Accumulate output as we go
	output = fst.outputs.NoOutput()
	for _, v := range input {
		ret, err := fst.FindTargetArc(int(v), arc, arc, fstReader)
		if ret == nil || err != nil {
			return ret, err
		}
		output = fst.outputs.Add(output, arc.Output)
	}

	if arc.IsFinal() {
		return fst.outputs.Add(output, arc.NextFinalOutput), nil
	} else {
		return nil, nil
	}
}
1293075
func (bf BitField) CountSet() (ret uint32) {
	for _, b := range bf.data {
		if b != 0 {
			ret += uint32(bitCount[b])
		}
	}
	return ret
}
110195
func getBits(min, max, step uint) uint64 {
	var bits uint64

	// If step is 1, use shifts.
	if step == 1 {
		return ^(math.MaxUint64 << (max + 1)) & (math.MaxUint64 << min)
	}

	// Else, use a simple loop.
	for i := min; i <= max; i += step {
		bits |= 1 << i
	}
	return bits
}