Merge branch 'master' into b
$ benchcmp gollrb.bench b-gen.bench benchmark old ns/op new ns/op delta BenchmarkNamePredicate 1369329 1444990 +5.53% BenchmarkLargeSetsNoIntersection 72329029 64975716 -10.17% BenchmarkVeryLargeSetsSmallIntersection 890824761 408784476 -54.11% BenchmarkHelplessContainsChecker 35314797618 30673240485 -13.14% BenchmarkNetAndSpeed 19694146 19486797 -1.05% BenchmarkKeanuAndNet 15340756 15317415 -0.15% BenchmarkKeanuAndSpeed 17902709 18042030 +0.78% BenchmarkKeanuOther 53452058 50984817 -4.62% BenchmarkKeanuBullockOther 90827780 86536510 -4.72% benchmark old allocs new allocs delta BenchmarkNamePredicate 1339 1339 +0.00% BenchmarkLargeSetsNoIntersection 22603 22674 +0.31% BenchmarkVeryLargeSetsSmallIntersection 65787 65860 +0.11% BenchmarkHelplessContainsChecker 1713541 1713669 +0.01% BenchmarkNetAndSpeed 17135 17146 +0.06% BenchmarkKeanuAndNet 15802 15802 +0.00% BenchmarkKeanuAndSpeed 16397 16396 -0.01% BenchmarkKeanuOther 30148 30149 +0.00% BenchmarkKeanuBullockOther 35542 35544 +0.01% benchmark old bytes new bytes delta BenchmarkNamePredicate 96226 95842 -0.40% BenchmarkLargeSetsNoIntersection 1165914 119725 +2.69% BenchmarkVeryLargeSetsSmallIntersection 2760072 2777798 +0.64% BenchmarkHelplessContainsChecker 84388448 84351168 -0.04% BenchmarkNetAndSpeed 1414837 1425752 +0.77% BenchmarkKeanuAndNet 1247249 1247453 +0.02% BenchmarkKeanuAndSpeed 1275522 1275243 -0.02% BenchmarkKeanuOther 2021107 2021497 +0.02% BenchmarkKeanuBullockOther 2682243 2683250 +0.04%
This commit is contained in:
commit
d98ca99974
6 changed files with 132 additions and 104 deletions
|
|
@ -48,6 +48,7 @@ func (it *And) UID() uint64 {
|
|||
|
||||
// Reset all internal iterators
|
||||
func (it *And) Reset() {
|
||||
it.result = nil
|
||||
it.primaryIt.Reset()
|
||||
for _, sub := range it.internalIterators {
|
||||
sub.Reset()
|
||||
|
|
@ -159,7 +160,7 @@ func (it *And) Next() bool {
|
|||
graph.NextLogIn(it)
|
||||
for graph.Next(it.primaryIt) {
|
||||
curr := it.primaryIt.Result()
|
||||
if it.subItsContain(curr) {
|
||||
if it.subItsContain(curr, nil) {
|
||||
it.result = curr
|
||||
return graph.NextLogOut(it, curr, true)
|
||||
}
|
||||
|
|
@ -172,22 +173,32 @@ func (it *And) Result() graph.Value {
|
|||
}
|
||||
|
||||
// Checks a value against the non-primary iterators, in order.
|
||||
func (it *And) subItsContain(val graph.Value) bool {
|
||||
func (it *And) subItsContain(val graph.Value, lastResult graph.Value) bool {
|
||||
var subIsGood = true
|
||||
for _, sub := range it.internalIterators {
|
||||
for i, sub := range it.internalIterators {
|
||||
subIsGood = sub.Contains(val)
|
||||
if !subIsGood {
|
||||
if lastResult != nil {
|
||||
for j := 0; j < i; j++ {
|
||||
it.internalIterators[j].Contains(lastResult)
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
return subIsGood
|
||||
}
|
||||
|
||||
func (it *And) checkContainsList(val graph.Value) bool {
|
||||
func (it *And) checkContainsList(val graph.Value, lastResult graph.Value) bool {
|
||||
ok := true
|
||||
for _, c := range it.checkList {
|
||||
for i, c := range it.checkList {
|
||||
ok = c.Contains(val)
|
||||
if !ok {
|
||||
if lastResult != nil {
|
||||
for j := 0; j < i; j++ {
|
||||
it.checkList[j].Contains(lastResult)
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
@ -200,19 +211,22 @@ func (it *And) checkContainsList(val graph.Value) bool {
|
|||
// Check a value against the entire iterator, in order.
|
||||
func (it *And) Contains(val graph.Value) bool {
|
||||
graph.ContainsLogIn(it, val)
|
||||
lastResult := it.result
|
||||
if it.checkList != nil {
|
||||
return it.checkContainsList(val)
|
||||
return it.checkContainsList(val, lastResult)
|
||||
}
|
||||
mainGood := it.primaryIt.Contains(val)
|
||||
if !mainGood {
|
||||
return graph.ContainsLogOut(it, val, false)
|
||||
if mainGood {
|
||||
othersGood := it.subItsContain(val, lastResult)
|
||||
if othersGood {
|
||||
it.result = val
|
||||
return graph.ContainsLogOut(it, val, true)
|
||||
}
|
||||
}
|
||||
othersGood := it.subItsContain(val)
|
||||
if !othersGood {
|
||||
return graph.ContainsLogOut(it, val, false)
|
||||
if lastResult != nil {
|
||||
it.primaryIt.Contains(lastResult)
|
||||
}
|
||||
it.result = val
|
||||
return graph.ContainsLogOut(it, val, true)
|
||||
return graph.ContainsLogOut(it, val, false)
|
||||
}
|
||||
|
||||
// Returns the approximate size of the And iterator. Because we're dealing
|
||||
|
|
|
|||
|
|
@ -327,7 +327,7 @@ func (it *And) Stats() graph.IteratorStats {
|
|||
}
|
||||
}
|
||||
return graph.IteratorStats{
|
||||
ContainsCost: ContainsCost,
|
||||
ContainsCost: ContainsCost * 2,
|
||||
NextCost: NextCost,
|
||||
Size: Size,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -179,10 +179,13 @@ func (it *HasA) NextPath() bool {
|
|||
//
|
||||
// The upshot is, the end of NextPath() bubbles up from the bottom of the
|
||||
// iterator tree up, and we need to respect that.
|
||||
glog.V(4).Infoln("HASA", it.UID(), "NextPath")
|
||||
if it.primaryIt.NextPath() {
|
||||
return true
|
||||
}
|
||||
return it.NextContains()
|
||||
result := it.NextContains()
|
||||
glog.V(4).Infoln("HASA", it.UID(), "NextPath Returns", result, "")
|
||||
return result
|
||||
}
|
||||
|
||||
// Next advances the iterator. This is simpler than Contains. We have a
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue