graph

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2014 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCannotBulkLoad = errors.New("triplestore: cannot bulk load")

Functions

func ContainsLogIn added in v0.3.1

func ContainsLogIn(it Iterator, val Value)

Utility logging functions for when an iterator gets called Next upon, or Contains upon, as well as what they return. Highly useful for tracing the execution path of a query.

func ContainsLogOut added in v0.3.1

func ContainsLogOut(it Iterator, val Value, good bool) bool

func InitTripleStore added in v0.3.1

func InitTripleStore(name, dbpath string, opts Options) error

func NextLogIn

func NextLogIn(it Iterator)

func PrintResultTreeEvaluator

func PrintResultTreeEvaluator(it Nexter)

func RegisterTripleStore added in v0.3.1

func RegisterTripleStore(name string, newFunc NewStoreFunc, initFunc InitStoreFunc)

func StringResultTreeEvaluator

func StringResultTreeEvaluator(it Nexter) string

func TripleStores added in v0.3.1

func TripleStores() []string

Types

type BulkLoader added in v0.3.1

type BulkLoader interface {
	// BulkLoad loads Quads from a quad.Unmarshaler in bulk to the TripleStore.
	// It returns ErrCannotBulkLoad if bulk loading is not possible. For example if
	// you cannot load in bulk to a non-empty database, and the db is non-empty.
	BulkLoad(quad.Unmarshaler) error
}

type FixedIterator

type FixedIterator interface {
	Iterator
	Add(Value)
}

FixedIterator wraps iterators that are modifiable by addition of fixed value sets.

type InitStoreFunc added in v0.3.1

type InitStoreFunc func(string, Options) error

type Iterator

type Iterator interface {
	Tagger() *Tagger

	// Fills a tag-to-result-value map.
	TagResults(map[string]Value)

	// Returns the current result.
	Result() Value

	// DEPRECATED -- Fills a ResultTree struct with Result().
	ResultTree() *ResultTree

	// These methods are the heart and soul of the iterator, as they constitute
	// the iteration interface.
	//
	// To get the full results of iteration, do the following:
	// while (!Next()):
	//   emit result
	//   while (!NextResult()):
	//       emit result
	//
	// All of them should set iterator.Last to be the last returned value, to
	// make results work.
	//
	// NextResult() advances iterators that may have more than one valid result,
	// from the bottom up.
	NextResult() bool

	// Contains returns whether the value is within the set held by the iterator.
	Contains(Value) bool

	// Start iteration from the beginning
	Reset()

	// Create a new iterator just like this one
	Clone() Iterator

	// These methods relate to choosing the right iterator, or optimizing an
	// iterator tree
	//
	// Stats() returns the relative costs of calling the iteration methods for
	// this iterator, as well as the size. Roughly, it will take NextCost * Size
	// "cost units" to get everything out of the iterator. This is a wibbly-wobbly
	// thing, and not exact, but a useful heuristic.
	Stats() IteratorStats

	// Helpful accessor for the number of things in the iterator. The first return
	// value is the size, and the second return value is whether that number is exact,
	// or a conservative estimate.
	Size() (int64, bool)

	// Returns a string relating to what the function of the iterator is. By
	// knowing the names of the iterators, we can devise optimization strategies.
	Type() Type

	// Optimizes an iterator. Can replace the iterator, or merely move things
	// around internally. if it chooses to replace it with a better iterator,
	// returns (the new iterator, true), if not, it returns (self, false).
	Optimize() (Iterator, bool)

	// Return a slice of the subiterators for this iterator.
	SubIterators() []Iterator

	// Return a string representation of the iterator, indented by the given amount.
	DebugString(int) string

	// Close the iterator and do internal cleanup.
	Close()

	// UID returns the unique identifier of the iterator.
	UID() uint64
}

type IteratorStats

type IteratorStats struct {
	ContainsCost int64
	NextCost     int64
	Size         int64
}

type NewStoreFunc added in v0.3.1

type NewStoreFunc func(string, Options) (TripleStore, error)

type Nexter added in v0.3.1

type Nexter interface {
	// Next() advances the iterator and returns the next valid result. Returns
	// (<value>, true) or (nil, false)
	Next() (Value, bool)

	Iterator
}

type Options added in v0.3.1

type Options map[string]interface{}

func (Options) IntKey added in v0.3.1

func (d Options) IntKey(key string) (int, bool)

func (Options) StringKey added in v0.3.1

func (d Options) StringKey(key string) (string, bool)

type ResultTree

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

func NewResultTree

func NewResultTree(result Value) *ResultTree

func (*ResultTree) AddSubtree

func (t *ResultTree) AddSubtree(sub *ResultTree)

func (*ResultTree) String added in v0.3.1

func (t *ResultTree) String() string

type Tagger added in v0.3.1

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

func (*Tagger) Add added in v0.3.1

func (t *Tagger) Add(tag string)

Adds a tag to the iterator.

func (*Tagger) AddFixed added in v0.3.1

func (t *Tagger) AddFixed(tag string, value Value)

func (*Tagger) CopyFrom added in v0.3.1

func (t *Tagger) CopyFrom(src Iterator)

func (*Tagger) Fixed added in v0.3.1

func (t *Tagger) Fixed() map[string]Value

Returns the fixed tags. The returned value must not be mutated.

func (*Tagger) Tags added in v0.3.1

func (t *Tagger) Tags() []string

Returns the tags. The returned value must not be mutated.

type TripleStore

type TripleStore interface {
	// Add a triple to the store.
	AddTriple(*quad.Quad)

	// Add a set of triples to the store, atomically if possible.
	AddTripleSet([]*quad.Quad)

	// Removes a triple matching the given one  from the database,
	// if it exists. Does nothing otherwise.
	RemoveTriple(*quad.Quad)

	// Given an opaque token, returns the triple for that token from the store.
	Quad(Value) *quad.Quad

	// Given a direction and a token, creates an iterator of links which have
	// that node token in that directional field.
	TripleIterator(quad.Direction, Value) Iterator

	// Returns an iterator enumerating all nodes in the graph.
	NodesAllIterator() Iterator

	// Returns an iterator enumerating all links in the graph.
	TriplesAllIterator() Iterator

	// Given a node ID, return the opaque token used by the TripleStore
	// to represent that id.
	ValueOf(string) Value

	// Given an opaque token, return the node that it represents.
	NameOf(Value) string

	// Returns the number of triples currently stored.
	Size() int64

	// Creates a fixed iterator which can compare Values
	FixedIterator() FixedIterator

	// Optimize an iterator in the context of the triple store.
	// Suppose we have a better index for the passed tree; this
	// gives the TripleStore the opportunity to replace it
	// with a more efficient iterator.
	OptimizeIterator(it Iterator) (Iterator, bool)

	// Close the triple store and clean up. (Flush to disk, cleanly
	// sever connections, etc)
	Close()

	// Convenience function for speed. Given a triple token and a direction
	// return the node token for that direction. Sometimes, a TripleStore
	// can do this without going all the way to the backing store, and
	// gives the TripleStore the opportunity to make this optimization.
	//
	// Iterators will call this. At worst, a valid implementation is
	// ts.IdFor(ts.quad.Quad(id).Get(dir))
	TripleDirection(id Value, d quad.Direction) Value
}

func NewTripleStore added in v0.3.1

func NewTripleStore(name, dbpath string, opts Options) (TripleStore, error)

type Type added in v0.3.1

type Type int

Type enumerates the set of Iterator types.

const (
	Invalid Type = iota
	All
	And
	Or
	HasA
	LinksTo
	Comparison
	Null
	Fixed
	Not
	Optional
)

func RegisterIterator added in v0.3.1

func RegisterIterator(name string) Type

RegisterIterator adds a new iterator type to the set of acceptable types, returning the registered Type. Calls to Register are idempotent and must be made prior to use of the iterator. The conventional approach for use is to include a call to Register in a package init() function, saving the Type to a private package var.

func (Type) String added in v0.3.1

func (t Type) String() string

String returns a string representation of the Type.

type Value added in v0.3.1

type Value interface{}

Defines an opaque "triple store value" type. However the backend wishes to implement it, a Value is merely a token to a triple or a node that the backing store itself understands, and the base iterators pass around.

For example, in a very traditional, graphd-style graph, these are int64s (guids of the primitives). In a very direct sort of graph, these could be pointers to structs, or merely triples, or whatever works best for the backing store.

func Next added in v0.3.1

func Next(it Iterator) (Value, bool)

Next is a convenience function that conditionally calls the Next method of an Iterator if it is a Nexter. If the Iterator is not a Nexter, Next return a nil Value and false.

func NextLogOut

func NextLogOut(it Iterator, val Value, ok bool) (Value, bool)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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