當前位置: 首頁>>代碼示例>>Golang>>正文


Golang graph.Iterator類代碼示例

本文整理匯總了Golang中github.com/google/cayley/graph.Iterator的典型用法代碼示例。如果您正苦於以下問題:Golang Iterator類的具體用法?Golang Iterator怎麽用?Golang Iterator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Iterator類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: checkIteratorContains

func checkIteratorContains(ts graph.TripleStore, it graph.Iterator, expected []string, t *testing.T) {
	var actual []string
	actual = nil
	for {
		val, ok := it.Next()
		if !ok {
			break
		}
		actual = append(actual, ts.GetNameFor(val))
	}
	actualSet := actual[:]
	for _, a := range expected {
		found := false
		for j, b := range actualSet {
			if a == b {
				actualSet = append(actualSet[:j], actualSet[j+1:]...)
				found = true
				break
			}
		}
		if !found {
			t.Error("Couldn't find", a, "in actual output.\nActual:", actual, "\nExpected: ", expected, "\nRemainder: ", actualSet)
			return
		}
	}
	if len(actualSet) != 0 {
		t.Error("Actual output has more than expected.\nActual:", actual, "\nExpected: ", expected, "\nRemainder: ", actualSet)
	}
}
開發者ID:netzheng,項目名稱:cayley,代碼行數:29,代碼來源:value_comparison_iterator_test.go

示例2: runIteratorWithCallback

func runIteratorWithCallback(it graph.Iterator, ses *Session, callback otto.Value, this otto.FunctionCall, limit int) {
	count := 0
	it, _ = it.Optimize()
	for {
		if ses.doHalt {
			return
		}
		_, ok := graph.Next(it)
		if !ok {
			break
		}
		tags := make(map[string]graph.Value)
		it.TagResults(tags)
		val, _ := this.Otto.ToValue(tagsToValueMap(tags, ses))
		val, _ = callback.Call(this.This, val)
		count++
		if limit >= 0 && count >= limit {
			break
		}
		for it.NextResult() == true {
			if ses.doHalt {
				return
			}
			tags := make(map[string]graph.Value)
			it.TagResults(tags)
			val, _ := this.Otto.ToValue(tagsToValueMap(tags, ses))
			val, _ = callback.Call(this.This, val)
			count++
			if limit >= 0 && count >= limit {
				break
			}
		}
	}
	it.Close()
}
開發者ID:neevor,項目名稱:cayley,代碼行數:35,代碼來源:finals.go

示例3: runIteratorToArray

func runIteratorToArray(it graph.Iterator, ses *Session, limit int) []map[string]string {
	output := make([]map[string]string, 0)
	count := 0
	it, _ = it.Optimize()
	for {
		if ses.doHalt {
			return nil
		}
		_, ok := graph.Next(it)
		if !ok {
			break
		}
		tags := make(map[string]graph.Value)
		it.TagResults(tags)
		output = append(output, tagsToValueMap(tags, ses))
		count++
		if limit >= 0 && count >= limit {
			break
		}
		for it.NextResult() == true {
			if ses.doHalt {
				return nil
			}
			tags := make(map[string]graph.Value)
			it.TagResults(tags)
			output = append(output, tagsToValueMap(tags, ses))
			count++
			if limit >= 0 && count >= limit {
				break
			}
		}
	}
	it.Close()
	return output
}
開發者ID:neevor,項目名稱:cayley,代碼行數:35,代碼來源:finals.go

示例4: iterated

func iterated(it graph.Iterator) []int {
	var res []int
	for graph.Next(it) {
		res = append(res, it.Result().(int))
	}
	return res
}
開發者ID:ericcapricorn,項目名稱:cayley,代碼行數:7,代碼來源:or_iterator_test.go

示例5: 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.Make("C", "follows", "B", ""),
		quad.Make("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.Make("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:dennwc,項目名稱:cayley,代碼行數:32,代碼來源:quadstore_test.go

示例6: OptimizeIterator

func (ts *QuadStore) OptimizeIterator(it graph.Iterator) (graph.Iterator, bool) {
	switch it.Type() {
	case graph.LinksTo:
		return ts.optimizeLinksTo(it.(*iterator.LinksTo))

	}
	return it, false
}
開發者ID:Joeento,項目名稱:cayley,代碼行數:8,代碼來源:quadstore_iterator_optimize.go

示例7: OptimizeIterator

func (ts *MongoTripleStore) OptimizeIterator(it graph.Iterator) (graph.Iterator, bool) {
	switch it.Type() {
	case "linksto":
		return ts.optimizeLinksTo(it.(*graph.LinksToIterator))

	}
	return it, false
}
開發者ID:java10000,項目名稱:cayley,代碼行數:8,代碼來源:mongo_triplestore_iterator_optimize.go

示例8: 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:oliverp19,項目名稱:cayley,代碼行數:8,代碼來源:bolt_test.go

示例9: 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:oliverp19,項目名稱:cayley,代碼行數:8,代碼來源:bolt_test.go

示例10: IteratedRawStrings

func IteratedRawStrings(t testing.TB, qs graph.QuadStore, it graph.Iterator) []string {
	var res []string
	for graph.Next(it) {
		res = append(res, qs.NameOf(it.Result()).String())
	}
	require.Nil(t, it.Err())
	sort.Strings(res)
	return res
}
開發者ID:dennwc,項目名稱:cayley,代碼行數:9,代碼來源:graphtest.go

示例11: IteratedValues

func IteratedValues(t testing.TB, qs graph.QuadStore, it graph.Iterator) []quad.Value {
	var res []quad.Value
	for graph.Next(it) {
		res = append(res, qs.NameOf(it.Result()))
	}
	require.Nil(t, it.Err())
	sort.Sort(quad.ByValueString(res))
	return res
}
開發者ID:dennwc,項目名稱:cayley,代碼行數:9,代碼來源:graphtest.go

示例12: IteratedQuads

func IteratedQuads(t testing.TB, qs graph.QuadStore, it graph.Iterator) []quad.Quad {
	var res quad.ByQuadString
	for graph.Next(it) {
		res = append(res, qs.Quad(it.Result()))
	}
	require.Nil(t, it.Err())
	sort.Sort(res)
	return res
}
開發者ID:dennwc,項目名稱:cayley,代碼行數:9,代碼來源:graphtest.go

示例13: Clone

func (it *Iterator) Clone() graph.Iterator {
	var newM graph.Iterator
	if it.isAll {
		newM = NewAllIterator(it.ts, it.collection)
	} else {
		newM = NewIterator(it.ts, it.collection, it.dir, it.hash)
	}
	newM.CopyTagsFrom(it)
	return newM
}
開發者ID:heshizhu,項目名稱:cayley,代碼行數:10,代碼來源:iterator.go

示例14: CopyTagsFrom

func (it *Base) CopyTagsFrom(other_it graph.Iterator) {
	for _, tag := range other_it.Tags() {
		it.AddTag(tag)
	}

	for k, v := range other_it.FixedTags() {
		it.AddFixedTag(k, v)
	}

}
開發者ID:ZSIT,項目名稱:cayley,代碼行數:10,代碼來源:iterator.go

示例15: OptimizeIterator

func (qs *QuadStore) OptimizeIterator(it graph.Iterator) (graph.Iterator, bool) {
	switch it.Type() {
	case graph.LinksTo:
		return qs.optimizeLinksTo(it.(*iterator.LinksTo))
	case graph.HasA:
		return qs.optimizeHasA(it.(*iterator.HasA))
	case graph.And:
		return qs.optimizeAnd(it.(*iterator.And))
	}
	return it, false
}
開發者ID:e4x,項目名稱:cayley,代碼行數:11,代碼來源:optimizers.go


注:本文中的github.com/google/cayley/graph.Iterator類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。