Rename TSVal
This commit is contained in:
parent
a1453da84e
commit
d87e227ff3
29 changed files with 118 additions and 118 deletions
|
|
@ -32,15 +32,15 @@ type Iterator interface {
|
|||
// Tag Accessors.
|
||||
AddTag(string)
|
||||
Tags() []string
|
||||
AddFixedTag(string, TSVal)
|
||||
FixedTags() map[string]TSVal
|
||||
AddFixedTag(string, Value)
|
||||
FixedTags() map[string]Value
|
||||
CopyTagsFrom(Iterator)
|
||||
|
||||
// Fills a tag-to-result-value map.
|
||||
TagResults(map[string]TSVal)
|
||||
TagResults(map[string]Value)
|
||||
|
||||
// Returns the current result.
|
||||
Result() TSVal
|
||||
Result() Value
|
||||
|
||||
// DEPRECATED -- Fills a ResultTree struct with Result().
|
||||
ResultTree() *ResultTree
|
||||
|
|
@ -59,7 +59,7 @@ type Iterator interface {
|
|||
//
|
||||
// Next() advances the iterator and returns the next valid result. Returns
|
||||
// (<value>, true) or (nil, false)
|
||||
Next() (TSVal, bool)
|
||||
Next() (Value, bool)
|
||||
|
||||
// NextResult() advances iterators that may have more than one valid result,
|
||||
// from the bottom up.
|
||||
|
|
@ -72,7 +72,7 @@ type Iterator interface {
|
|||
|
||||
// Check(), given a value, returns whether or not that value is within the set
|
||||
// held by this iterator.
|
||||
Check(TSVal) bool
|
||||
Check(Value) bool
|
||||
|
||||
// Start iteration from the beginning
|
||||
Reset()
|
||||
|
|
@ -117,7 +117,7 @@ type Iterator interface {
|
|||
|
||||
type FixedIterator interface {
|
||||
Iterator
|
||||
AddValue(TSVal)
|
||||
AddValue(Value)
|
||||
}
|
||||
|
||||
type IteratorStats struct {
|
||||
|
|
@ -128,13 +128,13 @@ type IteratorStats struct {
|
|||
|
||||
// Utility logging functions for when an iterator gets called Next upon, or Check upon, as
|
||||
// well as what they return. Highly useful for tracing the execution path of a query.
|
||||
func CheckLogIn(it Iterator, val TSVal) {
|
||||
func CheckLogIn(it Iterator, val Value) {
|
||||
if glog.V(4) {
|
||||
glog.V(4).Infof("%s %d CHECK %d", strings.ToUpper(it.Type()), it.UID(), val)
|
||||
}
|
||||
}
|
||||
|
||||
func CheckLogOut(it Iterator, val TSVal, good bool) bool {
|
||||
func CheckLogOut(it Iterator, val Value, good bool) bool {
|
||||
if glog.V(4) {
|
||||
if good {
|
||||
glog.V(4).Infof("%s %d CHECK %d GOOD", strings.ToUpper(it.Type()), it.UID(), val)
|
||||
|
|
@ -151,7 +151,7 @@ func NextLogIn(it Iterator) {
|
|||
}
|
||||
}
|
||||
|
||||
func NextLogOut(it Iterator, val TSVal, ok bool) (TSVal, bool) {
|
||||
func NextLogOut(it Iterator, val Value, ok bool) (Value, bool) {
|
||||
if glog.V(4) {
|
||||
if ok {
|
||||
glog.V(4).Infof("%s %d NEXT IS %d", strings.ToUpper(it.Type()), it.UID(), val)
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ func (it *Int64) DebugString(indent int) string {
|
|||
|
||||
// Next() on an Int64 all iterator is a simple incrementing counter.
|
||||
// Return the next integer, and mark it as the result.
|
||||
func (it *Int64) Next() (graph.TSVal, bool) {
|
||||
func (it *Int64) Next() (graph.Value, bool) {
|
||||
graph.NextLogIn(it)
|
||||
if it.at == -1 {
|
||||
return graph.NextLogOut(it, nil, false)
|
||||
|
|
@ -89,7 +89,7 @@ func (it *Int64) Size() (int64, bool) {
|
|||
|
||||
// Check() for an Int64 is merely seeing if the passed value is
|
||||
// withing the range, assuming the value is an int64.
|
||||
func (it *Int64) Check(tsv graph.TSVal) bool {
|
||||
func (it *Int64) Check(tsv graph.Value) bool {
|
||||
graph.CheckLogIn(it, tsv)
|
||||
v := tsv.(int64)
|
||||
if it.min <= v && v <= it.max {
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ func (it *And) SubIterators() []graph.Iterator {
|
|||
|
||||
// Overrides Base TagResults, as it needs to add it's own results and
|
||||
// recurse down it's subiterators.
|
||||
func (it *And) TagResults(dst map[string]graph.TSVal) {
|
||||
func (it *And) TagResults(dst map[string]graph.Value) {
|
||||
it.Base.TagResults(dst)
|
||||
if it.primaryIt != nil {
|
||||
it.primaryIt.TagResults(dst)
|
||||
|
|
@ -139,9 +139,9 @@ func (it *And) AddSubIterator(sub graph.Iterator) {
|
|||
// intersection of its subiterators, it must choose one subiterator to produce a
|
||||
// candidate, and check this value against the subiterators. A productive choice
|
||||
// of primary iterator is therefore very important.
|
||||
func (it *And) Next() (graph.TSVal, bool) {
|
||||
func (it *And) Next() (graph.Value, bool) {
|
||||
graph.NextLogIn(it)
|
||||
var curr graph.TSVal
|
||||
var curr graph.Value
|
||||
var exists bool
|
||||
for {
|
||||
curr, exists = it.primaryIt.Next()
|
||||
|
|
@ -157,7 +157,7 @@ func (it *And) Next() (graph.TSVal, bool) {
|
|||
}
|
||||
|
||||
// Checks a value against the non-primary iterators, in order.
|
||||
func (it *And) checkSubIts(val graph.TSVal) bool {
|
||||
func (it *And) checkSubIts(val graph.Value) bool {
|
||||
var subIsGood = true
|
||||
for _, sub := range it.internalIterators {
|
||||
subIsGood = sub.Check(val)
|
||||
|
|
@ -168,7 +168,7 @@ func (it *And) checkSubIts(val graph.TSVal) bool {
|
|||
return subIsGood
|
||||
}
|
||||
|
||||
func (it *And) checkCheckList(val graph.TSVal) bool {
|
||||
func (it *And) checkCheckList(val graph.Value) bool {
|
||||
ok := true
|
||||
for _, c := range it.checkList {
|
||||
ok = c.Check(val)
|
||||
|
|
@ -183,7 +183,7 @@ func (it *And) checkCheckList(val graph.TSVal) bool {
|
|||
}
|
||||
|
||||
// Check a value against the entire iterator, in order.
|
||||
func (it *And) Check(val graph.TSVal) bool {
|
||||
func (it *And) Check(val graph.Value) bool {
|
||||
graph.CheckLogIn(it, val)
|
||||
if it.checkList != nil {
|
||||
return it.checkCheckList(val)
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ func TestTag(t *testing.T) {
|
|||
if val != 234 {
|
||||
t.Errorf("Unexpected value")
|
||||
}
|
||||
tags := make(map[string]graph.TSVal)
|
||||
tags := make(map[string]graph.Value)
|
||||
and.TagResults(tags)
|
||||
if tags["bar"] != 234 {
|
||||
t.Errorf("no bar tag")
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ package iterator
|
|||
// Defines one of the base iterators, the Fixed iterator. A fixed iterator is quite simple; it
|
||||
// contains an explicit fixed array of values.
|
||||
//
|
||||
// A fixed iterator requires an Equality function to be passed to it, by reason that graph.TSVal, the
|
||||
// A fixed iterator requires an Equality function to be passed to it, by reason that graph.Value, the
|
||||
// opaque Triple store value, may not answer to ==.
|
||||
|
||||
import (
|
||||
|
|
@ -31,16 +31,16 @@ import (
|
|||
// an equality function.
|
||||
type Fixed struct {
|
||||
Base
|
||||
values []graph.TSVal
|
||||
values []graph.Value
|
||||
lastIndex int
|
||||
cmp Equality
|
||||
}
|
||||
|
||||
// Define the signature of an equality function.
|
||||
type Equality func(a, b graph.TSVal) bool
|
||||
type Equality func(a, b graph.Value) bool
|
||||
|
||||
// Define an equality function of purely ==, which works for native types.
|
||||
func BasicEquality(a, b graph.TSVal) bool {
|
||||
func BasicEquality(a, b graph.Value) bool {
|
||||
if a == b {
|
||||
return true
|
||||
}
|
||||
|
|
@ -56,7 +56,7 @@ func newFixed() *Fixed {
|
|||
func NewFixedIteratorWithCompare(compareFn Equality) *Fixed {
|
||||
var it Fixed
|
||||
BaseInit(&it.Base)
|
||||
it.values = make([]graph.TSVal, 0, 20)
|
||||
it.values = make([]graph.Value, 0, 20)
|
||||
it.lastIndex = 0
|
||||
it.cmp = compareFn
|
||||
return &it
|
||||
|
|
@ -79,7 +79,7 @@ func (it *Fixed) Clone() graph.Iterator {
|
|||
|
||||
// Add a value to the iterator. The array now contains this value.
|
||||
// TODO(barakmich): This ought to be a set someday, disallowing repeated values.
|
||||
func (it *Fixed) AddValue(v graph.TSVal) {
|
||||
func (it *Fixed) AddValue(v graph.Value) {
|
||||
it.values = append(it.values, v)
|
||||
}
|
||||
|
||||
|
|
@ -104,7 +104,7 @@ func (it *Fixed) Type() string {
|
|||
}
|
||||
|
||||
// Check if the passed value is equal to one of the values stored in the iterator.
|
||||
func (it *Fixed) Check(v graph.TSVal) bool {
|
||||
func (it *Fixed) Check(v graph.Value) bool {
|
||||
// Could be optimized by keeping it sorted or using a better datastructure.
|
||||
// However, for fixed iterators, which are by definition kind of tiny, this
|
||||
// isn't a big issue.
|
||||
|
|
@ -119,7 +119,7 @@ func (it *Fixed) Check(v graph.TSVal) bool {
|
|||
}
|
||||
|
||||
// Return the next stored value from the iterator.
|
||||
func (it *Fixed) Next() (graph.TSVal, bool) {
|
||||
func (it *Fixed) Next() (graph.Value, bool) {
|
||||
graph.NextLogIn(it)
|
||||
if it.lastIndex == len(it.values) {
|
||||
return graph.NextLogOut(it, nil, false)
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ func (it *HasA) Optimize() (graph.Iterator, bool) {
|
|||
}
|
||||
|
||||
// Pass the TagResults down the chain.
|
||||
func (it *HasA) TagResults(dst map[string]graph.TSVal) {
|
||||
func (it *HasA) TagResults(dst map[string]graph.Value) {
|
||||
it.Base.TagResults(dst)
|
||||
it.primaryIt.TagResults(dst)
|
||||
}
|
||||
|
|
@ -123,7 +123,7 @@ func (it *HasA) DebugString(indent int) string {
|
|||
// Check a value against our internal iterator. In order to do this, we must first open a new
|
||||
// iterator of "triples that have `val` in our direction", given to us by the triple store,
|
||||
// and then Next() values out of that iterator and Check() them against our subiterator.
|
||||
func (it *HasA) Check(val graph.TSVal) bool {
|
||||
func (it *HasA) Check(val graph.Value) bool {
|
||||
graph.CheckLogIn(it, val)
|
||||
if glog.V(4) {
|
||||
glog.V(4).Infoln("Id is", it.ts.NameOf(val))
|
||||
|
|
@ -173,7 +173,7 @@ func (it *HasA) NextResult() bool {
|
|||
// Get the next result from this iterator. This is simpler than Check. We have a
|
||||
// subiterator we can get a value from, and we can take that resultant triple,
|
||||
// pull our direction out of it, and return that.
|
||||
func (it *HasA) Next() (graph.TSVal, bool) {
|
||||
func (it *HasA) Next() (graph.Value, bool) {
|
||||
graph.NextLogIn(it)
|
||||
if it.resultIt != nil {
|
||||
it.resultIt.Close()
|
||||
|
|
|
|||
|
|
@ -36,9 +36,9 @@ func nextID() uintptr {
|
|||
// The Base iterator is the iterator other iterators inherit from to get some
|
||||
// default functionality.
|
||||
type Base struct {
|
||||
Last graph.TSVal
|
||||
Last graph.Value
|
||||
tags []string
|
||||
fixedTags map[string]graph.TSVal
|
||||
fixedTags map[string]graph.Value
|
||||
canNext bool
|
||||
uid uintptr
|
||||
}
|
||||
|
|
@ -64,9 +64,9 @@ func (it *Base) AddTag(tag string) {
|
|||
it.tags = append(it.tags, tag)
|
||||
}
|
||||
|
||||
func (it *Base) AddFixedTag(tag string, value graph.TSVal) {
|
||||
func (it *Base) AddFixedTag(tag string, value graph.Value) {
|
||||
if it.fixedTags == nil {
|
||||
it.fixedTags = make(map[string]graph.TSVal)
|
||||
it.fixedTags = make(map[string]graph.Value)
|
||||
}
|
||||
it.fixedTags[tag] = value
|
||||
}
|
||||
|
|
@ -76,7 +76,7 @@ func (it *Base) Tags() []string {
|
|||
return it.tags
|
||||
}
|
||||
|
||||
func (it *Base) FixedTags() map[string]graph.TSVal {
|
||||
func (it *Base) FixedTags() map[string]graph.Value {
|
||||
return it.fixedTags
|
||||
}
|
||||
|
||||
|
|
@ -97,7 +97,7 @@ func (it *Base) DebugString(indent int) string {
|
|||
}
|
||||
|
||||
// Nothing in a base iterator.
|
||||
func (it *Base) Check(v graph.TSVal) bool {
|
||||
func (it *Base) Check(v graph.Value) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
@ -114,7 +114,7 @@ func (it *Base) ResultTree() *graph.ResultTree {
|
|||
}
|
||||
|
||||
// Nothing in a base iterator.
|
||||
func (it *Base) Next() (graph.TSVal, bool) {
|
||||
func (it *Base) Next() (graph.Value, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
|
|
@ -123,7 +123,7 @@ func (it *Base) NextResult() bool {
|
|||
}
|
||||
|
||||
// Returns the last result of an iterator.
|
||||
func (it *Base) Result() graph.TSVal {
|
||||
func (it *Base) Result() graph.Value {
|
||||
return it.Last
|
||||
}
|
||||
|
||||
|
|
@ -142,7 +142,7 @@ func (it *Base) CanNext() bool { return it.canNext }
|
|||
|
||||
// Fill the map based on the tags assigned to this iterator. Default
|
||||
// functionality works well for most iterators.
|
||||
func (it *Base) TagResults(dst map[string]graph.TSVal) {
|
||||
func (it *Base) TagResults(dst map[string]graph.Value) {
|
||||
for _, tag := range it.Tags() {
|
||||
dst[tag] = it.Result()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ func (it *LinksTo) Clone() graph.Iterator {
|
|||
func (it *LinksTo) Direction() graph.Direction { return it.dir }
|
||||
|
||||
// Tag these results, and our subiterator's results.
|
||||
func (it *LinksTo) TagResults(dst map[string]graph.TSVal) {
|
||||
func (it *LinksTo) TagResults(dst map[string]graph.Value) {
|
||||
it.Base.TagResults(dst)
|
||||
it.primaryIt.TagResults(dst)
|
||||
}
|
||||
|
|
@ -98,7 +98,7 @@ func (it *LinksTo) DebugString(indent int) string {
|
|||
|
||||
// If it checks in the right direction for the subiterator, it is a valid link
|
||||
// for the LinksTo.
|
||||
func (it *LinksTo) Check(val graph.TSVal) bool {
|
||||
func (it *LinksTo) Check(val graph.Value) bool {
|
||||
graph.CheckLogIn(it, val)
|
||||
node := it.ts.TripleDirection(val, it.dir)
|
||||
if it.primaryIt.Check(node) {
|
||||
|
|
@ -135,7 +135,7 @@ func (it *LinksTo) Optimize() (graph.Iterator, bool) {
|
|||
}
|
||||
|
||||
// Next()ing a LinksTo operates as described above.
|
||||
func (it *LinksTo) Next() (graph.TSVal, bool) {
|
||||
func (it *LinksTo) Next() (graph.Value, bool) {
|
||||
graph.NextLogIn(it)
|
||||
val, ok := it.nextIt.Next()
|
||||
if !ok {
|
||||
|
|
|
|||
|
|
@ -27,14 +27,14 @@ type TestTripleStore struct {
|
|||
mock.Mock
|
||||
}
|
||||
|
||||
func (ts *TestTripleStore) ValueOf(s string) graph.TSVal {
|
||||
func (ts *TestTripleStore) ValueOf(s string) graph.Value {
|
||||
args := ts.Mock.Called(s)
|
||||
return args.Get(0)
|
||||
}
|
||||
func (ts *TestTripleStore) AddTriple(*graph.Triple) {}
|
||||
func (ts *TestTripleStore) AddTripleSet([]*graph.Triple) {}
|
||||
func (ts *TestTripleStore) Triple(graph.TSVal) *graph.Triple { return &graph.Triple{} }
|
||||
func (ts *TestTripleStore) TripleIterator(d graph.Direction, i graph.TSVal) graph.Iterator {
|
||||
func (ts *TestTripleStore) Triple(graph.Value) *graph.Triple { return &graph.Triple{} }
|
||||
func (ts *TestTripleStore) TripleIterator(d graph.Direction, i graph.Value) graph.Iterator {
|
||||
args := ts.Mock.Called(d, i)
|
||||
return args.Get(0).(graph.Iterator)
|
||||
}
|
||||
|
|
@ -43,7 +43,7 @@ func (ts *TestTripleStore) TriplesAllIterator() graph.Iterator { return &Null{}
|
|||
func (ts *TestTripleStore) GetIteratorByString(string, string, string) graph.Iterator {
|
||||
return &Null{}
|
||||
}
|
||||
func (ts *TestTripleStore) NameOf(v graph.TSVal) string {
|
||||
func (ts *TestTripleStore) NameOf(v graph.Value) string {
|
||||
args := ts.Mock.Called(v)
|
||||
return args.Get(0).(string)
|
||||
}
|
||||
|
|
@ -56,5 +56,5 @@ func (ts *TestTripleStore) FixedIterator() graph.FixedIterator {
|
|||
return NewFixedIteratorWithCompare(BasicEquality)
|
||||
}
|
||||
func (ts *TestTripleStore) Close() {}
|
||||
func (ts *TestTripleStore) TripleDirection(graph.TSVal, graph.Direction) graph.TSVal { return 0 }
|
||||
func (ts *TestTripleStore) TripleDirection(graph.Value, graph.Direction) graph.Value { return 0 }
|
||||
func (ts *TestTripleStore) RemoveTriple(t *graph.Triple) {}
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ func (it *Optional) Clone() graph.Iterator {
|
|||
|
||||
// Nexting the iterator is unsupported -- error and return an empty set.
|
||||
// (As above, a reasonable alternative would be to Next() an all iterator)
|
||||
func (it *Optional) Next() (graph.TSVal, bool) {
|
||||
func (it *Optional) Next() (graph.Value, bool) {
|
||||
glog.Errorln("Nexting an un-nextable iterator")
|
||||
return nil, false
|
||||
}
|
||||
|
|
@ -87,7 +87,7 @@ func (it *Optional) NextResult() bool {
|
|||
// Check() is the real hack of this iterator. It always returns true, regardless
|
||||
// of whether the subiterator matched. But we keep track of whether the subiterator
|
||||
// matched for results purposes.
|
||||
func (it *Optional) Check(val graph.TSVal) bool {
|
||||
func (it *Optional) Check(val graph.Value) bool {
|
||||
checked := it.subIt.Check(val)
|
||||
it.lastCheck = checked
|
||||
it.Last = val
|
||||
|
|
@ -96,7 +96,7 @@ func (it *Optional) Check(val graph.TSVal) bool {
|
|||
|
||||
// If we failed the check, then the subiterator should not contribute to the result
|
||||
// set. Otherwise, go ahead and tag it.
|
||||
func (it *Optional) TagResults(dst map[string]graph.TSVal) {
|
||||
func (it *Optional) TagResults(dst map[string]graph.Value) {
|
||||
if it.lastCheck == false {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ func (it *Or) SubIterators() []graph.Iterator {
|
|||
|
||||
// Overrides BaseIterator TagResults, as it needs to add it's own results and
|
||||
// recurse down it's subiterators.
|
||||
func (it *Or) TagResults(dst map[string]graph.TSVal) {
|
||||
func (it *Or) TagResults(dst map[string]graph.Value) {
|
||||
it.Base.TagResults(dst)
|
||||
it.internalIterators[it.currentIterator].TagResults(dst)
|
||||
}
|
||||
|
|
@ -128,9 +128,9 @@ func (it *Or) AddSubIterator(sub graph.Iterator) {
|
|||
// Returns the Next value from the Or graph.iterator. Because the Or is the
|
||||
// union of its subiterators, it must produce from all subiterators -- unless
|
||||
// it's shortcircuiting, in which case, it's the first one that returns anything.
|
||||
func (it *Or) Next() (graph.TSVal, bool) {
|
||||
func (it *Or) Next() (graph.Value, bool) {
|
||||
graph.NextLogIn(it)
|
||||
var curr graph.TSVal
|
||||
var curr graph.Value
|
||||
var exists bool
|
||||
firstTime := false
|
||||
for {
|
||||
|
|
@ -157,7 +157,7 @@ func (it *Or) Next() (graph.TSVal, bool) {
|
|||
}
|
||||
|
||||
// Checks a value against the iterators, in order.
|
||||
func (it *Or) checkSubIts(val graph.TSVal) bool {
|
||||
func (it *Or) checkSubIts(val graph.Value) bool {
|
||||
var subIsGood = false
|
||||
for i, sub := range it.internalIterators {
|
||||
subIsGood = sub.Check(val)
|
||||
|
|
@ -170,7 +170,7 @@ func (it *Or) checkSubIts(val graph.TSVal) bool {
|
|||
}
|
||||
|
||||
// Check a value against the entire graph.iterator, in order.
|
||||
func (it *Or) Check(val graph.TSVal) bool {
|
||||
func (it *Or) Check(val graph.Value) bool {
|
||||
graph.CheckLogIn(it, val)
|
||||
anyGood := it.checkSubIts(val)
|
||||
if !anyGood {
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ func NewComparison(sub graph.Iterator, op Operator, val interface{}, ts graph.Tr
|
|||
|
||||
// Here's the non-boilerplate part of the ValueComparison iterator. Given a value
|
||||
// and our operator, determine whether or not we meet the requirement.
|
||||
func (it *Comparison) doComparison(val graph.TSVal) bool {
|
||||
func (it *Comparison) doComparison(val graph.Value) bool {
|
||||
//TODO(barakmich): Implement string comparison.
|
||||
nodeStr := it.ts.NameOf(val)
|
||||
switch cVal := it.val.(type) {
|
||||
|
|
@ -117,8 +117,8 @@ func (it *Comparison) Clone() graph.Iterator {
|
|||
return out
|
||||
}
|
||||
|
||||
func (it *Comparison) Next() (graph.TSVal, bool) {
|
||||
var val graph.TSVal
|
||||
func (it *Comparison) Next() (graph.Value, bool) {
|
||||
var val graph.Value
|
||||
var ok bool
|
||||
for {
|
||||
val, ok = it.subIt.Next()
|
||||
|
|
@ -147,7 +147,7 @@ func (it *Comparison) NextResult() bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func (it *Comparison) Check(val graph.TSVal) bool {
|
||||
func (it *Comparison) Check(val graph.Value) bool {
|
||||
if !it.doComparison(val) {
|
||||
return false
|
||||
}
|
||||
|
|
@ -156,7 +156,7 @@ func (it *Comparison) Check(val graph.TSVal) bool {
|
|||
|
||||
// If we failed the check, then the subiterator should not contribute to the result
|
||||
// set. Otherwise, go ahead and tag it.
|
||||
func (it *Comparison) TagResults(dst map[string]graph.TSVal) {
|
||||
func (it *Comparison) TagResults(dst map[string]graph.Value) {
|
||||
it.Base.TagResults(dst)
|
||||
it.subIt.TagResults(dst)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ func (it *AllIterator) Clone() graph.Iterator {
|
|||
return out
|
||||
}
|
||||
|
||||
func (it *AllIterator) Next() (graph.TSVal, bool) {
|
||||
func (it *AllIterator) Next() (graph.Value, bool) {
|
||||
if !it.open {
|
||||
it.Last = nil
|
||||
return nil, false
|
||||
|
|
@ -92,7 +92,7 @@ func (it *AllIterator) Next() (graph.TSVal, bool) {
|
|||
return out, true
|
||||
}
|
||||
|
||||
func (it *AllIterator) Check(v graph.TSVal) bool {
|
||||
func (it *AllIterator) Check(v graph.Value) bool {
|
||||
it.Last = v
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ type Iterator struct {
|
|||
originalPrefix string
|
||||
}
|
||||
|
||||
func NewIterator(prefix string, d graph.Direction, value graph.TSVal, ts *TripleStore) *Iterator {
|
||||
func NewIterator(prefix string, d graph.Direction, value graph.Value, ts *TripleStore) *Iterator {
|
||||
var it Iterator
|
||||
iterator.BaseInit(&it.Base)
|
||||
it.checkId = value.([]byte)
|
||||
|
|
@ -85,7 +85,7 @@ func (it *Iterator) Close() {
|
|||
}
|
||||
}
|
||||
|
||||
func (it *Iterator) Next() (graph.TSVal, bool) {
|
||||
func (it *Iterator) Next() (graph.Value, bool) {
|
||||
if it.it == nil {
|
||||
it.Last = nil
|
||||
return nil, false
|
||||
|
|
@ -166,7 +166,7 @@ func GetPositionFromPrefix(prefix []byte, d graph.Direction, ts *TripleStore) in
|
|||
panic("unreachable")
|
||||
}
|
||||
|
||||
func (it *Iterator) Check(v graph.TSVal) bool {
|
||||
func (it *Iterator) Check(v graph.Value) bool {
|
||||
val := v.([]byte)
|
||||
if val[0] == 'z' {
|
||||
return false
|
||||
|
|
|
|||
|
|
@ -420,9 +420,9 @@ func TestOptimize(t *testing.T) {
|
|||
Convey("With the correct tags", func() {
|
||||
oldIt.Next()
|
||||
newIt.Next()
|
||||
oldResults := make(map[string]graph.TSVal)
|
||||
oldResults := make(map[string]graph.Value)
|
||||
oldIt.TagResults(oldResults)
|
||||
newResults := make(map[string]graph.TSVal)
|
||||
newResults := make(map[string]graph.Value)
|
||||
oldIt.TagResults(newResults)
|
||||
So(newResults, ShouldResemble, oldResults)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -301,7 +301,7 @@ func (ts *TripleStore) Close() {
|
|||
ts.open = false
|
||||
}
|
||||
|
||||
func (ts *TripleStore) Triple(k graph.TSVal) *graph.Triple {
|
||||
func (ts *TripleStore) Triple(k graph.Value) *graph.Triple {
|
||||
var triple graph.Triple
|
||||
b, err := ts.db.Get(k.([]byte), ts.readopts)
|
||||
if err != nil && err != leveldb.ErrNotFound {
|
||||
|
|
@ -328,7 +328,7 @@ func (ts *TripleStore) convertStringToByteHash(s string) []byte {
|
|||
return key
|
||||
}
|
||||
|
||||
func (ts *TripleStore) ValueOf(s string) graph.TSVal {
|
||||
func (ts *TripleStore) ValueOf(s string) graph.Value {
|
||||
return ts.createValueKeyFor(s)
|
||||
}
|
||||
|
||||
|
|
@ -352,7 +352,7 @@ func (ts *TripleStore) getValueData(value_key []byte) ValueData {
|
|||
return out
|
||||
}
|
||||
|
||||
func (ts *TripleStore) NameOf(k graph.TSVal) string {
|
||||
func (ts *TripleStore) NameOf(k graph.Value) string {
|
||||
if k == nil {
|
||||
glog.V(2).Infoln("k was nil")
|
||||
return ""
|
||||
|
|
@ -360,7 +360,7 @@ func (ts *TripleStore) NameOf(k graph.TSVal) string {
|
|||
return ts.getValueData(k.([]byte)).Name
|
||||
}
|
||||
|
||||
func (ts *TripleStore) GetSizeFor(k graph.TSVal) int64 {
|
||||
func (ts *TripleStore) GetSizeFor(k graph.Value) int64 {
|
||||
if k == nil {
|
||||
return 0
|
||||
}
|
||||
|
|
@ -401,7 +401,7 @@ func (ts *TripleStore) GetApproximateSizeForPrefix(pre []byte) (int64, error) {
|
|||
return 0, nil
|
||||
}
|
||||
|
||||
func (ts *TripleStore) TripleIterator(d graph.Direction, val graph.TSVal) graph.Iterator {
|
||||
func (ts *TripleStore) TripleIterator(d graph.Direction, val graph.Value) graph.Iterator {
|
||||
var prefix string
|
||||
switch d {
|
||||
case graph.Subject:
|
||||
|
|
@ -426,7 +426,7 @@ func (ts *TripleStore) TriplesAllIterator() graph.Iterator {
|
|||
return NewAllIterator("po", graph.Predicate, ts)
|
||||
}
|
||||
|
||||
func (ts *TripleStore) TripleDirection(val graph.TSVal, d graph.Direction) graph.TSVal {
|
||||
func (ts *TripleStore) TripleDirection(val graph.Value, d graph.Direction) graph.Value {
|
||||
v := val.([]uint8)
|
||||
offset := GetPositionFromPrefix(v[0:2], d, ts)
|
||||
if offset != -1 {
|
||||
|
|
@ -436,7 +436,7 @@ func (ts *TripleStore) TripleDirection(val graph.TSVal, d graph.Direction) graph
|
|||
}
|
||||
}
|
||||
|
||||
func compareBytes(a, b graph.TSVal) bool {
|
||||
func compareBytes(a, b graph.Value) bool {
|
||||
return bytes.Equal(a.([]uint8), b.([]uint8))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ func NewMemstoreAllIterator(ts *TripleStore) *AllIterator {
|
|||
return &out
|
||||
}
|
||||
|
||||
func (it *AllIterator) Next() (graph.TSVal, bool) {
|
||||
func (it *AllIterator) Next() (graph.Value, bool) {
|
||||
next, out := it.Int64.Next()
|
||||
if !out {
|
||||
return next, out
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ func (it *Iterator) Clone() graph.Iterator {
|
|||
|
||||
func (it *Iterator) Close() {}
|
||||
|
||||
func (it *Iterator) Next() (graph.TSVal, bool) {
|
||||
func (it *Iterator) Next() (graph.Value, bool) {
|
||||
graph.NextLogIn(it)
|
||||
if it.tree.Max() == nil || it.Last == int64(it.tree.Max().(Int64)) {
|
||||
return graph.NextLogOut(it, nil, false)
|
||||
|
|
@ -87,7 +87,7 @@ func (it *Iterator) Size() (int64, bool) {
|
|||
return int64(it.tree.Len()), true
|
||||
}
|
||||
|
||||
func (it *Iterator) Check(v graph.TSVal) bool {
|
||||
func (it *Iterator) Check(v graph.Value) bool {
|
||||
graph.CheckLogIn(it, v)
|
||||
if it.tree.Has(Int64(v.(int64))) {
|
||||
it.Last = v
|
||||
|
|
|
|||
|
|
@ -217,11 +217,11 @@ func (ts *TripleStore) RemoveTriple(t *graph.Triple) {
|
|||
}
|
||||
}
|
||||
|
||||
func (ts *TripleStore) Triple(index graph.TSVal) *graph.Triple {
|
||||
func (ts *TripleStore) Triple(index graph.Value) *graph.Triple {
|
||||
return &ts.triples[index.(int64)]
|
||||
}
|
||||
|
||||
func (ts *TripleStore) TripleIterator(d graph.Direction, value graph.TSVal) graph.Iterator {
|
||||
func (ts *TripleStore) TripleIterator(d graph.Direction, value graph.Value) graph.Iterator {
|
||||
index, ok := ts.index.Get(d, value.(int64))
|
||||
data := fmt.Sprintf("dir:%s val:%d", d, value.(int64))
|
||||
if ok {
|
||||
|
|
@ -243,11 +243,11 @@ func (ts *TripleStore) DebugPrint() {
|
|||
}
|
||||
}
|
||||
|
||||
func (ts *TripleStore) ValueOf(name string) graph.TSVal {
|
||||
func (ts *TripleStore) ValueOf(name string) graph.Value {
|
||||
return ts.idMap[name]
|
||||
}
|
||||
|
||||
func (ts *TripleStore) NameOf(id graph.TSVal) string {
|
||||
func (ts *TripleStore) NameOf(id graph.Value) string {
|
||||
return ts.revIdMap[id.(int64)]
|
||||
}
|
||||
|
||||
|
|
@ -259,7 +259,7 @@ func (ts *TripleStore) FixedIterator() graph.FixedIterator {
|
|||
return iterator.NewFixedIteratorWithCompare(iterator.BasicEquality)
|
||||
}
|
||||
|
||||
func (ts *TripleStore) TripleDirection(val graph.TSVal, d graph.Direction) graph.TSVal {
|
||||
func (ts *TripleStore) TripleDirection(val graph.Value, d graph.Direction) graph.Value {
|
||||
name := ts.Triple(val).Get(d)
|
||||
return ts.ValueOf(name)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ type Iterator struct {
|
|||
collection string
|
||||
}
|
||||
|
||||
func NewIterator(ts *TripleStore, collection string, d graph.Direction, val graph.TSVal) *Iterator {
|
||||
func NewIterator(ts *TripleStore, collection string, d graph.Direction, val graph.Value) *Iterator {
|
||||
var m Iterator
|
||||
iterator.BaseInit(&m.Base)
|
||||
|
||||
|
|
@ -109,7 +109,7 @@ func (it *Iterator) Clone() graph.Iterator {
|
|||
return newM
|
||||
}
|
||||
|
||||
func (it *Iterator) Next() (graph.TSVal, bool) {
|
||||
func (it *Iterator) Next() (graph.Value, bool) {
|
||||
var result struct {
|
||||
Id string "_id"
|
||||
//Sub string "Sub"
|
||||
|
|
@ -128,7 +128,7 @@ func (it *Iterator) Next() (graph.TSVal, bool) {
|
|||
return result.Id, true
|
||||
}
|
||||
|
||||
func (it *Iterator) Check(v graph.TSVal) bool {
|
||||
func (it *Iterator) Check(v graph.Value) bool {
|
||||
graph.CheckLogIn(it, v)
|
||||
if it.isAll {
|
||||
it.Last = v
|
||||
|
|
|
|||
|
|
@ -209,7 +209,7 @@ func (ts *TripleStore) RemoveTriple(t *graph.Triple) {
|
|||
}
|
||||
}
|
||||
|
||||
func (ts *TripleStore) Triple(val graph.TSVal) *graph.Triple {
|
||||
func (ts *TripleStore) Triple(val graph.Value) *graph.Triple {
|
||||
var bsonDoc bson.M
|
||||
err := ts.db.C("triples").FindId(val.(string)).One(&bsonDoc)
|
||||
if err != nil {
|
||||
|
|
@ -223,7 +223,7 @@ func (ts *TripleStore) Triple(val graph.TSVal) *graph.Triple {
|
|||
}
|
||||
}
|
||||
|
||||
func (ts *TripleStore) TripleIterator(d graph.Direction, val graph.TSVal) graph.Iterator {
|
||||
func (ts *TripleStore) TripleIterator(d graph.Direction, val graph.Value) graph.Iterator {
|
||||
return NewIterator(ts, "triples", d, val)
|
||||
}
|
||||
|
||||
|
|
@ -235,11 +235,11 @@ func (ts *TripleStore) TriplesAllIterator() graph.Iterator {
|
|||
return NewAllIterator(ts, "triples")
|
||||
}
|
||||
|
||||
func (ts *TripleStore) ValueOf(s string) graph.TSVal {
|
||||
func (ts *TripleStore) ValueOf(s string) graph.Value {
|
||||
return ts.ConvertStringToByteHash(s)
|
||||
}
|
||||
|
||||
func (ts *TripleStore) NameOf(v graph.TSVal) string {
|
||||
func (ts *TripleStore) NameOf(v graph.Value) string {
|
||||
val, ok := ts.idCache.Get(v.(string))
|
||||
if ok {
|
||||
return val
|
||||
|
|
@ -262,7 +262,7 @@ func (ts *TripleStore) Size() int64 {
|
|||
return int64(count)
|
||||
}
|
||||
|
||||
func compareStrings(a, b graph.TSVal) bool {
|
||||
func compareStrings(a, b graph.Value) bool {
|
||||
return a.(string) == b.(string)
|
||||
}
|
||||
|
||||
|
|
@ -274,7 +274,7 @@ func (ts *TripleStore) Close() {
|
|||
ts.db.Session.Close()
|
||||
}
|
||||
|
||||
func (ts *TripleStore) TripleDirection(in graph.TSVal, d graph.Direction) graph.TSVal {
|
||||
func (ts *TripleStore) TripleDirection(in graph.Value, d graph.Direction) graph.Value {
|
||||
// Maybe do the trick here
|
||||
var offset int
|
||||
switch d {
|
||||
|
|
|
|||
|
|
@ -17,11 +17,11 @@ package graph
|
|||
import "fmt"
|
||||
|
||||
type ResultTree struct {
|
||||
result TSVal
|
||||
result Value
|
||||
subtrees []*ResultTree
|
||||
}
|
||||
|
||||
func NewResultTree(result TSVal) *ResultTree {
|
||||
func NewResultTree(result Value) *ResultTree {
|
||||
return &ResultTree{result: result}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ func TestTreeConstraintTagParse(t *testing.T) {
|
|||
if !ok {
|
||||
t.Error("Got no results")
|
||||
}
|
||||
tags := make(map[string]graph.TSVal)
|
||||
tags := make(map[string]graph.Value)
|
||||
it.TagResults(tags)
|
||||
if ts.NameOf(tags["$a"]) != "food" {
|
||||
t.Errorf("Got %s, expected food", ts.NameOf(tags["$a"]))
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ func (s *Session) ExecInput(input string, out chan interface{}, limit int) {
|
|||
if !ok {
|
||||
break
|
||||
}
|
||||
tags := make(map[string]graph.TSVal)
|
||||
tags := make(map[string]graph.Value)
|
||||
it.TagResults(tags)
|
||||
out <- &tags
|
||||
nResults++
|
||||
|
|
@ -89,7 +89,7 @@ func (s *Session) ExecInput(input string, out chan interface{}, limit int) {
|
|||
break
|
||||
}
|
||||
for it.NextResult() == true {
|
||||
tags := make(map[string]graph.TSVal)
|
||||
tags := make(map[string]graph.Value)
|
||||
it.TagResults(tags)
|
||||
out <- &tags
|
||||
nResults++
|
||||
|
|
@ -103,7 +103,7 @@ func (s *Session) ExecInput(input string, out chan interface{}, limit int) {
|
|||
|
||||
func (s *Session) ToText(result interface{}) string {
|
||||
out := fmt.Sprintln("****")
|
||||
tags := result.(map[string]graph.TSVal)
|
||||
tags := result.(map[string]graph.Value)
|
||||
tagKeys := make([]string, len(tags))
|
||||
i := 0
|
||||
for k := range tags {
|
||||
|
|
|
|||
|
|
@ -26,14 +26,14 @@ import (
|
|||
)
|
||||
|
||||
// Defines an opaque "triple store value" type. However the backend wishes to
|
||||
// implement it, a TSVal is merely a token to a triple or a node that the backing
|
||||
// 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.
|
||||
type TSVal interface{}
|
||||
type Value interface{}
|
||||
|
||||
type TripleStore interface {
|
||||
// Add a triple to the store.
|
||||
|
|
@ -47,11 +47,11 @@ type TripleStore interface {
|
|||
RemoveTriple(*Triple)
|
||||
|
||||
// Given an opaque token, returns the triple for that token from the store.
|
||||
Triple(TSVal) *Triple
|
||||
Triple(Value) *Triple
|
||||
|
||||
// Given a direction and a token, creates an iterator of links which have
|
||||
// that node token in that directional field.
|
||||
TripleIterator(Direction, TSVal) Iterator
|
||||
TripleIterator(Direction, Value) Iterator
|
||||
|
||||
// Returns an iterator enumerating all nodes in the graph.
|
||||
NodesAllIterator() Iterator
|
||||
|
|
@ -61,15 +61,15 @@ type TripleStore interface {
|
|||
|
||||
// Given a node ID, return the opaque token used by the TripleStore
|
||||
// to represent that id.
|
||||
ValueOf(string) TSVal
|
||||
ValueOf(string) Value
|
||||
|
||||
// Given an opaque token, return the node that it represents.
|
||||
NameOf(TSVal) string
|
||||
NameOf(Value) string
|
||||
|
||||
// Returns the number of triples currently stored.
|
||||
Size() int64
|
||||
|
||||
// Creates a fixed iterator which can compare TSVals
|
||||
// Creates a fixed iterator which can compare Values
|
||||
FixedIterator() FixedIterator
|
||||
|
||||
// Optimize an iterator in the context of the triple store.
|
||||
|
|
@ -89,7 +89,7 @@ type TripleStore interface {
|
|||
//
|
||||
// Iterators will call this. At worst, a valid implementation is
|
||||
// ts.IdFor(ts.Triple(triple_id).Get(dir))
|
||||
TripleDirection(triple_id TSVal, d Direction) TSVal
|
||||
TripleDirection(triple_id Value, d Direction) Value
|
||||
}
|
||||
|
||||
type Options map[string]interface{}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue