import ( "github.com/google/cayley/graph" "github.com/google/cayley/graph/iterator/optimize" ) // create a base iterator it := graph.NewInt64(1,2,3,4,5) // optimize the iterator optIt, err := optimize.Optimize(it) if err != nil { log.Fatal(err) }
import ( "fmt" "github.com/google/cayley/graph" "github.com/google/cayley/graph/iterator/optimize" "github.com/google/cayley/graph/memstore" ) func main() { // create a new memstore graph g := memstore.NewGraph() // add some data to the graph g.AddQuad(quad.Make("Alice", "likes", "Bob", "graph")) g.AddQuad(quad.Make("Bob", "likes", "Charlie", "graph")) // create a basic iterator for the graph it := graph.NewIterator(g, graph.StartFrom("Alice")) // optimize the iterator optIt, err := optimize.Optimize(it) if err != nil { log.Fatal(err) } // iterate over the optimized iterator for optIt.Next() { fmt.Println(optIt.Result()) } }In this example, we create a memstore graph and add some data to it. Then we create a basic iterator to start at a certain point in the graph and use `optimize.Optimize` to optimize the iterator before iterating over the results. The package library for `IteratorOptimize` is `github.com/google/cayley/graph/iterator/optimize`.