func toVOffset(offset bgzf.Offset) uint64 {
	return uint64(offset.File)<<16 | uint64(offset.Block)
}
toVOffset takes a bgzf.Offset and returns a uint64 voffset.
package bam
import (
	"bytes"
	"encoding/binary"
	"fmt"
	"io"
	"sort"
	"github.com/grailbio/hts/bgzf"
	"github.com/grailbio/hts/sam"
	"github.com/klauspost/compress/gzip"
)
const (
	maxRecordSize = 0xffffff
)
type GIndex []GIndexEntry
var gbaiMagic = []byte{
	'G', 'B', 'A', 'I', 0x01, 0xf1, 0x78, 0x5c,
	0x7b, 0xcb, 0xc1, 0xba, 0x08, 0x23, 0xb1, 0x19,
}
type GIndexEntry struct {
	RefID   int32
	Pos     int32
	Seq     uint32
	VOffset uint64
}
func (idx *GIndex) RecordOffset(refID, pos int32, seq uint32) bgzf.Offset {
	if len(*idx) < 1 {
		panic("GIndex must have at least one entry")
	}
	target := GIndexEntry{refID, pos, seq, 0}
	x := sort.Search(len(*idx), func(i int) bool {
		return comparePos(&(*idx)[i], &target) >= 0
	})
	if x == len(*idx) {
		return ToBGZFOffset((*idx)[x-1].VOffset)
	}
	if comparePos(&(*idx)[x], &target) > 0 {
		if x > 0 {
			x--
		}
	}
	return ToBGZFOffset((*idx)[x].VOffset)
}
func (idx *GIndex) UnmappedOffset() bgzf.Offset {
	return idx.RecordOffset(-1, 0, 0)
}
func ToBGZFOffset(voffset uint64) bgzf.Offset {
	return bgzf.Offset{int64(voffset >> 16), uint16(voffset & 0xffff)}
}