本文整理汇总了Golang中github.com/cayleygraph/cayley/graph.Iterator类的典型用法代码示例。如果您正苦于以下问题:Golang Iterator类的具体用法?Golang Iterator怎么用?Golang Iterator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Iterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: iterated
func iterated(it graph.Iterator) []int {
var res []int
for graph.Next(it) {
res = append(res, it.Result().(int))
}
return res
}
示例2: iterated
func iterated(it graph.Iterator) []int {
var res []int
for it.Next() {
res = append(res, int(it.Result().(Int64Node)))
}
return res
}
示例3: TestIterators
func TestIterators(t *testing.T) {
qs, opts, closer := makeGAE(t)
defer closer()
graphtest.MakeWriter(t, qs, opts, graphtest.MakeQuadSet()...)
require.Equal(t, int64(11), qs.Size(), "Incorrect number of quads")
var expected = []quad.Quad{
quad.MakeRaw("C", "follows", "B", ""),
quad.MakeRaw("C", "follows", "D", ""),
}
it := qs.QuadIterator(quad.Subject, qs.ValueOf(quad.Raw("C")))
graphtest.ExpectIteratedQuads(t, qs, it, expected)
// Test contains
it = qs.QuadIterator(quad.Label, qs.ValueOf(quad.Raw("status_graph")))
gqs := qs.(*QuadStore)
key := gqs.createKeyForQuad(quad.MakeRaw("G", "status", "cool", "status_graph"))
token := &Token{quadKind, key.StringID()}
require.True(t, it.Contains(token), "Contains failed")
// Test cloning an iterator
var it2 graph.Iterator
it2 = it.Clone()
x := it2.Describe()
y := it.Describe()
require.Equal(t, y.Name, x.Name, "Iterator Clone was not successful")
}
示例4: OptimizeIterator
func (qs *QuadStore) OptimizeIterator(it graph.Iterator) (graph.Iterator, bool) {
switch it.Type() {
case graph.LinksTo:
return qs.optimizeLinksTo(it.(*iterator.LinksTo))
}
return it, false
}
示例5: iteratedQuads
func iteratedQuads(qs graph.QuadStore, it graph.Iterator) []quad.Quad {
var res ordered
for graph.Next(it) {
res = append(res, qs.Quad(it.Result()))
}
sort.Sort(res)
return res
}
示例6: iteratedNames
func iteratedNames(qs graph.QuadStore, it graph.Iterator) []string {
var res []string
for graph.Next(it) {
res = append(res, qs.NameOf(it.Result()))
}
sort.Strings(res)
return res
}
示例7: OutputQueryShapeForIterator
func OutputQueryShapeForIterator(it graph.Iterator, qs graph.QuadStore, outputMap map[string]interface{}) {
s := &queryShape{
qs: qs,
nodeID: 1,
}
node := s.MakeNode(it.Clone())
s.AddNode(node)
outputMap["nodes"] = s.nodes
outputMap["links"] = s.links
}
示例8: moveTagsTo
// moveTagsTo() gets the tags for all of the src's subiterators and the
// src itself, and moves them to dst.
func moveTagsTo(dst graph.Iterator, src *And) {
tags := src.getSubTags()
for _, tag := range dst.Tagger().Tags() {
if _, ok := tags[tag]; ok {
delete(tags, tag)
}
}
dt := dst.Tagger()
for k := range tags {
dt.Add(k)
}
}
示例9: TestIterators
func TestIterators(t *testing.T) {
clog.Infof("\n-----------\n")
inst, opts, err := createInstance()
defer inst.Close()
if err != nil {
t.Fatalf("failed to create instance: %v", err)
}
qs, _, _ := makeTestStore(simpleGraph, opts)
if qs.Size() != 11 {
t.Fatal("Incorrect number of quads")
}
var expected = []string{
quad.Quad{"C", "follows", "B", ""}.String(),
quad.Quad{"C", "follows", "D", ""}.String(),
}
it := qs.QuadIterator(quad.Subject, qs.ValueOf("C"))
if got, ok := compareResults(qs, it, expected); !ok {
t.Errorf("Unexpected iterated result, got:%v expect:%v", got, expected)
}
// Test contains
it = qs.QuadIterator(quad.Label, qs.ValueOf("status_graph"))
gqs := qs.(*QuadStore)
key := gqs.createKeyForQuad(quad.Quad{"G", "status", "cool", "status_graph"})
token := &Token{quadKind, key.StringID()}
if !it.Contains(token) {
t.Error("Contains failed")
}
// Test cloning an iterator
var it2 graph.Iterator
it2 = it.Clone()
x := it2.Describe()
y := it.Describe()
if x.Name != y.Name {
t.Errorf("Iterator Clone was not successful got: %v, expected: %v", x.Name, y.Name)
}
}
示例10: iterateResults
func iterateResults(qs graph.QuadStore, it graph.Iterator) []string {
var res []string
for graph.Next(it) {
v := it.Result()
if t, ok := v.(*Token); ok && t.Kind == nodeKind {
res = append(res, qs.NameOf(it.Result()))
} else {
res = append(res, qs.Quad(it.Result()).String())
}
}
sort.Strings(res)
it.Reset()
return res
}
示例11: runIteratorToArray
func (wk *worker) runIteratorToArray(it graph.Iterator, limit int) []map[string]string {
output := make([]map[string]string, 0)
n := 0
it, _ = it.Optimize()
for {
select {
case <-wk.kill:
return nil
default:
}
if !graph.Next(it) {
break
}
tags := make(map[string]graph.Value)
it.TagResults(tags)
output = append(output, wk.tagsToValueMap(tags))
n++
if limit >= 0 && n >= limit {
break
}
for it.NextPath() {
select {
case <-wk.kill:
return nil
default:
}
tags := make(map[string]graph.Value)
it.TagResults(tags)
output = append(output, wk.tagsToValueMap(tags))
n++
if limit >= 0 && n >= limit {
break
}
}
}
it.Close()
return output
}
示例12: IteratedRawStrings
func IteratedRawStrings(t testing.TB, qs graph.QuadStore, it graph.Iterator) []string {
var res []string
for it.Next() {
res = append(res, qs.NameOf(it.Result()).String())
}
require.Nil(t, it.Err())
sort.Strings(res)
return res
}
示例13: IteratedValues
func IteratedValues(t testing.TB, qs graph.QuadStore, it graph.Iterator) []quad.Value {
var res []quad.Value
for it.Next() {
res = append(res, qs.NameOf(it.Result()))
}
require.Nil(t, it.Err())
sort.Sort(quad.ByValueString(res))
return res
}
示例14: IteratedQuads
func IteratedQuads(t testing.TB, qs graph.QuadStore, it graph.Iterator) []quad.Quad {
var res quad.ByQuadString
for it.Next() {
res = append(res, qs.Quad(it.Result()))
}
require.Nil(t, it.Err())
sort.Sort(res)
return res
}
示例15: runIteratorToArrayNoTags
func (wk *worker) runIteratorToArrayNoTags(it graph.Iterator, limit int) []string {
output := make([]string, 0)
n := 0
it, _ = it.Optimize()
for {
select {
case <-wk.kill:
return nil
default:
}
if !graph.Next(it) {
break
}
output = append(output, wk.qs.NameOf(it.Result()))
n++
if limit >= 0 && n >= limit {
break
}
}
it.Close()
return output
}