index

package
v0.0.0-...-e82adf8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2017 License: MIT Imports: 12 Imported by: 11

Documentation

Index

Constants

View Source
const (
	Eavt = Type("eavt")
	Aevt = Type("aevt")
	Avet = Type("avet")
	Vaet = Type("vaet")
)

Variables

View Source
var (
	MinValue = Value{Min, nil}
	MaxValue = Value{Max, nil}
)
View Source
var MemoryReadHandlers = map[string]fressian.ReadHandler{
	"mu.memory.Index": func(r *fressian.Reader, tag string, fieldCount int) interface{} {
		datomsRaw, _ := r.ReadValue()
		datoms := datomsRaw.(*btset.Set)
		return &MemoryIndex{datoms}
	},
	"btset.Set":         btset.ReadHandlers["btset.Set"],
	"btset.PointerNode": btset.ReadHandlers["btset.PointerNode"],
	"btset.LeafNode":    btset.ReadHandlers["btset.LeafNode"],
}
View Source
var MemoryWriteHandler fressian.WriteHandler = func(w *fressian.Writer, val interface{}) error {
	switch val := val.(type) {
	case *MemoryIndex:
		return w.WriteExt("mu.memory.Index", val.datoms)
	case *MergedIndex:
		return w.WriteExt("mu.memory.Index", val.memory.datoms)
	default:
		return defaultHandler(w, val)
	}
}
View Source
var MinDatom = Datom{0, 0, MinValue, 0, false}
View Source
var ReadHandlers = map[string]fressian.ReadHandler{
	"mu.Datom": func(r *fressian.Reader, tag string, fieldCount int) interface{} {
		entityRaw, _ := r.ReadValue()
		attributeRaw, _ := r.ReadValue()
		valueRaw, _ := r.ReadValue()
		addedRaw, _ := r.ReadValue()
		transactionRaw, _ := r.ReadValue()
		return &Datom{
			entityRaw.(int),
			attributeRaw.(int),
			NewValue(valueRaw),
			txOffset + transactionRaw.(int),
			addedRaw.(bool),
		}
	},
}
View Source
var SegmentReadHandlers = map[string]fressian.ReadHandler{
	"index-root-node": func(r *fressian.Reader, tag string, fieldCount int) interface{} {
		tData, _ := r.ReadValue()
		directoriesRaw, _ := r.ReadValue()

		directories := make([]string, len(directoriesRaw.([]interface{})))
		for i, dir := range directoriesRaw.([]interface{}) {
			directories[i] = dir.(fressian.UUID).String()
		}
		return Root{
			tData:       tData.(TransposedData),
			directories: directories,
		}
	},
	"index-tdata": func(r *fressian.Reader, tag string, fieldCount int) interface{} {
		vs, _ := r.ReadValue()
		es, _ := r.ReadValue()
		as, _ := r.ReadValue()
		txs, _ := r.ReadValue()
		addeds, _ := r.ReadValue()
		transactions := make([]int, len(txs.([]int)))
		for i, tx := range txs.([]int) {
			transactions[i] = 3*(1<<42) + tx
		}
		var values []interface{}
		if values != nil {
			values = vs.([]interface{})
		}
		return TransposedData{
			entities:     es.([]int),
			attributes:   as.([]int),
			values:       values,
			transactions: transactions,
			addeds:       addeds.([]bool),
		}
	},
	"index-dir-node": func(r *fressian.Reader, tag string, fieldCount int) interface{} {
		tData, _ := r.ReadValue()
		segmentsRaw, _ := r.ReadValue()
		mystery1, _ := r.ReadValue()
		mystery2, _ := r.ReadValue()

		segments := make([]string, len(segmentsRaw.([]interface{})))
		for i, dir := range segmentsRaw.([]interface{}) {
			segments[i] = dir.(fressian.UUID).String()
		}
		return Directory{
			tData:    tData.(TransposedData),
			segments: segments,
			mystery1: mystery1.([]int),
			mystery2: mystery2.([]int),
		}
	},
}
View Source
var WriteHandler fressian.WriteHandler = func(w *fressian.Writer, val interface{}) error {
	switch val := val.(type) {
	case *Datom:
		return w.WriteExt("mu.Datom", val.entity, val.attribute, val.value, val.added, val.transaction%txOffset)
	case Value:
		return w.WriteValue(val.val)
	default:
		return fressian.DefaultHandler(w, val)
	}

}

Functions

func CompareAevt

func CompareAevt(ai, bi interface{}) int

func CompareAevtIndex

func CompareAevtIndex(tData TransposedData, idx int, datom Datom) int

func CompareAvet

func CompareAvet(ai, bi interface{}) int

func CompareAvetIndex

func CompareAvetIndex(tData TransposedData, idx int, datom Datom) int

func CompareEavt

func CompareEavt(ai, bi interface{}) int

func CompareEavtIndex

func CompareEavtIndex(tData TransposedData, idx int, datom Datom) int

func CompareVaet

func CompareVaet(ai, bi interface{}) int

func CompareVaetIndex

func CompareVaetIndex(tData TransposedData, idx int, datom Datom) int

func GetFromCache

func GetFromCache(store store.Store, id string) interface{}

func SegmentWriteHandler

func SegmentWriteHandler(w *fressian.Writer, val interface{}) error

Types

type Cache

type Cache interface {
	Get(id string) (interface{}, bool)
	Put(id string, val interface{})
}

type CompareFn

type CompareFn func(tData TransposedData, idx int, datom Datom) int

type Datom

type Datom struct {
	// contains filtered or unexported fields
}

func NewDatom

func NewDatom(e int, a int, v interface{}, tx int, added bool) Datom

func (Datom) A

func (d Datom) A() int

func (Datom) Added

func (d Datom) Added() bool

func (Datom) Attribute

func (d Datom) Attribute() int

func (Datom) E

func (d Datom) E() int

func (Datom) Entity

func (d Datom) Entity() int

func (Datom) Retraction

func (d Datom) Retraction() Datom

func (Datom) String

func (d Datom) String() string

func (Datom) Transaction

func (d Datom) Transaction() int

func (Datom) Tx

func (d Datom) Tx() int

func (Datom) V

func (d Datom) V() Value

func (Datom) Value

func (d Datom) Value() Value

type Directory

type Directory struct {
	// contains filtered or unexported fields
}

func (Directory) Find

func (d Directory) Find(store store.Store, compare CompareFn, datom Datom) (int, int)

type Index

type Index interface {
	Datoms() Iterator
	DatomsAt(start, end Datom) Iterator
	SeekDatoms(start Datom) Iterator
}

type Iterator

type Iterator interface {
	Next() *Datom
	Reverse() Iterator
}

func FilterIterator

func FilterIterator(iter Iterator, pred func(datom *Datom) bool) Iterator

type MemoryIndex

type MemoryIndex struct {
	// contains filtered or unexported fields
}

func NewMemoryIndex

func NewMemoryIndex(compare comparable.CompareFn) *MemoryIndex

func (MemoryIndex) AddDatoms

func (mi MemoryIndex) AddDatoms(datoms []Datom) *MemoryIndex

func (*MemoryIndex) Count

func (i *MemoryIndex) Count() int

func (MemoryIndex) Datoms

func (mi MemoryIndex) Datoms() Iterator

func (MemoryIndex) DatomsAt

func (mi MemoryIndex) DatomsAt(start, end Datom) Iterator

func (MemoryIndex) SeekDatoms

func (mi MemoryIndex) SeekDatoms(start Datom) Iterator

func (*MemoryIndex) UseCompare

func (i *MemoryIndex) UseCompare(compare comparable.CompareFn)

type MergedIndex

type MergedIndex struct {
	// contains filtered or unexported fields
}

func NewMergedIndex

func NewMergedIndex(mi *MemoryIndex, si *SegmentedIndex, compare comparable.CompareFn) *MergedIndex

func (MergedIndex) AddDatoms

func (mi MergedIndex) AddDatoms(datoms []Datom) *MergedIndex

func (MergedIndex) Datoms

func (mi MergedIndex) Datoms() Iterator

func (MergedIndex) DatomsAt

func (mi MergedIndex) DatomsAt(start, end Datom) Iterator

func (MergedIndex) SeekDatoms

func (mi MergedIndex) SeekDatoms(start Datom) Iterator

type Root

type Root struct {
	// contains filtered or unexported fields
}

func GetRoot

func GetRoot(store store.Store, id string) Root

TODO: make all of these public?

func (Root) Find

func (r Root) Find(store store.Store, compare CompareFn, datom Datom) (int, int, int)

type SegmentedIndex

type SegmentedIndex struct {
	// contains filtered or unexported fields
}

func NewSegmentedIndex

func NewSegmentedIndex(root *Root, store store.Store, compare CompareFn) *SegmentedIndex

func (SegmentedIndex) Datoms

func (si SegmentedIndex) Datoms() Iterator

func (SegmentedIndex) DatomsAt

func (si SegmentedIndex) DatomsAt(start, end Datom) Iterator

func (SegmentedIndex) SeekDatoms

func (si SegmentedIndex) SeekDatoms(start Datom) Iterator

type TransposedData

type TransposedData struct {
	// contains filtered or unexported fields
}

func (TransposedData) DatomAt

func (t TransposedData) DatomAt(idx int) Datom

func (TransposedData) Find

func (t TransposedData) Find(compare CompareFn, datom Datom) int

Find finds the closest (first) datom that is greater or equal to `datom`.

invariants:

  • returns len(t.entities) if all datoms are smaller
  • the datom at the index is greater or equal

func (TransposedData) FindApprox

func (t TransposedData) FindApprox(compare CompareFn, datom Datom) int

type Type

type Type string

type Value

type Value struct {
	// contains filtered or unexported fields
}

func NewRef

func NewRef(id int) Value

func NewValue

func NewValue(val interface{}) Value

func (Value) Compare

func (v Value) Compare(ovc comparable.Comparable) int

func (Value) String

func (v Value) String() string

func (Value) Type

func (v Value) Type() ValueType

func (Value) Val

func (v Value) Val() interface{}

type ValueType

type ValueType int
const (
	Ref ValueType = 20 + iota
	Keyword
	Long
	String
	Bool
	Instant
	Fn
	Bytes
	Int            = Long
	Date           = Instant
	Min  ValueType = -1
	Max  ValueType = 100
)
const (
	UUID ValueType = 56 + iota
	Double
	Float
	URI
	BigInt
	BigDec
)

func (ValueType) IsValid

func (t ValueType) IsValid() bool

func (ValueType) String

func (t ValueType) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL