diff --git a/graph/bolt/quadstore.go b/graph/bolt/quadstore.go index f81f353..0957bab 100644 --- a/graph/bolt/quadstore.go +++ b/graph/bolt/quadstore.go @@ -503,5 +503,5 @@ func compareTokens(a, b graph.Value) bool { } func (qs *QuadStore) FixedIterator() graph.FixedIterator { - return iterator.NewFixedIteratorWithCompare(compareTokens) + return iterator.NewFixed(compareTokens) } diff --git a/graph/iterator/and_iterator_optimize_test.go b/graph/iterator/and_iterator_optimize_test.go index 00b3807..0ae0bc5 100644 --- a/graph/iterator/and_iterator_optimize_test.go +++ b/graph/iterator/and_iterator_optimize_test.go @@ -27,7 +27,7 @@ import ( func TestIteratorPromotion(t *testing.T) { all := NewInt64(1, 3) - fixed := newFixed() + fixed := NewFixed(Identity) fixed.Add(3) a := NewAnd() a.AddSubIterator(all) diff --git a/graph/iterator/and_iterator_test.go b/graph/iterator/and_iterator_test.go index 3023bfd..3f96519 100644 --- a/graph/iterator/and_iterator_test.go +++ b/graph/iterator/and_iterator_test.go @@ -22,7 +22,7 @@ import ( // Make sure that tags work on the And. func TestTag(t *testing.T) { - fix1 := newFixed() + fix1 := NewFixed(Identity) fix1.Add(234) fix1.Tagger().Add("foo") and := NewAnd() @@ -55,12 +55,12 @@ func TestTag(t *testing.T) { // Do a simple itersection of fixed values. func TestAndAndFixedIterators(t *testing.T) { - fix1 := newFixed() + fix1 := NewFixed(Identity) fix1.Add(1) fix1.Add(2) fix1.Add(3) fix1.Add(4) - fix2 := newFixed() + fix2 := NewFixed(Identity) fix2.Add(3) fix2.Add(4) fix2.Add(5) @@ -93,12 +93,12 @@ func TestAndAndFixedIterators(t *testing.T) { // If there's no intersection, the size should still report the same, // but there should be nothing to Next() func TestNonOverlappingFixedIterators(t *testing.T) { - fix1 := newFixed() + fix1 := NewFixed(Identity) fix1.Add(1) fix1.Add(2) fix1.Add(3) fix1.Add(4) - fix2 := newFixed() + fix2 := NewFixed(Identity) fix2.Add(5) fix2.Add(6) fix2.Add(7) diff --git a/graph/iterator/fixed_iterator.go b/graph/iterator/fixed_iterator.go index e486ea9..80eb769 100644 --- a/graph/iterator/fixed_iterator.go +++ b/graph/iterator/fixed_iterator.go @@ -42,24 +42,16 @@ type Fixed struct { type Equality func(a, b graph.Value) bool // Define an equality function of purely ==, which works for native types. -func BasicEquality(a, b graph.Value) bool { - if a == b { - return true - } - return false +func Identity(a, b graph.Value) bool { + return a == b } -// Creates a new Fixed iterator based around == equality. -func newFixed() *Fixed { - return NewFixedIteratorWithCompare(BasicEquality) -} - -// Creates a new Fixed iterator with a custom comparitor. -func NewFixedIteratorWithCompare(compareFn Equality) *Fixed { +// Creates a new Fixed iterator with a custom comparator. +func NewFixed(cmp Equality) *Fixed { return &Fixed{ uid: NextUID(), values: make([]graph.Value, 0, 20), - cmp: compareFn, + cmp: cmp, } } @@ -88,7 +80,7 @@ func (it *Fixed) TagResults(dst map[string]graph.Value) { } func (it *Fixed) Clone() graph.Iterator { - out := NewFixedIteratorWithCompare(it.cmp) + out := NewFixed(it.cmp) for _, val := range it.values { out.Add(val) } diff --git a/graph/iterator/linksto_iterator_test.go b/graph/iterator/linksto_iterator_test.go index 5b188e0..f4f2059 100644 --- a/graph/iterator/linksto_iterator_test.go +++ b/graph/iterator/linksto_iterator_test.go @@ -23,10 +23,10 @@ import ( func TestLinksTo(t *testing.T) { qs := &store{ data: []string{1: "cool"}, - iter: newFixed(), + iter: NewFixed(Identity), } qs.iter.(*Fixed).Add(2) - fixed := newFixed() + fixed := NewFixed(Identity) val := qs.ValueOf("cool") if val != 1 { t.Fatalf("Failed to return correct value, got:%v expect:1", val) diff --git a/graph/iterator/mock_ts_test.go b/graph/iterator/mock_ts_test.go index 31ef93f..bf60406 100644 --- a/graph/iterator/mock_ts_test.go +++ b/graph/iterator/mock_ts_test.go @@ -65,7 +65,7 @@ func (qs *store) OptimizeIterator(it graph.Iterator) (graph.Iterator, bool) { } func (qs *store) FixedIterator() graph.FixedIterator { - return NewFixedIteratorWithCompare(BasicEquality) + return NewFixed(Identity) } func (qs *store) Close() {} diff --git a/graph/iterator/or_iterator_test.go b/graph/iterator/or_iterator_test.go index b147d56..2091569 100644 --- a/graph/iterator/or_iterator_test.go +++ b/graph/iterator/or_iterator_test.go @@ -31,11 +31,11 @@ func iterated(it graph.Iterator) []int { func TestOrIteratorBasics(t *testing.T) { or := NewOr() - f1 := newFixed() + f1 := NewFixed(Identity) f1.Add(1) f1.Add(2) f1.Add(3) - f2 := newFixed() + f2 := NewFixed(Identity) f2.Add(3) f2.Add(9) f2.Add(20) @@ -77,11 +77,11 @@ func TestOrIteratorBasics(t *testing.T) { func TestShortCircuitingOrBasics(t *testing.T) { var or *Or - f1 := newFixed() + f1 := NewFixed(Identity) f1.Add(1) f1.Add(2) f1.Add(3) - f2 := newFixed() + f2 := NewFixed(Identity) f2.Add(3) f2.Add(9) f2.Add(20) @@ -133,7 +133,7 @@ func TestShortCircuitingOrBasics(t *testing.T) { // Check that it pulls the second iterator's numbers if the first is empty. or = NewShortCircuitOr() - or.AddSubIterator(newFixed()) + or.AddSubIterator(NewFixed(Identity)) or.AddSubIterator(f2) expect = []int{3, 9, 20, 21} for i := 0; i < 2; i++ { diff --git a/graph/iterator/value_comparison_iterator_test.go b/graph/iterator/value_comparison_iterator_test.go index 72fc18a..b8a6cc8 100644 --- a/graph/iterator/value_comparison_iterator_test.go +++ b/graph/iterator/value_comparison_iterator_test.go @@ -24,7 +24,7 @@ import ( var simpleStore = &store{data: []string{"0", "1", "2", "3", "4", "5"}} func simpleFixedIterator() *Fixed { - f := newFixed() + f := NewFixed(Identity) for i := 0; i < 5; i++ { f.Add(i) } diff --git a/graph/leveldb/quadstore.go b/graph/leveldb/quadstore.go index ab61b16..641a6f5 100644 --- a/graph/leveldb/quadstore.go +++ b/graph/leveldb/quadstore.go @@ -480,5 +480,5 @@ func compareBytes(a, b graph.Value) bool { } func (qs *QuadStore) FixedIterator() graph.FixedIterator { - return iterator.NewFixedIteratorWithCompare(compareBytes) + return iterator.NewFixed(compareBytes) } diff --git a/graph/memstore/quadstore.go b/graph/memstore/quadstore.go index dea7551..9a0f32b 100644 --- a/graph/memstore/quadstore.go +++ b/graph/memstore/quadstore.go @@ -235,7 +235,7 @@ func (qs *QuadStore) QuadsAllIterator() graph.Iterator { } func (qs *QuadStore) FixedIterator() graph.FixedIterator { - return iterator.NewFixedIteratorWithCompare(iterator.BasicEquality) + return iterator.NewFixed(iterator.Identity) } func (qs *QuadStore) QuadDirection(val graph.Value, d quad.Direction) graph.Value { diff --git a/graph/mongo/quadstore.go b/graph/mongo/quadstore.go index 76550ae..1151357 100644 --- a/graph/mongo/quadstore.go +++ b/graph/mongo/quadstore.go @@ -327,12 +327,8 @@ func (qs *QuadStore) Horizon() int64 { return log.LogID } -func compareStrings(a, b graph.Value) bool { - return a.(string) == b.(string) -} - func (qs *QuadStore) FixedIterator() graph.FixedIterator { - return iterator.NewFixedIteratorWithCompare(compareStrings) + return iterator.NewFixed(iterator.Identity) } func (qs *QuadStore) Close() {