func (a UnsignedValues) Include(min, max int64) UnsignedValues {
	rmin, rmax := a.FindRange(min, max)
	if rmin == -1 && rmax == -1 {
		return nil
	}
	if rmax < len(a) && a[rmax].UnixNano() == max {
		rmax++
	}
	if rmin > -1 {
		b := a[:rmax-rmin]
		copy(b, a[rmin:rmax])
		return b
	}
	return a[:rmax]
}
Include returns the subset values between min and max inclusive. The values must
be deduplicated and sorted before calling Exclude or the results are undefined.
package tsm1
import (
	"fmt"
	"sort"
)
type Values []Value
func (a Values) MinTime() int64 {
	return a[0].UnixNano()
}
func (a Values) MaxTime() int64 {
	return a[len(a)-1].UnixNano()
}
func (a Values) Size() int {
	sz := 0
	for _, v := range a {
		sz += v.Size()
	}
	return sz
}
func (a Values) ordered() bool {
	if len(a) <= 1 {
		return true
	}
	for i := 1; i < len(a); i++ {
		if av, ab := a[i-1].UnixNano(), a[i].UnixNano(); av >= ab {
			return false
		}
	}
	return true
}
func (a Values) assertOrdered() {
	if len(a) <= 1 {
		return
	}
	for i := 1; i < len(a); i++ {
		if av, ab := a[i-1].UnixNano(), a[i].UnixNano(); av >= ab {
			panic(fmt.Sprintf("not ordered: %d %d >= %d", i, av, ab))
		}
	}
}
func (a Values) Deduplicate() Values {
	if len(a) <= 1 {
		return a
	}
	var needSort bool
	for i := 1; i < len(a); i++ {
		if a[i-1].UnixNano() >= a[i].UnixNano() {
			needSort = true
			break
		}
	}
	if !needSort {
		return a
	}
	sort.Stable(a)
	var i int
	for j := 1; j < len(a); j++ {
		v := a[j]
		if v.UnixNano() != a[i].UnixNano() {
			i++
		}
		a[i] = v
	}
	return a[:i+1]
}
func (a Values) Exclude(min, max int64) Values {
	rmin, rmax := a.FindRange(min, max)
	if rmin == -1 && rmax == -1 {
		return a
	}
	if rmax < len(a) {
		if a[rmax].UnixNano() == max {
			rmax++
		}
		rest := len(a) - rmax
		if rest > 0 {
			b := a[:rmin+rest]
			copy(b[rmin:], a[rmax:])
			return b
		}
	}
	return a[:rmin]
}
func (a Values) Include(min, max int64) Values {
	rmin, rmax := a.FindRange(min, max)
	if rmin == -1 && rmax == -1 {
		return nil
	}
	if rmax < len(a) && a[rmax].UnixNano() == max {
		rmax++
	}
	if rmin > -1 {
		b := a[:rmax-rmin]
		copy(b, a[rmin:rmax])
		return b
	}
	return a[:rmax]
}
func (a Values) search(v int64) int {
	lo := 0
	hi := len(a)
	for lo < hi {
		mid := int(uint(lo+hi) >> 1)
		if a[mid].UnixNano() < v {
			lo = mid + 1  
		} else {
			hi = mid  
		}
	}
	return lo
}
func (a Values) FindRange(min, max int64) (int, int) {
	if len(a) == 0 || min > max {
		return -1, -1
	}
	minVal := a[0].UnixNano()
	maxVal := a[len(a)-1].UnixNano()
	if maxVal < min || minVal > max {
		return -1, -1
	}
	return a.search(min), a.search(max)
}
func (a Values) Merge(b Values) Values {
	if len(a) == 0 {
		return b
	}
	if len(b) == 0 {
		return a
	}
	a = a.Deduplicate()
	b = b.Deduplicate()
	if a[len(a)-1].UnixNano() < b[0].UnixNano() {
		return append(a, b...)
	}
	if b[len(b)-1].UnixNano() < a[0].UnixNano() {
		return append(b, a...)
	}
	out := make(Values, 0, len(a)+len(b))
	for len(a) > 0 && len(b) > 0 {
		if a[0].UnixNano() < b[0].UnixNano() {
			out, a = append(out, a[0]), a[1:]
		} else if len(b) > 0 && a[0].UnixNano() == b[0].UnixNano() {
			a = a[1:]
		} else {
			out, b = append(out, b[0]), b[1:]
		}
	}
	if len(a) > 0 {
		return append(out, a...)
	}
	return append(out, b...)
}
func (a Values) Len() int           { return len(a) }
func (a Values) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a Values) Less(i, j int) bool { return a[i].UnixNano() < a[j].UnixNano() }
type FloatValues []FloatValue
func (a FloatValues) MinTime() int64 {
	return a[0].UnixNano()
}
func (a FloatValues) MaxTime() int64 {
	return a[len(a)-1].UnixNano()
}
func (a FloatValues) Size() int {
	sz := 0
	for _, v := range a {
		sz += v.Size()
	}
	return sz
}
func (a FloatValues) ordered() bool {
	if len(a) <= 1 {
		return true
	}
	for i := 1; i < len(a); i++ {
		if av, ab := a[i-1].UnixNano(), a[i].UnixNano(); av >= ab {
			return false
		}
	}
	return true
}
func (a FloatValues) assertOrdered() {
	if len(a) <= 1 {
		return
	}
	for i := 1; i < len(a); i++ {
		if av, ab := a[i-1].UnixNano(), a[i].UnixNano(); av >= ab {
			panic(fmt.Sprintf("not ordered: %d %d >= %d", i, av, ab))
		}
	}
}
func (a FloatValues) Deduplicate() FloatValues {
	if len(a) <= 1 {
		return a
	}
	var needSort bool
	for i := 1; i < len(a); i++ {
		if a[i-1].UnixNano() >= a[i].UnixNano() {
			needSort = true
			break
		}
	}
	if !needSort {
		return a
	}
	sort.Stable(a)
	var i int
	for j := 1; j < len(a); j++ {
		v := a[j]
		if v.UnixNano() != a[i].UnixNano() {
			i++
		}
		a[i] = v
	}
	return a[:i+1]
}
func (a FloatValues) Exclude(min, max int64) FloatValues {
	rmin, rmax := a.FindRange(min, max)
	if rmin == -1 && rmax == -1 {
		return a
	}
	if rmax < len(a) {
		if a[rmax].UnixNano() == max {
			rmax++
		}
		rest := len(a) - rmax
		if rest > 0 {
			b := a[:rmin+rest]
			copy(b[rmin:], a[rmax:])
			return b
		}
	}
	return a[:rmin]
}
func (a FloatValues) Include(min, max int64) FloatValues {
	rmin, rmax := a.FindRange(min, max)
	if rmin == -1 && rmax == -1 {
		return nil
	}
	if rmax < len(a) && a[rmax].UnixNano() == max {
		rmax++
	}
	if rmin > -1 {
		b := a[:rmax-rmin]
		copy(b, a[rmin:rmax])
		return b
	}
	return a[:rmax]
}
func (a FloatValues) search(v int64) int {
	lo := 0
	hi := len(a)
	for lo < hi {
		mid := int(uint(lo+hi) >> 1)
		if a[mid].UnixNano() < v {
			lo = mid + 1  
		} else {
			hi = mid  
		}
	}
	return lo
}
func (a FloatValues) FindRange(min, max int64) (int, int) {
	if len(a) == 0 || min > max {
		return -1, -1
	}
	minVal := a[0].UnixNano()
	maxVal := a[len(a)-1].UnixNano()
	if maxVal < min || minVal > max {
		return -1, -1
	}
	return a.search(min), a.search(max)
}
func (a FloatValues) Merge(b FloatValues) FloatValues {
	if len(a) == 0 {
		return b
	}
	if len(b) == 0 {
		return a
	}
	a = a.Deduplicate()
	b = b.Deduplicate()
	if a[len(a)-1].UnixNano() < b[0].UnixNano() {
		return append(a, b...)
	}
	if b[len(b)-1].UnixNano() < a[0].UnixNano() {
		return append(b, a...)
	}
	out := make(FloatValues, 0, len(a)+len(b))
	for len(a) > 0 && len(b) > 0 {
		if a[0].UnixNano() < b[0].UnixNano() {
			out, a = append(out, a[0]), a[1:]
		} else if len(b) > 0 && a[0].UnixNano() == b[0].UnixNano() {
			a = a[1:]
		} else {
			out, b = append(out, b[0]), b[1:]
		}
	}
	if len(a) > 0 {
		return append(out, a...)
	}
	return append(out, b...)
}
func (a FloatValues) Encode(buf []byte) ([]byte, error) {
	return encodeFloatValuesBlock(buf, a)
}
func encodeFloatValuesBlock(buf []byte, values []FloatValue) ([]byte, error) {
	if len(values) == 0 {
		return nil, nil
	}
	venc := getFloatEncoder(len(values))
	tsenc := getTimeEncoder(len(values))
	var b []byte
	err := func() error {
		for _, v := range values {
			tsenc.Write(v.unixnano)
			venc.Write(v.value)
		}
		venc.Flush()
		tb, err := tsenc.Bytes()
		if err != nil {
			return err
		}
		vb, err := venc.Bytes()
		if err != nil {
			return err
		}
		b = packBlock(buf, BlockFloat64, tb, vb)
		return nil
	}()
	putTimeEncoder(tsenc)
	putFloatEncoder(venc)
	return b, err
}
func (a FloatValues) Len() int           { return len(a) }
func (a FloatValues) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a FloatValues) Less(i, j int) bool { return a[i].UnixNano() < a[j].UnixNano() }
type IntegerValues []IntegerValue
func (a IntegerValues) MinTime() int64 {
	return a[0].UnixNano()
}
func (a IntegerValues) MaxTime() int64 {
	return a[len(a)-1].UnixNano()
}
func (a IntegerValues) Size() int {
	sz := 0
	for _, v := range a {
		sz += v.Size()
	}
	return sz
}
func (a IntegerValues) ordered() bool {
	if len(a) <= 1 {
		return true
	}
	for i := 1; i < len(a); i++ {
		if av, ab := a[i-1].UnixNano(), a[i].UnixNano(); av >= ab {
			return false
		}
	}
	return true
}
func (a IntegerValues) assertOrdered() {
	if len(a) <= 1 {
		return
	}
	for i := 1; i < len(a); i++ {
		if av, ab := a[i-1].UnixNano(), a[i].UnixNano(); av >= ab {
			panic(fmt.Sprintf("not ordered: %d %d >= %d", i, av, ab))
		}
	}
}
func (a IntegerValues) Deduplicate() IntegerValues {
	if len(a) <= 1 {
		return a
	}
	var needSort bool
	for i := 1; i < len(a); i++ {
		if a[i-1].UnixNano() >= a[i].UnixNano() {
			needSort = true
			break
		}
	}
	if !needSort {
		return a
	}
	sort.Stable(a)
	var i int
	for j := 1; j < len(a); j++ {
		v := a[j]
		if v.UnixNano() != a[i].UnixNano() {
			i++
		}
		a[i] = v
	}
	return a[:i+1]
}
func (a IntegerValues) Exclude(min, max int64) IntegerValues {
	rmin, rmax := a.FindRange(min, max)
	if rmin == -1 && rmax == -1 {
		return a
	}
	if rmax < len(a) {
		if a[rmax].UnixNano() == max {
			rmax++
		}
		rest := len(a) - rmax
		if rest > 0 {
			b := a[:rmin+rest]
			copy(b[rmin:], a[rmax:])
			return b
		}
	}
	return a[:rmin]
}
func (a IntegerValues) Include(min, max int64) IntegerValues {
	rmin, rmax := a.FindRange(min, max)
	if rmin == -1 && rmax == -1 {
		return nil
	}
	if rmax < len(a) && a[rmax].UnixNano() == max {
		rmax++
	}
	if rmin > -1 {
		b := a[:rmax-rmin]
		copy(b, a[rmin:rmax])
		return b
	}
	return a[:rmax]
}
func (a IntegerValues) search(v int64) int {
	lo := 0
	hi := len(a)
	for lo < hi {
		mid := int(uint(lo+hi) >> 1)
		if a[mid].UnixNano() < v {
			lo = mid + 1  
		} else {
			hi = mid  
		}
	}
	return lo
}
func (a IntegerValues) FindRange(min, max int64) (int, int) {
	if len(a) == 0 || min > max {
		return -1, -1
	}
	minVal := a[0].UnixNano()
	maxVal := a[len(a)-1].UnixNano()
	if maxVal < min || minVal > max {
		return -1, -1
	}
	return a.search(min), a.search(max)
}
func (a IntegerValues) Merge(b IntegerValues) IntegerValues {
	if len(a) == 0 {
		return b
	}
	if len(b) == 0 {
		return a
	}
	a = a.Deduplicate()
	b = b.Deduplicate()
	if a[len(a)-1].UnixNano() < b[0].UnixNano() {
		return append(a, b...)
	}
	if b[len(b)-1].UnixNano() < a[0].UnixNano() {
		return append(b, a...)
	}
	out := make(IntegerValues, 0, len(a)+len(b))
	for len(a) > 0 && len(b) > 0 {
		if a[0].UnixNano() < b[0].UnixNano() {
			out, a = append(out, a[0]), a[1:]
		} else if len(b) > 0 && a[0].UnixNano() == b[0].UnixNano() {
			a = a[1:]
		} else {
			out, b = append(out, b[0]), b[1:]
		}
	}
	if len(a) > 0 {
		return append(out, a...)
	}
	return append(out, b...)
}
func (a IntegerValues) Encode(buf []byte) ([]byte, error) {
	return encodeIntegerValuesBlock(buf, a)
}
func encodeIntegerValuesBlock(buf []byte, values []IntegerValue) ([]byte, error) {
	if len(values) == 0 {
		return nil, nil
	}
	venc := getIntegerEncoder(len(values))
	tsenc := getTimeEncoder(len(values))
	var b []byte
	err := func() error {
		for _, v := range values {
			tsenc.Write(v.unixnano)
			venc.Write(v.value)
		}
		venc.Flush()
		tb, err := tsenc.Bytes()
		if err != nil {
			return err
		}
		vb, err := venc.Bytes()
		if err != nil {
			return err
		}
		b = packBlock(buf, BlockInteger, tb, vb)
		return nil
	}()
	putTimeEncoder(tsenc)
	putIntegerEncoder(venc)
	return b, err
}
func (a IntegerValues) Len() int           { return len(a) }
func (a IntegerValues) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a IntegerValues) Less(i, j int) bool { return a[i].UnixNano() < a[j].UnixNano() }
type UnsignedValues []UnsignedValue
func (a UnsignedValues) MinTime() int64 {
	return a[0].UnixNano()
}
func (a UnsignedValues) MaxTime() int64 {
	return a[len(a)-1].UnixNano()
}
func (a UnsignedValues) Size() int {
	sz := 0
	for _, v := range a {
		sz += v.Size()
	}
	return sz
}
func (a UnsignedValues) ordered() bool {
	if len(a) <= 1 {
		return true
	}
	for i := 1; i < len(a); i++ {
		if av, ab := a[i-1].UnixNano(), a[i].UnixNano(); av >= ab {
			return false
		}
	}
	return true
}
func (a UnsignedValues) assertOrdered() {
	if len(a) <= 1 {
		return
	}
	for i := 1; i < len(a); i++ {
		if av, ab := a[i-1].UnixNano(), a[i].UnixNano(); av >= ab {
			panic(fmt.Sprintf("not ordered: %d %d >= %d", i, av, ab))
		}
	}
}
func (a UnsignedValues) Deduplicate() UnsignedValues {
	if len(a) <= 1 {
		return a
	}
	var needSort bool
	for i := 1; i < len(a); i++ {
		if a[i-1].UnixNano() >= a[i].UnixNano() {
			needSort = true
			break
		}
	}
	if !needSort {
		return a
	}
	sort.Stable(a)
	var i int
	for j := 1; j < len(a); j++ {
		v := a[j]
		if v.UnixNano() != a[i].UnixNano() {
			i++
		}
		a[i] = v
	}
	return a[:i+1]
}
func (a UnsignedValues) Exclude(min, max int64) UnsignedValues {
	rmin, rmax := a.FindRange(min, max)
	if rmin == -1 && rmax == -1 {
		return a
	}
	if rmax < len(a) {
		if a[rmax].UnixNano() == max {
			rmax++
		}
		rest := len(a) - rmax
		if rest > 0 {
			b := a[:rmin+rest]
			copy(b[rmin:], a[rmax:])
			return b
		}
	}
	return a[:rmin]
}