Merge pull request #46 from kortschak/reduction
Reduce the complexity of names and types in graph.{Iterator,TripleStore}
This commit is contained in:
commit
5b207947ce
44 changed files with 442 additions and 423 deletions
|
|
@ -32,15 +32,18 @@ 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.
|
||||
LastResult() TSVal
|
||||
Result() Value
|
||||
|
||||
// DEPRECATED -- Fills a ResultTree struct with Result().
|
||||
GetResultTree() *ResultTree
|
||||
ResultTree() *ResultTree
|
||||
|
||||
// These methods are the heart and soul of the iterator, as they constitute
|
||||
// the iteration interface.
|
||||
|
|
@ -56,54 +59,65 @@ 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.
|
||||
NextResult() bool
|
||||
|
||||
// Return whether this iterator is reliably nextable. Most iterators are.
|
||||
// However, some iterators, like "not" are, by definition, the whole database
|
||||
// except themselves. Next() on these is unproductive, if impossible.
|
||||
CanNext() bool
|
||||
|
||||
// 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()
|
||||
|
||||
// Create a new iterator just like this one
|
||||
Clone() Iterator
|
||||
|
||||
// These methods relate to choosing the right iterator, or optimizing an
|
||||
// iterator tree
|
||||
//
|
||||
// GetStats() returns the relative costs of calling the iteration methods for
|
||||
// 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.
|
||||
GetStats() *IteratorStats
|
||||
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() string
|
||||
|
||||
// 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.
|
||||
GetSubIterators() []Iterator
|
||||
SubIterators() []Iterator
|
||||
|
||||
// Return a string representation of the iterator, indented by the given amount.
|
||||
DebugString(int) string
|
||||
// Return whether this iterator is relaiably nextable. Most iterators are.
|
||||
// However, some iterators, like "not" are, by definition, the whole database
|
||||
// except themselves. Next() on these is unproductive, if impossible.
|
||||
Nextable() bool
|
||||
|
||||
// Close the iterator and do internal cleanup.
|
||||
Close()
|
||||
GetUid() int
|
||||
|
||||
UID() uintptr
|
||||
}
|
||||
|
||||
type FixedIterator interface {
|
||||
Iterator
|
||||
AddValue(TSVal)
|
||||
Add(Value)
|
||||
}
|
||||
|
||||
type IteratorStats struct {
|
||||
|
|
@ -114,18 +128,18 @@ 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.GetUid(), val)
|
||||
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.GetUid(), val)
|
||||
glog.V(4).Infof("%s %d CHECK %d GOOD", strings.ToUpper(it.Type()), it.UID(), val)
|
||||
} else {
|
||||
glog.V(4).Infof("%s %d CHECK %d BAD", strings.ToUpper(it.Type()), it.GetUid(), val)
|
||||
glog.V(4).Infof("%s %d CHECK %d BAD", strings.ToUpper(it.Type()), it.UID(), val)
|
||||
}
|
||||
}
|
||||
return good
|
||||
|
|
@ -133,16 +147,16 @@ func CheckLogOut(it Iterator, val TSVal, good bool) bool {
|
|||
|
||||
func NextLogIn(it Iterator) {
|
||||
if glog.V(4) {
|
||||
glog.V(4).Infof("%s %d NEXT", strings.ToUpper(it.Type()), it.GetUid())
|
||||
glog.V(4).Infof("%s %d NEXT", strings.ToUpper(it.Type()), it.UID())
|
||||
}
|
||||
}
|
||||
|
||||
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.GetUid(), val)
|
||||
glog.V(4).Infof("%s %d NEXT IS %d", strings.ToUpper(it.Type()), it.UID(), val)
|
||||
} else {
|
||||
glog.V(4).Infof("%s %d NEXT DONE", strings.ToUpper(it.Type()), it.GetUid())
|
||||
glog.V(4).Infof("%s %d NEXT DONE", strings.ToUpper(it.Type()), it.UID())
|
||||
}
|
||||
}
|
||||
return val, ok
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
@ -108,9 +108,9 @@ func (it *Int64) Optimize() (graph.Iterator, bool) { return it, false }
|
|||
|
||||
// Stats for an Int64 are simple. Super cheap to do any operation,
|
||||
// and as big as the range.
|
||||
func (it *Int64) GetStats() *graph.IteratorStats {
|
||||
func (it *Int64) Stats() graph.IteratorStats {
|
||||
s, _ := it.Size()
|
||||
return &graph.IteratorStats{
|
||||
return graph.IteratorStats{
|
||||
CheckCost: 1,
|
||||
NextCost: 1,
|
||||
Size: s,
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ func (it *And) Clone() graph.Iterator {
|
|||
}
|
||||
|
||||
// Returns a slice of the subiterators, in order (primary iterator first).
|
||||
func (it *And) GetSubIterators() []graph.Iterator {
|
||||
func (it *And) SubIterators() []graph.Iterator {
|
||||
iters := make([]graph.Iterator, len(it.internalIterators)+1)
|
||||
iters[0] = it.primaryIt
|
||||
copy(iters[1:], it.internalIterators)
|
||||
|
|
@ -73,22 +73,22 @@ func (it *And) GetSubIterators() []graph.Iterator {
|
|||
|
||||
// Overrides Base TagResults, as it needs to add it's own results and
|
||||
// recurse down it's subiterators.
|
||||
func (it *And) TagResults(out *map[string]graph.TSVal) {
|
||||
it.Base.TagResults(out)
|
||||
func (it *And) TagResults(dst map[string]graph.Value) {
|
||||
it.Base.TagResults(dst)
|
||||
if it.primaryIt != nil {
|
||||
it.primaryIt.TagResults(out)
|
||||
it.primaryIt.TagResults(dst)
|
||||
}
|
||||
for _, sub := range it.internalIterators {
|
||||
sub.TagResults(out)
|
||||
sub.TagResults(dst)
|
||||
}
|
||||
}
|
||||
|
||||
// DEPRECATED Returns the ResultTree for this iterator, recurses to it's subiterators.
|
||||
func (it *And) GetResultTree() *graph.ResultTree {
|
||||
tree := graph.NewResultTree(it.LastResult())
|
||||
tree.AddSubtree(it.primaryIt.GetResultTree())
|
||||
func (it *And) ResultTree() *graph.ResultTree {
|
||||
tree := graph.NewResultTree(it.Result())
|
||||
tree.AddSubtree(it.primaryIt.ResultTree())
|
||||
for _, sub := range it.internalIterators {
|
||||
tree.AddSubtree(sub.GetResultTree())
|
||||
tree.AddSubtree(sub.ResultTree())
|
||||
}
|
||||
return tree
|
||||
}
|
||||
|
|
@ -109,13 +109,14 @@ func (it *And) DebugString(indent int) string {
|
|||
return fmt.Sprintf("%s(%s %d\n%stags:%s\n%sprimary_it:\n%s\n%sother_its:\n%s)",
|
||||
strings.Repeat(" ", indent),
|
||||
it.Type(),
|
||||
it.GetUid(),
|
||||
it.UID(),
|
||||
spaces,
|
||||
tags,
|
||||
spaces,
|
||||
it.primaryIt.DebugString(indent+4),
|
||||
spaces,
|
||||
total)
|
||||
total,
|
||||
)
|
||||
}
|
||||
|
||||
// Add a subiterator to this And iterator.
|
||||
|
|
@ -138,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()
|
||||
|
|
@ -156,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)
|
||||
|
|
@ -167,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)
|
||||
|
|
@ -182,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)
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ import (
|
|||
func (it *And) Optimize() (graph.Iterator, bool) {
|
||||
// First, let's get the slice of iterators, in order (first one is Next()ed,
|
||||
// the rest are Check()ed)
|
||||
old := it.GetSubIterators()
|
||||
old := it.SubIterators()
|
||||
|
||||
// And call Optimize() on our subtree, replacing each one in the order we
|
||||
// found them. it_list is the newly optimized versions of these, and changed
|
||||
|
|
@ -145,20 +145,20 @@ func optimizeOrder(its []graph.Iterator) []graph.Iterator {
|
|||
// all of it's contents, and to Check() each of those against everyone
|
||||
// else.
|
||||
for _, it := range its {
|
||||
if !it.Nextable() {
|
||||
if !it.CanNext() {
|
||||
bad = append(bad, it)
|
||||
continue
|
||||
}
|
||||
rootStats := it.GetStats()
|
||||
rootStats := it.Stats()
|
||||
cost := rootStats.NextCost
|
||||
for _, f := range its {
|
||||
if !f.Nextable() {
|
||||
if !f.CanNext() {
|
||||
continue
|
||||
}
|
||||
if f == it {
|
||||
continue
|
||||
}
|
||||
stats := f.GetStats()
|
||||
stats := f.Stats()
|
||||
cost += stats.CheckCost
|
||||
}
|
||||
cost *= rootStats.Size
|
||||
|
|
@ -177,7 +177,7 @@ func optimizeOrder(its []graph.Iterator) []graph.Iterator {
|
|||
|
||||
// ... push everyone else after...
|
||||
for _, it := range its {
|
||||
if !it.Nextable() {
|
||||
if !it.CanNext() {
|
||||
continue
|
||||
}
|
||||
if it != best {
|
||||
|
|
@ -192,7 +192,7 @@ func optimizeOrder(its []graph.Iterator) []graph.Iterator {
|
|||
type byCost []graph.Iterator
|
||||
|
||||
func (c byCost) Len() int { return len(c) }
|
||||
func (c byCost) Less(i, j int) bool { return c[i].GetStats().CheckCost < c[j].GetStats().CheckCost }
|
||||
func (c byCost) Less(i, j int) bool { return c[i].Stats().CheckCost < c[j].Stats().CheckCost }
|
||||
func (c byCost) Swap(i, j int) { c[i], c[j] = c[j], c[i] }
|
||||
|
||||
// optimizeCheck(l) creates an alternate check list, containing the same contents
|
||||
|
|
@ -202,7 +202,7 @@ func (it *And) optimizeCheck() {
|
|||
// TODO(kortschak) Reuse it.checkList if possible.
|
||||
// This involves providing GetSubIterators with a slice to fill.
|
||||
// Generally this is a worthwhile thing to do in other places as well.
|
||||
it.checkList = it.GetSubIterators()
|
||||
it.checkList = it.SubIterators()
|
||||
sort.Sort(byCost(it.checkList))
|
||||
}
|
||||
|
||||
|
|
@ -212,7 +212,7 @@ func (it *And) optimizeCheck() {
|
|||
// getSubTags() returns a map of the tags for all the subiterators.
|
||||
func (it *And) getSubTags() map[string]struct{} {
|
||||
tags := make(map[string]struct{})
|
||||
for _, sub := range it.GetSubIterators() {
|
||||
for _, sub := range it.SubIterators() {
|
||||
for _, tag := range sub.Tags() {
|
||||
tags[tag] = struct{}{}
|
||||
}
|
||||
|
|
@ -292,23 +292,23 @@ func hasOneUsefulIterator(its []graph.Iterator) graph.Iterator {
|
|||
return nil
|
||||
}
|
||||
|
||||
// and.GetStats() lives here in and-iterator-optimize.go because it may
|
||||
// and.Stats() lives here in and-iterator-optimize.go because it may
|
||||
// in the future return different statistics based on how it is optimized.
|
||||
// For now, however, it's pretty static.
|
||||
func (it *And) GetStats() *graph.IteratorStats {
|
||||
primaryStats := it.primaryIt.GetStats()
|
||||
func (it *And) Stats() graph.IteratorStats {
|
||||
primaryStats := it.primaryIt.Stats()
|
||||
CheckCost := primaryStats.CheckCost
|
||||
NextCost := primaryStats.NextCost
|
||||
Size := primaryStats.Size
|
||||
for _, sub := range it.internalIterators {
|
||||
stats := sub.GetStats()
|
||||
stats := sub.Stats()
|
||||
NextCost += stats.CheckCost
|
||||
CheckCost += stats.CheckCost
|
||||
if Size > stats.Size {
|
||||
Size = stats.Size
|
||||
}
|
||||
}
|
||||
return &graph.IteratorStats{
|
||||
return graph.IteratorStats{
|
||||
CheckCost: CheckCost,
|
||||
NextCost: NextCost,
|
||||
Size: Size,
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import (
|
|||
func TestIteratorPromotion(t *testing.T) {
|
||||
all := NewInt64(1, 3)
|
||||
fixed := newFixed()
|
||||
fixed.AddValue(3)
|
||||
fixed.Add(3)
|
||||
a := NewAnd()
|
||||
a.AddSubIterator(all)
|
||||
a.AddSubIterator(fixed)
|
||||
|
|
@ -79,7 +79,7 @@ func TestReorderWithTag(t *testing.T) {
|
|||
}
|
||||
expectedTags := []string{"good", "slow"}
|
||||
tagsOut := make([]string, 0)
|
||||
for _, sub := range newIt.GetSubIterators() {
|
||||
for _, sub := range newIt.SubIterators() {
|
||||
for _, x := range sub.Tags() {
|
||||
tagsOut = append(tagsOut, x)
|
||||
}
|
||||
|
|
@ -98,12 +98,12 @@ func TestAndStatistics(t *testing.T) {
|
|||
// Make all2 the default iterator
|
||||
a.AddSubIterator(all2)
|
||||
a.AddSubIterator(all)
|
||||
stats1 := a.GetStats()
|
||||
stats1 := a.Stats()
|
||||
newIt, changed := a.Optimize()
|
||||
if !changed {
|
||||
t.Error("Didn't optimize")
|
||||
}
|
||||
stats2 := newIt.GetStats()
|
||||
stats2 := newIt.Stats()
|
||||
if stats2.NextCost > stats1.NextCost {
|
||||
t.Error("And didn't optimize. Next cost old ", stats1.NextCost, "and new ", stats2.NextCost)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import (
|
|||
// Make sure that tags work on the And.
|
||||
func TestTag(t *testing.T) {
|
||||
fix1 := newFixed()
|
||||
fix1.AddValue(234)
|
||||
fix1.Add(234)
|
||||
fix1.AddTag("foo")
|
||||
and := NewAnd()
|
||||
and.AddSubIterator(fix1)
|
||||
|
|
@ -43,8 +43,8 @@ func TestTag(t *testing.T) {
|
|||
if val != 234 {
|
||||
t.Errorf("Unexpected value")
|
||||
}
|
||||
tags := make(map[string]graph.TSVal)
|
||||
and.TagResults(&tags)
|
||||
tags := make(map[string]graph.Value)
|
||||
and.TagResults(tags)
|
||||
if tags["bar"] != 234 {
|
||||
t.Errorf("no bar tag")
|
||||
}
|
||||
|
|
@ -56,14 +56,14 @@ func TestTag(t *testing.T) {
|
|||
// Do a simple itersection of fixed values.
|
||||
func TestAndAndFixedIterators(t *testing.T) {
|
||||
fix1 := newFixed()
|
||||
fix1.AddValue(1)
|
||||
fix1.AddValue(2)
|
||||
fix1.AddValue(3)
|
||||
fix1.AddValue(4)
|
||||
fix1.Add(1)
|
||||
fix1.Add(2)
|
||||
fix1.Add(3)
|
||||
fix1.Add(4)
|
||||
fix2 := newFixed()
|
||||
fix2.AddValue(3)
|
||||
fix2.AddValue(4)
|
||||
fix2.AddValue(5)
|
||||
fix2.Add(3)
|
||||
fix2.Add(4)
|
||||
fix2.Add(5)
|
||||
and := NewAnd()
|
||||
and.AddSubIterator(fix1)
|
||||
and.AddSubIterator(fix2)
|
||||
|
|
@ -97,14 +97,14 @@ func TestAndAndFixedIterators(t *testing.T) {
|
|||
// but there should be nothing to Next()
|
||||
func TestNonOverlappingFixedIterators(t *testing.T) {
|
||||
fix1 := newFixed()
|
||||
fix1.AddValue(1)
|
||||
fix1.AddValue(2)
|
||||
fix1.AddValue(3)
|
||||
fix1.AddValue(4)
|
||||
fix1.Add(1)
|
||||
fix1.Add(2)
|
||||
fix1.Add(3)
|
||||
fix1.Add(4)
|
||||
fix2 := newFixed()
|
||||
fix2.AddValue(5)
|
||||
fix2.AddValue(6)
|
||||
fix2.AddValue(7)
|
||||
fix2.Add(5)
|
||||
fix2.Add(6)
|
||||
fix2.Add(7)
|
||||
and := NewAnd()
|
||||
and.AddSubIterator(fix1)
|
||||
and.AddSubIterator(fix2)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -71,7 +71,7 @@ func (it *Fixed) Close() {}
|
|||
func (it *Fixed) Clone() graph.Iterator {
|
||||
out := NewFixedIteratorWithCompare(it.cmp)
|
||||
for _, val := range it.values {
|
||||
out.AddValue(val)
|
||||
out.Add(val)
|
||||
}
|
||||
out.CopyTagsFrom(it)
|
||||
return out
|
||||
|
|
@ -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) Add(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)
|
||||
|
|
@ -148,8 +148,8 @@ func (it *Fixed) Size() (int64, bool) {
|
|||
|
||||
// As we right now have to scan the entire list, Next and Check are linear with the
|
||||
// size. However, a better data structure could remove these limits.
|
||||
func (it *Fixed) GetStats() *graph.IteratorStats {
|
||||
return &graph.IteratorStats{
|
||||
func (it *Fixed) Stats() graph.IteratorStats {
|
||||
return graph.IteratorStats{
|
||||
CheckCost: int64(len(it.values)),
|
||||
NextCost: int64(len(it.values)),
|
||||
Size: int64(len(it.values)),
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ func NewHasA(ts graph.TripleStore, subIt graph.Iterator, d graph.Direction) *Has
|
|||
}
|
||||
|
||||
// Return our sole subiterator.
|
||||
func (it *HasA) GetSubIterators() []graph.Iterator {
|
||||
func (it *HasA) SubIterators() []graph.Iterator {
|
||||
return []graph.Iterator{it.primaryIt}
|
||||
}
|
||||
|
||||
|
|
@ -99,15 +99,15 @@ func (it *HasA) Optimize() (graph.Iterator, bool) {
|
|||
}
|
||||
|
||||
// Pass the TagResults down the chain.
|
||||
func (it *HasA) TagResults(out *map[string]graph.TSVal) {
|
||||
it.Base.TagResults(out)
|
||||
it.primaryIt.TagResults(out)
|
||||
func (it *HasA) TagResults(dst map[string]graph.Value) {
|
||||
it.Base.TagResults(dst)
|
||||
it.primaryIt.TagResults(dst)
|
||||
}
|
||||
|
||||
// DEPRECATED Return results in a ResultTree.
|
||||
func (it *HasA) GetResultTree() *graph.ResultTree {
|
||||
tree := graph.NewResultTree(it.LastResult())
|
||||
tree.AddSubtree(it.primaryIt.GetResultTree())
|
||||
func (it *HasA) ResultTree() *graph.ResultTree {
|
||||
tree := graph.NewResultTree(it.Result())
|
||||
tree.AddSubtree(it.primaryIt.ResultTree())
|
||||
return tree
|
||||
}
|
||||
|
||||
|
|
@ -117,22 +117,22 @@ func (it *HasA) DebugString(indent int) string {
|
|||
for _, k := range it.Tags() {
|
||||
tags += fmt.Sprintf("%s;", k)
|
||||
}
|
||||
return fmt.Sprintf("%s(%s %d tags:%s direction:%s\n%s)", strings.Repeat(" ", indent), it.Type(), it.GetUid(), tags, it.dir, it.primaryIt.DebugString(indent+4))
|
||||
return fmt.Sprintf("%s(%s %d tags:%s direction:%s\n%s)", strings.Repeat(" ", indent), it.Type(), it.UID(), tags, it.dir, it.primaryIt.DebugString(indent+4))
|
||||
}
|
||||
|
||||
// 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.GetNameFor(val))
|
||||
glog.V(4).Infoln("Id is", it.ts.NameOf(val))
|
||||
}
|
||||
// TODO(barakmich): Optimize this
|
||||
if it.resultIt != nil {
|
||||
it.resultIt.Close()
|
||||
}
|
||||
it.resultIt = it.ts.GetTripleIterator(it.dir, val)
|
||||
it.resultIt = it.ts.TripleIterator(it.dir, val)
|
||||
return graph.CheckLogOut(it, val, it.GetCheckResult())
|
||||
}
|
||||
|
||||
|
|
@ -146,10 +146,10 @@ func (it *HasA) GetCheckResult() bool {
|
|||
break
|
||||
}
|
||||
if glog.V(4) {
|
||||
glog.V(4).Infoln("Triple is", it.ts.GetTriple(linkVal))
|
||||
glog.V(4).Infoln("Triple is", it.ts.Triple(linkVal))
|
||||
}
|
||||
if it.primaryIt.Check(linkVal) {
|
||||
it.Last = it.ts.GetTripleDirection(linkVal, it.dir)
|
||||
it.Last = it.ts.TripleDirection(linkVal, it.dir)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
|
@ -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()
|
||||
|
|
@ -184,8 +184,8 @@ func (it *HasA) Next() (graph.TSVal, bool) {
|
|||
if !ok {
|
||||
return graph.NextLogOut(it, 0, false)
|
||||
}
|
||||
name := it.ts.GetTriple(tID).Get(it.dir)
|
||||
val := it.ts.GetIdFor(name)
|
||||
name := it.ts.Triple(tID).Get(it.dir)
|
||||
val := it.ts.ValueOf(name)
|
||||
it.Last = val
|
||||
return graph.NextLogOut(it, val, true)
|
||||
}
|
||||
|
|
@ -196,15 +196,15 @@ func (it *HasA) Next() (graph.TSVal, bool) {
|
|||
// one sticks -- potentially expensive, depending on fanout. Size, however, is
|
||||
// potentially smaller. we know at worst it's the size of the subiterator, but
|
||||
// if there are many repeated values, it could be much smaller in totality.
|
||||
func (it *HasA) GetStats() *graph.IteratorStats {
|
||||
subitStats := it.primaryIt.GetStats()
|
||||
func (it *HasA) Stats() graph.IteratorStats {
|
||||
subitStats := it.primaryIt.Stats()
|
||||
// TODO(barakmich): These should really come from the triplestore itself
|
||||
// and be optimized.
|
||||
faninFactor := int64(1)
|
||||
fanoutFactor := int64(30)
|
||||
nextConstant := int64(2)
|
||||
tripleConstant := int64(1)
|
||||
return &graph.IteratorStats{
|
||||
return graph.IteratorStats{
|
||||
NextCost: tripleConstant + subitStats.NextCost,
|
||||
CheckCost: (fanoutFactor * nextConstant) * subitStats.CheckCost,
|
||||
Size: faninFactor * subitStats.Size,
|
||||
|
|
|
|||
|
|
@ -20,35 +20,39 @@ package iterator
|
|||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/barakmich/glog"
|
||||
|
||||
"github.com/google/cayley/graph"
|
||||
)
|
||||
|
||||
var iterator_n int = 0
|
||||
var nextIteratorID uintptr
|
||||
|
||||
func nextID() uintptr {
|
||||
return atomic.AddUintptr(&nextIteratorID, 1) - 1
|
||||
}
|
||||
|
||||
// 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
|
||||
nextable bool
|
||||
uid int
|
||||
fixedTags map[string]graph.Value
|
||||
canNext bool
|
||||
uid uintptr
|
||||
}
|
||||
|
||||
// Called by subclases.
|
||||
func BaseInit(it *Base) {
|
||||
// Your basic iterator is nextable
|
||||
it.nextable = true
|
||||
it.uid = iterator_n
|
||||
it.canNext = true
|
||||
if glog.V(2) {
|
||||
iterator_n++
|
||||
it.uid = nextID()
|
||||
}
|
||||
}
|
||||
|
||||
func (it *Base) GetUid() int {
|
||||
func (it *Base) UID() uintptr {
|
||||
return it.uid
|
||||
}
|
||||
|
||||
|
|
@ -60,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
|
||||
}
|
||||
|
|
@ -72,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
|
||||
}
|
||||
|
||||
|
|
@ -93,24 +97,24 @@ 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
|
||||
}
|
||||
|
||||
// Base iterators should never appear in a tree if they are, select against
|
||||
// them.
|
||||
func (it *Base) GetStats() *graph.IteratorStats {
|
||||
return &graph.IteratorStats{100000, 100000, 100000}
|
||||
func (it *Base) Stats() graph.IteratorStats {
|
||||
return graph.IteratorStats{100000, 100000, 100000}
|
||||
}
|
||||
|
||||
// DEPRECATED
|
||||
func (it *Base) GetResultTree() *graph.ResultTree {
|
||||
tree := graph.NewResultTree(it.LastResult())
|
||||
func (it *Base) ResultTree() *graph.ResultTree {
|
||||
tree := graph.NewResultTree(it.Result())
|
||||
return tree
|
||||
}
|
||||
|
||||
// Nothing in a base iterator.
|
||||
func (it *Base) Next() (graph.TSVal, bool) {
|
||||
func (it *Base) Next() (graph.Value, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
|
|
@ -119,7 +123,7 @@ func (it *Base) NextResult() bool {
|
|||
}
|
||||
|
||||
// Returns the last result of an iterator.
|
||||
func (it *Base) LastResult() graph.TSVal {
|
||||
func (it *Base) Result() graph.Value {
|
||||
return it.Last
|
||||
}
|
||||
|
||||
|
|
@ -129,22 +133,22 @@ func (it *Base) Size() (int64, bool) {
|
|||
}
|
||||
|
||||
// No subiterators. Only those with subiterators need to do anything here.
|
||||
func (it *Base) GetSubIterators() []graph.Iterator {
|
||||
func (it *Base) SubIterators() []graph.Iterator {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Accessor
|
||||
func (it *Base) Nextable() bool { return it.nextable }
|
||||
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(out_map *map[string]graph.TSVal) {
|
||||
func (it *Base) TagResults(dst map[string]graph.Value) {
|
||||
for _, tag := range it.Tags() {
|
||||
(*out_map)[tag] = it.LastResult()
|
||||
dst[tag] = it.Result()
|
||||
}
|
||||
|
||||
for tag, value := range it.FixedTags() {
|
||||
(*out_map)[tag] = value
|
||||
dst[tag] = value
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -182,6 +186,6 @@ func (it *Null) DebugString(indent int) string {
|
|||
}
|
||||
|
||||
// A null iterator costs nothing. Use it!
|
||||
func (it *Null) GetStats() *graph.IteratorStats {
|
||||
return &graph.IteratorStats{}
|
||||
func (it *Null) Stats() graph.IteratorStats {
|
||||
return graph.IteratorStats{}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,15 +77,15 @@ 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(out *map[string]graph.TSVal) {
|
||||
it.Base.TagResults(out)
|
||||
it.primaryIt.TagResults(out)
|
||||
func (it *LinksTo) TagResults(dst map[string]graph.Value) {
|
||||
it.Base.TagResults(dst)
|
||||
it.primaryIt.TagResults(dst)
|
||||
}
|
||||
|
||||
// DEPRECATED
|
||||
func (it *LinksTo) GetResultTree() *graph.ResultTree {
|
||||
tree := graph.NewResultTree(it.LastResult())
|
||||
tree.AddSubtree(it.primaryIt.GetResultTree())
|
||||
func (it *LinksTo) ResultTree() *graph.ResultTree {
|
||||
tree := graph.NewResultTree(it.Result())
|
||||
tree.AddSubtree(it.primaryIt.ResultTree())
|
||||
return tree
|
||||
}
|
||||
|
||||
|
|
@ -93,14 +93,14 @@ func (it *LinksTo) GetResultTree() *graph.ResultTree {
|
|||
func (it *LinksTo) DebugString(indent int) string {
|
||||
return fmt.Sprintf("%s(%s %d direction:%s\n%s)",
|
||||
strings.Repeat(" ", indent),
|
||||
it.Type(), it.GetUid(), it.dir, it.primaryIt.DebugString(indent+4))
|
||||
it.Type(), it.UID(), it.dir, it.primaryIt.DebugString(indent+4))
|
||||
}
|
||||
|
||||
// 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.GetTripleDirection(val, it.dir)
|
||||
node := it.ts.TripleDirection(val, it.dir)
|
||||
if it.primaryIt.Check(node) {
|
||||
it.Last = val
|
||||
return graph.CheckLogOut(it, val, true)
|
||||
|
|
@ -109,7 +109,7 @@ func (it *LinksTo) Check(val graph.TSVal) bool {
|
|||
}
|
||||
|
||||
// Return a list containing only our subiterator.
|
||||
func (it *LinksTo) GetSubIterators() []graph.Iterator {
|
||||
func (it *LinksTo) SubIterators() []graph.Iterator {
|
||||
return []graph.Iterator{it.primaryIt}
|
||||
}
|
||||
|
||||
|
|
@ -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 {
|
||||
|
|
@ -146,7 +146,7 @@ func (it *LinksTo) Next() (graph.TSVal, bool) {
|
|||
return graph.NextLogOut(it, 0, false)
|
||||
}
|
||||
it.nextIt.Close()
|
||||
it.nextIt = it.ts.GetTripleIterator(it.dir, candidate)
|
||||
it.nextIt = it.ts.TripleIterator(it.dir, candidate)
|
||||
// Recurse -- return the first in the next set.
|
||||
return it.Next()
|
||||
}
|
||||
|
|
@ -169,13 +169,13 @@ func (it *LinksTo) NextResult() bool {
|
|||
func (it *LinksTo) Type() string { return "linksto" }
|
||||
|
||||
// Return a guess as to how big or costly it is to next the iterator.
|
||||
func (it *LinksTo) GetStats() *graph.IteratorStats {
|
||||
subitStats := it.primaryIt.GetStats()
|
||||
func (it *LinksTo) Stats() graph.IteratorStats {
|
||||
subitStats := it.primaryIt.Stats()
|
||||
// TODO(barakmich): These should really come from the triplestore itself
|
||||
fanoutFactor := int64(20)
|
||||
checkConstant := int64(1)
|
||||
nextConstant := int64(2)
|
||||
return &graph.IteratorStats{
|
||||
return graph.IteratorStats{
|
||||
NextCost: nextConstant + subitStats.NextCost,
|
||||
CheckCost: checkConstant + subitStats.CheckCost,
|
||||
Size: fanoutFactor * subitStats.Size,
|
||||
|
|
|
|||
|
|
@ -23,17 +23,17 @@ import (
|
|||
func TestLinksTo(t *testing.T) {
|
||||
ts := new(TestTripleStore)
|
||||
tsFixed := newFixed()
|
||||
tsFixed.AddValue(2)
|
||||
ts.On("GetIdFor", "cool").Return(1)
|
||||
ts.On("GetTripleIterator", graph.Object, 1).Return(tsFixed)
|
||||
tsFixed.Add(2)
|
||||
ts.On("ValueOf", "cool").Return(1)
|
||||
ts.On("TripleIterator", graph.Object, 1).Return(tsFixed)
|
||||
fixed := newFixed()
|
||||
fixed.AddValue(ts.GetIdFor("cool"))
|
||||
fixed.Add(ts.ValueOf("cool"))
|
||||
lto := NewLinksTo(ts, fixed, graph.Object)
|
||||
val, ok := lto.Next()
|
||||
if !ok {
|
||||
t.Error("At least one triple matches the fixed object")
|
||||
}
|
||||
if val != 2 {
|
||||
t.Errorf("Triple index 2, such as %s, should match %s", ts.GetTriple(2), ts.GetTriple(val))
|
||||
t.Errorf("Triple index 2, such as %s, should match %s", ts.Triple(2), ts.Triple(val))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,23 +27,23 @@ type TestTripleStore struct {
|
|||
mock.Mock
|
||||
}
|
||||
|
||||
func (ts *TestTripleStore) GetIdFor(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) GetTriple(graph.TSVal) *graph.Triple { return &graph.Triple{} }
|
||||
func (ts *TestTripleStore) GetTripleIterator(d graph.Direction, i graph.TSVal) graph.Iterator {
|
||||
func (ts *TestTripleStore) AddTriple(*graph.Triple) {}
|
||||
func (ts *TestTripleStore) AddTripleSet([]*graph.Triple) {}
|
||||
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)
|
||||
}
|
||||
func (ts *TestTripleStore) GetNodesAllIterator() graph.Iterator { return &Null{} }
|
||||
func (ts *TestTripleStore) GetTriplesAllIterator() graph.Iterator { return &Null{} }
|
||||
func (ts *TestTripleStore) NodesAllIterator() graph.Iterator { return &Null{} }
|
||||
func (ts *TestTripleStore) TriplesAllIterator() graph.Iterator { return &Null{} }
|
||||
func (ts *TestTripleStore) GetIteratorByString(string, string, string) graph.Iterator {
|
||||
return &Null{}
|
||||
}
|
||||
func (ts *TestTripleStore) GetNameFor(v graph.TSVal) string {
|
||||
func (ts *TestTripleStore) NameOf(v graph.Value) string {
|
||||
args := ts.Mock.Called(v)
|
||||
return args.Get(0).(string)
|
||||
}
|
||||
|
|
@ -55,6 +55,6 @@ func (ts *TestTripleStore) OptimizeIterator(it graph.Iterator) (graph.Iterator,
|
|||
func (ts *TestTripleStore) FixedIterator() graph.FixedIterator {
|
||||
return NewFixedIteratorWithCompare(BasicEquality)
|
||||
}
|
||||
func (ts *TestTripleStore) Close() {}
|
||||
func (ts *TestTripleStore) GetTripleDirection(graph.TSVal, graph.Direction) graph.TSVal { return 0 }
|
||||
func (ts *TestTripleStore) RemoveTriple(t *graph.Triple) {}
|
||||
func (ts *TestTripleStore) Close() {}
|
||||
func (ts *TestTripleStore) TripleDirection(graph.Value, graph.Direction) graph.Value { return 0 }
|
||||
func (ts *TestTripleStore) RemoveTriple(t *graph.Triple) {}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ type Optional struct {
|
|||
func NewOptional(it graph.Iterator) *Optional {
|
||||
var o Optional
|
||||
BaseInit(&o.Base)
|
||||
o.nextable = false
|
||||
o.canNext = false
|
||||
o.subIt = it
|
||||
return &o
|
||||
}
|
||||
|
|
@ -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,11 +96,11 @@ 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(out *map[string]graph.TSVal) {
|
||||
func (it *Optional) TagResults(dst map[string]graph.Value) {
|
||||
if it.lastCheck == false {
|
||||
return
|
||||
}
|
||||
it.subIt.TagResults(out)
|
||||
it.subIt.TagResults(dst)
|
||||
}
|
||||
|
||||
// Registers the optional iterator.
|
||||
|
|
@ -127,9 +127,9 @@ func (it *Optional) Optimize() (graph.Iterator, bool) {
|
|||
}
|
||||
|
||||
// We're only as expensive as our subiterator. Except, we can't be nexted.
|
||||
func (it *Optional) GetStats() *graph.IteratorStats {
|
||||
subStats := it.subIt.GetStats()
|
||||
return &graph.IteratorStats{
|
||||
func (it *Optional) Stats() graph.IteratorStats {
|
||||
subStats := it.subIt.Stats()
|
||||
return graph.IteratorStats{
|
||||
CheckCost: subStats.CheckCost,
|
||||
NextCost: int64(1 << 62),
|
||||
Size: subStats.Size,
|
||||
|
|
|
|||
|
|
@ -77,22 +77,22 @@ func (it *Or) Clone() graph.Iterator {
|
|||
}
|
||||
|
||||
// Returns a list.List of the subiterators, in order. The returned slice must not be modified.
|
||||
func (it *Or) GetSubIterators() []graph.Iterator {
|
||||
func (it *Or) SubIterators() []graph.Iterator {
|
||||
return it.internalIterators
|
||||
}
|
||||
|
||||
// Overrides BaseIterator TagResults, as it needs to add it's own results and
|
||||
// recurse down it's subiterators.
|
||||
func (it *Or) TagResults(out *map[string]graph.TSVal) {
|
||||
it.Base.TagResults(out)
|
||||
it.internalIterators[it.currentIterator].TagResults(out)
|
||||
func (it *Or) TagResults(dst map[string]graph.Value) {
|
||||
it.Base.TagResults(dst)
|
||||
it.internalIterators[it.currentIterator].TagResults(dst)
|
||||
}
|
||||
|
||||
// DEPRECATED Returns the ResultTree for this graph.iterator, recurses to it's subiterators.
|
||||
func (it *Or) GetResultTree() *graph.ResultTree {
|
||||
tree := graph.NewResultTree(it.LastResult())
|
||||
func (it *Or) ResultTree() *graph.ResultTree {
|
||||
tree := graph.NewResultTree(it.Result())
|
||||
for _, sub := range it.internalIterators {
|
||||
tree.AddSubtree(sub.GetResultTree())
|
||||
tree.AddSubtree(sub.ResultTree())
|
||||
}
|
||||
return tree
|
||||
}
|
||||
|
|
@ -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 {
|
||||
|
|
@ -233,7 +233,7 @@ func (it *Or) Close() {
|
|||
}
|
||||
|
||||
func (it *Or) Optimize() (graph.Iterator, bool) {
|
||||
old := it.GetSubIterators()
|
||||
old := it.SubIterators()
|
||||
optIts := optimizeSubIterators(old)
|
||||
// Close the replaced iterators (they ought to close themselves, but Close()
|
||||
// is idempotent, so this just protects against any machinations).
|
||||
|
|
@ -256,12 +256,12 @@ func (it *Or) Optimize() (graph.Iterator, bool) {
|
|||
return newOr, true
|
||||
}
|
||||
|
||||
func (it *Or) GetStats() *graph.IteratorStats {
|
||||
func (it *Or) Stats() graph.IteratorStats {
|
||||
CheckCost := int64(0)
|
||||
NextCost := int64(0)
|
||||
Size := int64(0)
|
||||
for _, sub := range it.internalIterators {
|
||||
stats := sub.GetStats()
|
||||
stats := sub.Stats()
|
||||
NextCost += stats.NextCost
|
||||
CheckCost += stats.CheckCost
|
||||
if it.isShortCircuiting {
|
||||
|
|
@ -272,7 +272,7 @@ func (it *Or) GetStats() *graph.IteratorStats {
|
|||
Size += stats.Size
|
||||
}
|
||||
}
|
||||
return &graph.IteratorStats{
|
||||
return graph.IteratorStats{
|
||||
CheckCost: CheckCost,
|
||||
NextCost: NextCost,
|
||||
Size: Size,
|
||||
|
|
|
|||
|
|
@ -40,14 +40,14 @@ func TestOrIteratorBasics(t *testing.T) {
|
|||
Convey("Given an Or Iterator of two fixed iterators", t, func() {
|
||||
orIt = NewOr()
|
||||
fixed1 := newFixed()
|
||||
fixed1.AddValue(1)
|
||||
fixed1.AddValue(2)
|
||||
fixed1.AddValue(3)
|
||||
fixed1.Add(1)
|
||||
fixed1.Add(2)
|
||||
fixed1.Add(3)
|
||||
fixed2 := newFixed()
|
||||
fixed2.AddValue(3)
|
||||
fixed2.AddValue(9)
|
||||
fixed2.AddValue(20)
|
||||
fixed2.AddValue(21)
|
||||
fixed2.Add(3)
|
||||
fixed2.Add(9)
|
||||
fixed2.Add(20)
|
||||
fixed2.Add(21)
|
||||
orIt.AddSubIterator(fixed1)
|
||||
orIt.AddSubIterator(fixed2)
|
||||
|
||||
|
|
@ -88,14 +88,14 @@ func TestShortCircuitingOrBasics(t *testing.T) {
|
|||
Convey("Given a short-circuiting Or of two fixed iterators", t, func() {
|
||||
orIt = NewShortCircuitOr()
|
||||
fixed1 := newFixed()
|
||||
fixed1.AddValue(1)
|
||||
fixed1.AddValue(2)
|
||||
fixed1.AddValue(3)
|
||||
fixed1.Add(1)
|
||||
fixed1.Add(2)
|
||||
fixed1.Add(3)
|
||||
fixed2 := newFixed()
|
||||
fixed2.AddValue(3)
|
||||
fixed2.AddValue(9)
|
||||
fixed2.AddValue(20)
|
||||
fixed2.AddValue(21)
|
||||
fixed2.Add(3)
|
||||
fixed2.Add(9)
|
||||
fixed2.Add(20)
|
||||
fixed2.Add(21)
|
||||
|
||||
Convey("It should guess its size.", func() {
|
||||
orIt.AddSubIterator(fixed1)
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ func (qs *queryShape) MakeNode(it graph.Iterator) *Node {
|
|||
|
||||
switch it.Type() {
|
||||
case "and":
|
||||
for _, sub := range it.GetSubIterators() {
|
||||
for _, sub := range it.SubIterators() {
|
||||
qs.nodeId++
|
||||
newNode := qs.MakeNode(sub)
|
||||
if sub.Type() != "or" {
|
||||
|
|
@ -133,7 +133,7 @@ func (qs *queryShape) MakeNode(it graph.Iterator) *Node {
|
|||
if !more {
|
||||
break
|
||||
}
|
||||
n.Values = append(n.Values, qs.ts.GetNameFor(val))
|
||||
n.Values = append(n.Values, qs.ts.NameOf(val))
|
||||
}
|
||||
case "hasa":
|
||||
hasa := it.(*HasA)
|
||||
|
|
@ -143,7 +143,7 @@ func (qs *queryShape) MakeNode(it graph.Iterator) *Node {
|
|||
qs.AddNode(newNode)
|
||||
qs.RemoveHasa()
|
||||
case "or":
|
||||
for _, sub := range it.GetSubIterators() {
|
||||
for _, sub := range it.SubIterators() {
|
||||
qs.nodeId++
|
||||
newNode := qs.MakeNode(sub)
|
||||
if sub.Type() == "or" {
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ import (
|
|||
func buildHasaWithTag(ts graph.TripleStore, tag string, target string) *HasA {
|
||||
fixed_obj := ts.FixedIterator()
|
||||
fixed_pred := ts.FixedIterator()
|
||||
fixed_obj.AddValue(ts.GetIdFor(target))
|
||||
fixed_pred.AddValue(ts.GetIdFor("status"))
|
||||
fixed_obj.Add(ts.ValueOf(target))
|
||||
fixed_pred.Add(ts.ValueOf("status"))
|
||||
fixed_obj.AddTag(tag)
|
||||
lto1 := NewLinksTo(ts, fixed_obj, graph.Object)
|
||||
lto2 := NewLinksTo(ts, fixed_pred, graph.Predicate)
|
||||
|
|
@ -40,14 +40,14 @@ func buildHasaWithTag(ts graph.TripleStore, tag string, target string) *HasA {
|
|||
func TestQueryShape(t *testing.T) {
|
||||
var queryShape map[string]interface{}
|
||||
ts := new(TestTripleStore)
|
||||
ts.On("GetIdFor", "cool").Return(1)
|
||||
ts.On("GetNameFor", 1).Return("cool")
|
||||
ts.On("GetIdFor", "status").Return(2)
|
||||
ts.On("GetNameFor", 2).Return("status")
|
||||
ts.On("GetIdFor", "fun").Return(3)
|
||||
ts.On("GetNameFor", 3).Return("fun")
|
||||
ts.On("GetIdFor", "name").Return(4)
|
||||
ts.On("GetNameFor", 4).Return("name")
|
||||
ts.On("ValueOf", "cool").Return(1)
|
||||
ts.On("NameOf", 1).Return("cool")
|
||||
ts.On("ValueOf", "status").Return(2)
|
||||
ts.On("NameOf", 2).Return("status")
|
||||
ts.On("ValueOf", "fun").Return(3)
|
||||
ts.On("NameOf", 3).Return("fun")
|
||||
ts.On("ValueOf", "name").Return(4)
|
||||
ts.On("NameOf", 4).Return("name")
|
||||
|
||||
Convey("Given a single linkage iterator's shape", t, func() {
|
||||
queryShape = make(map[string]interface{})
|
||||
|
|
@ -92,7 +92,7 @@ func TestQueryShape(t *testing.T) {
|
|||
andInternal.AddSubIterator(hasa1)
|
||||
andInternal.AddSubIterator(hasa2)
|
||||
fixed_pred := ts.FixedIterator()
|
||||
fixed_pred.AddValue(ts.GetIdFor("name"))
|
||||
fixed_pred.Add(ts.ValueOf("name"))
|
||||
lto1 := NewLinksTo(ts, andInternal, graph.Subject)
|
||||
lto2 := NewLinksTo(ts, fixed_pred, graph.Predicate)
|
||||
and := NewAnd()
|
||||
|
|
|
|||
|
|
@ -65,9 +65,9 @@ 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.GetNameFor(val)
|
||||
nodeStr := it.ts.NameOf(val)
|
||||
switch cVal := it.val.(type) {
|
||||
case int:
|
||||
cInt := int64(cVal)
|
||||
|
|
@ -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()
|
||||
|
|
@ -139,15 +139,15 @@ func (it *Comparison) NextResult() bool {
|
|||
if !hasNext {
|
||||
return false
|
||||
}
|
||||
if it.doComparison(it.subIt.LastResult()) {
|
||||
if it.doComparison(it.subIt.Result()) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
it.Last = it.subIt.LastResult()
|
||||
it.Last = it.subIt.Result()
|
||||
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,9 +156,9 @@ 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(out *map[string]graph.TSVal) {
|
||||
it.Base.TagResults(out)
|
||||
it.subIt.TagResults(out)
|
||||
func (it *Comparison) TagResults(dst map[string]graph.Value) {
|
||||
it.Base.TagResults(dst)
|
||||
it.subIt.TagResults(dst)
|
||||
}
|
||||
|
||||
// Registers the value-comparison iterator.
|
||||
|
|
@ -185,6 +185,6 @@ func (it *Comparison) Optimize() (graph.Iterator, bool) {
|
|||
|
||||
// We're only as expensive as our subiterator.
|
||||
// Again, optimized value comparison iterators should do better.
|
||||
func (it *Comparison) GetStats() *graph.IteratorStats {
|
||||
return it.subIt.GetStats()
|
||||
func (it *Comparison) Stats() graph.IteratorStats {
|
||||
return it.subIt.Stats()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@ import (
|
|||
func SetupMockTripleStore(nameMap map[string]int) *TestTripleStore {
|
||||
ts := new(TestTripleStore)
|
||||
for k, v := range nameMap {
|
||||
ts.On("GetIdFor", k).Return(v)
|
||||
ts.On("GetNameFor", v).Return(k)
|
||||
ts.On("ValueOf", k).Return(v)
|
||||
ts.On("NameOf", v).Return(k)
|
||||
}
|
||||
return ts
|
||||
}
|
||||
|
|
@ -43,11 +43,11 @@ func SimpleValueTripleStore() *TestTripleStore {
|
|||
|
||||
func BuildFixedIterator() *Fixed {
|
||||
fixed := newFixed()
|
||||
fixed.AddValue(0)
|
||||
fixed.AddValue(1)
|
||||
fixed.AddValue(2)
|
||||
fixed.AddValue(3)
|
||||
fixed.AddValue(4)
|
||||
fixed.Add(0)
|
||||
fixed.Add(1)
|
||||
fixed.Add(2)
|
||||
fixed.Add(3)
|
||||
fixed.Add(4)
|
||||
return fixed
|
||||
}
|
||||
|
||||
|
|
@ -59,7 +59,7 @@ func checkIteratorContains(ts graph.TripleStore, it graph.Iterator, expected []s
|
|||
if !ok {
|
||||
break
|
||||
}
|
||||
actual = append(actual, ts.GetNameFor(val))
|
||||
actual = append(actual, ts.NameOf(val))
|
||||
}
|
||||
actualSet := actual[:]
|
||||
for _, a := range expected {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
@ -125,9 +125,9 @@ func (it *AllIterator) Optimize() (graph.Iterator, bool) {
|
|||
return it, false
|
||||
}
|
||||
|
||||
func (it *AllIterator) GetStats() *graph.IteratorStats {
|
||||
func (it *AllIterator) Stats() graph.IteratorStats {
|
||||
s, _ := it.Size()
|
||||
return &graph.IteratorStats{
|
||||
return graph.IteratorStats{
|
||||
CheckCost: 1,
|
||||
NextCost: 2,
|
||||
Size: s,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -177,8 +177,8 @@ func (it *Iterator) Check(v graph.TSVal) bool {
|
|||
return true
|
||||
}
|
||||
} else {
|
||||
nameForDir := it.ts.GetTriple(v).Get(it.dir)
|
||||
hashForDir := it.ts.GetIdFor(nameForDir).([]byte)
|
||||
nameForDir := it.ts.Triple(v).Get(it.dir)
|
||||
hashForDir := it.ts.ValueOf(nameForDir).([]byte)
|
||||
if bytes.Equal(hashForDir, it.checkId) {
|
||||
return true
|
||||
}
|
||||
|
|
@ -192,7 +192,7 @@ func (it *Iterator) Size() (int64, bool) {
|
|||
|
||||
func (it *Iterator) DebugString(indent int) string {
|
||||
size, _ := it.Size()
|
||||
return fmt.Sprintf("%s(%s %d tags: %v dir: %s size:%d %s)", strings.Repeat(" ", indent), it.Type(), it.GetUid(), it.Tags(), it.dir, size, it.ts.GetNameFor(it.checkId))
|
||||
return fmt.Sprintf("%s(%s %d tags: %v dir: %s size:%d %s)", strings.Repeat(" ", indent), it.Type(), it.UID(), it.Tags(), it.dir, size, it.ts.NameOf(it.checkId))
|
||||
}
|
||||
|
||||
func (it *Iterator) Type() string { return "leveldb" }
|
||||
|
|
@ -202,9 +202,9 @@ func (it *Iterator) Optimize() (graph.Iterator, bool) {
|
|||
return it, false
|
||||
}
|
||||
|
||||
func (it *Iterator) GetStats() *graph.IteratorStats {
|
||||
func (it *Iterator) Stats() graph.IteratorStats {
|
||||
s, _ := it.Size()
|
||||
return &graph.IteratorStats{
|
||||
return graph.IteratorStats{
|
||||
CheckCost: 1,
|
||||
NextCost: 2,
|
||||
Size: s,
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ func extractTripleFromIterator(ts graph.TripleStore, it graph.Iterator) []string
|
|||
if !ok {
|
||||
break
|
||||
}
|
||||
output = append(output, ts.GetTriple(val).String())
|
||||
output = append(output, ts.Triple(val).String())
|
||||
}
|
||||
return output
|
||||
}
|
||||
|
|
@ -62,7 +62,7 @@ func extractValuesFromIterator(ts graph.TripleStore, it graph.Iterator) []string
|
|||
if !ok {
|
||||
break
|
||||
}
|
||||
output = append(output, ts.GetNameFor(val))
|
||||
output = append(output, ts.NameOf(val))
|
||||
}
|
||||
return output
|
||||
}
|
||||
|
|
@ -113,7 +113,7 @@ func TestLoadDatabase(t *testing.T) {
|
|||
|
||||
Convey("Can load a single triple", func() {
|
||||
ts.AddTriple(&graph.Triple{"Something", "points_to", "Something Else", "context"})
|
||||
So(ts.GetNameFor(ts.GetIdFor("Something")), ShouldEqual, "Something")
|
||||
So(ts.NameOf(ts.ValueOf("Something")), ShouldEqual, "Something")
|
||||
So(ts.Size(), ShouldEqual, 1)
|
||||
})
|
||||
|
||||
|
|
@ -121,12 +121,12 @@ func TestLoadDatabase(t *testing.T) {
|
|||
|
||||
ts.AddTripleSet(makeTripleSet())
|
||||
So(ts.Size(), ShouldEqual, 11)
|
||||
So(ts.GetSizeFor(ts.GetIdFor("B")), ShouldEqual, 5)
|
||||
So(ts.GetSizeFor(ts.ValueOf("B")), ShouldEqual, 5)
|
||||
|
||||
Convey("Can delete triples", func() {
|
||||
ts.RemoveTriple(&graph.Triple{"A", "follows", "B", ""})
|
||||
So(ts.Size(), ShouldEqual, 10)
|
||||
So(ts.GetSizeFor(ts.GetIdFor("B")), ShouldEqual, 4)
|
||||
So(ts.GetSizeFor(ts.ValueOf("B")), ShouldEqual, 4)
|
||||
})
|
||||
})
|
||||
|
||||
|
|
@ -153,7 +153,7 @@ func TestIterator(t *testing.T) {
|
|||
var it graph.Iterator
|
||||
|
||||
Convey("Can create an all iterator for nodes", func() {
|
||||
it = ts.GetNodesAllIterator()
|
||||
it = ts.NodesAllIterator()
|
||||
So(it, ShouldNotBeNil)
|
||||
|
||||
Convey("Has basics", func() {
|
||||
|
|
@ -192,9 +192,9 @@ func TestIterator(t *testing.T) {
|
|||
})
|
||||
|
||||
Convey("Contains a couple nodes", func() {
|
||||
So(it.Check(ts.GetIdFor("A")), ShouldBeTrue)
|
||||
So(it.Check(ts.GetIdFor("cool")), ShouldBeTrue)
|
||||
//So(it.Check(ts.GetIdFor("baller")), ShouldBeFalse)
|
||||
So(it.Check(ts.ValueOf("A")), ShouldBeTrue)
|
||||
So(it.Check(ts.ValueOf("cool")), ShouldBeTrue)
|
||||
//So(it.Check(ts.ValueOf("baller")), ShouldBeFalse)
|
||||
})
|
||||
|
||||
Reset(func() {
|
||||
|
|
@ -203,7 +203,7 @@ func TestIterator(t *testing.T) {
|
|||
})
|
||||
|
||||
Convey("Can create an all iterator for edges", func() {
|
||||
it := ts.GetTriplesAllIterator()
|
||||
it := ts.TriplesAllIterator()
|
||||
So(it, ShouldNotBeNil)
|
||||
Convey("Has basics", func() {
|
||||
size, accurate := it.Size()
|
||||
|
|
@ -217,7 +217,7 @@ func TestIterator(t *testing.T) {
|
|||
|
||||
Convey("Iterates an edge", func() {
|
||||
edge_val, _ := it.Next()
|
||||
triple := ts.GetTriple(edge_val)
|
||||
triple := ts.Triple(edge_val)
|
||||
set := makeTripleSet()
|
||||
var string_set []string
|
||||
for _, t := range set {
|
||||
|
|
@ -249,7 +249,7 @@ func TestSetIterator(t *testing.T) {
|
|||
var it graph.Iterator
|
||||
|
||||
Convey("Can create a subject iterator", func() {
|
||||
it = ts.GetTripleIterator(graph.Subject, ts.GetIdFor("C"))
|
||||
it = ts.TripleIterator(graph.Subject, ts.ValueOf("C"))
|
||||
|
||||
Convey("Containing the right things", func() {
|
||||
expected := []string{
|
||||
|
|
@ -264,7 +264,7 @@ func TestSetIterator(t *testing.T) {
|
|||
|
||||
Convey("And checkable", func() {
|
||||
and := iterator.NewAnd()
|
||||
and.AddSubIterator(ts.GetTriplesAllIterator())
|
||||
and.AddSubIterator(ts.TriplesAllIterator())
|
||||
and.AddSubIterator(it)
|
||||
|
||||
expected := []string{
|
||||
|
|
@ -283,7 +283,7 @@ func TestSetIterator(t *testing.T) {
|
|||
})
|
||||
|
||||
Convey("Can create an object iterator", func() {
|
||||
it = ts.GetTripleIterator(graph.Object, ts.GetIdFor("F"))
|
||||
it = ts.TripleIterator(graph.Object, ts.ValueOf("F"))
|
||||
|
||||
Convey("Containing the right things", func() {
|
||||
expected := []string{
|
||||
|
|
@ -298,7 +298,7 @@ func TestSetIterator(t *testing.T) {
|
|||
|
||||
Convey("Mutually and-checkable", func() {
|
||||
and := iterator.NewAnd()
|
||||
and.AddSubIterator(ts.GetTripleIterator(graph.Subject, ts.GetIdFor("B")))
|
||||
and.AddSubIterator(ts.TripleIterator(graph.Subject, ts.ValueOf("B")))
|
||||
and.AddSubIterator(it)
|
||||
|
||||
expected := []string{
|
||||
|
|
@ -313,7 +313,7 @@ func TestSetIterator(t *testing.T) {
|
|||
})
|
||||
|
||||
Convey("Can create a predicate iterator", func() {
|
||||
it = ts.GetTripleIterator(graph.Predicate, ts.GetIdFor("status"))
|
||||
it = ts.TripleIterator(graph.Predicate, ts.ValueOf("status"))
|
||||
|
||||
Convey("Containing the right things", func() {
|
||||
expected := []string{
|
||||
|
|
@ -330,7 +330,7 @@ func TestSetIterator(t *testing.T) {
|
|||
})
|
||||
|
||||
Convey("Can create a provenance iterator", func() {
|
||||
it = ts.GetTripleIterator(graph.Provenance, ts.GetIdFor("status_graph"))
|
||||
it = ts.TripleIterator(graph.Provenance, ts.ValueOf("status_graph"))
|
||||
|
||||
Convey("Containing the right things", func() {
|
||||
expected := []string{
|
||||
|
|
@ -347,7 +347,7 @@ func TestSetIterator(t *testing.T) {
|
|||
Convey("Can be cross-checked", func() {
|
||||
and := iterator.NewAnd()
|
||||
// Order is important
|
||||
and.AddSubIterator(ts.GetTripleIterator(graph.Subject, ts.GetIdFor("B")))
|
||||
and.AddSubIterator(ts.TripleIterator(graph.Subject, ts.ValueOf("B")))
|
||||
and.AddSubIterator(it)
|
||||
|
||||
expected := []string{
|
||||
|
|
@ -361,7 +361,7 @@ func TestSetIterator(t *testing.T) {
|
|||
and := iterator.NewAnd()
|
||||
// Order is important
|
||||
and.AddSubIterator(it)
|
||||
and.AddSubIterator(ts.GetTripleIterator(graph.Subject, ts.GetIdFor("B")))
|
||||
and.AddSubIterator(ts.TripleIterator(graph.Subject, ts.ValueOf("B")))
|
||||
|
||||
expected := []string{
|
||||
(&graph.Triple{"B", "status", "cool", "status_graph"}).String(),
|
||||
|
|
@ -399,7 +399,7 @@ func TestOptimize(t *testing.T) {
|
|||
|
||||
Convey("With an linksto-fixed pair", func() {
|
||||
fixed := ts.FixedIterator()
|
||||
fixed.AddValue(ts.GetIdFor("F"))
|
||||
fixed.Add(ts.ValueOf("F"))
|
||||
fixed.AddTag("internal")
|
||||
lto = iterator.NewLinksTo(ts, fixed, graph.Object)
|
||||
|
||||
|
|
@ -420,10 +420,10 @@ func TestOptimize(t *testing.T) {
|
|||
Convey("With the correct tags", func() {
|
||||
oldIt.Next()
|
||||
newIt.Next()
|
||||
oldResults := make(map[string]graph.TSVal)
|
||||
oldIt.TagResults(&oldResults)
|
||||
newResults := make(map[string]graph.TSVal)
|
||||
oldIt.TagResults(&newResults)
|
||||
oldResults := make(map[string]graph.Value)
|
||||
oldIt.TagResults(oldResults)
|
||||
newResults := make(map[string]graph.Value)
|
||||
oldIt.TagResults(newResults)
|
||||
So(newResults, ShouldResemble, oldResults)
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -65,11 +65,11 @@ func CreateNewLevelDB(path string) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func NewTripleStore(path string, options graph.OptionsDict) *TripleStore {
|
||||
func NewTripleStore(path string, options graph.Options) *TripleStore {
|
||||
var ts TripleStore
|
||||
ts.path = path
|
||||
cache_size := DefaultCacheSize
|
||||
if val, ok := options.GetIntKey("cache_size_mb"); ok {
|
||||
if val, ok := options.IntKey("cache_size_mb"); ok {
|
||||
cache_size = val
|
||||
}
|
||||
ts.dbOpts = &opt.Options{
|
||||
|
|
@ -78,7 +78,7 @@ func NewTripleStore(path string, options graph.OptionsDict) *TripleStore {
|
|||
ts.dbOpts.ErrorIfMissing = true
|
||||
|
||||
write_buffer_mb := DefaultWriteBufferSize
|
||||
if val, ok := options.GetIntKey("write_buffer_mb"); ok {
|
||||
if val, ok := options.IntKey("write_buffer_mb"); ok {
|
||||
write_buffer_mb = val
|
||||
}
|
||||
ts.dbOpts.WriteBuffer = write_buffer_mb * opt.MiB
|
||||
|
|
@ -301,7 +301,7 @@ func (ts *TripleStore) Close() {
|
|||
ts.open = false
|
||||
}
|
||||
|
||||
func (ts *TripleStore) GetTriple(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) GetIdFor(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) GetNameFor(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) GetNameFor(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) GetTripleIterator(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:
|
||||
|
|
@ -418,25 +418,25 @@ func (ts *TripleStore) GetTripleIterator(d graph.Direction, val graph.TSVal) gra
|
|||
return NewIterator(prefix, d, val, ts)
|
||||
}
|
||||
|
||||
func (ts *TripleStore) GetNodesAllIterator() graph.Iterator {
|
||||
func (ts *TripleStore) NodesAllIterator() graph.Iterator {
|
||||
return NewAllIterator("z", graph.Any, ts)
|
||||
}
|
||||
|
||||
func (ts *TripleStore) GetTriplesAllIterator() graph.Iterator {
|
||||
func (ts *TripleStore) TriplesAllIterator() graph.Iterator {
|
||||
return NewAllIterator("po", graph.Predicate, ts)
|
||||
}
|
||||
|
||||
func (ts *TripleStore) GetTripleDirection(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 {
|
||||
return append([]byte("z"), v[offset:offset+ts.hasher.Size()]...)
|
||||
} else {
|
||||
return ts.GetTriple(val).Get(d)
|
||||
return ts.Triple(val).Get(d)
|
||||
}
|
||||
}
|
||||
|
||||
func compareBytes(a, b graph.TSVal) bool {
|
||||
func compareBytes(a, b graph.Value) bool {
|
||||
return bytes.Equal(a.([]uint8), b.([]uint8))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ func (ts *TripleStore) OptimizeIterator(it graph.Iterator) (graph.Iterator, bool
|
|||
}
|
||||
|
||||
func (ts *TripleStore) optimizeLinksTo(it *iterator.LinksTo) (graph.Iterator, bool) {
|
||||
subs := it.GetSubIterators()
|
||||
subs := it.SubIterators()
|
||||
if len(subs) != 1 {
|
||||
return it, false
|
||||
}
|
||||
|
|
@ -41,7 +41,7 @@ func (ts *TripleStore) optimizeLinksTo(it *iterator.LinksTo) (graph.Iterator, bo
|
|||
if !ok {
|
||||
panic("Sizes lie")
|
||||
}
|
||||
newIt := ts.GetTripleIterator(it.Direction(), val)
|
||||
newIt := ts.TripleIterator(it.Direction(), val)
|
||||
newIt.CopyTagsFrom(it)
|
||||
for _, tag := range primary.Tags() {
|
||||
newIt.AddFixedTag(tag, val)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -111,8 +111,8 @@ func (it *Iterator) Optimize() (graph.Iterator, bool) {
|
|||
return it, false
|
||||
}
|
||||
|
||||
func (it *Iterator) GetStats() *graph.IteratorStats {
|
||||
return &graph.IteratorStats{
|
||||
func (it *Iterator) Stats() graph.IteratorStats {
|
||||
return graph.IteratorStats{
|
||||
CheckCost: int64(math.Log(float64(it.tree.Len()))) + 1,
|
||||
NextCost: 1,
|
||||
Size: int64(it.tree.Len()),
|
||||
|
|
|
|||
|
|
@ -217,11 +217,11 @@ func (ts *TripleStore) RemoveTriple(t *graph.Triple) {
|
|||
}
|
||||
}
|
||||
|
||||
func (ts *TripleStore) GetTriple(index graph.TSVal) *graph.Triple {
|
||||
func (ts *TripleStore) Triple(index graph.Value) *graph.Triple {
|
||||
return &ts.triples[index.(int64)]
|
||||
}
|
||||
|
||||
func (ts *TripleStore) GetTripleIterator(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,15 +243,15 @@ func (ts *TripleStore) DebugPrint() {
|
|||
}
|
||||
}
|
||||
|
||||
func (ts *TripleStore) GetIdFor(name string) graph.TSVal {
|
||||
func (ts *TripleStore) ValueOf(name string) graph.Value {
|
||||
return ts.idMap[name]
|
||||
}
|
||||
|
||||
func (ts *TripleStore) GetNameFor(id graph.TSVal) string {
|
||||
func (ts *TripleStore) NameOf(id graph.Value) string {
|
||||
return ts.revIdMap[id.(int64)]
|
||||
}
|
||||
|
||||
func (ts *TripleStore) GetTriplesAllIterator() graph.Iterator {
|
||||
func (ts *TripleStore) TriplesAllIterator() graph.Iterator {
|
||||
return iterator.NewInt64(0, ts.Size())
|
||||
}
|
||||
|
||||
|
|
@ -259,12 +259,12 @@ func (ts *TripleStore) FixedIterator() graph.FixedIterator {
|
|||
return iterator.NewFixedIteratorWithCompare(iterator.BasicEquality)
|
||||
}
|
||||
|
||||
func (ts *TripleStore) GetTripleDirection(val graph.TSVal, d graph.Direction) graph.TSVal {
|
||||
name := ts.GetTriple(val).Get(d)
|
||||
return ts.GetIdFor(name)
|
||||
func (ts *TripleStore) TripleDirection(val graph.Value, d graph.Direction) graph.Value {
|
||||
name := ts.Triple(val).Get(d)
|
||||
return ts.ValueOf(name)
|
||||
}
|
||||
|
||||
func (ts *TripleStore) GetNodesAllIterator() graph.Iterator {
|
||||
func (ts *TripleStore) NodesAllIterator() graph.Iterator {
|
||||
return NewMemstoreAllIterator(ts)
|
||||
}
|
||||
func (ts *TripleStore) Close() {}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ func (ts *TripleStore) OptimizeIterator(it graph.Iterator) (graph.Iterator, bool
|
|||
}
|
||||
|
||||
func (ts *TripleStore) optimizeLinksTo(it *iterator.LinksTo) (graph.Iterator, bool) {
|
||||
subs := it.GetSubIterators()
|
||||
subs := it.SubIterators()
|
||||
if len(subs) != 1 {
|
||||
return it, false
|
||||
}
|
||||
|
|
@ -41,7 +41,7 @@ func (ts *TripleStore) optimizeLinksTo(it *iterator.LinksTo) (graph.Iterator, bo
|
|||
if !ok {
|
||||
panic("Sizes lie")
|
||||
}
|
||||
newIt := ts.GetTripleIterator(it.Direction(), val)
|
||||
newIt := ts.TripleIterator(it.Direction(), val)
|
||||
newIt.CopyTagsFrom(it)
|
||||
for _, tag := range primary.Tags() {
|
||||
newIt.AddFixedTag(tag, val)
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ func TestMemstore(t *testing.T) {
|
|||
So(ts.Size(), ShouldEqual, 11)
|
||||
})
|
||||
Convey("It should have an Id Space that makes sense", func() {
|
||||
v := ts.GetIdFor("C")
|
||||
v := ts.ValueOf("C")
|
||||
So(v.(int64), ShouldEqual, 4)
|
||||
})
|
||||
})
|
||||
|
|
@ -40,13 +40,13 @@ func TestMemstore(t *testing.T) {
|
|||
func TestIteratorsAndNextResultOrderA(t *testing.T) {
|
||||
ts := MakeTestingMemstore()
|
||||
fixed := ts.FixedIterator()
|
||||
fixed.AddValue(ts.GetIdFor("C"))
|
||||
all := ts.GetNodesAllIterator()
|
||||
fixed.Add(ts.ValueOf("C"))
|
||||
all := ts.NodesAllIterator()
|
||||
lto := iterator.NewLinksTo(ts, all, graph.Object)
|
||||
innerAnd := iterator.NewAnd()
|
||||
|
||||
fixed2 := ts.FixedIterator()
|
||||
fixed2.AddValue(ts.GetIdFor("follows"))
|
||||
fixed2.Add(ts.ValueOf("follows"))
|
||||
lto2 := iterator.NewLinksTo(ts, fixed2, graph.Predicate)
|
||||
innerAnd.AddSubIterator(lto2)
|
||||
innerAnd.AddSubIterator(lto)
|
||||
|
|
@ -58,19 +58,19 @@ func TestIteratorsAndNextResultOrderA(t *testing.T) {
|
|||
if !ok {
|
||||
t.Error("Expected one matching subtree")
|
||||
}
|
||||
if ts.GetNameFor(val) != "C" {
|
||||
t.Errorf("Matching subtree should be %s, got %s", "barak", ts.GetNameFor(val))
|
||||
if ts.NameOf(val) != "C" {
|
||||
t.Errorf("Matching subtree should be %s, got %s", "barak", ts.NameOf(val))
|
||||
}
|
||||
expected := make([]string, 2)
|
||||
expected[0] = "B"
|
||||
expected[1] = "D"
|
||||
actualOut := make([]string, 2)
|
||||
actualOut[0] = ts.GetNameFor(all.LastResult())
|
||||
actualOut[0] = ts.NameOf(all.Result())
|
||||
nresultOk := outerAnd.NextResult()
|
||||
if !nresultOk {
|
||||
t.Error("Expected two results got one")
|
||||
}
|
||||
actualOut[1] = ts.GetNameFor(all.LastResult())
|
||||
actualOut[1] = ts.NameOf(all.Result())
|
||||
nresultOk = outerAnd.NextResult()
|
||||
if nresultOk {
|
||||
t.Error("Expected two results got three")
|
||||
|
|
@ -98,7 +98,7 @@ func CompareStringSlices(t *testing.T, expected []string, actual []string) {
|
|||
func TestLinksToOptimization(t *testing.T) {
|
||||
ts := MakeTestingMemstore()
|
||||
fixed := ts.FixedIterator()
|
||||
fixed.AddValue(ts.GetIdFor("cool"))
|
||||
fixed.Add(ts.ValueOf("cool"))
|
||||
lto := iterator.NewLinksTo(ts, fixed, graph.Object)
|
||||
lto.AddTag("foo")
|
||||
newIt, changed := lto.Optimize()
|
||||
|
|
@ -122,10 +122,10 @@ func TestRemoveTriple(t *testing.T) {
|
|||
ts := MakeTestingMemstore()
|
||||
ts.RemoveTriple(&graph.Triple{"E", "follows", "F", ""})
|
||||
fixed := ts.FixedIterator()
|
||||
fixed.AddValue(ts.GetIdFor("E"))
|
||||
fixed.Add(ts.ValueOf("E"))
|
||||
lto := iterator.NewLinksTo(ts, fixed, graph.Subject)
|
||||
fixed2 := ts.FixedIterator()
|
||||
fixed2.AddValue(ts.GetIdFor("follows"))
|
||||
fixed2.Add(ts.ValueOf("follows"))
|
||||
lto2 := iterator.NewLinksTo(ts, fixed2, graph.Predicate)
|
||||
innerAnd := iterator.NewAnd()
|
||||
innerAnd.AddSubIterator(lto2)
|
||||
|
|
|
|||
|
|
@ -39,11 +39,11 @@ 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)
|
||||
|
||||
m.name = ts.GetNameFor(val)
|
||||
m.name = ts.NameOf(val)
|
||||
m.collection = collection
|
||||
switch d {
|
||||
case graph.Subject:
|
||||
|
|
@ -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
|
||||
|
|
@ -171,9 +171,9 @@ func (it *Iterator) DebugString(indent int) string {
|
|||
return fmt.Sprintf("%s(%s size:%d %s %s)", strings.Repeat(" ", indent), it.Type(), size, it.hash, it.name)
|
||||
}
|
||||
|
||||
func (it *Iterator) GetStats() *graph.IteratorStats {
|
||||
func (it *Iterator) Stats() graph.IteratorStats {
|
||||
size, _ := it.Size()
|
||||
return &graph.IteratorStats{
|
||||
return graph.IteratorStats{
|
||||
CheckCost: 1,
|
||||
NextCost: 5,
|
||||
Size: size,
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ type TripleStore struct {
|
|||
idCache *IDLru
|
||||
}
|
||||
|
||||
func CreateNewMongoGraph(addr string, options graph.OptionsDict) bool {
|
||||
func CreateNewMongoGraph(addr string, options graph.Options) bool {
|
||||
conn, err := mgo.Dial(addr)
|
||||
if err != nil {
|
||||
glog.Fatal("Error connecting: ", err)
|
||||
|
|
@ -45,7 +45,7 @@ func CreateNewMongoGraph(addr string, options graph.OptionsDict) bool {
|
|||
}
|
||||
conn.SetSafe(&mgo.Safe{})
|
||||
dbName := DefaultDBName
|
||||
if val, ok := options.GetStringKey("database_name"); ok {
|
||||
if val, ok := options.StringKey("database_name"); ok {
|
||||
dbName = val
|
||||
}
|
||||
db := conn.DB(dbName)
|
||||
|
|
@ -66,7 +66,7 @@ func CreateNewMongoGraph(addr string, options graph.OptionsDict) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func NewTripleStore(addr string, options graph.OptionsDict) *TripleStore {
|
||||
func NewTripleStore(addr string, options graph.Options) *TripleStore {
|
||||
var ts TripleStore
|
||||
conn, err := mgo.Dial(addr)
|
||||
if err != nil {
|
||||
|
|
@ -74,7 +74,7 @@ func NewTripleStore(addr string, options graph.OptionsDict) *TripleStore {
|
|||
}
|
||||
conn.SetSafe(&mgo.Safe{})
|
||||
dbName := DefaultDBName
|
||||
if val, ok := options.GetStringKey("database_name"); ok {
|
||||
if val, ok := options.StringKey("database_name"); ok {
|
||||
dbName = val
|
||||
}
|
||||
ts.db = conn.DB(dbName)
|
||||
|
|
@ -108,7 +108,7 @@ type MongoNode struct {
|
|||
|
||||
func (ts *TripleStore) updateNodeBy(node_name string, inc int) {
|
||||
var size MongoNode
|
||||
node := ts.GetIdFor(node_name)
|
||||
node := ts.ValueOf(node_name)
|
||||
err := ts.db.C("nodes").FindId(node).One(&size)
|
||||
if err != nil {
|
||||
if err.Error() == "not found" {
|
||||
|
|
@ -209,7 +209,7 @@ func (ts *TripleStore) RemoveTriple(t *graph.Triple) {
|
|||
}
|
||||
}
|
||||
|
||||
func (ts *TripleStore) GetTriple(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,23 +223,23 @@ func (ts *TripleStore) GetTriple(val graph.TSVal) *graph.Triple {
|
|||
}
|
||||
}
|
||||
|
||||
func (ts *TripleStore) GetTripleIterator(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)
|
||||
}
|
||||
|
||||
func (ts *TripleStore) GetNodesAllIterator() graph.Iterator {
|
||||
func (ts *TripleStore) NodesAllIterator() graph.Iterator {
|
||||
return NewAllIterator(ts, "nodes")
|
||||
}
|
||||
|
||||
func (ts *TripleStore) GetTriplesAllIterator() graph.Iterator {
|
||||
func (ts *TripleStore) TriplesAllIterator() graph.Iterator {
|
||||
return NewAllIterator(ts, "triples")
|
||||
}
|
||||
|
||||
func (ts *TripleStore) GetIdFor(s string) graph.TSVal {
|
||||
func (ts *TripleStore) ValueOf(s string) graph.Value {
|
||||
return ts.ConvertStringToByteHash(s)
|
||||
}
|
||||
|
||||
func (ts *TripleStore) GetNameFor(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) GetTripleDirection(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 {
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ func (ts *TripleStore) OptimizeIterator(it graph.Iterator) (graph.Iterator, bool
|
|||
}
|
||||
|
||||
func (ts *TripleStore) optimizeLinksTo(it *iterator.LinksTo) (graph.Iterator, bool) {
|
||||
subs := it.GetSubIterators()
|
||||
subs := it.SubIterators()
|
||||
if len(subs) != 1 {
|
||||
return it, false
|
||||
}
|
||||
|
|
@ -41,7 +41,7 @@ func (ts *TripleStore) optimizeLinksTo(it *iterator.LinksTo) (graph.Iterator, bo
|
|||
if !ok {
|
||||
panic("Sizes lie")
|
||||
}
|
||||
newIt := ts.GetTripleIterator(it.Direction(), val)
|
||||
newIt := ts.TripleIterator(it.Direction(), val)
|
||||
newIt.CopyTagsFrom(it)
|
||||
for _, tag := range primary.Tags() {
|
||||
newIt.AddFixedTag(tag, val)
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
}
|
||||
|
||||
|
|
@ -48,11 +48,11 @@ func StringResultTreeEvaluator(it Iterator) string {
|
|||
if !ok {
|
||||
break
|
||||
}
|
||||
out += it.GetResultTree().String()
|
||||
out += it.ResultTree().String()
|
||||
out += "\n"
|
||||
for it.NextResult() == true {
|
||||
out += " "
|
||||
out += it.GetResultTree().String()
|
||||
out += it.ResultTree().String()
|
||||
out += "\n"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -188,7 +188,7 @@ func buildIteratorTree(tree *peg.ExpressionTree, ts graph.TripleStore) graph.Ite
|
|||
var out graph.Iterator
|
||||
nodeID := getIdentString(tree)
|
||||
if tree.Children[0].Name == "Variable" {
|
||||
allIt := ts.GetNodesAllIterator()
|
||||
allIt := ts.NodesAllIterator()
|
||||
allIt.AddTag(nodeID)
|
||||
out = allIt
|
||||
} else {
|
||||
|
|
@ -197,7 +197,7 @@ func buildIteratorTree(tree *peg.ExpressionTree, ts graph.TripleStore) graph.Ite
|
|||
n = nodeID[1:]
|
||||
}
|
||||
fixed := ts.FixedIterator()
|
||||
fixed.AddValue(ts.GetIdFor(n))
|
||||
fixed.Add(ts.ValueOf(n))
|
||||
out = fixed
|
||||
}
|
||||
return out
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ func TestParseSexpWithMemstore(t *testing.T) {
|
|||
So(it.Type(), ShouldEqual, "and")
|
||||
out, ok := it.Next()
|
||||
So(ok, ShouldBeTrue)
|
||||
So(out, ShouldEqual, ts.GetIdFor("i"))
|
||||
So(out, ShouldEqual, ts.ValueOf("i"))
|
||||
})
|
||||
|
||||
Convey("It can get an internal linkage", func() {
|
||||
|
|
@ -57,7 +57,7 @@ func TestParseSexpWithMemstore(t *testing.T) {
|
|||
So(it.Type(), ShouldEqual, "and")
|
||||
out, ok := it.Next()
|
||||
So(ok, ShouldBeTrue)
|
||||
So(out, ShouldEqual, ts.GetIdFor("i"))
|
||||
So(out, ShouldEqual, ts.ValueOf("i"))
|
||||
})
|
||||
|
||||
})
|
||||
|
|
@ -78,8 +78,8 @@ func TestTreeConstraintParse(t *testing.T) {
|
|||
if !ok {
|
||||
t.Error("Got no results")
|
||||
}
|
||||
if out != ts.GetIdFor("i") {
|
||||
t.Errorf("Got %d, expected %d", out, ts.GetIdFor("i"))
|
||||
if out != ts.ValueOf("i") {
|
||||
t.Errorf("Got %d, expected %d", out, ts.ValueOf("i"))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -95,10 +95,10 @@ func TestTreeConstraintTagParse(t *testing.T) {
|
|||
if !ok {
|
||||
t.Error("Got no results")
|
||||
}
|
||||
tags := make(map[string]graph.TSVal)
|
||||
it.TagResults(&tags)
|
||||
if ts.GetNameFor(tags["$a"]) != "food" {
|
||||
t.Errorf("Got %s, expected food", ts.GetNameFor(tags["$a"]))
|
||||
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"]))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -119,8 +119,8 @@ func TestMultipleConstraintParse(t *testing.T) {
|
|||
if !ok {
|
||||
t.Error("Got no results")
|
||||
}
|
||||
if out != ts.GetIdFor("i") {
|
||||
t.Errorf("Got %d, expected %d", out, ts.GetIdFor("i"))
|
||||
if out != ts.ValueOf("i") {
|
||||
t.Errorf("Got %d, expected %d", out, ts.ValueOf("i"))
|
||||
}
|
||||
_, ok = it.Next()
|
||||
if ok {
|
||||
|
|
|
|||
|
|
@ -81,16 +81,16 @@ func (s *Session) ExecInput(input string, out chan interface{}, limit int) {
|
|||
if !ok {
|
||||
break
|
||||
}
|
||||
tags := make(map[string]graph.TSVal)
|
||||
it.TagResults(&tags)
|
||||
tags := make(map[string]graph.Value)
|
||||
it.TagResults(tags)
|
||||
out <- &tags
|
||||
nResults++
|
||||
if nResults > limit && limit != -1 {
|
||||
break
|
||||
}
|
||||
for it.NextResult() == true {
|
||||
tags := make(map[string]graph.TSVal)
|
||||
it.TagResults(&tags)
|
||||
tags := make(map[string]graph.Value)
|
||||
it.TagResults(tags)
|
||||
out <- &tags
|
||||
nResults++
|
||||
if nResults > limit && limit != -1 {
|
||||
|
|
@ -103,10 +103,10 @@ 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)
|
||||
tagKeys := make([]string, len(*tags))
|
||||
tags := result.(map[string]graph.Value)
|
||||
tagKeys := make([]string, len(tags))
|
||||
i := 0
|
||||
for k, _ := range *tags {
|
||||
for k := range tags {
|
||||
tagKeys[i] = k
|
||||
i++
|
||||
}
|
||||
|
|
@ -115,7 +115,7 @@ func (s *Session) ToText(result interface{}) string {
|
|||
if k == "$_" {
|
||||
continue
|
||||
}
|
||||
out += fmt.Sprintf("%s : %s\n", k, s.ts.GetNameFor((*tags)[k]))
|
||||
out += fmt.Sprintf("%s : %s\n", k, s.ts.NameOf(tags[k]))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,29 +47,29 @@ type TripleStore interface {
|
|||
RemoveTriple(*Triple)
|
||||
|
||||
// Given an opaque token, returns the triple for that token from the store.
|
||||
GetTriple(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.
|
||||
GetTripleIterator(Direction, TSVal) Iterator
|
||||
TripleIterator(Direction, Value) Iterator
|
||||
|
||||
// Returns an iterator enumerating all nodes in the graph.
|
||||
GetNodesAllIterator() Iterator
|
||||
NodesAllIterator() Iterator
|
||||
|
||||
// Returns an iterator enumerating all links in the graph.
|
||||
GetTriplesAllIterator() Iterator
|
||||
TriplesAllIterator() Iterator
|
||||
|
||||
// Given a node ID, return the opaque token used by the TripleStore
|
||||
// to represent that id.
|
||||
GetIdFor(string) TSVal
|
||||
ValueOf(string) Value
|
||||
|
||||
// Given an opaque token, return the node that it represents.
|
||||
GetNameFor(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.
|
||||
|
|
@ -88,13 +88,13 @@ type TripleStore interface {
|
|||
// gives the TripleStore the opportunity to make this optimization.
|
||||
//
|
||||
// Iterators will call this. At worst, a valid implementation is
|
||||
// self.GetIdFor(self.GetTriple(triple_id).Get(dir))
|
||||
GetTripleDirection(triple_id TSVal, d Direction) TSVal
|
||||
// ts.IdFor(ts.Triple(triple_id).Get(dir))
|
||||
TripleDirection(triple_id Value, d Direction) Value
|
||||
}
|
||||
|
||||
type OptionsDict map[string]interface{}
|
||||
type Options map[string]interface{}
|
||||
|
||||
func (d OptionsDict) GetIntKey(key string) (int, bool) {
|
||||
func (d Options) IntKey(key string) (int, bool) {
|
||||
if val, ok := d[key]; ok {
|
||||
switch vv := val.(type) {
|
||||
case float64:
|
||||
|
|
@ -106,7 +106,7 @@ func (d OptionsDict) GetIntKey(key string) (int, bool) {
|
|||
return 0, false
|
||||
}
|
||||
|
||||
func (d OptionsDict) GetStringKey(key string) (string, bool) {
|
||||
func (d Options) StringKey(key string) (string, bool) {
|
||||
if val, ok := d[key]; ok {
|
||||
switch vv := val.(type) {
|
||||
case string:
|
||||
|
|
|
|||
|
|
@ -68,14 +68,14 @@ func makeListOfStringsFromArrayValue(obj *otto.Object) []string {
|
|||
|
||||
func buildIteratorFromValue(val otto.Value, ts graph.TripleStore) graph.Iterator {
|
||||
if val.IsNull() || val.IsUndefined() {
|
||||
return ts.GetNodesAllIterator()
|
||||
return ts.NodesAllIterator()
|
||||
}
|
||||
if val.IsPrimitive() {
|
||||
thing, _ := val.Export()
|
||||
switch v := thing.(type) {
|
||||
case string:
|
||||
it := ts.FixedIterator()
|
||||
it.AddValue(ts.GetIdFor(v))
|
||||
it.Add(ts.ValueOf(v))
|
||||
return it
|
||||
default:
|
||||
glog.Errorln("Trying to build unknown primitive value.")
|
||||
|
|
@ -89,7 +89,7 @@ func buildIteratorFromValue(val otto.Value, ts graph.TripleStore) graph.Iterator
|
|||
strings := makeListOfStringsFromArrayValue(val.Object())
|
||||
it := ts.FixedIterator()
|
||||
for _, x := range strings {
|
||||
it.AddValue(ts.GetIdFor(x))
|
||||
it.Add(ts.ValueOf(x))
|
||||
}
|
||||
return it
|
||||
case "Number":
|
||||
|
|
@ -101,7 +101,7 @@ func buildIteratorFromValue(val otto.Value, ts graph.TripleStore) graph.Iterator
|
|||
case "String":
|
||||
it := ts.FixedIterator()
|
||||
str, _ := val.ToString()
|
||||
it.AddValue(ts.GetIdFor(str))
|
||||
it.Add(ts.ValueOf(str))
|
||||
return it
|
||||
default:
|
||||
glog.Errorln("Trying to handle unsupported Javascript value.")
|
||||
|
|
@ -120,7 +120,7 @@ func buildInOutIterator(obj *otto.Object, ts graph.TripleStore, base graph.Itera
|
|||
length, _ := lengthVal.ToInteger()
|
||||
var predicateNodeIterator graph.Iterator
|
||||
if length == 0 {
|
||||
predicateNodeIterator = ts.GetNodesAllIterator()
|
||||
predicateNodeIterator = ts.NodesAllIterator()
|
||||
} else {
|
||||
zero, _ := argArray.Get("0")
|
||||
predicateNodeIterator = buildIteratorFromValue(zero, ts)
|
||||
|
|
@ -168,11 +168,11 @@ func buildIteratorTreeHelper(obj *otto.Object, ts graph.TripleStore, base graph.
|
|||
switch kind {
|
||||
case "vertex":
|
||||
if len(stringArgs) == 0 {
|
||||
it = ts.GetNodesAllIterator()
|
||||
it = ts.NodesAllIterator()
|
||||
} else {
|
||||
fixed := ts.FixedIterator()
|
||||
for _, name := range stringArgs {
|
||||
fixed.AddValue(ts.GetIdFor(name))
|
||||
fixed.Add(ts.ValueOf(name))
|
||||
}
|
||||
it = fixed
|
||||
}
|
||||
|
|
@ -182,7 +182,7 @@ func buildIteratorTreeHelper(obj *otto.Object, ts graph.TripleStore, base graph.
|
|||
it.AddTag(tag)
|
||||
}
|
||||
case "save":
|
||||
all := ts.GetNodesAllIterator()
|
||||
all := ts.NodesAllIterator()
|
||||
if len(stringArgs) > 2 || len(stringArgs) == 0 {
|
||||
return iterator.NewNull()
|
||||
}
|
||||
|
|
@ -192,7 +192,7 @@ func buildIteratorTreeHelper(obj *otto.Object, ts graph.TripleStore, base graph.
|
|||
all.AddTag(stringArgs[0])
|
||||
}
|
||||
predFixed := ts.FixedIterator()
|
||||
predFixed.AddValue(ts.GetIdFor(stringArgs[0]))
|
||||
predFixed.Add(ts.ValueOf(stringArgs[0]))
|
||||
subAnd := iterator.NewAnd()
|
||||
subAnd.AddSubIterator(iterator.NewLinksTo(ts, predFixed, graph.Predicate))
|
||||
subAnd.AddSubIterator(iterator.NewLinksTo(ts, all, graph.Object))
|
||||
|
|
@ -202,7 +202,7 @@ func buildIteratorTreeHelper(obj *otto.Object, ts graph.TripleStore, base graph.
|
|||
and.AddSubIterator(subIt)
|
||||
it = and
|
||||
case "saver":
|
||||
all := ts.GetNodesAllIterator()
|
||||
all := ts.NodesAllIterator()
|
||||
if len(stringArgs) > 2 || len(stringArgs) == 0 {
|
||||
return iterator.NewNull()
|
||||
}
|
||||
|
|
@ -212,7 +212,7 @@ func buildIteratorTreeHelper(obj *otto.Object, ts graph.TripleStore, base graph.
|
|||
all.AddTag(stringArgs[0])
|
||||
}
|
||||
predFixed := ts.FixedIterator()
|
||||
predFixed.AddValue(ts.GetIdFor(stringArgs[0]))
|
||||
predFixed.Add(ts.ValueOf(stringArgs[0]))
|
||||
subAnd := iterator.NewAnd()
|
||||
subAnd.AddSubIterator(iterator.NewLinksTo(ts, predFixed, graph.Predicate))
|
||||
subAnd.AddSubIterator(iterator.NewLinksTo(ts, all, graph.Subject))
|
||||
|
|
@ -227,10 +227,10 @@ func buildIteratorTreeHelper(obj *otto.Object, ts graph.TripleStore, base graph.
|
|||
return iterator.NewNull()
|
||||
}
|
||||
for _, name := range stringArgs[1:] {
|
||||
fixed.AddValue(ts.GetIdFor(name))
|
||||
fixed.Add(ts.ValueOf(name))
|
||||
}
|
||||
predFixed := ts.FixedIterator()
|
||||
predFixed.AddValue(ts.GetIdFor(stringArgs[0]))
|
||||
predFixed.Add(ts.ValueOf(stringArgs[0]))
|
||||
subAnd := iterator.NewAnd()
|
||||
subAnd.AddSubIterator(iterator.NewLinksTo(ts, predFixed, graph.Predicate))
|
||||
subAnd.AddSubIterator(iterator.NewLinksTo(ts, fixed, graph.Object))
|
||||
|
|
@ -263,7 +263,7 @@ func buildIteratorTreeHelper(obj *otto.Object, ts graph.TripleStore, base graph.
|
|||
case "is":
|
||||
fixed := ts.FixedIterator()
|
||||
for _, name := range stringArgs {
|
||||
fixed.AddValue(ts.GetIdFor(name))
|
||||
fixed.Add(ts.ValueOf(name))
|
||||
}
|
||||
and := iterator.NewAnd()
|
||||
and.AddSubIterator(fixed)
|
||||
|
|
|
|||
|
|
@ -135,10 +135,10 @@ func mapFunc(env *otto.Otto, ses *Session, obj *otto.Object) func(otto.FunctionC
|
|||
}
|
||||
}
|
||||
|
||||
func tagsToValueMap(m map[string]graph.TSVal, ses *Session) map[string]string {
|
||||
func tagsToValueMap(m map[string]graph.Value, ses *Session) map[string]string {
|
||||
outputMap := make(map[string]string)
|
||||
for k, v := range m {
|
||||
outputMap[k] = ses.ts.GetNameFor(v)
|
||||
outputMap[k] = ses.ts.NameOf(v)
|
||||
}
|
||||
return outputMap
|
||||
}
|
||||
|
|
@ -155,8 +155,8 @@ func runIteratorToArray(it graph.Iterator, ses *Session, limit int) []map[string
|
|||
if !ok {
|
||||
break
|
||||
}
|
||||
tags := make(map[string]graph.TSVal)
|
||||
it.TagResults(&tags)
|
||||
tags := make(map[string]graph.Value)
|
||||
it.TagResults(tags)
|
||||
output = append(output, tagsToValueMap(tags, ses))
|
||||
count++
|
||||
if limit >= 0 && count >= limit {
|
||||
|
|
@ -166,8 +166,8 @@ func runIteratorToArray(it graph.Iterator, ses *Session, limit int) []map[string
|
|||
if ses.doHalt {
|
||||
return nil
|
||||
}
|
||||
tags := make(map[string]graph.TSVal)
|
||||
it.TagResults(&tags)
|
||||
tags := make(map[string]graph.Value)
|
||||
it.TagResults(tags)
|
||||
output = append(output, tagsToValueMap(tags, ses))
|
||||
count++
|
||||
if limit >= 0 && count >= limit {
|
||||
|
|
@ -191,7 +191,7 @@ func runIteratorToArrayNoTags(it graph.Iterator, ses *Session, limit int) []stri
|
|||
if !ok {
|
||||
break
|
||||
}
|
||||
output = append(output, ses.ts.GetNameFor(val))
|
||||
output = append(output, ses.ts.NameOf(val))
|
||||
count++
|
||||
if limit >= 0 && count >= limit {
|
||||
break
|
||||
|
|
@ -212,8 +212,8 @@ func runIteratorWithCallback(it graph.Iterator, ses *Session, callback otto.Valu
|
|||
if !ok {
|
||||
break
|
||||
}
|
||||
tags := make(map[string]graph.TSVal)
|
||||
it.TagResults(&tags)
|
||||
tags := make(map[string]graph.Value)
|
||||
it.TagResults(tags)
|
||||
val, _ := this.Otto.ToValue(tagsToValueMap(tags, ses))
|
||||
val, _ = callback.Call(this.This, val)
|
||||
count++
|
||||
|
|
@ -224,8 +224,8 @@ func runIteratorWithCallback(it graph.Iterator, ses *Session, callback otto.Valu
|
|||
if ses.doHalt {
|
||||
return
|
||||
}
|
||||
tags := make(map[string]graph.TSVal)
|
||||
it.TagResults(&tags)
|
||||
tags := make(map[string]graph.Value)
|
||||
it.TagResults(tags)
|
||||
val, _ := this.Otto.ToValue(tagsToValueMap(tags, ses))
|
||||
val, _ = callback.Call(this.This, val)
|
||||
count++
|
||||
|
|
@ -253,8 +253,8 @@ func runIteratorOnSession(it graph.Iterator, ses *Session) {
|
|||
if !ok {
|
||||
break
|
||||
}
|
||||
tags := make(map[string]graph.TSVal)
|
||||
it.TagResults(&tags)
|
||||
tags := make(map[string]graph.Value)
|
||||
it.TagResults(tags)
|
||||
cont := ses.SendResult(&GremlinResult{metaresult: false, err: "", val: nil, actualResults: &tags})
|
||||
if !cont {
|
||||
break
|
||||
|
|
@ -263,8 +263,8 @@ func runIteratorOnSession(it graph.Iterator, ses *Session) {
|
|||
if ses.doHalt {
|
||||
return
|
||||
}
|
||||
tags := make(map[string]graph.TSVal)
|
||||
it.TagResults(&tags)
|
||||
tags := make(map[string]graph.Value)
|
||||
it.TagResults(tags)
|
||||
cont := ses.SendResult(&GremlinResult{metaresult: false, err: "", val: nil, actualResults: &tags})
|
||||
if !cont {
|
||||
break
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ func runQueryGetTag(query string, tag string) ([]string, int) {
|
|||
if data.val == nil {
|
||||
val := (*data.actualResults)[tag]
|
||||
if val != nil {
|
||||
output = append(output, js.ts.GetNameFor(val))
|
||||
output = append(output, js.ts.NameOf(val))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ type GremlinResult struct {
|
|||
metaresult bool
|
||||
err string
|
||||
val *otto.Value
|
||||
actualResults *map[string]graph.TSVal
|
||||
actualResults *map[string]graph.Value
|
||||
}
|
||||
|
||||
func (s *Session) ToggleDebug() {
|
||||
|
|
@ -202,7 +202,7 @@ func (s *Session) ToText(result interface{}) string {
|
|||
if k == "$_" {
|
||||
continue
|
||||
}
|
||||
out += fmt.Sprintf("%s : %s\n", k, s.ts.GetNameFor((*tags)[k]))
|
||||
out += fmt.Sprintf("%s : %s\n", k, s.ts.NameOf((*tags)[k]))
|
||||
}
|
||||
} else {
|
||||
if data.val.IsObject() {
|
||||
|
|
@ -234,7 +234,7 @@ func (ses *Session) BuildJson(result interface{}) {
|
|||
}
|
||||
sort.Strings(tagKeys)
|
||||
for _, k := range tagKeys {
|
||||
obj[k] = ses.ts.GetNameFor((*tags)[k])
|
||||
obj[k] = ses.ts.NameOf((*tags)[k])
|
||||
}
|
||||
ses.dataOutput = append(ses.dataOutput, obj)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -27,12 +27,12 @@ import (
|
|||
|
||||
func (q *Query) buildFixed(s string) graph.Iterator {
|
||||
f := q.ses.ts.FixedIterator()
|
||||
f.AddValue(q.ses.ts.GetIdFor(s))
|
||||
f.Add(q.ses.ts.ValueOf(s))
|
||||
return f
|
||||
}
|
||||
|
||||
func (q *Query) buildResultIterator(path Path) graph.Iterator {
|
||||
all := q.ses.ts.GetNodesAllIterator()
|
||||
all := q.ses.ts.NodesAllIterator()
|
||||
all.AddTag(string(path))
|
||||
return all
|
||||
}
|
||||
|
|
@ -103,7 +103,7 @@ func (q *Query) buildIteratorTreeInternal(query interface{}, path Path) (it grap
|
|||
|
||||
func (q *Query) buildIteratorTreeMapInternal(query map[string]interface{}, path Path) (graph.Iterator, error) {
|
||||
it := iterator.NewAnd()
|
||||
it.AddSubIterator(q.ses.ts.GetNodesAllIterator())
|
||||
it.AddSubIterator(q.ses.ts.NodesAllIterator())
|
||||
var err error
|
||||
err = nil
|
||||
outputStructure := make(map[string]interface{})
|
||||
|
|
@ -138,7 +138,7 @@ func (q *Query) buildIteratorTreeMapInternal(query map[string]interface{}, path
|
|||
}
|
||||
subAnd := iterator.NewAnd()
|
||||
predFixed := q.ses.ts.FixedIterator()
|
||||
predFixed.AddValue(q.ses.ts.GetIdFor(pred))
|
||||
predFixed.Add(q.ses.ts.ValueOf(pred))
|
||||
subAnd.AddSubIterator(iterator.NewLinksTo(q.ses.ts, predFixed, graph.Predicate))
|
||||
if reverse {
|
||||
lto := iterator.NewLinksTo(q.ses.ts, builtIt, graph.Subject)
|
||||
|
|
|
|||
|
|
@ -20,14 +20,14 @@ import (
|
|||
"github.com/google/cayley/graph"
|
||||
)
|
||||
|
||||
func (q *Query) treeifyResult(tags map[string]graph.TSVal) map[ResultPath]string {
|
||||
func (q *Query) treeifyResult(tags map[string]graph.Value) map[ResultPath]string {
|
||||
// Transform the map into something a little more interesting.
|
||||
results := make(map[Path]string)
|
||||
for k, v := range tags {
|
||||
if v == nil {
|
||||
continue
|
||||
}
|
||||
results[Path(k)] = q.ses.ts.GetNameFor(v)
|
||||
results[Path(k)] = q.ses.ts.NameOf(v)
|
||||
}
|
||||
resultPaths := make(map[ResultPath]string)
|
||||
for k, v := range results {
|
||||
|
|
|
|||
|
|
@ -92,19 +92,19 @@ func (s *Session) ExecInput(input string, c chan interface{}, limit int) {
|
|||
if !ok {
|
||||
break
|
||||
}
|
||||
tags := make(map[string]graph.TSVal)
|
||||
it.TagResults(&tags)
|
||||
c <- &tags
|
||||
tags := make(map[string]graph.Value)
|
||||
it.TagResults(tags)
|
||||
c <- tags
|
||||
for it.NextResult() == true {
|
||||
tags := make(map[string]graph.TSVal)
|
||||
it.TagResults(&tags)
|
||||
c <- &tags
|
||||
tags := make(map[string]graph.Value)
|
||||
it.TagResults(tags)
|
||||
c <- tags
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Session) ToText(result interface{}) string {
|
||||
tags := *(result.(*map[string]graph.TSVal))
|
||||
tags := result.(map[string]graph.Value)
|
||||
out := fmt.Sprintln("****")
|
||||
tagKeys := make([]string, len(tags))
|
||||
s.currentQuery.treeifyResult(tags)
|
||||
|
|
@ -121,13 +121,13 @@ func (s *Session) ToText(result interface{}) string {
|
|||
if k == "$_" {
|
||||
continue
|
||||
}
|
||||
out += fmt.Sprintf("%s : %s\n", k, s.ts.GetNameFor(tags[k]))
|
||||
out += fmt.Sprintf("%s : %s\n", k, s.ts.NameOf(tags[k]))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (s *Session) BuildJson(result interface{}) {
|
||||
s.currentQuery.treeifyResult(*(result.(*map[string]graph.TSVal)))
|
||||
s.currentQuery.treeifyResult(result.(map[string]graph.Value))
|
||||
}
|
||||
|
||||
func (s *Session) GetJson() (interface{}, error) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue