Don't indirect map values

We already have reference behaviour, so this is not necessary.

This change highlighted fairly baroque architecture in mql that deserves
some attention; the use of channels is somewhat confusing.

Also rename LastResult to Result.
This commit is contained in:
kortschak 2014-07-02 12:08:49 +09:30
parent b89d4f392c
commit a1453da84e
15 changed files with 59 additions and 57 deletions

View file

@ -73,19 +73,19 @@ 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(out *map[string]graph.TSVal) {
it.Base.TagResults(out)
func (it *And) TagResults(dst map[string]graph.TSVal) {
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) ResultTree() *graph.ResultTree {
tree := graph.NewResultTree(it.LastResult())
tree := graph.NewResultTree(it.Result())
tree.AddSubtree(it.primaryIt.ResultTree())
for _, sub := range it.internalIterators {
tree.AddSubtree(sub.ResultTree())

View file

@ -44,7 +44,7 @@ func TestTag(t *testing.T) {
t.Errorf("Unexpected value")
}
tags := make(map[string]graph.TSVal)
and.TagResults(&tags)
and.TagResults(tags)
if tags["bar"] != 234 {
t.Errorf("no bar tag")
}

View file

@ -99,14 +99,14 @@ 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.TSVal) {
it.Base.TagResults(dst)
it.primaryIt.TagResults(dst)
}
// DEPRECATED Return results in a ResultTree.
func (it *HasA) ResultTree() *graph.ResultTree {
tree := graph.NewResultTree(it.LastResult())
tree := graph.NewResultTree(it.Result())
tree.AddSubtree(it.primaryIt.ResultTree())
return tree
}

View file

@ -109,7 +109,7 @@ func (it *Base) Stats() graph.IteratorStats {
// DEPRECATED
func (it *Base) ResultTree() *graph.ResultTree {
tree := graph.NewResultTree(it.LastResult())
tree := graph.NewResultTree(it.Result())
return tree
}
@ -123,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.TSVal {
return it.Last
}
@ -142,13 +142,13 @@ 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.TSVal) {
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
}
}

View file

@ -77,14 +77,14 @@ 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.TSVal) {
it.Base.TagResults(dst)
it.primaryIt.TagResults(dst)
}
// DEPRECATED
func (it *LinksTo) ResultTree() *graph.ResultTree {
tree := graph.NewResultTree(it.LastResult())
tree := graph.NewResultTree(it.Result())
tree.AddSubtree(it.primaryIt.ResultTree())
return tree
}

View file

@ -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.TSVal) {
if it.lastCheck == false {
return
}
it.subIt.TagResults(out)
it.subIt.TagResults(dst)
}
// Registers the optional iterator.

View file

@ -83,14 +83,14 @@ 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(out *map[string]graph.TSVal) {
it.Base.TagResults(out)
it.internalIterators[it.currentIterator].TagResults(out)
func (it *Or) TagResults(dst map[string]graph.TSVal) {
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) ResultTree() *graph.ResultTree {
tree := graph.NewResultTree(it.LastResult())
tree := graph.NewResultTree(it.Result())
for _, sub := range it.internalIterators {
tree.AddSubtree(sub.ResultTree())
}

View file

@ -139,11 +139,11 @@ 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
}
@ -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.TSVal) {
it.Base.TagResults(dst)
it.subIt.TagResults(dst)
}
// Registers the value-comparison iterator.