Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Resolver iterator #741

Merged
merged 2 commits into from
Nov 26, 2018
Merged

Conversation

phyrwork
Copy link
Contributor

Implement an iterator that takes a slice of nodes and an
associated QuadStore and resolves to their respective
values during iteration.

Resolves #663

@phyrwork phyrwork requested a review from dennwc as a code owner October 18, 2018 13:19
@phyrwork phyrwork force-pushed the resolver-iterator branch 4 times, most recently from 07bd42f to 6072cdd Compare October 18, 2018 13:28
Copy link
Member

@dennwc dennwc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all, thank you for the contribution! The code looks good, but there are few places that need to be improved :)

graph/iterator/resolver.go Outdated Show resolved Hide resolved
nodes: make([]quad.Value, 0, 20),
}
// Enforce uniqueness
unique := make(map[quad.Value]bool, 20)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would actually expect it to iterate over duplicates. It might resolve duplicates once, but in general, it should preserve an order and the number of values.

graph/iterator/resolver.go Outdated Show resolved Hide resolved
graph/iterator/resolver.go Outdated Show resolved Hide resolved
graph/iterator/resolver.go Outdated Show resolved Hide resolved
graph/iterator/resolver.go Outdated Show resolved Hide resolved

func TestResolverIteratorIterate(t *testing.T) {
var ctx context.Context
qs, err := cayley.NewMemoryGraph()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requiring the top-level cayley package from low-level iterators package is a bit an overkill. Please check other iterator tests, there should be a mock store for such tests.

package iterator_test

import (
"testing"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

running goimports over it will be nice (analog of gofmt)

graph/iterator/resolver_test.go Outdated Show resolved Hide resolved
graph/iterator/resolver_test.go Show resolved Hide resolved
graph/iterator/resolver.go Outdated Show resolved Hide resolved
graph/iterator/resolver.go Outdated Show resolved Hide resolved
Copy link
Member

@dennwc dennwc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, almost there :)

func (it *Resolver) Contains(ctx context.Context, value graph.Value) bool {
graph.ContainsLogIn(it, value)
if !it.cached {
it.resolve(ctx)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should set it.err, same for Next

// Next advances the iterator.
func (it *Resolver) Next(ctx context.Context) bool {
graph.NextLogIn(it)
if it.index == len(it.order) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

>=, just to be on the safe side

Implement an iterator that takes a slice of nodes and an
associated QuadStore and resolves to their respective
values during iteration.

Resolves cayleygraph#663
@dennwc
Copy link
Member

dennwc commented Nov 26, 2018

@phyrwork There are only a few small changes left. Do you have time to finish it? Will be happy to merge it.

@dennwc dennwc merged commit 6ce5dd0 into cayleygraph:master Nov 26, 2018
@dennwc
Copy link
Member

dennwc commented Nov 26, 2018

Nevermind, I fixed and merged it. Thanks for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Resolver iterator
2 participants