From d87e227ff3625643fc1494a39824afdd0e3b4fa5 Mon Sep 17 00:00:00 2001 From: kortschak Date: Wed, 2 Jul 2014 12:13:15 +0930 Subject: [PATCH] Rename TSVal --- graph/iterator.go | 20 ++++++++++---------- graph/iterator/all_iterator.go | 4 ++-- graph/iterator/and_iterator.go | 12 ++++++------ graph/iterator/and_iterator_test.go | 2 +- graph/iterator/fixed_iterator.go | 16 ++++++++-------- graph/iterator/hasa_iterator.go | 6 +++--- graph/iterator/iterator.go | 18 +++++++++--------- graph/iterator/linksto_iterator.go | 6 +++--- graph/iterator/mock_ts_test.go | 10 +++++----- graph/iterator/optional_iterator.go | 6 +++--- graph/iterator/or_iterator.go | 10 +++++----- graph/iterator/value_comparison_iterator.go | 10 +++++----- graph/leveldb/all_iterator.go | 4 ++-- graph/leveldb/iterator.go | 6 +++--- graph/leveldb/leveldb_test.go | 4 ++-- graph/leveldb/triplestore.go | 14 +++++++------- graph/memstore/all_iterator.go | 2 +- graph/memstore/iterator.go | 4 ++-- graph/memstore/triplestore.go | 10 +++++----- graph/mongo/iterator.go | 6 +++--- graph/mongo/triplestore.go | 12 ++++++------ graph/result_tree_evaluator.go | 4 ++-- graph/sexp/parser_test.go | 2 +- graph/sexp/session.go | 6 +++--- graph/triplestore.go | 16 ++++++++-------- query/gremlin/finals.go | 14 +++++++------- query/gremlin/session.go | 2 +- query/mql/fill.go | 2 +- query/mql/session.go | 8 ++++---- 29 files changed, 118 insertions(+), 118 deletions(-) diff --git a/graph/iterator.go b/graph/iterator.go index fd68740..709b7d3 100644 --- a/graph/iterator.go +++ b/graph/iterator.go @@ -32,15 +32,15 @@ type Iterator interface { // Tag Accessors. AddTag(string) Tags() []string - AddFixedTag(string, TSVal) - FixedTags() map[string]TSVal + AddFixedTag(string, Value) + FixedTags() map[string]Value CopyTagsFrom(Iterator) // Fills a tag-to-result-value map. - TagResults(map[string]TSVal) + TagResults(map[string]Value) // Returns the current result. - Result() TSVal + Result() Value // DEPRECATED -- Fills a ResultTree struct with Result(). ResultTree() *ResultTree @@ -59,7 +59,7 @@ type Iterator interface { // // Next() advances the iterator and returns the next valid result. Returns // (, true) or (nil, false) - Next() (TSVal, bool) + Next() (Value, bool) // NextResult() advances iterators that may have more than one valid result, // from the bottom up. @@ -72,7 +72,7 @@ type Iterator interface { // Check(), given a value, returns whether or not that value is within the set // held by this iterator. - Check(TSVal) bool + Check(Value) bool // Start iteration from the beginning Reset() @@ -117,7 +117,7 @@ type Iterator interface { type FixedIterator interface { Iterator - AddValue(TSVal) + AddValue(Value) } type IteratorStats struct { @@ -128,13 +128,13 @@ type IteratorStats struct { // Utility logging functions for when an iterator gets called Next upon, or Check upon, as // well as what they return. Highly useful for tracing the execution path of a query. -func CheckLogIn(it Iterator, val TSVal) { +func CheckLogIn(it Iterator, val Value) { if glog.V(4) { glog.V(4).Infof("%s %d CHECK %d", strings.ToUpper(it.Type()), it.UID(), val) } } -func CheckLogOut(it Iterator, val TSVal, good bool) bool { +func CheckLogOut(it Iterator, val Value, good bool) bool { if glog.V(4) { if good { glog.V(4).Infof("%s %d CHECK %d GOOD", strings.ToUpper(it.Type()), it.UID(), val) @@ -151,7 +151,7 @@ func NextLogIn(it Iterator) { } } -func NextLogOut(it Iterator, val TSVal, ok bool) (TSVal, bool) { +func NextLogOut(it Iterator, val Value, ok bool) (Value, bool) { if glog.V(4) { if ok { glog.V(4).Infof("%s %d NEXT IS %d", strings.ToUpper(it.Type()), it.UID(), val) diff --git a/graph/iterator/all_iterator.go b/graph/iterator/all_iterator.go index e7bc809..4cd6aa1 100644 --- a/graph/iterator/all_iterator.go +++ b/graph/iterator/all_iterator.go @@ -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 { diff --git a/graph/iterator/and_iterator.go b/graph/iterator/and_iterator.go index 8d8fe73..66a51cf 100644 --- a/graph/iterator/and_iterator.go +++ b/graph/iterator/and_iterator.go @@ -73,7 +73,7 @@ func (it *And) SubIterators() []graph.Iterator { // Overrides Base TagResults, as it needs to add it's own results and // recurse down it's subiterators. -func (it *And) TagResults(dst map[string]graph.TSVal) { +func (it *And) TagResults(dst map[string]graph.Value) { it.Base.TagResults(dst) if it.primaryIt != nil { it.primaryIt.TagResults(dst) @@ -139,9 +139,9 @@ func (it *And) AddSubIterator(sub graph.Iterator) { // intersection of its subiterators, it must choose one subiterator to produce a // candidate, and check this value against the subiterators. A productive choice // of primary iterator is therefore very important. -func (it *And) Next() (graph.TSVal, bool) { +func (it *And) Next() (graph.Value, bool) { graph.NextLogIn(it) - var curr graph.TSVal + var curr graph.Value var exists bool for { curr, exists = it.primaryIt.Next() @@ -157,7 +157,7 @@ func (it *And) Next() (graph.TSVal, bool) { } // Checks a value against the non-primary iterators, in order. -func (it *And) checkSubIts(val graph.TSVal) bool { +func (it *And) checkSubIts(val graph.Value) bool { var subIsGood = true for _, sub := range it.internalIterators { subIsGood = sub.Check(val) @@ -168,7 +168,7 @@ func (it *And) checkSubIts(val graph.TSVal) bool { return subIsGood } -func (it *And) checkCheckList(val graph.TSVal) bool { +func (it *And) checkCheckList(val graph.Value) bool { ok := true for _, c := range it.checkList { ok = c.Check(val) @@ -183,7 +183,7 @@ func (it *And) checkCheckList(val graph.TSVal) bool { } // Check a value against the entire iterator, in order. -func (it *And) Check(val graph.TSVal) bool { +func (it *And) Check(val graph.Value) bool { graph.CheckLogIn(it, val) if it.checkList != nil { return it.checkCheckList(val) diff --git a/graph/iterator/and_iterator_test.go b/graph/iterator/and_iterator_test.go index 4e18560..ef76903 100644 --- a/graph/iterator/and_iterator_test.go +++ b/graph/iterator/and_iterator_test.go @@ -43,7 +43,7 @@ func TestTag(t *testing.T) { if val != 234 { t.Errorf("Unexpected value") } - tags := make(map[string]graph.TSVal) + tags := make(map[string]graph.Value) and.TagResults(tags) if tags["bar"] != 234 { t.Errorf("no bar tag") diff --git a/graph/iterator/fixed_iterator.go b/graph/iterator/fixed_iterator.go index dc6ecbb..8dd7190 100644 --- a/graph/iterator/fixed_iterator.go +++ b/graph/iterator/fixed_iterator.go @@ -17,7 +17,7 @@ package iterator // Defines one of the base iterators, the Fixed iterator. A fixed iterator is quite simple; it // contains an explicit fixed array of values. // -// A fixed iterator requires an Equality function to be passed to it, by reason that graph.TSVal, the +// A fixed iterator requires an Equality function to be passed to it, by reason that graph.Value, the // opaque Triple store value, may not answer to ==. import ( @@ -31,16 +31,16 @@ import ( // an equality function. type Fixed struct { Base - values []graph.TSVal + values []graph.Value lastIndex int cmp Equality } // Define the signature of an equality function. -type Equality func(a, b graph.TSVal) bool +type Equality func(a, b graph.Value) bool // Define an equality function of purely ==, which works for native types. -func BasicEquality(a, b graph.TSVal) bool { +func BasicEquality(a, b graph.Value) bool { if a == b { return true } @@ -56,7 +56,7 @@ func newFixed() *Fixed { func NewFixedIteratorWithCompare(compareFn Equality) *Fixed { var it Fixed BaseInit(&it.Base) - it.values = make([]graph.TSVal, 0, 20) + it.values = make([]graph.Value, 0, 20) it.lastIndex = 0 it.cmp = compareFn return &it @@ -79,7 +79,7 @@ func (it *Fixed) Clone() graph.Iterator { // Add a value to the iterator. The array now contains this value. // TODO(barakmich): This ought to be a set someday, disallowing repeated values. -func (it *Fixed) AddValue(v graph.TSVal) { +func (it *Fixed) AddValue(v graph.Value) { it.values = append(it.values, v) } @@ -104,7 +104,7 @@ func (it *Fixed) Type() string { } // Check if the passed value is equal to one of the values stored in the iterator. -func (it *Fixed) Check(v graph.TSVal) bool { +func (it *Fixed) Check(v graph.Value) bool { // Could be optimized by keeping it sorted or using a better datastructure. // However, for fixed iterators, which are by definition kind of tiny, this // isn't a big issue. @@ -119,7 +119,7 @@ func (it *Fixed) Check(v graph.TSVal) bool { } // Return the next stored value from the iterator. -func (it *Fixed) Next() (graph.TSVal, bool) { +func (it *Fixed) Next() (graph.Value, bool) { graph.NextLogIn(it) if it.lastIndex == len(it.values) { return graph.NextLogOut(it, nil, false) diff --git a/graph/iterator/hasa_iterator.go b/graph/iterator/hasa_iterator.go index 1abddc4..c253923 100644 --- a/graph/iterator/hasa_iterator.go +++ b/graph/iterator/hasa_iterator.go @@ -99,7 +99,7 @@ func (it *HasA) Optimize() (graph.Iterator, bool) { } // Pass the TagResults down the chain. -func (it *HasA) TagResults(dst map[string]graph.TSVal) { +func (it *HasA) TagResults(dst map[string]graph.Value) { it.Base.TagResults(dst) it.primaryIt.TagResults(dst) } @@ -123,7 +123,7 @@ func (it *HasA) DebugString(indent int) string { // Check a value against our internal iterator. In order to do this, we must first open a new // iterator of "triples that have `val` in our direction", given to us by the triple store, // and then Next() values out of that iterator and Check() them against our subiterator. -func (it *HasA) Check(val graph.TSVal) bool { +func (it *HasA) Check(val graph.Value) bool { graph.CheckLogIn(it, val) if glog.V(4) { glog.V(4).Infoln("Id is", it.ts.NameOf(val)) @@ -173,7 +173,7 @@ func (it *HasA) NextResult() bool { // Get the next result from this iterator. This is simpler than Check. We have a // subiterator we can get a value from, and we can take that resultant triple, // pull our direction out of it, and return that. -func (it *HasA) Next() (graph.TSVal, bool) { +func (it *HasA) Next() (graph.Value, bool) { graph.NextLogIn(it) if it.resultIt != nil { it.resultIt.Close() diff --git a/graph/iterator/iterator.go b/graph/iterator/iterator.go index 8ee107c..8658137 100644 --- a/graph/iterator/iterator.go +++ b/graph/iterator/iterator.go @@ -36,9 +36,9 @@ func nextID() uintptr { // The Base iterator is the iterator other iterators inherit from to get some // default functionality. type Base struct { - Last graph.TSVal + Last graph.Value tags []string - fixedTags map[string]graph.TSVal + fixedTags map[string]graph.Value canNext bool uid uintptr } @@ -64,9 +64,9 @@ func (it *Base) AddTag(tag string) { it.tags = append(it.tags, tag) } -func (it *Base) AddFixedTag(tag string, value graph.TSVal) { +func (it *Base) AddFixedTag(tag string, value graph.Value) { if it.fixedTags == nil { - it.fixedTags = make(map[string]graph.TSVal) + it.fixedTags = make(map[string]graph.Value) } it.fixedTags[tag] = value } @@ -76,7 +76,7 @@ func (it *Base) Tags() []string { return it.tags } -func (it *Base) FixedTags() map[string]graph.TSVal { +func (it *Base) FixedTags() map[string]graph.Value { return it.fixedTags } @@ -97,7 +97,7 @@ func (it *Base) DebugString(indent int) string { } // Nothing in a base iterator. -func (it *Base) Check(v graph.TSVal) bool { +func (it *Base) Check(v graph.Value) bool { return false } @@ -114,7 +114,7 @@ func (it *Base) ResultTree() *graph.ResultTree { } // Nothing in a base iterator. -func (it *Base) Next() (graph.TSVal, bool) { +func (it *Base) Next() (graph.Value, bool) { return nil, false } @@ -123,7 +123,7 @@ func (it *Base) NextResult() bool { } // Returns the last result of an iterator. -func (it *Base) Result() graph.TSVal { +func (it *Base) Result() graph.Value { return it.Last } @@ -142,7 +142,7 @@ func (it *Base) CanNext() bool { return it.canNext } // Fill the map based on the tags assigned to this iterator. Default // functionality works well for most iterators. -func (it *Base) TagResults(dst map[string]graph.TSVal) { +func (it *Base) TagResults(dst map[string]graph.Value) { for _, tag := range it.Tags() { dst[tag] = it.Result() } diff --git a/graph/iterator/linksto_iterator.go b/graph/iterator/linksto_iterator.go index 76b9a55..27d496e 100644 --- a/graph/iterator/linksto_iterator.go +++ b/graph/iterator/linksto_iterator.go @@ -77,7 +77,7 @@ func (it *LinksTo) Clone() graph.Iterator { func (it *LinksTo) Direction() graph.Direction { return it.dir } // Tag these results, and our subiterator's results. -func (it *LinksTo) TagResults(dst map[string]graph.TSVal) { +func (it *LinksTo) TagResults(dst map[string]graph.Value) { it.Base.TagResults(dst) it.primaryIt.TagResults(dst) } @@ -98,7 +98,7 @@ func (it *LinksTo) DebugString(indent int) string { // If it checks in the right direction for the subiterator, it is a valid link // for the LinksTo. -func (it *LinksTo) Check(val graph.TSVal) bool { +func (it *LinksTo) Check(val graph.Value) bool { graph.CheckLogIn(it, val) node := it.ts.TripleDirection(val, it.dir) if it.primaryIt.Check(node) { @@ -135,7 +135,7 @@ func (it *LinksTo) Optimize() (graph.Iterator, bool) { } // Next()ing a LinksTo operates as described above. -func (it *LinksTo) Next() (graph.TSVal, bool) { +func (it *LinksTo) Next() (graph.Value, bool) { graph.NextLogIn(it) val, ok := it.nextIt.Next() if !ok { diff --git a/graph/iterator/mock_ts_test.go b/graph/iterator/mock_ts_test.go index bb2c031..7ab3090 100644 --- a/graph/iterator/mock_ts_test.go +++ b/graph/iterator/mock_ts_test.go @@ -27,14 +27,14 @@ type TestTripleStore struct { mock.Mock } -func (ts *TestTripleStore) ValueOf(s string) graph.TSVal { +func (ts *TestTripleStore) ValueOf(s string) graph.Value { args := ts.Mock.Called(s) return args.Get(0) } func (ts *TestTripleStore) AddTriple(*graph.Triple) {} func (ts *TestTripleStore) AddTripleSet([]*graph.Triple) {} -func (ts *TestTripleStore) Triple(graph.TSVal) *graph.Triple { return &graph.Triple{} } -func (ts *TestTripleStore) TripleIterator(d graph.Direction, i graph.TSVal) graph.Iterator { +func (ts *TestTripleStore) Triple(graph.Value) *graph.Triple { return &graph.Triple{} } +func (ts *TestTripleStore) TripleIterator(d graph.Direction, i graph.Value) graph.Iterator { args := ts.Mock.Called(d, i) return args.Get(0).(graph.Iterator) } @@ -43,7 +43,7 @@ func (ts *TestTripleStore) TriplesAllIterator() graph.Iterator { return &Null{} func (ts *TestTripleStore) GetIteratorByString(string, string, string) graph.Iterator { return &Null{} } -func (ts *TestTripleStore) NameOf(v graph.TSVal) string { +func (ts *TestTripleStore) NameOf(v graph.Value) string { args := ts.Mock.Called(v) return args.Get(0).(string) } @@ -56,5 +56,5 @@ func (ts *TestTripleStore) FixedIterator() graph.FixedIterator { return NewFixedIteratorWithCompare(BasicEquality) } func (ts *TestTripleStore) Close() {} -func (ts *TestTripleStore) TripleDirection(graph.TSVal, graph.Direction) graph.TSVal { return 0 } +func (ts *TestTripleStore) TripleDirection(graph.Value, graph.Direction) graph.Value { return 0 } func (ts *TestTripleStore) RemoveTriple(t *graph.Triple) {} diff --git a/graph/iterator/optional_iterator.go b/graph/iterator/optional_iterator.go index 1e0eedd..f69959b 100644 --- a/graph/iterator/optional_iterator.go +++ b/graph/iterator/optional_iterator.go @@ -69,7 +69,7 @@ func (it *Optional) Clone() graph.Iterator { // Nexting the iterator is unsupported -- error and return an empty set. // (As above, a reasonable alternative would be to Next() an all iterator) -func (it *Optional) Next() (graph.TSVal, bool) { +func (it *Optional) Next() (graph.Value, bool) { glog.Errorln("Nexting an un-nextable iterator") return nil, false } @@ -87,7 +87,7 @@ func (it *Optional) NextResult() bool { // Check() is the real hack of this iterator. It always returns true, regardless // of whether the subiterator matched. But we keep track of whether the subiterator // matched for results purposes. -func (it *Optional) Check(val graph.TSVal) bool { +func (it *Optional) Check(val graph.Value) bool { checked := it.subIt.Check(val) it.lastCheck = checked it.Last = val @@ -96,7 +96,7 @@ func (it *Optional) Check(val graph.TSVal) bool { // If we failed the check, then the subiterator should not contribute to the result // set. Otherwise, go ahead and tag it. -func (it *Optional) TagResults(dst map[string]graph.TSVal) { +func (it *Optional) TagResults(dst map[string]graph.Value) { if it.lastCheck == false { return } diff --git a/graph/iterator/or_iterator.go b/graph/iterator/or_iterator.go index 68c97da..6b98185 100644 --- a/graph/iterator/or_iterator.go +++ b/graph/iterator/or_iterator.go @@ -83,7 +83,7 @@ func (it *Or) SubIterators() []graph.Iterator { // Overrides BaseIterator TagResults, as it needs to add it's own results and // recurse down it's subiterators. -func (it *Or) TagResults(dst map[string]graph.TSVal) { +func (it *Or) TagResults(dst map[string]graph.Value) { it.Base.TagResults(dst) it.internalIterators[it.currentIterator].TagResults(dst) } @@ -128,9 +128,9 @@ func (it *Or) AddSubIterator(sub graph.Iterator) { // Returns the Next value from the Or graph.iterator. Because the Or is the // union of its subiterators, it must produce from all subiterators -- unless // it's shortcircuiting, in which case, it's the first one that returns anything. -func (it *Or) Next() (graph.TSVal, bool) { +func (it *Or) Next() (graph.Value, bool) { graph.NextLogIn(it) - var curr graph.TSVal + var curr graph.Value var exists bool firstTime := false for { @@ -157,7 +157,7 @@ func (it *Or) Next() (graph.TSVal, bool) { } // Checks a value against the iterators, in order. -func (it *Or) checkSubIts(val graph.TSVal) bool { +func (it *Or) checkSubIts(val graph.Value) bool { var subIsGood = false for i, sub := range it.internalIterators { subIsGood = sub.Check(val) @@ -170,7 +170,7 @@ func (it *Or) checkSubIts(val graph.TSVal) bool { } // Check a value against the entire graph.iterator, in order. -func (it *Or) Check(val graph.TSVal) bool { +func (it *Or) Check(val graph.Value) bool { graph.CheckLogIn(it, val) anyGood := it.checkSubIts(val) if !anyGood { diff --git a/graph/iterator/value_comparison_iterator.go b/graph/iterator/value_comparison_iterator.go index bec6723..8c36795 100644 --- a/graph/iterator/value_comparison_iterator.go +++ b/graph/iterator/value_comparison_iterator.go @@ -65,7 +65,7 @@ func NewComparison(sub graph.Iterator, op Operator, val interface{}, ts graph.Tr // Here's the non-boilerplate part of the ValueComparison iterator. Given a value // and our operator, determine whether or not we meet the requirement. -func (it *Comparison) doComparison(val graph.TSVal) bool { +func (it *Comparison) doComparison(val graph.Value) bool { //TODO(barakmich): Implement string comparison. nodeStr := it.ts.NameOf(val) switch cVal := it.val.(type) { @@ -117,8 +117,8 @@ func (it *Comparison) Clone() graph.Iterator { return out } -func (it *Comparison) Next() (graph.TSVal, bool) { - var val graph.TSVal +func (it *Comparison) Next() (graph.Value, bool) { + var val graph.Value var ok bool for { val, ok = it.subIt.Next() @@ -147,7 +147,7 @@ func (it *Comparison) NextResult() bool { return true } -func (it *Comparison) Check(val graph.TSVal) bool { +func (it *Comparison) Check(val graph.Value) bool { if !it.doComparison(val) { return false } @@ -156,7 +156,7 @@ func (it *Comparison) Check(val graph.TSVal) bool { // If we failed the check, then the subiterator should not contribute to the result // set. Otherwise, go ahead and tag it. -func (it *Comparison) TagResults(dst map[string]graph.TSVal) { +func (it *Comparison) TagResults(dst map[string]graph.Value) { it.Base.TagResults(dst) it.subIt.TagResults(dst) } diff --git a/graph/leveldb/all_iterator.go b/graph/leveldb/all_iterator.go index 6115910..e9ab3c4 100644 --- a/graph/leveldb/all_iterator.go +++ b/graph/leveldb/all_iterator.go @@ -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 } diff --git a/graph/leveldb/iterator.go b/graph/leveldb/iterator.go index 26219be..f6969e5 100644 --- a/graph/leveldb/iterator.go +++ b/graph/leveldb/iterator.go @@ -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 diff --git a/graph/leveldb/leveldb_test.go b/graph/leveldb/leveldb_test.go index aaddc5c..a7e9be9 100644 --- a/graph/leveldb/leveldb_test.go +++ b/graph/leveldb/leveldb_test.go @@ -420,9 +420,9 @@ func TestOptimize(t *testing.T) { Convey("With the correct tags", func() { oldIt.Next() newIt.Next() - oldResults := make(map[string]graph.TSVal) + oldResults := make(map[string]graph.Value) oldIt.TagResults(oldResults) - newResults := make(map[string]graph.TSVal) + newResults := make(map[string]graph.Value) oldIt.TagResults(newResults) So(newResults, ShouldResemble, oldResults) }) diff --git a/graph/leveldb/triplestore.go b/graph/leveldb/triplestore.go index 0b88993..5b6acd7 100644 --- a/graph/leveldb/triplestore.go +++ b/graph/leveldb/triplestore.go @@ -301,7 +301,7 @@ func (ts *TripleStore) Close() { ts.open = false } -func (ts *TripleStore) Triple(k graph.TSVal) *graph.Triple { +func (ts *TripleStore) Triple(k graph.Value) *graph.Triple { var triple graph.Triple b, err := ts.db.Get(k.([]byte), ts.readopts) if err != nil && err != leveldb.ErrNotFound { @@ -328,7 +328,7 @@ func (ts *TripleStore) convertStringToByteHash(s string) []byte { return key } -func (ts *TripleStore) ValueOf(s string) graph.TSVal { +func (ts *TripleStore) ValueOf(s string) graph.Value { return ts.createValueKeyFor(s) } @@ -352,7 +352,7 @@ func (ts *TripleStore) getValueData(value_key []byte) ValueData { return out } -func (ts *TripleStore) NameOf(k graph.TSVal) string { +func (ts *TripleStore) NameOf(k graph.Value) string { if k == nil { glog.V(2).Infoln("k was nil") return "" @@ -360,7 +360,7 @@ func (ts *TripleStore) NameOf(k graph.TSVal) string { return ts.getValueData(k.([]byte)).Name } -func (ts *TripleStore) GetSizeFor(k graph.TSVal) int64 { +func (ts *TripleStore) GetSizeFor(k graph.Value) int64 { if k == nil { return 0 } @@ -401,7 +401,7 @@ func (ts *TripleStore) GetApproximateSizeForPrefix(pre []byte) (int64, error) { return 0, nil } -func (ts *TripleStore) TripleIterator(d graph.Direction, val graph.TSVal) graph.Iterator { +func (ts *TripleStore) TripleIterator(d graph.Direction, val graph.Value) graph.Iterator { var prefix string switch d { case graph.Subject: @@ -426,7 +426,7 @@ func (ts *TripleStore) TriplesAllIterator() graph.Iterator { return NewAllIterator("po", graph.Predicate, ts) } -func (ts *TripleStore) TripleDirection(val graph.TSVal, d graph.Direction) graph.TSVal { +func (ts *TripleStore) TripleDirection(val graph.Value, d graph.Direction) graph.Value { v := val.([]uint8) offset := GetPositionFromPrefix(v[0:2], d, ts) if offset != -1 { @@ -436,7 +436,7 @@ func (ts *TripleStore) TripleDirection(val graph.TSVal, d graph.Direction) graph } } -func compareBytes(a, b graph.TSVal) bool { +func compareBytes(a, b graph.Value) bool { return bytes.Equal(a.([]uint8), b.([]uint8)) } diff --git a/graph/memstore/all_iterator.go b/graph/memstore/all_iterator.go index f2c5b8e..371a958 100644 --- a/graph/memstore/all_iterator.go +++ b/graph/memstore/all_iterator.go @@ -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 diff --git a/graph/memstore/iterator.go b/graph/memstore/iterator.go index a9a0339..8df0e2e 100644 --- a/graph/memstore/iterator.go +++ b/graph/memstore/iterator.go @@ -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 diff --git a/graph/memstore/triplestore.go b/graph/memstore/triplestore.go index 5cb1be7..a53422c 100644 --- a/graph/memstore/triplestore.go +++ b/graph/memstore/triplestore.go @@ -217,11 +217,11 @@ func (ts *TripleStore) RemoveTriple(t *graph.Triple) { } } -func (ts *TripleStore) Triple(index graph.TSVal) *graph.Triple { +func (ts *TripleStore) Triple(index graph.Value) *graph.Triple { return &ts.triples[index.(int64)] } -func (ts *TripleStore) TripleIterator(d graph.Direction, value graph.TSVal) graph.Iterator { +func (ts *TripleStore) TripleIterator(d graph.Direction, value graph.Value) graph.Iterator { index, ok := ts.index.Get(d, value.(int64)) data := fmt.Sprintf("dir:%s val:%d", d, value.(int64)) if ok { @@ -243,11 +243,11 @@ func (ts *TripleStore) DebugPrint() { } } -func (ts *TripleStore) ValueOf(name string) graph.TSVal { +func (ts *TripleStore) ValueOf(name string) graph.Value { return ts.idMap[name] } -func (ts *TripleStore) NameOf(id graph.TSVal) string { +func (ts *TripleStore) NameOf(id graph.Value) string { return ts.revIdMap[id.(int64)] } @@ -259,7 +259,7 @@ func (ts *TripleStore) FixedIterator() graph.FixedIterator { return iterator.NewFixedIteratorWithCompare(iterator.BasicEquality) } -func (ts *TripleStore) TripleDirection(val graph.TSVal, d graph.Direction) graph.TSVal { +func (ts *TripleStore) TripleDirection(val graph.Value, d graph.Direction) graph.Value { name := ts.Triple(val).Get(d) return ts.ValueOf(name) } diff --git a/graph/mongo/iterator.go b/graph/mongo/iterator.go index 4b1c1c8..4ebf890 100644 --- a/graph/mongo/iterator.go +++ b/graph/mongo/iterator.go @@ -39,7 +39,7 @@ type Iterator struct { collection string } -func NewIterator(ts *TripleStore, collection string, d graph.Direction, val graph.TSVal) *Iterator { +func NewIterator(ts *TripleStore, collection string, d graph.Direction, val graph.Value) *Iterator { var m Iterator iterator.BaseInit(&m.Base) @@ -109,7 +109,7 @@ func (it *Iterator) Clone() graph.Iterator { return newM } -func (it *Iterator) Next() (graph.TSVal, bool) { +func (it *Iterator) Next() (graph.Value, bool) { var result struct { Id string "_id" //Sub string "Sub" @@ -128,7 +128,7 @@ func (it *Iterator) Next() (graph.TSVal, bool) { return result.Id, true } -func (it *Iterator) Check(v graph.TSVal) bool { +func (it *Iterator) Check(v graph.Value) bool { graph.CheckLogIn(it, v) if it.isAll { it.Last = v diff --git a/graph/mongo/triplestore.go b/graph/mongo/triplestore.go index 8fc0fab..001c539 100644 --- a/graph/mongo/triplestore.go +++ b/graph/mongo/triplestore.go @@ -209,7 +209,7 @@ func (ts *TripleStore) RemoveTriple(t *graph.Triple) { } } -func (ts *TripleStore) Triple(val graph.TSVal) *graph.Triple { +func (ts *TripleStore) Triple(val graph.Value) *graph.Triple { var bsonDoc bson.M err := ts.db.C("triples").FindId(val.(string)).One(&bsonDoc) if err != nil { @@ -223,7 +223,7 @@ func (ts *TripleStore) Triple(val graph.TSVal) *graph.Triple { } } -func (ts *TripleStore) TripleIterator(d graph.Direction, val graph.TSVal) graph.Iterator { +func (ts *TripleStore) TripleIterator(d graph.Direction, val graph.Value) graph.Iterator { return NewIterator(ts, "triples", d, val) } @@ -235,11 +235,11 @@ func (ts *TripleStore) TriplesAllIterator() graph.Iterator { return NewAllIterator(ts, "triples") } -func (ts *TripleStore) ValueOf(s string) graph.TSVal { +func (ts *TripleStore) ValueOf(s string) graph.Value { return ts.ConvertStringToByteHash(s) } -func (ts *TripleStore) NameOf(v graph.TSVal) string { +func (ts *TripleStore) NameOf(v graph.Value) string { val, ok := ts.idCache.Get(v.(string)) if ok { return val @@ -262,7 +262,7 @@ func (ts *TripleStore) Size() int64 { return int64(count) } -func compareStrings(a, b graph.TSVal) bool { +func compareStrings(a, b graph.Value) bool { return a.(string) == b.(string) } @@ -274,7 +274,7 @@ func (ts *TripleStore) Close() { ts.db.Session.Close() } -func (ts *TripleStore) TripleDirection(in graph.TSVal, d graph.Direction) graph.TSVal { +func (ts *TripleStore) TripleDirection(in graph.Value, d graph.Direction) graph.Value { // Maybe do the trick here var offset int switch d { diff --git a/graph/result_tree_evaluator.go b/graph/result_tree_evaluator.go index d04941a..e1588d2 100644 --- a/graph/result_tree_evaluator.go +++ b/graph/result_tree_evaluator.go @@ -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} } diff --git a/graph/sexp/parser_test.go b/graph/sexp/parser_test.go index 6d88113..4ae9c57 100644 --- a/graph/sexp/parser_test.go +++ b/graph/sexp/parser_test.go @@ -95,7 +95,7 @@ func TestTreeConstraintTagParse(t *testing.T) { if !ok { t.Error("Got no results") } - tags := make(map[string]graph.TSVal) + tags := make(map[string]graph.Value) it.TagResults(tags) if ts.NameOf(tags["$a"]) != "food" { t.Errorf("Got %s, expected food", ts.NameOf(tags["$a"])) diff --git a/graph/sexp/session.go b/graph/sexp/session.go index e67a0df..8d243f0 100644 --- a/graph/sexp/session.go +++ b/graph/sexp/session.go @@ -81,7 +81,7 @@ func (s *Session) ExecInput(input string, out chan interface{}, limit int) { if !ok { break } - tags := make(map[string]graph.TSVal) + tags := make(map[string]graph.Value) it.TagResults(tags) out <- &tags nResults++ @@ -89,7 +89,7 @@ func (s *Session) ExecInput(input string, out chan interface{}, limit int) { break } for it.NextResult() == true { - tags := make(map[string]graph.TSVal) + tags := make(map[string]graph.Value) it.TagResults(tags) out <- &tags nResults++ @@ -103,7 +103,7 @@ func (s *Session) ExecInput(input string, out chan interface{}, limit int) { func (s *Session) ToText(result interface{}) string { out := fmt.Sprintln("****") - tags := result.(map[string]graph.TSVal) + tags := result.(map[string]graph.Value) tagKeys := make([]string, len(tags)) i := 0 for k := range tags { diff --git a/graph/triplestore.go b/graph/triplestore.go index 7309779..d6aa326 100644 --- a/graph/triplestore.go +++ b/graph/triplestore.go @@ -26,14 +26,14 @@ import ( ) // Defines an opaque "triple store value" type. However the backend wishes to -// implement it, a TSVal is merely a token to a triple or a node that the backing +// implement it, a Value is merely a token to a triple or a node that the backing // store itself understands, and the base iterators pass around. // // For example, in a very traditional, graphd-style graph, these are int64s // (guids of the primitives). In a very direct sort of graph, these could be // pointers to structs, or merely triples, or whatever works best for the // backing store. -type TSVal interface{} +type Value interface{} type TripleStore interface { // Add a triple to the store. @@ -47,11 +47,11 @@ type TripleStore interface { RemoveTriple(*Triple) // Given an opaque token, returns the triple for that token from the store. - Triple(TSVal) *Triple + Triple(Value) *Triple // Given a direction and a token, creates an iterator of links which have // that node token in that directional field. - TripleIterator(Direction, TSVal) Iterator + TripleIterator(Direction, Value) Iterator // Returns an iterator enumerating all nodes in the graph. NodesAllIterator() Iterator @@ -61,15 +61,15 @@ type TripleStore interface { // Given a node ID, return the opaque token used by the TripleStore // to represent that id. - ValueOf(string) TSVal + ValueOf(string) Value // Given an opaque token, return the node that it represents. - NameOf(TSVal) string + NameOf(Value) string // Returns the number of triples currently stored. Size() int64 - // Creates a fixed iterator which can compare TSVals + // Creates a fixed iterator which can compare Values FixedIterator() FixedIterator // Optimize an iterator in the context of the triple store. @@ -89,7 +89,7 @@ type TripleStore interface { // // Iterators will call this. At worst, a valid implementation is // ts.IdFor(ts.Triple(triple_id).Get(dir)) - TripleDirection(triple_id TSVal, d Direction) TSVal + TripleDirection(triple_id Value, d Direction) Value } type Options map[string]interface{} diff --git a/query/gremlin/finals.go b/query/gremlin/finals.go index 1ac67af..d38512e 100644 --- a/query/gremlin/finals.go +++ b/query/gremlin/finals.go @@ -135,7 +135,7 @@ 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.NameOf(v) @@ -155,7 +155,7 @@ func runIteratorToArray(it graph.Iterator, ses *Session, limit int) []map[string if !ok { break } - tags := make(map[string]graph.TSVal) + tags := make(map[string]graph.Value) it.TagResults(tags) output = append(output, tagsToValueMap(tags, ses)) count++ @@ -166,7 +166,7 @@ func runIteratorToArray(it graph.Iterator, ses *Session, limit int) []map[string if ses.doHalt { return nil } - tags := make(map[string]graph.TSVal) + tags := make(map[string]graph.Value) it.TagResults(tags) output = append(output, tagsToValueMap(tags, ses)) count++ @@ -212,7 +212,7 @@ func runIteratorWithCallback(it graph.Iterator, ses *Session, callback otto.Valu if !ok { break } - tags := make(map[string]graph.TSVal) + tags := make(map[string]graph.Value) it.TagResults(tags) val, _ := this.Otto.ToValue(tagsToValueMap(tags, ses)) val, _ = callback.Call(this.This, val) @@ -224,7 +224,7 @@ func runIteratorWithCallback(it graph.Iterator, ses *Session, callback otto.Valu if ses.doHalt { return } - tags := make(map[string]graph.TSVal) + tags := make(map[string]graph.Value) it.TagResults(tags) val, _ := this.Otto.ToValue(tagsToValueMap(tags, ses)) val, _ = callback.Call(this.This, val) @@ -253,7 +253,7 @@ func runIteratorOnSession(it graph.Iterator, ses *Session) { if !ok { break } - tags := make(map[string]graph.TSVal) + tags := make(map[string]graph.Value) it.TagResults(tags) cont := ses.SendResult(&GremlinResult{metaresult: false, err: "", val: nil, actualResults: &tags}) if !cont { @@ -263,7 +263,7 @@ func runIteratorOnSession(it graph.Iterator, ses *Session) { if ses.doHalt { return } - tags := make(map[string]graph.TSVal) + tags := make(map[string]graph.Value) it.TagResults(tags) cont := ses.SendResult(&GremlinResult{metaresult: false, err: "", val: nil, actualResults: &tags}) if !cont { diff --git a/query/gremlin/session.go b/query/gremlin/session.go index 7f07443..210aed3 100644 --- a/query/gremlin/session.go +++ b/query/gremlin/session.go @@ -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() { diff --git a/query/mql/fill.go b/query/mql/fill.go index d93da62..248e2bb 100644 --- a/query/mql/fill.go +++ b/query/mql/fill.go @@ -20,7 +20,7 @@ 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 { diff --git a/query/mql/session.go b/query/mql/session.go index 1955aeb..056389e 100644 --- a/query/mql/session.go +++ b/query/mql/session.go @@ -92,11 +92,11 @@ func (s *Session) ExecInput(input string, c chan interface{}, limit int) { if !ok { break } - tags := make(map[string]graph.TSVal) + tags := make(map[string]graph.Value) it.TagResults(tags) c <- tags for it.NextResult() == true { - tags := make(map[string]graph.TSVal) + tags := make(map[string]graph.Value) it.TagResults(tags) c <- tags } @@ -104,7 +104,7 @@ func (s *Session) ExecInput(input string, c chan interface{}, limit int) { } 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) @@ -127,7 +127,7 @@ func (s *Session) ToText(result interface{}) string { } 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) {