func readBlock(bks *bstorage.Blocks, idx int) (*block, error) {
	buf, err := bks.Block(idx)
	if err != nil {
		return nil, errCorrupted
	}
	return &block{idx, buf, bks}, nil
}
readBlock reads block by its index idx. If the block could not be read, the error is considered
like fatal, so errCorrupted is returned
package tmindex
import (
	"fmt"
	"github.com/logrange/range/pkg/bstorage"
	"github.com/logrange/range/pkg/utils/encoding/xbinary"
	"github.com/logrange/range/pkg/utils/errors"
	"strings"
	"sync"
)
type (
	ckindex struct {
		lock  sync.Mutex
		cond  *sync.Cond
		users int
		state int
		bks   *bstorage.Blocks
	}
	block struct {
		idx int
		buf []byte
		bks *bstorage.Blocks
	}
	record struct {
		ts  int64
		idx uint32
	}
	interval struct {
		p0, p1 record
	}
)
var (
	errFullBlock  = fmt.Errorf("block is full")
	errAllMatches = fmt.Errorf("all values from the block matches the condition")
	errNoMatches  = fmt.Errorf("no matches in the block")
	errCorrupted  = fmt.Errorf("fatal error, storage is corrupted")
	emptyBlock    [blockSize]byte
)
const (
	hdrRecCountOffs = 0
	hdrLevelOffset  = 1
	hdrSize = 2
	recSize = 12
	maxRecsPerBlock      = 41
	maxIntervalsPerBlock = maxRecsPerBlock - 1
	blockSize = 512
)
const (
	stOk = iota
	stWaiting
	stWriting
	stClosed
)
var (
	stateNames = map[int]string{stOk: "Ok", stWaiting: "Waiting", stWriting: "Writing", stClosed: "Closed"}
)