当前位置: 首页>>代码示例>>Golang>>正文


Golang graph.Iterator类代码示例

本文整理汇总了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
}
开发者ID:RamboWANG,项目名称:cayley,代码行数:7,代码来源:or_iterator_test.go

示例2: iterated

func iterated(it graph.Iterator) []int {
	var res []int
	for it.Next() {
		res = append(res, int(it.Result().(Int64Node)))
	}
	return res
}
开发者ID:rlugojr,项目名称:cayley,代码行数:7,代码来源:or_iterator_test.go

示例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")
}
开发者ID:oren,项目名称:cayley,代码行数:32,代码来源:quadstore_test.go

示例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
}
开发者ID:rlugojr,项目名称:cayley,代码行数:8,代码来源:quadstore_iterator_optimize.go

示例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
}
开发者ID:RamboWANG,项目名称:cayley,代码行数:8,代码来源:leveldb_test.go

示例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
}
开发者ID:RamboWANG,项目名称:cayley,代码行数:8,代码来源:leveldb_test.go

示例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
}
开发者ID:rlugojr,项目名称:cayley,代码行数:11,代码来源:query_shape.go

示例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)
	}
}
开发者ID:RamboWANG,项目名称:cayley,代码行数:14,代码来源:and_iterator_optimize.go

示例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)
	}
}
开发者ID:RamboWANG,项目名称:cayley,代码行数:42,代码来源:quadstore_test.go

示例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
}
开发者ID:RamboWANG,项目名称:cayley,代码行数:14,代码来源:quadstore_test.go

示例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
}
开发者ID:RamboWANG,项目名称:cayley,代码行数:38,代码来源:finals.go

示例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
}
开发者ID:rlugojr,项目名称:cayley,代码行数:9,代码来源:graphtest.go

示例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
}
开发者ID:rlugojr,项目名称:cayley,代码行数:9,代码来源:graphtest.go

示例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
}
开发者ID:rlugojr,项目名称:cayley,代码行数:9,代码来源:graphtest.go

示例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
}
开发者ID:RamboWANG,项目名称:cayley,代码行数:22,代码来源:finals.go


注:本文中的github.com/cayleygraph/cayley/graph.Iterator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。