本文整理汇总了Golang中github.com/google/cayley/graph.Iterator类的典型用法代码示例。如果您正苦于以下问题:Golang Iterator类的具体用法?Golang Iterator怎么用?Golang Iterator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Iterator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: OutputQueryShapeForIterator
func OutputQueryShapeForIterator(it graph.Iterator, ts graph.TripleStore, outputMap map[string]interface{}) {
qs := &queryShape{
ts: ts,
nodeId: 1,
}
node := qs.MakeNode(it.Clone())
qs.AddNode(node)
outputMap["nodes"] = qs.nodes
outputMap["links"] = qs.links
}
开发者ID:ZSIT,项目名称:cayley,代码行数:11,代码来源:query_shape.go
示例17: extractNumbersFromIterator
func extractNumbersFromIterator(it graph.Iterator) []int {
var outputNumbers []int
for {
val, ok := it.Next()
if !ok {
break
}
outputNumbers = append(outputNumbers, val.(int))
}
return outputNumbers
}
开发者ID:heshizhu,项目名称:cayley,代码行数:11,代码来源:or_iterator_test.go
示例18: 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.Tags() {
if _, ok := tags[tag]; ok {
delete(tags, tag)
}
}
for k := range tags {
dst.AddTag(k)
}
}
开发者ID:heshizhu,项目名称:cayley,代码行数:13,代码来源:and_iterator_optimize.go
示例19: 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.And:
return qs.optimizeAndIterator(it.(*iterator.And))
case graph.Comparison:
return qs.optimizeComparison(it.(*iterator.Comparison))
}
return it, false
}
开发者ID:dennwc,项目名称:cayley,代码行数:11,代码来源:quadstore_iterator_optimize.go
示例20: iterated
func iterated(it graph.Iterator) []int {
var res []int
for {
val, ok := it.Next()
if !ok {
break
}
res = append(res, val.(int))
}
return res
}
开发者ID:ZSIT,项目名称:cayley,代码行数:11,代码来源:or_iterator_test.go
注:本文中的github.com/google/cayley/graph.Iterator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论