func NewDiskIndexWriter(f *os.File) IndexWriter {
	return &directIndex{fd: f, w: bufio.NewWriterSize(f, 1024*1024)}
}
NewIndexWriter returns a new IndexWriter.
package tsm1
import (
	"bufio"
	"bytes"
	"encoding/binary"
	"fmt"
	"hash/crc32"
	"io"
	"os"
	"sort"
	"strings"
	"time"
)
const (
	MagicNumber uint32 = 0x16D116D1
	Version byte = 1
	indexEntrySize = 28
	indexCountSize = 2
	indexTypeSize = 1
	maxIndexEntries = (1 << (indexCountSize * 8)) - 1
	maxKeyLength = (1 << (2 * 8)) - 1
	fsyncEvery = 25 * 1024 * 1024
)
var (
	ErrNoValues = fmt.Errorf("no values written")
	ErrTSMClosed = fmt.Errorf("tsm file closed")
	ErrMaxKeyLengthExceeded = fmt.Errorf("max key length exceeded")
	ErrMaxBlocksExceeded = fmt.Errorf("max blocks exceeded")
)
type TSMWriter interface {
	Write(key []byte, values Values) error
	WriteBlock(key []byte, minTime, maxTime int64, block []byte) error
	WriteIndex() error
	Flush() error
	Close() error
	Size() uint32
	Remove() error
}
type IndexWriter interface {
	Add(key []byte, blockType byte, minTime, maxTime int64, offset int64, size uint32)
	Entries(key []byte) []IndexEntry
	KeyCount() int
	Size() uint32
	MarshalBinary() ([]byte, error)
	WriteTo(w io.Writer) (int64, error)
	Close() error
	Remove() error
}
type IndexEntry struct {
	MinTime, MaxTime int64
	Offset int64
	Size uint32
}
func (e *IndexEntry) UnmarshalBinary(b []byte) error {
	if len(b) < indexEntrySize {
		return fmt.Errorf("unmarshalBinary: short buf: %v < %v", len(b), indexEntrySize)
	}
	e.MinTime = int64(binary.BigEndian.Uint64(b[:8]))
	e.MaxTime = int64(binary.BigEndian.Uint64(b[8:16]))
	e.Offset = int64(binary.BigEndian.Uint64(b[16:24]))
	e.Size = binary.BigEndian.Uint32(b[24:28])
	return nil
}
func (e *IndexEntry) AppendTo(b []byte) []byte {
	if len(b) < indexEntrySize {
		if cap(b) < indexEntrySize {
			b = make([]byte, indexEntrySize)
		} else {
			b = b[:indexEntrySize]
		}
	}
	binary.BigEndian.PutUint64(b[:8], uint64(e.MinTime))
	binary.BigEndian.PutUint64(b[8:16], uint64(e.MaxTime))
	binary.BigEndian.PutUint64(b[16:24], uint64(e.Offset))
	binary.BigEndian.PutUint32(b[24:28], uint32(e.Size))
	return b
}
func (e *IndexEntry) Contains(t int64) bool {
	return e.MinTime <= t && e.MaxTime >= t
}
func (e *IndexEntry) OverlapsTimeRange(min, max int64) bool {
	return e.MinTime <= max && e.MaxTime >= min
}
func (e *IndexEntry) String() string {
	return fmt.Sprintf("min=%s max=%s ofs=%d siz=%d",
		time.Unix(0, e.MinTime).UTC(), time.Unix(0, e.MaxTime).UTC(), e.Offset, e.Size)
}
func NewIndexWriter() IndexWriter {
	buf := bytes.NewBuffer(make([]byte, 0, 1024*1024))
	return &directIndex{buf: buf, w: bufio.NewWriter(buf)}
}