func newChecker(o *storage.LookupOptions, op *predicate.Predicate) *checker {
	var ta *time.Time
	if op != nil {
		if t, err := op.TimeAnchor(); err == nil {
			ta = t
		}
	}
	return &checker{
		max:            o.MaxElements > 0,
		pageSize:       o.MaxElements,
		paddedPageSize: o.MaxElements * o.Offset,
		o:              o,
		op:             op,
		ota:            ta,
	}
}
newChecker creates a new checker for a given LookupOptions configuration.
package memory
import (
	"context"
	"fmt"
	"sort"
	"sync"
	"time"
	"github.com/google/badwolf/bql/planner/filter"
	"github.com/google/badwolf/storage"
	"github.com/google/badwolf/triple"
	"github.com/google/badwolf/triple/node"
	"github.com/google/badwolf/triple/predicate"
)
const initialAllocation = 10000
var DefaultStore storage.Store
func init() {
	DefaultStore = NewStore()
}
type memoryStore struct {
	graphs map[string]storage.Graph
	rwmu   sync.RWMutex
}
func NewStore() storage.Store {
	return &memoryStore{
		graphs: make(map[string]storage.Graph),
	}
}
func (s *memoryStore) Name(ctx context.Context) string {
	return "VOLATILE"
}
func (s *memoryStore) Version(ctx context.Context) string {
	return "0.2.vcli"
}
func (s *memoryStore) NewGraph(ctx context.Context, id string) (storage.Graph, error) {
	g := &memory{
		id:    id,
		idx:   make(map[string]*triple.Triple, initialAllocation),
		idxS:  make(map[string]map[string]*triple.Triple, initialAllocation),
		idxP:  make(map[string]map[string]*triple.Triple, initialAllocation),
		idxO:  make(map[string]map[string]*triple.Triple, initialAllocation),
		idxSP: make(map[string]map[string]*triple.Triple, initialAllocation),
		idxPO: make(map[string]map[string]*triple.Triple, initialAllocation),
		idxSO: make(map[string]map[string]*triple.Triple, initialAllocation),
	}
	s.rwmu.Lock()
	defer s.rwmu.Unlock()
	if _, ok := s.graphs[id]; ok {
		return nil, fmt.Errorf("memory.NewGraph(%q): graph already exists", id)
	}
	s.graphs[id] = g
	return g, nil
}
func (s *memoryStore) Graph(ctx context.Context, id string) (storage.Graph, error) {
	s.rwmu.RLock()
	defer s.rwmu.RUnlock()
	if g, ok := s.graphs[id]; ok {
		return g, nil
	}
	return nil, fmt.Errorf("memory.Graph(%q): graph does not exist", id)
}
func (s *memoryStore) DeleteGraph(ctx context.Context, id string) error {
	s.rwmu.Lock()
	defer s.rwmu.Unlock()
	if _, ok := s.graphs[id]; ok {
		delete(s.graphs, id)
		return nil
	}
	return fmt.Errorf("memory.DeleteGraph(%q): graph does not exist", id)
}
func (s *memoryStore) GraphNames(ctx context.Context, names chan<- string) error {
	if names == nil {
		return fmt.Errorf("cannot provide an empty channel")
	}
	s.rwmu.RLock()
	defer s.rwmu.RUnlock()
	for k := range s.graphs {
		names <- k
	}
	close(names)
	return nil
}
type memory struct {
	id    string
	rwmu  sync.RWMutex
	idx   map[string]*triple.Triple
	idxS  map[string]map[string]*triple.Triple
	idxP  map[string]map[string]*triple.Triple
	idxO  map[string]map[string]*triple.Triple
	idxSP map[string]map[string]*triple.Triple
	idxPO map[string]map[string]*triple.Triple
	idxSO map[string]map[string]*triple.Triple
}
func (m *memory) ID(ctx context.Context) string {
	return m.id
}
func (m *memory) AddTriples(ctx context.Context, ts []*triple.Triple) error {
	m.rwmu.Lock()
	defer m.rwmu.Unlock()
	for _, t := range ts {
		tuuid := UUIDToByteString(t.UUID())
		sUUID := UUIDToByteString(t.Subject().UUID())
		pUUID := UUIDToByteString(t.Predicate().PartialUUID())
		oUUID := UUIDToByteString(t.Object().UUID())
		m.idx[tuuid] = t
		if _, ok := m.idxS[sUUID]; !ok {
			m.idxS[sUUID] = make(map[string]*triple.Triple)
		}
		m.idxS[sUUID][tuuid] = t
		if _, ok := m.idxP[pUUID]; !ok {
			m.idxP[pUUID] = make(map[string]*triple.Triple)
		}
		m.idxP[pUUID][tuuid] = t
		if _, ok := m.idxO[oUUID]; !ok {
			m.idxO[oUUID] = make(map[string]*triple.Triple)
		}
		m.idxO[oUUID][tuuid] = t
		key := sUUID + pUUID
		if _, ok := m.idxSP[key]; !ok {
			m.idxSP[key] = make(map[string]*triple.Triple)
		}
		m.idxSP[key][tuuid] = t
		key = pUUID + oUUID
		if _, ok := m.idxPO[key]; !ok {
			m.idxPO[key] = make(map[string]*triple.Triple)
		}
		m.idxPO[key][tuuid] = t
		key = sUUID + oUUID
		if _, ok := m.idxSO[key]; !ok {
			m.idxSO[key] = make(map[string]*triple.Triple)
		}
		m.idxSO[key][tuuid] = t
	}
	return nil
}
func (m *memory) RemoveTriples(ctx context.Context, ts []*triple.Triple) error {
	for _, t := range ts {
		suuid := UUIDToByteString(t.UUID())
		sUUID := UUIDToByteString(t.Subject().UUID())
		pUUID := UUIDToByteString(t.Predicate().PartialUUID())
		oUUID := UUIDToByteString(t.Object().UUID())
		m.rwmu.Lock()
		delete(m.idx, suuid)
		delete(m.idxS[sUUID], suuid)
		delete(m.idxP[pUUID], suuid)
		delete(m.idxO[oUUID], suuid)
		key := sUUID + pUUID
		delete(m.idxSP[key], suuid)
		if len(m.idxSP[key]) == 0 {
			delete(m.idxSP, key)
		}
		key = pUUID + oUUID
		delete(m.idxPO[key], suuid)
		if len(m.idxPO[key]) == 0 {
			delete(m.idxPO, key)
		}
		key = sUUID + oUUID
		delete(m.idxSO[key], suuid)
		if len(m.idxSO[key]) == 0 {
			delete(m.idxSO, key)
		}
		m.rwmu.Unlock()
	}
	return nil
}
type checker struct {
	max            bool
	pageSize       int
	paddedPageSize int
	o              *storage.LookupOptions
	op             *predicate.Predicate
	ota            *time.Time
}