repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequence
docstring
stringlengths
6
2.61k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
cayleygraph/cayley
query/session.go
GetLanguage
func GetLanguage(lang string) *Language { l, ok := languages[lang] if ok { return &l } return nil }
go
func GetLanguage(lang string) *Language { l, ok := languages[lang] if ok { return &l } return nil }
[ "func", "GetLanguage", "(", "lang", "string", ")", "*", "Language", "{", "l", ",", "ok", ":=", "languages", "[", "lang", "]", "\n", "if", "ok", "{", "return", "&", "l", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// GetLanguage returns a query language description. // It returns nil if language was not registered.
[ "GetLanguage", "returns", "a", "query", "language", "description", ".", "It", "returns", "nil", "if", "language", "was", "not", "registered", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/query/session.go#L113-L119
train
cayleygraph/cayley
query/session.go
Languages
func Languages() []string { out := make([]string, 0, len(languages)) for name := range languages { out = append(out, name) } return out }
go
func Languages() []string { out := make([]string, 0, len(languages)) for name := range languages { out = append(out, name) } return out }
[ "func", "Languages", "(", ")", "[", "]", "string", "{", "out", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "languages", ")", ")", "\n", "for", "name", ":=", "range", "languages", "{", "out", "=", "append", "(", "out", ",", "name", ")", "\n", "}", "\n", "return", "out", "\n", "}" ]
// Languages returns names of registered query languages.
[ "Languages", "returns", "names", "of", "registered", "query", "languages", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/query/session.go#L122-L128
train
cayleygraph/cayley
query/gizmo/traversals.go
HasR
func (p *pathObject) HasR(call goja.FunctionCall) goja.Value { return p.has(call, true) }
go
func (p *pathObject) HasR(call goja.FunctionCall) goja.Value { return p.has(call, true) }
[ "func", "(", "p", "*", "pathObject", ")", "HasR", "(", "call", "goja", ".", "FunctionCall", ")", "goja", ".", "Value", "{", "return", "p", ".", "has", "(", "call", ",", "true", ")", "\n", "}" ]
// HasR is the same as Has, but sets constraint in reverse direction.
[ "HasR", "is", "the", "same", "as", "Has", "but", "sets", "constraint", "in", "reverse", "direction", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/query/gizmo/traversals.go#L395-L397
train
cayleygraph/cayley
query/gizmo/traversals.go
SaveR
func (p *pathObject) SaveR(call goja.FunctionCall) goja.Value { return p.save(call, true, false) }
go
func (p *pathObject) SaveR(call goja.FunctionCall) goja.Value { return p.save(call, true, false) }
[ "func", "(", "p", "*", "pathObject", ")", "SaveR", "(", "call", "goja", ".", "FunctionCall", ")", "goja", ".", "Value", "{", "return", "p", ".", "save", "(", "call", ",", "true", ",", "false", ")", "\n", "}" ]
// SaveR is the same as Save, but tags values via reverse predicate.
[ "SaveR", "is", "the", "same", "as", "Save", "but", "tags", "values", "via", "reverse", "predicate", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/query/gizmo/traversals.go#L510-L512
train
cayleygraph/cayley
query/gizmo/traversals.go
SaveOptR
func (p *pathObject) SaveOptR(call goja.FunctionCall) goja.Value { return p.save(call, true, true) }
go
func (p *pathObject) SaveOptR(call goja.FunctionCall) goja.Value { return p.save(call, true, true) }
[ "func", "(", "p", "*", "pathObject", ")", "SaveOptR", "(", "call", "goja", ".", "FunctionCall", ")", "goja", ".", "Value", "{", "return", "p", ".", "save", "(", "call", ",", "true", ",", "true", ")", "\n", "}" ]
// SaveOptR is the same as SaveOpt, but tags values via reverse predicate.
[ "SaveOptR", "is", "the", "same", "as", "SaveOpt", "but", "tags", "values", "via", "reverse", "predicate", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/query/gizmo/traversals.go#L520-L522
train
cayleygraph/cayley
query/gizmo/traversals.go
Unique
func (p *pathObject) Unique() *pathObject { np := p.clonePath().Unique() return p.new(np) }
go
func (p *pathObject) Unique() *pathObject { np := p.clonePath().Unique() return p.new(np) }
[ "func", "(", "p", "*", "pathObject", ")", "Unique", "(", ")", "*", "pathObject", "{", "np", ":=", "p", ".", "clonePath", "(", ")", ".", "Unique", "(", ")", "\n", "return", "p", ".", "new", "(", "np", ")", "\n", "}" ]
// Unique removes duplicate values from the path.
[ "Unique", "removes", "duplicate", "values", "from", "the", "path", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/query/gizmo/traversals.go#L543-L546
train
cayleygraph/cayley
query/gizmo/traversals.go
Labels
func (p *pathObject) Labels() *pathObject { np := p.clonePath().Labels() return p.new(np) }
go
func (p *pathObject) Labels() *pathObject { np := p.clonePath().Labels() return p.new(np) }
[ "func", "(", "p", "*", "pathObject", ")", "Labels", "(", ")", "*", "pathObject", "{", "np", ":=", "p", ".", "clonePath", "(", ")", ".", "Labels", "(", ")", "\n", "return", "p", ".", "new", "(", "np", ")", "\n", "}" ]
// Labels gets the list of inbound and outbound quad labels
[ "Labels", "gets", "the", "list", "of", "inbound", "and", "outbound", "quad", "labels" ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/query/gizmo/traversals.go#L554-L557
train
cayleygraph/cayley
query/gizmo/traversals.go
Filter
func (p *pathObject) Filter(args ...valFilter) (*pathObject, error) { if len(args) == 0 { return nil, errArgCount{Got: len(args)} } filt := make([]shape.ValueFilter, 0, len(args)) for _, f := range args { filt = append(filt, f.f) } np := p.clonePath().Filters(filt...) return p.new(np), nil }
go
func (p *pathObject) Filter(args ...valFilter) (*pathObject, error) { if len(args) == 0 { return nil, errArgCount{Got: len(args)} } filt := make([]shape.ValueFilter, 0, len(args)) for _, f := range args { filt = append(filt, f.f) } np := p.clonePath().Filters(filt...) return p.new(np), nil }
[ "func", "(", "p", "*", "pathObject", ")", "Filter", "(", "args", "...", "valFilter", ")", "(", "*", "pathObject", ",", "error", ")", "{", "if", "len", "(", "args", ")", "==", "0", "{", "return", "nil", ",", "errArgCount", "{", "Got", ":", "len", "(", "args", ")", "}", "\n", "}", "\n", "filt", ":=", "make", "(", "[", "]", "shape", ".", "ValueFilter", ",", "0", ",", "len", "(", "args", ")", ")", "\n", "for", "_", ",", "f", ":=", "range", "args", "{", "filt", "=", "append", "(", "filt", ",", "f", ".", "f", ")", "\n", "}", "\n", "np", ":=", "p", ".", "clonePath", "(", ")", ".", "Filters", "(", "filt", "...", ")", "\n", "return", "p", ".", "new", "(", "np", ")", ",", "nil", "\n", "}" ]
// Filter applies constraints to a set of nodes. Can be used to filter values by range or match strings.
[ "Filter", "applies", "constraints", "to", "a", "set", "of", "nodes", ".", "Can", "be", "used", "to", "filter", "values", "by", "range", "or", "match", "strings", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/query/gizmo/traversals.go#L641-L651
train
cayleygraph/cayley
quad/jsonld/jsonld.go
NewReader
func NewReader(r io.Reader) *Reader { var o interface{} if err := json.NewDecoder(r).Decode(&o); err != nil { return &Reader{err: err} } return NewReaderFromMap(o) }
go
func NewReader(r io.Reader) *Reader { var o interface{} if err := json.NewDecoder(r).Decode(&o); err != nil { return &Reader{err: err} } return NewReaderFromMap(o) }
[ "func", "NewReader", "(", "r", "io", ".", "Reader", ")", "*", "Reader", "{", "var", "o", "interface", "{", "}", "\n", "if", "err", ":=", "json", ".", "NewDecoder", "(", "r", ")", ".", "Decode", "(", "&", "o", ")", ";", "err", "!=", "nil", "{", "return", "&", "Reader", "{", "err", ":", "err", "}", "\n", "}", "\n", "return", "NewReaderFromMap", "(", "o", ")", "\n", "}" ]
// NewReader returns quad reader for JSON-LD stream.
[ "NewReader", "returns", "quad", "reader", "for", "JSON", "-", "LD", "stream", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/quad/jsonld/jsonld.go#L30-L36
train
cayleygraph/cayley
quad/jsonld/jsonld.go
NewReaderFromMap
func NewReaderFromMap(o interface{}) *Reader { options := gojsonld.NewOptions("") options.DocumentLoader = gojsonld.NewDocumentLoader() data, err := gojsonld.ToRDF(o, options) if err != nil { return &Reader{err: err} } return &Reader{ graphs: data.Graphs, } }
go
func NewReaderFromMap(o interface{}) *Reader { options := gojsonld.NewOptions("") options.DocumentLoader = gojsonld.NewDocumentLoader() data, err := gojsonld.ToRDF(o, options) if err != nil { return &Reader{err: err} } return &Reader{ graphs: data.Graphs, } }
[ "func", "NewReaderFromMap", "(", "o", "interface", "{", "}", ")", "*", "Reader", "{", "options", ":=", "gojsonld", ".", "NewOptions", "(", "\"", "\"", ")", "\n", "options", ".", "DocumentLoader", "=", "gojsonld", ".", "NewDocumentLoader", "(", ")", "\n", "data", ",", "err", ":=", "gojsonld", ".", "ToRDF", "(", "o", ",", "options", ")", "\n", "if", "err", "!=", "nil", "{", "return", "&", "Reader", "{", "err", ":", "err", "}", "\n", "}", "\n", "return", "&", "Reader", "{", "graphs", ":", "data", ".", "Graphs", ",", "}", "\n", "}" ]
// NewReaderFromMap returns quad reader for JSON-LD map object.
[ "NewReaderFromMap", "returns", "quad", "reader", "for", "JSON", "-", "LD", "map", "object", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/quad/jsonld/jsonld.go#L39-L49
train
cayleygraph/cayley
graph/iterator/resolver.go
NewResolver
func NewResolver(qs graph.QuadStore, nodes ...quad.Value) *Resolver { it := &Resolver{ uid: NextUID(), qs: qs, order: make([]quad.Value, len(nodes)), // Generally there are going to be no/few duplicates given // so allocate maps large enough to accommodate all values: make(map[quad.Value]graph.Value, len(nodes)), nodes: make(map[interface{}]quad.Value, len(nodes)), } copy(it.order, nodes) return it }
go
func NewResolver(qs graph.QuadStore, nodes ...quad.Value) *Resolver { it := &Resolver{ uid: NextUID(), qs: qs, order: make([]quad.Value, len(nodes)), // Generally there are going to be no/few duplicates given // so allocate maps large enough to accommodate all values: make(map[quad.Value]graph.Value, len(nodes)), nodes: make(map[interface{}]quad.Value, len(nodes)), } copy(it.order, nodes) return it }
[ "func", "NewResolver", "(", "qs", "graph", ".", "QuadStore", ",", "nodes", "...", "quad", ".", "Value", ")", "*", "Resolver", "{", "it", ":=", "&", "Resolver", "{", "uid", ":", "NextUID", "(", ")", ",", "qs", ":", "qs", ",", "order", ":", "make", "(", "[", "]", "quad", ".", "Value", ",", "len", "(", "nodes", ")", ")", ",", "// Generally there are going to be no/few duplicates given", "// so allocate maps large enough to accommodate all", "values", ":", "make", "(", "map", "[", "quad", ".", "Value", "]", "graph", ".", "Value", ",", "len", "(", "nodes", ")", ")", ",", "nodes", ":", "make", "(", "map", "[", "interface", "{", "}", "]", "quad", ".", "Value", ",", "len", "(", "nodes", ")", ")", ",", "}", "\n", "copy", "(", "it", ".", "order", ",", "nodes", ")", "\n", "return", "it", "\n", "}" ]
// Creates a new Resolver iterator.
[ "Creates", "a", "new", "Resolver", "iterator", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterator/resolver.go#L43-L55
train
cayleygraph/cayley
graph/iterator/resolver.go
resolve
func (it *Resolver) resolve(ctx context.Context) error { values, err := graph.RefsOf(ctx, it.qs, it.order) if err != nil { return err } for index, value := range values { node := it.order[index] it.values[node] = value it.nodes[value.Key()] = node } it.cached = true return nil }
go
func (it *Resolver) resolve(ctx context.Context) error { values, err := graph.RefsOf(ctx, it.qs, it.order) if err != nil { return err } for index, value := range values { node := it.order[index] it.values[node] = value it.nodes[value.Key()] = node } it.cached = true return nil }
[ "func", "(", "it", "*", "Resolver", ")", "resolve", "(", "ctx", "context", ".", "Context", ")", "error", "{", "values", ",", "err", ":=", "graph", ".", "RefsOf", "(", "ctx", ",", "it", ".", "qs", ",", "it", ".", "order", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "for", "index", ",", "value", ":=", "range", "values", "{", "node", ":=", "it", ".", "order", "[", "index", "]", "\n", "it", ".", "values", "[", "node", "]", "=", "value", "\n", "it", ".", "nodes", "[", "value", ".", "Key", "(", ")", "]", "=", "node", "\n", "}", "\n", "it", ".", "cached", "=", "true", "\n", "return", "nil", "\n", "}" ]
// Resolve nodes to values
[ "Resolve", "nodes", "to", "values" ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterator/resolver.go#L99-L111
train
cayleygraph/cayley
graph/iterator/resolver.go
Contains
func (it *Resolver) Contains(ctx context.Context, value graph.Value) bool { graph.ContainsLogIn(it, value) if !it.cached { it.err = it.resolve(ctx) if it.err != nil { return false } } _, ok := it.nodes[value.Key()] return graph.ContainsLogOut(it, value, ok) }
go
func (it *Resolver) Contains(ctx context.Context, value graph.Value) bool { graph.ContainsLogIn(it, value) if !it.cached { it.err = it.resolve(ctx) if it.err != nil { return false } } _, ok := it.nodes[value.Key()] return graph.ContainsLogOut(it, value, ok) }
[ "func", "(", "it", "*", "Resolver", ")", "Contains", "(", "ctx", "context", ".", "Context", ",", "value", "graph", ".", "Value", ")", "bool", "{", "graph", ".", "ContainsLogIn", "(", "it", ",", "value", ")", "\n", "if", "!", "it", ".", "cached", "{", "it", ".", "err", "=", "it", ".", "resolve", "(", "ctx", ")", "\n", "if", "it", ".", "err", "!=", "nil", "{", "return", "false", "\n", "}", "\n", "}", "\n", "_", ",", "ok", ":=", "it", ".", "nodes", "[", "value", ".", "Key", "(", ")", "]", "\n", "return", "graph", ".", "ContainsLogOut", "(", "it", ",", "value", ",", "ok", ")", "\n", "}" ]
// Check if the passed value is equal to one of the order stored in the iterator.
[ "Check", "if", "the", "passed", "value", "is", "equal", "to", "one", "of", "the", "order", "stored", "in", "the", "iterator", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterator/resolver.go#L114-L124
train
cayleygraph/cayley
graph/iterator/resolver.go
Optimize
func (it *Resolver) Optimize() (graph.Iterator, bool) { if len(it.order) == 0 { return NewNull(), true } return it, false }
go
func (it *Resolver) Optimize() (graph.Iterator, bool) { if len(it.order) == 0 { return NewNull(), true } return it, false }
[ "func", "(", "it", "*", "Resolver", ")", "Optimize", "(", ")", "(", "graph", ".", "Iterator", ",", "bool", ")", "{", "if", "len", "(", "it", ".", "order", ")", "==", "0", "{", "return", "NewNull", "(", ")", ",", "true", "\n", "}", "\n", "return", "it", ",", "false", "\n", "}" ]
// Returns a Null iterator if it's empty so that upstream iterators can optimize it // away, otherwise there is no optimization.
[ "Returns", "a", "Null", "iterator", "if", "it", "s", "empty", "so", "that", "upstream", "iterators", "can", "optimize", "it", "away", "otherwise", "there", "is", "no", "optimization", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterator/resolver.go#L169-L174
train
cayleygraph/cayley
graph/iterator/resolver.go
Size
func (it *Resolver) Size() (int64, bool) { return int64(len(it.order)), true }
go
func (it *Resolver) Size() (int64, bool) { return int64(len(it.order)), true }
[ "func", "(", "it", "*", "Resolver", ")", "Size", "(", ")", "(", "int64", ",", "bool", ")", "{", "return", "int64", "(", "len", "(", "it", ".", "order", ")", ")", ",", "true", "\n", "}" ]
// Size is the number of m stored.
[ "Size", "is", "the", "number", "of", "m", "stored", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterator/resolver.go#L177-L179
train
cayleygraph/cayley
graph/iterator/iterator.go
TagResults
func (it *Null) TagResults(dst map[string]graph.Value) { it.tags.TagResult(dst, it.Result()) }
go
func (it *Null) TagResults(dst map[string]graph.Value) { it.tags.TagResult(dst, it.Result()) }
[ "func", "(", "it", "*", "Null", ")", "TagResults", "(", "dst", "map", "[", "string", "]", "graph", ".", "Value", ")", "{", "it", ".", "tags", ".", "TagResult", "(", "dst", ",", "it", ".", "Result", "(", ")", ")", "\n", "}" ]
// Fill the map based on the tags assigned to this iterator.
[ "Fill", "the", "map", "based", "on", "the", "tags", "assigned", "to", "this", "iterator", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterator/iterator.go#L64-L66
train
cayleygraph/cayley
graph/iterator/and.go
NewAnd
func NewAnd(qs graph.QuadStore, sub ...graph.Iterator) *And { it := &And{ uid: NextUID(), internalIterators: make([]graph.Iterator, 0, 20), qs: qs, } for _, s := range sub { it.AddSubIterator(s) } return it }
go
func NewAnd(qs graph.QuadStore, sub ...graph.Iterator) *And { it := &And{ uid: NextUID(), internalIterators: make([]graph.Iterator, 0, 20), qs: qs, } for _, s := range sub { it.AddSubIterator(s) } return it }
[ "func", "NewAnd", "(", "qs", "graph", ".", "QuadStore", ",", "sub", "...", "graph", ".", "Iterator", ")", "*", "And", "{", "it", ":=", "&", "And", "{", "uid", ":", "NextUID", "(", ")", ",", "internalIterators", ":", "make", "(", "[", "]", "graph", ".", "Iterator", ",", "0", ",", "20", ")", ",", "qs", ":", "qs", ",", "}", "\n", "for", "_", ",", "s", ":=", "range", "sub", "{", "it", ".", "AddSubIterator", "(", "s", ")", "\n", "}", "\n", "return", "it", "\n", "}" ]
// NewAnd creates an And iterator. `qs` is only required when needing a handle // for QuadStore-specific optimizations, otherwise nil is acceptable.
[ "NewAnd", "creates", "an", "And", "iterator", ".", "qs", "is", "only", "required", "when", "needing", "a", "handle", "for", "QuadStore", "-", "specific", "optimizations", "otherwise", "nil", "is", "acceptable", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterator/and.go#L43-L53
train
cayleygraph/cayley
graph/iterator/and.go
TagResults
func (it *And) TagResults(dst map[string]graph.Value) { it.tags.TagResult(dst, it.Result()) if it.primaryIt != nil { it.primaryIt.TagResults(dst) } for _, sub := range it.internalIterators { sub.TagResults(dst) } }
go
func (it *And) TagResults(dst map[string]graph.Value) { it.tags.TagResult(dst, it.Result()) if it.primaryIt != nil { it.primaryIt.TagResults(dst) } for _, sub := range it.internalIterators { sub.TagResults(dst) } }
[ "func", "(", "it", "*", "And", ")", "TagResults", "(", "dst", "map", "[", "string", "]", "graph", ".", "Value", ")", "{", "it", ".", "tags", ".", "TagResult", "(", "dst", ",", "it", ".", "Result", "(", ")", ")", "\n\n", "if", "it", ".", "primaryIt", "!=", "nil", "{", "it", ".", "primaryIt", ".", "TagResults", "(", "dst", ")", "\n", "}", "\n", "for", "_", ",", "sub", ":=", "range", "it", ".", "internalIterators", "{", "sub", ".", "TagResults", "(", "dst", ")", "\n", "}", "\n", "}" ]
// An extended TagResults, as it needs to add it's own results and // recurse down it's subiterators.
[ "An", "extended", "TagResults", "as", "it", "needs", "to", "add", "it", "s", "own", "results", "and", "recurse", "down", "it", "s", "subiterators", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterator/and.go#L75-L84
train
cayleygraph/cayley
graph/iterator/and.go
Next
func (it *And) Next(ctx context.Context) bool { graph.NextLogIn(it) it.runstats.Next += 1 for it.primaryIt.Next(ctx) { curr := it.primaryIt.Result() if it.subItsContain(ctx, curr, nil) { it.result = curr return graph.NextLogOut(it, true) } } it.err = it.primaryIt.Err() return graph.NextLogOut(it, false) }
go
func (it *And) Next(ctx context.Context) bool { graph.NextLogIn(it) it.runstats.Next += 1 for it.primaryIt.Next(ctx) { curr := it.primaryIt.Result() if it.subItsContain(ctx, curr, nil) { it.result = curr return graph.NextLogOut(it, true) } } it.err = it.primaryIt.Err() return graph.NextLogOut(it, false) }
[ "func", "(", "it", "*", "And", ")", "Next", "(", "ctx", "context", ".", "Context", ")", "bool", "{", "graph", ".", "NextLogIn", "(", "it", ")", "\n", "it", ".", "runstats", ".", "Next", "+=", "1", "\n", "for", "it", ".", "primaryIt", ".", "Next", "(", "ctx", ")", "{", "curr", ":=", "it", ".", "primaryIt", ".", "Result", "(", ")", "\n", "if", "it", ".", "subItsContain", "(", "ctx", ",", "curr", ",", "nil", ")", "{", "it", ".", "result", "=", "curr", "\n", "return", "graph", ".", "NextLogOut", "(", "it", ",", "true", ")", "\n", "}", "\n", "}", "\n", "it", ".", "err", "=", "it", ".", "primaryIt", ".", "Err", "(", ")", "\n", "return", "graph", ".", "NextLogOut", "(", "it", ",", "false", ")", "\n", "}" ]
// Returns advances the And iterator. Because the And is the intersection of its // subiterators, it must choose one subiterator to produce a candidate, and check // this value against the subiterators. A productive choice of primary iterator // is therefore very important.
[ "Returns", "advances", "the", "And", "iterator", ".", "Because", "the", "And", "is", "the", "intersection", "of", "its", "subiterators", "it", "must", "choose", "one", "subiterator", "to", "produce", "a", "candidate", "and", "check", "this", "value", "against", "the", "subiterators", ".", "A", "productive", "choice", "of", "primary", "iterator", "is", "therefore", "very", "important", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterator/and.go#L133-L145
train
cayleygraph/cayley
graph/iterator/and.go
subItsContain
func (it *And) subItsContain(ctx context.Context, val graph.Value, lastResult graph.Value) bool { var subIsGood = true for i, sub := range it.internalIterators { subIsGood = sub.Contains(ctx, val) if !subIsGood { if lastResult != nil { for j := 0; j < i; j++ { it.internalIterators[j].Contains(ctx, lastResult) } } break } } return subIsGood }
go
func (it *And) subItsContain(ctx context.Context, val graph.Value, lastResult graph.Value) bool { var subIsGood = true for i, sub := range it.internalIterators { subIsGood = sub.Contains(ctx, val) if !subIsGood { if lastResult != nil { for j := 0; j < i; j++ { it.internalIterators[j].Contains(ctx, lastResult) } } break } } return subIsGood }
[ "func", "(", "it", "*", "And", ")", "subItsContain", "(", "ctx", "context", ".", "Context", ",", "val", "graph", ".", "Value", ",", "lastResult", "graph", ".", "Value", ")", "bool", "{", "var", "subIsGood", "=", "true", "\n", "for", "i", ",", "sub", ":=", "range", "it", ".", "internalIterators", "{", "subIsGood", "=", "sub", ".", "Contains", "(", "ctx", ",", "val", ")", "\n", "if", "!", "subIsGood", "{", "if", "lastResult", "!=", "nil", "{", "for", "j", ":=", "0", ";", "j", "<", "i", ";", "j", "++", "{", "it", ".", "internalIterators", "[", "j", "]", ".", "Contains", "(", "ctx", ",", "lastResult", ")", "\n", "}", "\n", "}", "\n", "break", "\n", "}", "\n", "}", "\n", "return", "subIsGood", "\n", "}" ]
// Checks a value against the non-primary iterators, in order.
[ "Checks", "a", "value", "against", "the", "non", "-", "primary", "iterators", "in", "order", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterator/and.go#L167-L181
train
cayleygraph/cayley
graph/iterator/and.go
Contains
func (it *And) Contains(ctx context.Context, val graph.Value) bool { graph.ContainsLogIn(it, val) it.runstats.Contains += 1 lastResult := it.result if it.checkList != nil { return it.checkContainsList(ctx, val, lastResult) } mainGood := it.primaryIt.Contains(ctx, val) if mainGood { othersGood := it.subItsContain(ctx, val, lastResult) if othersGood { it.result = val return graph.ContainsLogOut(it, val, true) } } if lastResult != nil { it.primaryIt.Contains(ctx, lastResult) } return graph.ContainsLogOut(it, val, false) }
go
func (it *And) Contains(ctx context.Context, val graph.Value) bool { graph.ContainsLogIn(it, val) it.runstats.Contains += 1 lastResult := it.result if it.checkList != nil { return it.checkContainsList(ctx, val, lastResult) } mainGood := it.primaryIt.Contains(ctx, val) if mainGood { othersGood := it.subItsContain(ctx, val, lastResult) if othersGood { it.result = val return graph.ContainsLogOut(it, val, true) } } if lastResult != nil { it.primaryIt.Contains(ctx, lastResult) } return graph.ContainsLogOut(it, val, false) }
[ "func", "(", "it", "*", "And", ")", "Contains", "(", "ctx", "context", ".", "Context", ",", "val", "graph", ".", "Value", ")", "bool", "{", "graph", ".", "ContainsLogIn", "(", "it", ",", "val", ")", "\n", "it", ".", "runstats", ".", "Contains", "+=", "1", "\n", "lastResult", ":=", "it", ".", "result", "\n", "if", "it", ".", "checkList", "!=", "nil", "{", "return", "it", ".", "checkContainsList", "(", "ctx", ",", "val", ",", "lastResult", ")", "\n", "}", "\n", "mainGood", ":=", "it", ".", "primaryIt", ".", "Contains", "(", "ctx", ",", "val", ")", "\n", "if", "mainGood", "{", "othersGood", ":=", "it", ".", "subItsContain", "(", "ctx", ",", "val", ",", "lastResult", ")", "\n", "if", "othersGood", "{", "it", ".", "result", "=", "val", "\n", "return", "graph", ".", "ContainsLogOut", "(", "it", ",", "val", ",", "true", ")", "\n", "}", "\n", "}", "\n", "if", "lastResult", "!=", "nil", "{", "it", ".", "primaryIt", ".", "Contains", "(", "ctx", ",", "lastResult", ")", "\n", "}", "\n", "return", "graph", ".", "ContainsLogOut", "(", "it", ",", "val", ",", "false", ")", "\n", "}" ]
// Check a value against the entire iterator, in order.
[ "Check", "a", "value", "against", "the", "entire", "iterator", "in", "order", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterator/and.go#L220-L239
train
cayleygraph/cayley
graph/iterator/and.go
Size
func (it *And) Size() (int64, bool) { val, b := it.primaryIt.Size() for _, sub := range it.internalIterators { newval, newb := sub.Size() if val > newval { val = newval } b = newb && b } return val, b }
go
func (it *And) Size() (int64, bool) { val, b := it.primaryIt.Size() for _, sub := range it.internalIterators { newval, newb := sub.Size() if val > newval { val = newval } b = newb && b } return val, b }
[ "func", "(", "it", "*", "And", ")", "Size", "(", ")", "(", "int64", ",", "bool", ")", "{", "val", ",", "b", ":=", "it", ".", "primaryIt", ".", "Size", "(", ")", "\n", "for", "_", ",", "sub", ":=", "range", "it", ".", "internalIterators", "{", "newval", ",", "newb", ":=", "sub", ".", "Size", "(", ")", "\n", "if", "val", ">", "newval", "{", "val", "=", "newval", "\n", "}", "\n", "b", "=", "newb", "&&", "b", "\n", "}", "\n", "return", "val", ",", "b", "\n", "}" ]
// Returns the approximate size of the And iterator. Because we're dealing // with an intersection, we know that the largest we can be is the size of the // smallest iterator. This is the heuristic we shall follow. Better heuristics // welcome.
[ "Returns", "the", "approximate", "size", "of", "the", "And", "iterator", ".", "Because", "we", "re", "dealing", "with", "an", "intersection", "we", "know", "that", "the", "largest", "we", "can", "be", "is", "the", "size", "of", "the", "smallest", "iterator", ".", "This", "is", "the", "heuristic", "we", "shall", "follow", ".", "Better", "heuristics", "welcome", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterator/and.go#L245-L255
train
cayleygraph/cayley
graph/iterator/and.go
Close
func (it *And) Close() error { it.cleanUp() err := it.primaryIt.Close() for _, sub := range it.internalIterators { _err := sub.Close() if _err != nil && err == nil { err = _err } } return err }
go
func (it *And) Close() error { it.cleanUp() err := it.primaryIt.Close() for _, sub := range it.internalIterators { _err := sub.Close() if _err != nil && err == nil { err = _err } } return err }
[ "func", "(", "it", "*", "And", ")", "Close", "(", ")", "error", "{", "it", ".", "cleanUp", "(", ")", "\n\n", "err", ":=", "it", ".", "primaryIt", ".", "Close", "(", ")", "\n", "for", "_", ",", "sub", ":=", "range", "it", ".", "internalIterators", "{", "_err", ":=", "sub", ".", "Close", "(", ")", "\n", "if", "_err", "!=", "nil", "&&", "err", "==", "nil", "{", "err", "=", "_err", "\n", "}", "\n", "}", "\n\n", "return", "err", "\n", "}" ]
// Close this iterator, and, by extension, close the subiterators. // Close should be idempotent, and it follows that if it's subiterators // follow this contract, the And follows the contract. It closes all // subiterators it can, but returns the first error it encounters.
[ "Close", "this", "iterator", "and", "by", "extension", "close", "the", "subiterators", ".", "Close", "should", "be", "idempotent", "and", "it", "follows", "that", "if", "it", "s", "subiterators", "follow", "this", "contract", "the", "And", "follows", "the", "contract", ".", "It", "closes", "all", "subiterators", "it", "can", "but", "returns", "the", "first", "error", "it", "encounters", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterator/and.go#L288-L300
train
cayleygraph/cayley
graph/nosql/shapes.go
itos
func itos(i int64) string { s := strconv.FormatUint(uint64(i)+int64Adjust, 32) const z = "0000000000000" return z[len(s):] + s }
go
func itos(i int64) string { s := strconv.FormatUint(uint64(i)+int64Adjust, 32) const z = "0000000000000" return z[len(s):] + s }
[ "func", "itos", "(", "i", "int64", ")", "string", "{", "s", ":=", "strconv", ".", "FormatUint", "(", "uint64", "(", "i", ")", "+", "int64Adjust", ",", "32", ")", "\n", "const", "z", "=", "\"", "\"", "\n", "return", "z", "[", "len", "(", "s", ")", ":", "]", "+", "s", "\n", "}" ]
// itos serializes int64 into a sortable string 13 chars long.
[ "itos", "serializes", "int64", "into", "a", "sortable", "string", "13", "chars", "long", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/nosql/shapes.go#L76-L80
train
cayleygraph/cayley
graph/nosql/shapes.go
stoi
func stoi(s string) int64 { ret, err := strconv.ParseUint(s, 32, 64) if err != nil { //TODO handle error? return 0 } return int64(ret - int64Adjust) }
go
func stoi(s string) int64 { ret, err := strconv.ParseUint(s, 32, 64) if err != nil { //TODO handle error? return 0 } return int64(ret - int64Adjust) }
[ "func", "stoi", "(", "s", "string", ")", "int64", "{", "ret", ",", "err", ":=", "strconv", ".", "ParseUint", "(", "s", ",", "32", ",", "64", ")", "\n", "if", "err", "!=", "nil", "{", "//TODO handle error?", "return", "0", "\n", "}", "\n", "return", "int64", "(", "ret", "-", "int64Adjust", ")", "\n", "}" ]
// stoi de-serializes int64 from a sortable string 13 chars long.
[ "stoi", "de", "-", "serializes", "int64", "from", "a", "sortable", "string", "13", "chars", "long", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/nosql/shapes.go#L83-L90
train
cayleygraph/cayley
graph/iterator/all.go
NewInt64
func NewInt64(min, max int64, node bool) *Int64 { return &Int64{ uid: NextUID(), node: node, min: min, max: max, at: min, } }
go
func NewInt64(min, max int64, node bool) *Int64 { return &Int64{ uid: NextUID(), node: node, min: min, max: max, at: min, } }
[ "func", "NewInt64", "(", "min", ",", "max", "int64", ",", "node", "bool", ")", "*", "Int64", "{", "return", "&", "Int64", "{", "uid", ":", "NextUID", "(", ")", ",", "node", ":", "node", ",", "min", ":", "min", ",", "max", ":", "max", ",", "at", ":", "min", ",", "}", "\n", "}" ]
// Creates a new Int64 with the given range.
[ "Creates", "a", "new", "Int64", "with", "the", "given", "range", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterator/all.go#L58-L66
train
cayleygraph/cayley
graph/iterator/all.go
Size
func (it *Int64) Size() (int64, bool) { sz := (it.max - it.min) + 1 return sz, true }
go
func (it *Int64) Size() (int64, bool) { sz := (it.max - it.min) + 1 return sz, true }
[ "func", "(", "it", "*", "Int64", ")", "Size", "(", ")", "(", "int64", ",", "bool", ")", "{", "sz", ":=", "(", "it", ".", "max", "-", "it", ".", "min", ")", "+", "1", "\n", "return", "sz", ",", "true", "\n", "}" ]
// The number of elements in an Int64 is the size of the range. // The size is exact.
[ "The", "number", "of", "elements", "in", "an", "Int64", "is", "the", "size", "of", "the", "range", ".", "The", "size", "is", "exact", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterator/all.go#L143-L146
train
cayleygraph/cayley
graph/iterator/all.go
Stats
func (it *Int64) Stats() graph.IteratorStats { s, exact := it.Size() return graph.IteratorStats{ ContainsCost: 1, NextCost: 1, Size: s, ExactSize: exact, Next: it.runstats.Next, Contains: it.runstats.Contains, } }
go
func (it *Int64) Stats() graph.IteratorStats { s, exact := it.Size() return graph.IteratorStats{ ContainsCost: 1, NextCost: 1, Size: s, ExactSize: exact, Next: it.runstats.Next, Contains: it.runstats.Contains, } }
[ "func", "(", "it", "*", "Int64", ")", "Stats", "(", ")", "graph", ".", "IteratorStats", "{", "s", ",", "exact", ":=", "it", ".", "Size", "(", ")", "\n", "return", "graph", ".", "IteratorStats", "{", "ContainsCost", ":", "1", ",", "NextCost", ":", "1", ",", "Size", ":", "s", ",", "ExactSize", ":", "exact", ",", "Next", ":", "it", ".", "runstats", ".", "Next", ",", "Contains", ":", "it", ".", "runstats", ".", "Contains", ",", "}", "\n", "}" ]
// Stats for an Int64 are simple. Super cheap to do any operation, // and as big as the range.
[ "Stats", "for", "an", "Int64", "are", "simple", ".", "Super", "cheap", "to", "do", "any", "operation", "and", "as", "big", "as", "the", "range", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterator/all.go#L177-L187
train
cayleygraph/cayley
graph/path/morphism_apply_functions.go
filterMorphism
func filterMorphism(filt []shape.ValueFilter) morphism { return morphism{ Reversal: func(ctx *pathContext) (morphism, *pathContext) { return filterMorphism(filt), ctx }, Apply: func(in shape.Shape, ctx *pathContext) (shape.Shape, *pathContext) { return shape.AddFilters(in, filt...), ctx }, } }
go
func filterMorphism(filt []shape.ValueFilter) morphism { return morphism{ Reversal: func(ctx *pathContext) (morphism, *pathContext) { return filterMorphism(filt), ctx }, Apply: func(in shape.Shape, ctx *pathContext) (shape.Shape, *pathContext) { return shape.AddFilters(in, filt...), ctx }, } }
[ "func", "filterMorphism", "(", "filt", "[", "]", "shape", ".", "ValueFilter", ")", "morphism", "{", "return", "morphism", "{", "Reversal", ":", "func", "(", "ctx", "*", "pathContext", ")", "(", "morphism", ",", "*", "pathContext", ")", "{", "return", "filterMorphism", "(", "filt", ")", ",", "ctx", "}", ",", "Apply", ":", "func", "(", "in", "shape", ".", "Shape", ",", "ctx", "*", "pathContext", ")", "(", "shape", ".", "Shape", ",", "*", "pathContext", ")", "{", "return", "shape", ".", "AddFilters", "(", "in", ",", "filt", "...", ")", ",", "ctx", "\n", "}", ",", "}", "\n", "}" ]
// filterMorphism is the set of nodes that passes filters.
[ "filterMorphism", "is", "the", "set", "of", "nodes", "that", "passes", "filters", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/path/morphism_apply_functions.go#L81-L88
train
cayleygraph/cayley
graph/path/morphism_apply_functions.go
outMorphism
func outMorphism(tags []string, via ...interface{}) morphism { return morphism{ Reversal: func(ctx *pathContext) (morphism, *pathContext) { return inMorphism(tags, via...), ctx }, Apply: func(in shape.Shape, ctx *pathContext) (shape.Shape, *pathContext) { return shape.Out(in, buildVia(via...), ctx.labelSet, tags...), ctx }, tags: tags, } }
go
func outMorphism(tags []string, via ...interface{}) morphism { return morphism{ Reversal: func(ctx *pathContext) (morphism, *pathContext) { return inMorphism(tags, via...), ctx }, Apply: func(in shape.Shape, ctx *pathContext) (shape.Shape, *pathContext) { return shape.Out(in, buildVia(via...), ctx.labelSet, tags...), ctx }, tags: tags, } }
[ "func", "outMorphism", "(", "tags", "[", "]", "string", ",", "via", "...", "interface", "{", "}", ")", "morphism", "{", "return", "morphism", "{", "Reversal", ":", "func", "(", "ctx", "*", "pathContext", ")", "(", "morphism", ",", "*", "pathContext", ")", "{", "return", "inMorphism", "(", "tags", ",", "via", "...", ")", ",", "ctx", "}", ",", "Apply", ":", "func", "(", "in", "shape", ".", "Shape", ",", "ctx", "*", "pathContext", ")", "(", "shape", ".", "Shape", ",", "*", "pathContext", ")", "{", "return", "shape", ".", "Out", "(", "in", ",", "buildVia", "(", "via", "...", ")", ",", "ctx", ".", "labelSet", ",", "tags", "...", ")", ",", "ctx", "\n", "}", ",", "tags", ":", "tags", ",", "}", "\n", "}" ]
// outMorphism iterates forward one RDF triple or via an entire path.
[ "outMorphism", "iterates", "forward", "one", "RDF", "triple", "or", "via", "an", "entire", "path", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/path/morphism_apply_functions.go#L134-L142
train
cayleygraph/cayley
graph/path/morphism_apply_functions.go
labelsMorphism
func labelsMorphism() morphism { return morphism{ Reversal: func(ctx *pathContext) (morphism, *pathContext) { panic("not implemented") }, Apply: func(in shape.Shape, ctx *pathContext) (shape.Shape, *pathContext) { return shape.Labels(in), ctx }, } }
go
func labelsMorphism() morphism { return morphism{ Reversal: func(ctx *pathContext) (morphism, *pathContext) { panic("not implemented") }, Apply: func(in shape.Shape, ctx *pathContext) (shape.Shape, *pathContext) { return shape.Labels(in), ctx }, } }
[ "func", "labelsMorphism", "(", ")", "morphism", "{", "return", "morphism", "{", "Reversal", ":", "func", "(", "ctx", "*", "pathContext", ")", "(", "morphism", ",", "*", "pathContext", ")", "{", "panic", "(", "\"", "\"", ")", "\n", "}", ",", "Apply", ":", "func", "(", "in", "shape", ".", "Shape", ",", "ctx", "*", "pathContext", ")", "(", "shape", ".", "Shape", ",", "*", "pathContext", ")", "{", "return", "shape", ".", "Labels", "(", "in", ")", ",", "ctx", "\n", "}", ",", "}", "\n", "}" ]
// labelsMorphism iterates to the uniqified set of labels from // the given set of nodes in the path.
[ "labelsMorphism", "iterates", "to", "the", "uniqified", "set", "of", "labels", "from", "the", "given", "set", "of", "nodes", "in", "the", "path", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/path/morphism_apply_functions.go#L193-L202
train
cayleygraph/cayley
graph/path/morphism_apply_functions.go
predicatesMorphism
func predicatesMorphism(isIn bool) morphism { return morphism{ Reversal: func(ctx *pathContext) (morphism, *pathContext) { panic("not implemented: need a function from predicates to their associated edges") }, Apply: func(in shape.Shape, ctx *pathContext) (shape.Shape, *pathContext) { return shape.Predicates(in, isIn), ctx }, } }
go
func predicatesMorphism(isIn bool) morphism { return morphism{ Reversal: func(ctx *pathContext) (morphism, *pathContext) { panic("not implemented: need a function from predicates to their associated edges") }, Apply: func(in shape.Shape, ctx *pathContext) (shape.Shape, *pathContext) { return shape.Predicates(in, isIn), ctx }, } }
[ "func", "predicatesMorphism", "(", "isIn", "bool", ")", "morphism", "{", "return", "morphism", "{", "Reversal", ":", "func", "(", "ctx", "*", "pathContext", ")", "(", "morphism", ",", "*", "pathContext", ")", "{", "panic", "(", "\"", "\"", ")", "\n", "}", ",", "Apply", ":", "func", "(", "in", "shape", ".", "Shape", ",", "ctx", "*", "pathContext", ")", "(", "shape", ".", "Shape", ",", "*", "pathContext", ")", "{", "return", "shape", ".", "Predicates", "(", "in", ",", "isIn", ")", ",", "ctx", "\n", "}", ",", "}", "\n", "}" ]
// predicatesMorphism iterates to the uniqified set of predicates from // the given set of nodes in the path.
[ "predicatesMorphism", "iterates", "to", "the", "uniqified", "set", "of", "predicates", "from", "the", "given", "set", "of", "nodes", "in", "the", "path", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/path/morphism_apply_functions.go#L206-L215
train
cayleygraph/cayley
graph/path/morphism_apply_functions.go
savePredicatesMorphism
func savePredicatesMorphism(isIn bool, tag string) morphism { return morphism{ Reversal: func(ctx *pathContext) (morphism, *pathContext) { return savePredicatesMorphism(isIn, tag), ctx }, Apply: func(in shape.Shape, ctx *pathContext) (shape.Shape, *pathContext) { return shape.SavePredicates(in, isIn, tag), ctx }, } }
go
func savePredicatesMorphism(isIn bool, tag string) morphism { return morphism{ Reversal: func(ctx *pathContext) (morphism, *pathContext) { return savePredicatesMorphism(isIn, tag), ctx }, Apply: func(in shape.Shape, ctx *pathContext) (shape.Shape, *pathContext) { return shape.SavePredicates(in, isIn, tag), ctx }, } }
[ "func", "savePredicatesMorphism", "(", "isIn", "bool", ",", "tag", "string", ")", "morphism", "{", "return", "morphism", "{", "Reversal", ":", "func", "(", "ctx", "*", "pathContext", ")", "(", "morphism", ",", "*", "pathContext", ")", "{", "return", "savePredicatesMorphism", "(", "isIn", ",", "tag", ")", ",", "ctx", "\n", "}", ",", "Apply", ":", "func", "(", "in", "shape", ".", "Shape", ",", "ctx", "*", "pathContext", ")", "(", "shape", ".", "Shape", ",", "*", "pathContext", ")", "{", "return", "shape", ".", "SavePredicates", "(", "in", ",", "isIn", ",", "tag", ")", ",", "ctx", "\n", "}", ",", "}", "\n", "}" ]
// savePredicatesMorphism tags either forward or reverse predicates from current node // without affecting path.
[ "savePredicatesMorphism", "tags", "either", "forward", "or", "reverse", "predicates", "from", "current", "node", "without", "affecting", "path", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/path/morphism_apply_functions.go#L219-L228
train
cayleygraph/cayley
graph/path/morphism_apply_functions.go
iteratorMorphism
func iteratorMorphism(it graph.Iterator) morphism { return morphism{ Reversal: func(ctx *pathContext) (morphism, *pathContext) { return iteratorMorphism(it), ctx }, Apply: func(in shape.Shape, ctx *pathContext) (shape.Shape, *pathContext) { return join(iteratorShape{it}, in), ctx }, } }
go
func iteratorMorphism(it graph.Iterator) morphism { return morphism{ Reversal: func(ctx *pathContext) (morphism, *pathContext) { return iteratorMorphism(it), ctx }, Apply: func(in shape.Shape, ctx *pathContext) (shape.Shape, *pathContext) { return join(iteratorShape{it}, in), ctx }, } }
[ "func", "iteratorMorphism", "(", "it", "graph", ".", "Iterator", ")", "morphism", "{", "return", "morphism", "{", "Reversal", ":", "func", "(", "ctx", "*", "pathContext", ")", "(", "morphism", ",", "*", "pathContext", ")", "{", "return", "iteratorMorphism", "(", "it", ")", ",", "ctx", "}", ",", "Apply", ":", "func", "(", "in", "shape", ".", "Shape", ",", "ctx", "*", "pathContext", ")", "(", "shape", ".", "Shape", ",", "*", "pathContext", ")", "{", "return", "join", "(", "iteratorShape", "{", "it", "}", ",", "in", ")", ",", "ctx", "\n", "}", ",", "}", "\n", "}" ]
// iteratorMorphism simply tacks the input iterator onto the chain.
[ "iteratorMorphism", "simply", "tacks", "the", "input", "iterator", "onto", "the", "chain", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/path/morphism_apply_functions.go#L242-L249
train
cayleygraph/cayley
graph/path/morphism_apply_functions.go
andMorphism
func andMorphism(p *Path) morphism { return morphism{ Reversal: func(ctx *pathContext) (morphism, *pathContext) { return andMorphism(p), ctx }, Apply: func(in shape.Shape, ctx *pathContext) (shape.Shape, *pathContext) { return join(in, p.Shape()), ctx }, } }
go
func andMorphism(p *Path) morphism { return morphism{ Reversal: func(ctx *pathContext) (morphism, *pathContext) { return andMorphism(p), ctx }, Apply: func(in shape.Shape, ctx *pathContext) (shape.Shape, *pathContext) { return join(in, p.Shape()), ctx }, } }
[ "func", "andMorphism", "(", "p", "*", "Path", ")", "morphism", "{", "return", "morphism", "{", "Reversal", ":", "func", "(", "ctx", "*", "pathContext", ")", "(", "morphism", ",", "*", "pathContext", ")", "{", "return", "andMorphism", "(", "p", ")", ",", "ctx", "}", ",", "Apply", ":", "func", "(", "in", "shape", ".", "Shape", ",", "ctx", "*", "pathContext", ")", "(", "shape", ".", "Shape", ",", "*", "pathContext", ")", "{", "return", "join", "(", "in", ",", "p", ".", "Shape", "(", ")", ")", ",", "ctx", "\n", "}", ",", "}", "\n", "}" ]
// andMorphism sticks a path onto the current iterator chain.
[ "andMorphism", "sticks", "a", "path", "onto", "the", "current", "iterator", "chain", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/path/morphism_apply_functions.go#L252-L259
train
cayleygraph/cayley
graph/path/morphism_apply_functions.go
orMorphism
func orMorphism(p *Path) morphism { return morphism{ Reversal: func(ctx *pathContext) (morphism, *pathContext) { return orMorphism(p), ctx }, Apply: func(in shape.Shape, ctx *pathContext) (shape.Shape, *pathContext) { return shape.Union{in, p.Shape()}, ctx }, } }
go
func orMorphism(p *Path) morphism { return morphism{ Reversal: func(ctx *pathContext) (morphism, *pathContext) { return orMorphism(p), ctx }, Apply: func(in shape.Shape, ctx *pathContext) (shape.Shape, *pathContext) { return shape.Union{in, p.Shape()}, ctx }, } }
[ "func", "orMorphism", "(", "p", "*", "Path", ")", "morphism", "{", "return", "morphism", "{", "Reversal", ":", "func", "(", "ctx", "*", "pathContext", ")", "(", "morphism", ",", "*", "pathContext", ")", "{", "return", "orMorphism", "(", "p", ")", ",", "ctx", "}", ",", "Apply", ":", "func", "(", "in", "shape", ".", "Shape", ",", "ctx", "*", "pathContext", ")", "(", "shape", ".", "Shape", ",", "*", "pathContext", ")", "{", "return", "shape", ".", "Union", "{", "in", ",", "p", ".", "Shape", "(", ")", "}", ",", "ctx", "\n", "}", ",", "}", "\n", "}" ]
// orMorphism is the union, vice intersection, of a path and the current iterator.
[ "orMorphism", "is", "the", "union", "vice", "intersection", "of", "a", "path", "and", "the", "current", "iterator", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/path/morphism_apply_functions.go#L262-L269
train
cayleygraph/cayley
graph/path/morphism_apply_functions.go
uniqueMorphism
func uniqueMorphism() morphism { return morphism{ Reversal: func(ctx *pathContext) (morphism, *pathContext) { return uniqueMorphism(), ctx }, Apply: func(in shape.Shape, ctx *pathContext) (shape.Shape, *pathContext) { return shape.Unique{in}, ctx }, } }
go
func uniqueMorphism() morphism { return morphism{ Reversal: func(ctx *pathContext) (morphism, *pathContext) { return uniqueMorphism(), ctx }, Apply: func(in shape.Shape, ctx *pathContext) (shape.Shape, *pathContext) { return shape.Unique{in}, ctx }, } }
[ "func", "uniqueMorphism", "(", ")", "morphism", "{", "return", "morphism", "{", "Reversal", ":", "func", "(", "ctx", "*", "pathContext", ")", "(", "morphism", ",", "*", "pathContext", ")", "{", "return", "uniqueMorphism", "(", ")", ",", "ctx", "}", ",", "Apply", ":", "func", "(", "in", "shape", ".", "Shape", ",", "ctx", "*", "pathContext", ")", "(", "shape", ".", "Shape", ",", "*", "pathContext", ")", "{", "return", "shape", ".", "Unique", "{", "in", "}", ",", "ctx", "\n", "}", ",", "}", "\n", "}" ]
// uniqueMorphism removes duplicate values from current path.
[ "uniqueMorphism", "removes", "duplicate", "values", "from", "current", "path", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/path/morphism_apply_functions.go#L318-L325
train
cayleygraph/cayley
graph/path/morphism_apply_functions.go
countMorphism
func countMorphism() morphism { return morphism{ Reversal: func(ctx *pathContext) (morphism, *pathContext) { return countMorphism(), ctx }, Apply: func(in shape.Shape, ctx *pathContext) (shape.Shape, *pathContext) { return shape.Count{Values: in}, ctx }, } }
go
func countMorphism() morphism { return morphism{ Reversal: func(ctx *pathContext) (morphism, *pathContext) { return countMorphism(), ctx }, Apply: func(in shape.Shape, ctx *pathContext) (shape.Shape, *pathContext) { return shape.Count{Values: in}, ctx }, } }
[ "func", "countMorphism", "(", ")", "morphism", "{", "return", "morphism", "{", "Reversal", ":", "func", "(", "ctx", "*", "pathContext", ")", "(", "morphism", ",", "*", "pathContext", ")", "{", "return", "countMorphism", "(", ")", ",", "ctx", "}", ",", "Apply", ":", "func", "(", "in", "shape", ".", "Shape", ",", "ctx", "*", "pathContext", ")", "(", "shape", ".", "Shape", ",", "*", "pathContext", ")", "{", "return", "shape", ".", "Count", "{", "Values", ":", "in", "}", ",", "ctx", "\n", "}", ",", "}", "\n", "}" ]
// countMorphism will return count of values.
[ "countMorphism", "will", "return", "count", "of", "values", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/path/morphism_apply_functions.go#L425-L432
train
cayleygraph/cayley
graph/iterator.go
DescribeIterator
func DescribeIterator(it Iterator) Description { sz, exact := it.Size() d := Description{ UID: it.UID(), Name: it.String(), Type: it.Type(), Tags: it.Tagger().Tags(), Size: sz, Exact: exact, } if sub := it.SubIterators(); len(sub) != 0 { d.Iterators = make([]Description, 0, len(sub)) for _, sit := range sub { d.Iterators = append(d.Iterators, DescribeIterator(sit)) } } return d }
go
func DescribeIterator(it Iterator) Description { sz, exact := it.Size() d := Description{ UID: it.UID(), Name: it.String(), Type: it.Type(), Tags: it.Tagger().Tags(), Size: sz, Exact: exact, } if sub := it.SubIterators(); len(sub) != 0 { d.Iterators = make([]Description, 0, len(sub)) for _, sit := range sub { d.Iterators = append(d.Iterators, DescribeIterator(sit)) } } return d }
[ "func", "DescribeIterator", "(", "it", "Iterator", ")", "Description", "{", "sz", ",", "exact", ":=", "it", ".", "Size", "(", ")", "\n", "d", ":=", "Description", "{", "UID", ":", "it", ".", "UID", "(", ")", ",", "Name", ":", "it", ".", "String", "(", ")", ",", "Type", ":", "it", ".", "Type", "(", ")", ",", "Tags", ":", "it", ".", "Tagger", "(", ")", ".", "Tags", "(", ")", ",", "Size", ":", "sz", ",", "Exact", ":", "exact", ",", "}", "\n", "if", "sub", ":=", "it", ".", "SubIterators", "(", ")", ";", "len", "(", "sub", ")", "!=", "0", "{", "d", ".", "Iterators", "=", "make", "(", "[", "]", "Description", ",", "0", ",", "len", "(", "sub", ")", ")", "\n", "for", "_", ",", "sit", ":=", "range", "sub", "{", "d", ".", "Iterators", "=", "append", "(", "d", ".", "Iterators", ",", "DescribeIterator", "(", "sit", ")", ")", "\n", "}", "\n", "}", "\n", "return", "d", "\n", "}" ]
// DescribeIterator returns a description of the iterator tree.
[ "DescribeIterator", "returns", "a", "description", "of", "the", "iterator", "tree", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterator.go#L177-L193
train
cayleygraph/cayley
graph/iterator.go
Height
func Height(it Iterator, until Type) int { if it.Type() == until { return 1 } subs := it.SubIterators() maxDepth := 0 for _, sub := range subs { h := Height(sub, until) if h > maxDepth { maxDepth = h } } return maxDepth + 1 }
go
func Height(it Iterator, until Type) int { if it.Type() == until { return 1 } subs := it.SubIterators() maxDepth := 0 for _, sub := range subs { h := Height(sub, until) if h > maxDepth { maxDepth = h } } return maxDepth + 1 }
[ "func", "Height", "(", "it", "Iterator", ",", "until", "Type", ")", "int", "{", "if", "it", ".", "Type", "(", ")", "==", "until", "{", "return", "1", "\n", "}", "\n", "subs", ":=", "it", ".", "SubIterators", "(", ")", "\n", "maxDepth", ":=", "0", "\n", "for", "_", ",", "sub", ":=", "range", "subs", "{", "h", ":=", "Height", "(", "sub", ",", "until", ")", "\n", "if", "h", ">", "maxDepth", "{", "maxDepth", "=", "h", "\n", "}", "\n", "}", "\n", "return", "maxDepth", "+", "1", "\n", "}" ]
// Height is a convienence function to measure the height of an iterator tree.
[ "Height", "is", "a", "convienence", "function", "to", "measure", "the", "height", "of", "an", "iterator", "tree", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterator.go#L220-L233
train
cayleygraph/cayley
graph/iterator.go
ContainsLogIn
func ContainsLogIn(it Iterator, val Value) { if clog.V(4) { clog.Infof("%s %d CHECK CONTAINS %v", strings.ToUpper(it.Type().String()), it.UID(), val) } }
go
func ContainsLogIn(it Iterator, val Value) { if clog.V(4) { clog.Infof("%s %d CHECK CONTAINS %v", strings.ToUpper(it.Type().String()), it.UID(), val) } }
[ "func", "ContainsLogIn", "(", "it", "Iterator", ",", "val", "Value", ")", "{", "if", "clog", ".", "V", "(", "4", ")", "{", "clog", ".", "Infof", "(", "\"", "\"", ",", "strings", ".", "ToUpper", "(", "it", ".", "Type", "(", ")", ".", "String", "(", ")", ")", ",", "it", ".", "UID", "(", ")", ",", "val", ")", "\n", "}", "\n", "}" ]
// Utility logging functions for when an iterator gets called Next upon, or Contains upon, as // well as what they return. Highly useful for tracing the execution path of a query.
[ "Utility", "logging", "functions", "for", "when", "an", "iterator", "gets", "called", "Next", "upon", "or", "Contains", "upon", "as", "well", "as", "what", "they", "return", ".", "Highly", "useful", "for", "tracing", "the", "execution", "path", "of", "a", "query", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterator.go#L307-L311
train
cayleygraph/cayley
schema/schema.go
RegisterType
func RegisterType(iri quad.IRI, obj interface{}) { var rt reflect.Type if obj != nil { if t, ok := obj.(reflect.Type); ok { rt = t } else { rt = reflect.TypeOf(obj) if rt.Kind() == reflect.Ptr { rt = rt.Elem() } } } full := iri.Full() typesMu.Lock() defer typesMu.Unlock() if obj == nil { tp := iriToType[full] delete(typeToIRI, tp) delete(iriToType, full) return } if _, exists := typeToIRI[rt]; exists { panic(fmt.Errorf("type %v is already registered", rt)) } if _, exists := iriToType[full]; exists { panic(fmt.Errorf("IRI %v is already registered", iri)) } typeToIRI[rt] = iri iriToType[full] = rt }
go
func RegisterType(iri quad.IRI, obj interface{}) { var rt reflect.Type if obj != nil { if t, ok := obj.(reflect.Type); ok { rt = t } else { rt = reflect.TypeOf(obj) if rt.Kind() == reflect.Ptr { rt = rt.Elem() } } } full := iri.Full() typesMu.Lock() defer typesMu.Unlock() if obj == nil { tp := iriToType[full] delete(typeToIRI, tp) delete(iriToType, full) return } if _, exists := typeToIRI[rt]; exists { panic(fmt.Errorf("type %v is already registered", rt)) } if _, exists := iriToType[full]; exists { panic(fmt.Errorf("IRI %v is already registered", iri)) } typeToIRI[rt] = iri iriToType[full] = rt }
[ "func", "RegisterType", "(", "iri", "quad", ".", "IRI", ",", "obj", "interface", "{", "}", ")", "{", "var", "rt", "reflect", ".", "Type", "\n", "if", "obj", "!=", "nil", "{", "if", "t", ",", "ok", ":=", "obj", ".", "(", "reflect", ".", "Type", ")", ";", "ok", "{", "rt", "=", "t", "\n", "}", "else", "{", "rt", "=", "reflect", ".", "TypeOf", "(", "obj", ")", "\n", "if", "rt", ".", "Kind", "(", ")", "==", "reflect", ".", "Ptr", "{", "rt", "=", "rt", ".", "Elem", "(", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "full", ":=", "iri", ".", "Full", "(", ")", "\n", "typesMu", ".", "Lock", "(", ")", "\n", "defer", "typesMu", ".", "Unlock", "(", ")", "\n", "if", "obj", "==", "nil", "{", "tp", ":=", "iriToType", "[", "full", "]", "\n", "delete", "(", "typeToIRI", ",", "tp", ")", "\n", "delete", "(", "iriToType", ",", "full", ")", "\n", "return", "\n", "}", "\n", "if", "_", ",", "exists", ":=", "typeToIRI", "[", "rt", "]", ";", "exists", "{", "panic", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "rt", ")", ")", "\n", "}", "\n", "if", "_", ",", "exists", ":=", "iriToType", "[", "full", "]", ";", "exists", "{", "panic", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "iri", ")", ")", "\n", "}", "\n", "typeToIRI", "[", "rt", "]", "=", "iri", "\n", "iriToType", "[", "full", "]", "=", "rt", "\n", "}" ]
// RegisterType associates an IRI with a given Go type. // // All queries and writes will require or add a type triple.
[ "RegisterType", "associates", "an", "IRI", "with", "a", "given", "Go", "type", ".", "All", "queries", "and", "writes", "will", "require", "or", "add", "a", "type", "triple", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/schema/schema.go#L230-L259
train
cayleygraph/cayley
schema/schema.go
rulesFor
func (c *Config) rulesFor(rt reflect.Type) (fieldRules, error) { // if rt.Kind() != reflect.Struct { // return nil, fmt.Errorf("expected struct, got: %v", rt) // } c.rulesForTypeMu.RLock() rules, ok := c.rulesForType[rt] c.rulesForTypeMu.RUnlock() if ok { return rules, nil } out := make(fieldRules) if err := c.rulesForStructTo(out, "", rt); err != nil { return nil, err } c.rulesForTypeMu.Lock() if c.rulesForType == nil { c.rulesForType = make(map[reflect.Type]fieldRules) } c.rulesForType[rt] = out c.rulesForTypeMu.Unlock() return out, nil }
go
func (c *Config) rulesFor(rt reflect.Type) (fieldRules, error) { // if rt.Kind() != reflect.Struct { // return nil, fmt.Errorf("expected struct, got: %v", rt) // } c.rulesForTypeMu.RLock() rules, ok := c.rulesForType[rt] c.rulesForTypeMu.RUnlock() if ok { return rules, nil } out := make(fieldRules) if err := c.rulesForStructTo(out, "", rt); err != nil { return nil, err } c.rulesForTypeMu.Lock() if c.rulesForType == nil { c.rulesForType = make(map[reflect.Type]fieldRules) } c.rulesForType[rt] = out c.rulesForTypeMu.Unlock() return out, nil }
[ "func", "(", "c", "*", "Config", ")", "rulesFor", "(", "rt", "reflect", ".", "Type", ")", "(", "fieldRules", ",", "error", ")", "{", "//\tif rt.Kind() != reflect.Struct {", "//\t\treturn nil, fmt.Errorf(\"expected struct, got: %v\", rt)", "//\t}", "c", ".", "rulesForTypeMu", ".", "RLock", "(", ")", "\n", "rules", ",", "ok", ":=", "c", ".", "rulesForType", "[", "rt", "]", "\n", "c", ".", "rulesForTypeMu", ".", "RUnlock", "(", ")", "\n", "if", "ok", "{", "return", "rules", ",", "nil", "\n", "}", "\n", "out", ":=", "make", "(", "fieldRules", ")", "\n", "if", "err", ":=", "c", ".", "rulesForStructTo", "(", "out", ",", "\"", "\"", ",", "rt", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "c", ".", "rulesForTypeMu", ".", "Lock", "(", ")", "\n", "if", "c", ".", "rulesForType", "==", "nil", "{", "c", ".", "rulesForType", "=", "make", "(", "map", "[", "reflect", ".", "Type", "]", "fieldRules", ")", "\n", "}", "\n", "c", ".", "rulesForType", "[", "rt", "]", "=", "out", "\n", "c", ".", "rulesForTypeMu", ".", "Unlock", "(", ")", "\n", "return", "out", ",", "nil", "\n", "}" ]
// rulesFor // // Returned map should not be changed.
[ "rulesFor", "Returned", "map", "should", "not", "be", "changed", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/schema/schema.go#L304-L325
train
cayleygraph/cayley
schema/namespaces.go
WriteNamespaces
func (c *Config) WriteNamespaces(w quad.Writer, n *voc.Namespaces) error { rules, err := c.rulesFor(reflect.TypeOf(namespace{})) if err != nil { return fmt.Errorf("can't load rules: %v", err) } wr := c.newWriter(w) for _, ns := range n.List() { obj := namespace{ Full: quad.IRI(ns.Full), Prefix: quad.IRI(ns.Prefix), } rv := reflect.ValueOf(obj) if err = wr.writeValueAs(obj.Full, rv, "", rules); err != nil { return err } } return nil }
go
func (c *Config) WriteNamespaces(w quad.Writer, n *voc.Namespaces) error { rules, err := c.rulesFor(reflect.TypeOf(namespace{})) if err != nil { return fmt.Errorf("can't load rules: %v", err) } wr := c.newWriter(w) for _, ns := range n.List() { obj := namespace{ Full: quad.IRI(ns.Full), Prefix: quad.IRI(ns.Prefix), } rv := reflect.ValueOf(obj) if err = wr.writeValueAs(obj.Full, rv, "", rules); err != nil { return err } } return nil }
[ "func", "(", "c", "*", "Config", ")", "WriteNamespaces", "(", "w", "quad", ".", "Writer", ",", "n", "*", "voc", ".", "Namespaces", ")", "error", "{", "rules", ",", "err", ":=", "c", ".", "rulesFor", "(", "reflect", ".", "TypeOf", "(", "namespace", "{", "}", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "wr", ":=", "c", ".", "newWriter", "(", "w", ")", "\n", "for", "_", ",", "ns", ":=", "range", "n", ".", "List", "(", ")", "{", "obj", ":=", "namespace", "{", "Full", ":", "quad", ".", "IRI", "(", "ns", ".", "Full", ")", ",", "Prefix", ":", "quad", ".", "IRI", "(", "ns", ".", "Prefix", ")", ",", "}", "\n", "rv", ":=", "reflect", ".", "ValueOf", "(", "obj", ")", "\n", "if", "err", "=", "wr", ".", "writeValueAs", "(", "obj", ".", "Full", ",", "rv", ",", "\"", "\"", ",", "rules", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// WriteNamespaces will writes namespaces list into graph.
[ "WriteNamespaces", "will", "writes", "namespaces", "list", "into", "graph", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/schema/namespaces.go#L20-L37
train
cayleygraph/cayley
schema/namespaces.go
LoadNamespaces
func (c *Config) LoadNamespaces(ctx context.Context, qs graph.QuadStore, dest *voc.Namespaces) error { var list []namespace if err := c.LoadTo(ctx, qs, &list); err != nil { return err } register := dest.Register if dest == nil { register = voc.Register } for _, ns := range list { register(voc.Namespace{ Prefix: string(ns.Prefix), Full: string(ns.Full), }) } return nil }
go
func (c *Config) LoadNamespaces(ctx context.Context, qs graph.QuadStore, dest *voc.Namespaces) error { var list []namespace if err := c.LoadTo(ctx, qs, &list); err != nil { return err } register := dest.Register if dest == nil { register = voc.Register } for _, ns := range list { register(voc.Namespace{ Prefix: string(ns.Prefix), Full: string(ns.Full), }) } return nil }
[ "func", "(", "c", "*", "Config", ")", "LoadNamespaces", "(", "ctx", "context", ".", "Context", ",", "qs", "graph", ".", "QuadStore", ",", "dest", "*", "voc", ".", "Namespaces", ")", "error", "{", "var", "list", "[", "]", "namespace", "\n", "if", "err", ":=", "c", ".", "LoadTo", "(", "ctx", ",", "qs", ",", "&", "list", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "register", ":=", "dest", ".", "Register", "\n", "if", "dest", "==", "nil", "{", "register", "=", "voc", ".", "Register", "\n", "}", "\n", "for", "_", ",", "ns", ":=", "range", "list", "{", "register", "(", "voc", ".", "Namespace", "{", "Prefix", ":", "string", "(", "ns", ".", "Prefix", ")", ",", "Full", ":", "string", "(", "ns", ".", "Full", ")", ",", "}", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// LoadNamespaces will load namespaces stored in graph to a specified list. // If destination list is empty, global namespace registry will be used.
[ "LoadNamespaces", "will", "load", "namespaces", "stored", "in", "graph", "to", "a", "specified", "list", ".", "If", "destination", "list", "is", "empty", "global", "namespace", "registry", "will", "be", "used", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/schema/namespaces.go#L41-L57
train
cayleygraph/cayley
quad/pquads/quads.go
MarshalValue
func MarshalValue(v quad.Value) ([]byte, error) { if v == nil { return nil, nil } return MakeValue(v).Marshal() }
go
func MarshalValue(v quad.Value) ([]byte, error) { if v == nil { return nil, nil } return MakeValue(v).Marshal() }
[ "func", "MarshalValue", "(", "v", "quad", ".", "Value", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "if", "v", "==", "nil", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "return", "MakeValue", "(", "v", ")", ".", "Marshal", "(", ")", "\n", "}" ]
// MarshalValue is a helper for serialization of quad.Value.
[ "MarshalValue", "is", "a", "helper", "for", "serialization", "of", "quad", ".", "Value", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/quad/pquads/quads.go#L56-L61
train
cayleygraph/cayley
quad/pquads/quads.go
UnmarshalValue
func UnmarshalValue(data []byte) (quad.Value, error) { if len(data) == 0 { return nil, nil } var v Value if err := v.Unmarshal(data); err != nil { return nil, err } return v.ToNative(), nil }
go
func UnmarshalValue(data []byte) (quad.Value, error) { if len(data) == 0 { return nil, nil } var v Value if err := v.Unmarshal(data); err != nil { return nil, err } return v.ToNative(), nil }
[ "func", "UnmarshalValue", "(", "data", "[", "]", "byte", ")", "(", "quad", ".", "Value", ",", "error", ")", "{", "if", "len", "(", "data", ")", "==", "0", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "var", "v", "Value", "\n", "if", "err", ":=", "v", ".", "Unmarshal", "(", "data", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "v", ".", "ToNative", "(", ")", ",", "nil", "\n", "}" ]
// UnmarshalValue is a helper for deserialization of quad.Value.
[ "UnmarshalValue", "is", "a", "helper", "for", "deserialization", "of", "quad", ".", "Value", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/quad/pquads/quads.go#L64-L73
train
cayleygraph/cayley
quad/pquads/quads.go
MakeQuad
func MakeQuad(q quad.Quad) *Quad { return &Quad{ SubjectValue: MakeValue(q.Subject), PredicateValue: MakeValue(q.Predicate), ObjectValue: MakeValue(q.Object), LabelValue: MakeValue(q.Label), } }
go
func MakeQuad(q quad.Quad) *Quad { return &Quad{ SubjectValue: MakeValue(q.Subject), PredicateValue: MakeValue(q.Predicate), ObjectValue: MakeValue(q.Object), LabelValue: MakeValue(q.Label), } }
[ "func", "MakeQuad", "(", "q", "quad", ".", "Quad", ")", "*", "Quad", "{", "return", "&", "Quad", "{", "SubjectValue", ":", "MakeValue", "(", "q", ".", "Subject", ")", ",", "PredicateValue", ":", "MakeValue", "(", "q", ".", "Predicate", ")", ",", "ObjectValue", ":", "MakeValue", "(", "q", ".", "Object", ")", ",", "LabelValue", ":", "MakeValue", "(", "q", ".", "Label", ")", ",", "}", "\n", "}" ]
// MakeQuad converts quad.Quad to its protobuf representation.
[ "MakeQuad", "converts", "quad", ".", "Quad", "to", "its", "protobuf", "representation", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/quad/pquads/quads.go#L134-L141
train
cayleygraph/cayley
quad/pquads/quads.go
ToNative
func (m *Quad) ToNative() (q quad.Quad) { if m == nil { return } if m.SubjectValue != nil { q.Subject = m.SubjectValue.ToNative() } else if m.Subject != "" { q.Subject = quad.StringToValue(m.Subject) } if m.PredicateValue != nil { q.Predicate = m.PredicateValue.ToNative() } else if m.Predicate != "" { q.Predicate = quad.StringToValue(m.Predicate) } if m.ObjectValue != nil { q.Object = m.ObjectValue.ToNative() } else if m.Object != "" { q.Object = quad.StringToValue(m.Object) } if m.LabelValue != nil { q.Label = m.LabelValue.ToNative() } else if m.Label != "" { q.Label = quad.StringToValue(m.Label) } return }
go
func (m *Quad) ToNative() (q quad.Quad) { if m == nil { return } if m.SubjectValue != nil { q.Subject = m.SubjectValue.ToNative() } else if m.Subject != "" { q.Subject = quad.StringToValue(m.Subject) } if m.PredicateValue != nil { q.Predicate = m.PredicateValue.ToNative() } else if m.Predicate != "" { q.Predicate = quad.StringToValue(m.Predicate) } if m.ObjectValue != nil { q.Object = m.ObjectValue.ToNative() } else if m.Object != "" { q.Object = quad.StringToValue(m.Object) } if m.LabelValue != nil { q.Label = m.LabelValue.ToNative() } else if m.Label != "" { q.Label = quad.StringToValue(m.Label) } return }
[ "func", "(", "m", "*", "Quad", ")", "ToNative", "(", ")", "(", "q", "quad", ".", "Quad", ")", "{", "if", "m", "==", "nil", "{", "return", "\n", "}", "\n", "if", "m", ".", "SubjectValue", "!=", "nil", "{", "q", ".", "Subject", "=", "m", ".", "SubjectValue", ".", "ToNative", "(", ")", "\n", "}", "else", "if", "m", ".", "Subject", "!=", "\"", "\"", "{", "q", ".", "Subject", "=", "quad", ".", "StringToValue", "(", "m", ".", "Subject", ")", "\n", "}", "\n", "if", "m", ".", "PredicateValue", "!=", "nil", "{", "q", ".", "Predicate", "=", "m", ".", "PredicateValue", ".", "ToNative", "(", ")", "\n", "}", "else", "if", "m", ".", "Predicate", "!=", "\"", "\"", "{", "q", ".", "Predicate", "=", "quad", ".", "StringToValue", "(", "m", ".", "Predicate", ")", "\n", "}", "\n", "if", "m", ".", "ObjectValue", "!=", "nil", "{", "q", ".", "Object", "=", "m", ".", "ObjectValue", ".", "ToNative", "(", ")", "\n", "}", "else", "if", "m", ".", "Object", "!=", "\"", "\"", "{", "q", ".", "Object", "=", "quad", ".", "StringToValue", "(", "m", ".", "Object", ")", "\n", "}", "\n", "if", "m", ".", "LabelValue", "!=", "nil", "{", "q", ".", "Label", "=", "m", ".", "LabelValue", ".", "ToNative", "(", ")", "\n", "}", "else", "if", "m", ".", "Label", "!=", "\"", "\"", "{", "q", ".", "Label", "=", "quad", ".", "StringToValue", "(", "m", ".", "Label", ")", "\n", "}", "\n", "return", "\n", "}" ]
// ToNative converts protobuf Quad to quad.Quad.
[ "ToNative", "converts", "protobuf", "Quad", "to", "quad", ".", "Quad", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/quad/pquads/quads.go#L184-L209
train
cayleygraph/cayley
quad/pquads/quads.go
ToNative
func (m *StrictQuad) ToNative() (q quad.Quad) { if m == nil { return } if m.Subject != nil { q.Subject = m.Subject.ToNative() } if m.Predicate != nil { q.Predicate = m.Predicate.ToNative() } if m.Object != nil { q.Object = m.Object.ToNative() } if m.Label != nil { q.Label = m.Label.ToNative() } return }
go
func (m *StrictQuad) ToNative() (q quad.Quad) { if m == nil { return } if m.Subject != nil { q.Subject = m.Subject.ToNative() } if m.Predicate != nil { q.Predicate = m.Predicate.ToNative() } if m.Object != nil { q.Object = m.Object.ToNative() } if m.Label != nil { q.Label = m.Label.ToNative() } return }
[ "func", "(", "m", "*", "StrictQuad", ")", "ToNative", "(", ")", "(", "q", "quad", ".", "Quad", ")", "{", "if", "m", "==", "nil", "{", "return", "\n", "}", "\n", "if", "m", ".", "Subject", "!=", "nil", "{", "q", ".", "Subject", "=", "m", ".", "Subject", ".", "ToNative", "(", ")", "\n", "}", "\n", "if", "m", ".", "Predicate", "!=", "nil", "{", "q", ".", "Predicate", "=", "m", ".", "Predicate", ".", "ToNative", "(", ")", "\n", "}", "\n", "if", "m", ".", "Object", "!=", "nil", "{", "q", ".", "Object", "=", "m", ".", "Object", ".", "ToNative", "(", ")", "\n", "}", "\n", "if", "m", ".", "Label", "!=", "nil", "{", "q", ".", "Label", "=", "m", ".", "Label", ".", "ToNative", "(", ")", "\n", "}", "\n", "return", "\n", "}" ]
// ToNative converts protobuf StrictQuad to quad.Quad.
[ "ToNative", "converts", "protobuf", "StrictQuad", "to", "quad", ".", "Quad", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/quad/pquads/quads.go#L212-L229
train
cayleygraph/cayley
quad/formats.go
RegisterFormat
func RegisterFormat(f Format) { if _, ok := formatsByName[f.Name]; ok { panic(fmt.Errorf("format %s is allready registered", f.Name)) } formatsByName[f.Name] = &f for _, m := range f.Ext { if sf, ok := formatsByExt[m]; ok { panic(fmt.Errorf("format %s is allready registered with MIME %s", sf.Name, m)) } formatsByExt[m] = &f } for _, m := range f.Mime { if sf, ok := formatsByMime[m]; ok { panic(fmt.Errorf("format %s is allready registered with MIME %s", sf.Name, m)) } formatsByMime[m] = &f } }
go
func RegisterFormat(f Format) { if _, ok := formatsByName[f.Name]; ok { panic(fmt.Errorf("format %s is allready registered", f.Name)) } formatsByName[f.Name] = &f for _, m := range f.Ext { if sf, ok := formatsByExt[m]; ok { panic(fmt.Errorf("format %s is allready registered with MIME %s", sf.Name, m)) } formatsByExt[m] = &f } for _, m := range f.Mime { if sf, ok := formatsByMime[m]; ok { panic(fmt.Errorf("format %s is allready registered with MIME %s", sf.Name, m)) } formatsByMime[m] = &f } }
[ "func", "RegisterFormat", "(", "f", "Format", ")", "{", "if", "_", ",", "ok", ":=", "formatsByName", "[", "f", ".", "Name", "]", ";", "ok", "{", "panic", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "f", ".", "Name", ")", ")", "\n", "}", "\n", "formatsByName", "[", "f", ".", "Name", "]", "=", "&", "f", "\n", "for", "_", ",", "m", ":=", "range", "f", ".", "Ext", "{", "if", "sf", ",", "ok", ":=", "formatsByExt", "[", "m", "]", ";", "ok", "{", "panic", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "sf", ".", "Name", ",", "m", ")", ")", "\n", "}", "\n", "formatsByExt", "[", "m", "]", "=", "&", "f", "\n", "}", "\n", "for", "_", ",", "m", ":=", "range", "f", ".", "Mime", "{", "if", "sf", ",", "ok", ":=", "formatsByMime", "[", "m", "]", ";", "ok", "{", "panic", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "sf", ".", "Name", ",", "m", ")", ")", "\n", "}", "\n", "formatsByMime", "[", "m", "]", "=", "&", "f", "\n", "}", "\n", "}" ]
// RegisterFormat registers a new quad-file format.
[ "RegisterFormat", "registers", "a", "new", "quad", "-", "file", "format", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/quad/formats.go#L35-L52
train
cayleygraph/cayley
quad/formats.go
Formats
func Formats() []Format { list := make([]Format, 0, len(formatsByName)) for _, f := range formatsByName { list = append(list, *f) } return list }
go
func Formats() []Format { list := make([]Format, 0, len(formatsByName)) for _, f := range formatsByName { list = append(list, *f) } return list }
[ "func", "Formats", "(", ")", "[", "]", "Format", "{", "list", ":=", "make", "(", "[", "]", "Format", ",", "0", ",", "len", "(", "formatsByName", ")", ")", "\n", "for", "_", ",", "f", ":=", "range", "formatsByName", "{", "list", "=", "append", "(", "list", ",", "*", "f", ")", "\n", "}", "\n", "return", "list", "\n", "}" ]
// Formats returns a list of all supported quad formats.
[ "Formats", "returns", "a", "list", "of", "all", "supported", "quad", "formats", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/quad/formats.go#L73-L79
train
cayleygraph/cayley
graph/iterator/regex.go
Optimize
func (it *Regex) Optimize() (graph.Iterator, bool) { newSub, changed := it.subIt.Optimize() if changed { it.subIt.Close() it.subIt = newSub } return it, false }
go
func (it *Regex) Optimize() (graph.Iterator, bool) { newSub, changed := it.subIt.Optimize() if changed { it.subIt.Close() it.subIt = newSub } return it, false }
[ "func", "(", "it", "*", "Regex", ")", "Optimize", "(", ")", "(", "graph", ".", "Iterator", ",", "bool", ")", "{", "newSub", ",", "changed", ":=", "it", ".", "subIt", ".", "Optimize", "(", ")", "\n", "if", "changed", "{", "it", ".", "subIt", ".", "Close", "(", ")", "\n", "it", ".", "subIt", "=", "newSub", "\n", "}", "\n", "return", "it", ",", "false", "\n", "}" ]
// There's nothing to optimize, locally, for a Regex iterator. // Replace the underlying iterator if need be.
[ "There", "s", "nothing", "to", "optimize", "locally", "for", "a", "Regex", "iterator", ".", "Replace", "the", "underlying", "iterator", "if", "need", "be", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterator/regex.go#L175-L182
train
cayleygraph/cayley
graph/iterator/optional.go
NewOptional
func NewOptional(it graph.Iterator) *Optional { return &Optional{ uid: NextUID(), subIt: it, } }
go
func NewOptional(it graph.Iterator) *Optional { return &Optional{ uid: NextUID(), subIt: it, } }
[ "func", "NewOptional", "(", "it", "graph", ".", "Iterator", ")", "*", "Optional", "{", "return", "&", "Optional", "{", "uid", ":", "NextUID", "(", ")", ",", "subIt", ":", "it", ",", "}", "\n", "}" ]
// Creates a new optional iterator.
[ "Creates", "a", "new", "optional", "iterator", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterator/optional.go#L53-L58
train
cayleygraph/cayley
graph/iterator/optional.go
Stats
func (it *Optional) Stats() graph.IteratorStats { subStats := it.subIt.Stats() return graph.IteratorStats{ ContainsCost: subStats.ContainsCost, NextCost: int64(1 << 62), // If it's empty, pretend like it's not. Size: subStats.Size + 1, ExactSize: subStats.ExactSize, } }
go
func (it *Optional) Stats() graph.IteratorStats { subStats := it.subIt.Stats() return graph.IteratorStats{ ContainsCost: subStats.ContainsCost, NextCost: int64(1 << 62), // If it's empty, pretend like it's not. Size: subStats.Size + 1, ExactSize: subStats.ExactSize, } }
[ "func", "(", "it", "*", "Optional", ")", "Stats", "(", ")", "graph", ".", "IteratorStats", "{", "subStats", ":=", "it", ".", "subIt", ".", "Stats", "(", ")", "\n", "return", "graph", ".", "IteratorStats", "{", "ContainsCost", ":", "subStats", ".", "ContainsCost", ",", "NextCost", ":", "int64", "(", "1", "<<", "62", ")", ",", "// If it's empty, pretend like it's not.", "Size", ":", "subStats", ".", "Size", "+", "1", ",", "ExactSize", ":", "subStats", ".", "ExactSize", ",", "}", "\n", "}" ]
// We're only as expensive as our subiterator. Except, we can't be nexted.
[ "We", "re", "only", "as", "expensive", "as", "our", "subiterator", ".", "Except", "we", "can", "t", "be", "nexted", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterator/optional.go#L159-L168
train
cayleygraph/cayley
graph/nosql/value.go
ValuesEqual
func ValuesEqual(v1, v2 Value) bool { switch v1 := v2.(type) { case Document: v2, ok := v2.(Document) if !ok || len(v1) != len(v2) { return false } for k, s1 := range v1 { if s2, ok := v2[k]; !ok || !ValuesEqual(s1, s2) { return false } } return true case Strings: v2, ok := v2.(Strings) if !ok || len(v1) != len(v2) { return false } for i := range v1 { if v1[i] != v2[i] { return false } } return true case Bytes: v2, ok := v2.(Bytes) if !ok || len(v1) != len(v2) { return false } return bytes.Equal(v1, v2) case Time: v2, ok := v2.(Time) if !ok { return false } return time.Time(v1).Equal(time.Time(v2)) } return v1 == v2 }
go
func ValuesEqual(v1, v2 Value) bool { switch v1 := v2.(type) { case Document: v2, ok := v2.(Document) if !ok || len(v1) != len(v2) { return false } for k, s1 := range v1 { if s2, ok := v2[k]; !ok || !ValuesEqual(s1, s2) { return false } } return true case Strings: v2, ok := v2.(Strings) if !ok || len(v1) != len(v2) { return false } for i := range v1 { if v1[i] != v2[i] { return false } } return true case Bytes: v2, ok := v2.(Bytes) if !ok || len(v1) != len(v2) { return false } return bytes.Equal(v1, v2) case Time: v2, ok := v2.(Time) if !ok { return false } return time.Time(v1).Equal(time.Time(v2)) } return v1 == v2 }
[ "func", "ValuesEqual", "(", "v1", ",", "v2", "Value", ")", "bool", "{", "switch", "v1", ":=", "v2", ".", "(", "type", ")", "{", "case", "Document", ":", "v2", ",", "ok", ":=", "v2", ".", "(", "Document", ")", "\n", "if", "!", "ok", "||", "len", "(", "v1", ")", "!=", "len", "(", "v2", ")", "{", "return", "false", "\n", "}", "\n", "for", "k", ",", "s1", ":=", "range", "v1", "{", "if", "s2", ",", "ok", ":=", "v2", "[", "k", "]", ";", "!", "ok", "||", "!", "ValuesEqual", "(", "s1", ",", "s2", ")", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "case", "Strings", ":", "v2", ",", "ok", ":=", "v2", ".", "(", "Strings", ")", "\n", "if", "!", "ok", "||", "len", "(", "v1", ")", "!=", "len", "(", "v2", ")", "{", "return", "false", "\n", "}", "\n", "for", "i", ":=", "range", "v1", "{", "if", "v1", "[", "i", "]", "!=", "v2", "[", "i", "]", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "case", "Bytes", ":", "v2", ",", "ok", ":=", "v2", ".", "(", "Bytes", ")", "\n", "if", "!", "ok", "||", "len", "(", "v1", ")", "!=", "len", "(", "v2", ")", "{", "return", "false", "\n", "}", "\n", "return", "bytes", ".", "Equal", "(", "v1", ",", "v2", ")", "\n", "case", "Time", ":", "v2", ",", "ok", ":=", "v2", ".", "(", "Time", ")", "\n", "if", "!", "ok", "{", "return", "false", "\n", "}", "\n", "return", "time", ".", "Time", "(", "v1", ")", ".", "Equal", "(", "time", ".", "Time", "(", "v2", ")", ")", "\n", "}", "\n", "return", "v1", "==", "v2", "\n", "}" ]
// ValuesEqual returns true if values are strictly equal.
[ "ValuesEqual", "returns", "true", "if", "values", "are", "strictly", "equal", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/nosql/value.go#L67-L105
train
cayleygraph/cayley
graph/nosql/value.go
CompareValues
func CompareValues(v1, v2 Value) int { switch v1 := v1.(type) { case Document: v2, ok := v2.(Document) if !ok { return -1 } else if len(v1) != len(v2) { return len(v1) - len(v2) } return -1 // TODO: implement proper sorting? case Strings: v2, ok := v2.(Strings) if !ok { return -1 } else if len(v1) != len(v2) { return len(v1) - len(v2) } for i := range v1 { if dn := CompareValues(String(v1[i]), String(v2[i])); dn != 0 { return dn } } return 0 case Bytes: v2, ok := v2.(Bytes) if !ok { return -1 } return bytes.Compare(v1, v2) case Time: v2, ok := v2.(Time) if !ok { return -1 } t1, t2 := time.Time(v1), time.Time(v2) if t1.Equal(t2) { return 0 } else if t1.Before(t2) { return -1 } return +1 case String: v2, ok := v2.(String) if !ok { return -1 } return strings.Compare(string(v1), string(v2)) case Int: v2, ok := v2.(Int) if !ok { return -1 } if v1 == v2 { return 0 } else if v1 < v2 { return -1 } return +1 case Float: v2, ok := v2.(Float) if !ok { return -1 } if v1 == v2 { return 0 } else if v1 < v2 { return -1 } return +1 } return -1 }
go
func CompareValues(v1, v2 Value) int { switch v1 := v1.(type) { case Document: v2, ok := v2.(Document) if !ok { return -1 } else if len(v1) != len(v2) { return len(v1) - len(v2) } return -1 // TODO: implement proper sorting? case Strings: v2, ok := v2.(Strings) if !ok { return -1 } else if len(v1) != len(v2) { return len(v1) - len(v2) } for i := range v1 { if dn := CompareValues(String(v1[i]), String(v2[i])); dn != 0 { return dn } } return 0 case Bytes: v2, ok := v2.(Bytes) if !ok { return -1 } return bytes.Compare(v1, v2) case Time: v2, ok := v2.(Time) if !ok { return -1 } t1, t2 := time.Time(v1), time.Time(v2) if t1.Equal(t2) { return 0 } else if t1.Before(t2) { return -1 } return +1 case String: v2, ok := v2.(String) if !ok { return -1 } return strings.Compare(string(v1), string(v2)) case Int: v2, ok := v2.(Int) if !ok { return -1 } if v1 == v2 { return 0 } else if v1 < v2 { return -1 } return +1 case Float: v2, ok := v2.(Float) if !ok { return -1 } if v1 == v2 { return 0 } else if v1 < v2 { return -1 } return +1 } return -1 }
[ "func", "CompareValues", "(", "v1", ",", "v2", "Value", ")", "int", "{", "switch", "v1", ":=", "v1", ".", "(", "type", ")", "{", "case", "Document", ":", "v2", ",", "ok", ":=", "v2", ".", "(", "Document", ")", "\n", "if", "!", "ok", "{", "return", "-", "1", "\n", "}", "else", "if", "len", "(", "v1", ")", "!=", "len", "(", "v2", ")", "{", "return", "len", "(", "v1", ")", "-", "len", "(", "v2", ")", "\n", "}", "\n", "return", "-", "1", "// TODO: implement proper sorting?", "\n", "case", "Strings", ":", "v2", ",", "ok", ":=", "v2", ".", "(", "Strings", ")", "\n", "if", "!", "ok", "{", "return", "-", "1", "\n", "}", "else", "if", "len", "(", "v1", ")", "!=", "len", "(", "v2", ")", "{", "return", "len", "(", "v1", ")", "-", "len", "(", "v2", ")", "\n", "}", "\n", "for", "i", ":=", "range", "v1", "{", "if", "dn", ":=", "CompareValues", "(", "String", "(", "v1", "[", "i", "]", ")", ",", "String", "(", "v2", "[", "i", "]", ")", ")", ";", "dn", "!=", "0", "{", "return", "dn", "\n", "}", "\n", "}", "\n", "return", "0", "\n", "case", "Bytes", ":", "v2", ",", "ok", ":=", "v2", ".", "(", "Bytes", ")", "\n", "if", "!", "ok", "{", "return", "-", "1", "\n", "}", "\n", "return", "bytes", ".", "Compare", "(", "v1", ",", "v2", ")", "\n", "case", "Time", ":", "v2", ",", "ok", ":=", "v2", ".", "(", "Time", ")", "\n", "if", "!", "ok", "{", "return", "-", "1", "\n", "}", "\n", "t1", ",", "t2", ":=", "time", ".", "Time", "(", "v1", ")", ",", "time", ".", "Time", "(", "v2", ")", "\n", "if", "t1", ".", "Equal", "(", "t2", ")", "{", "return", "0", "\n", "}", "else", "if", "t1", ".", "Before", "(", "t2", ")", "{", "return", "-", "1", "\n", "}", "\n", "return", "+", "1", "\n", "case", "String", ":", "v2", ",", "ok", ":=", "v2", ".", "(", "String", ")", "\n", "if", "!", "ok", "{", "return", "-", "1", "\n", "}", "\n", "return", "strings", ".", "Compare", "(", "string", "(", "v1", ")", ",", "string", "(", "v2", ")", ")", "\n", "case", "Int", ":", "v2", ",", "ok", ":=", "v2", ".", "(", "Int", ")", "\n", "if", "!", "ok", "{", "return", "-", "1", "\n", "}", "\n", "if", "v1", "==", "v2", "{", "return", "0", "\n", "}", "else", "if", "v1", "<", "v2", "{", "return", "-", "1", "\n", "}", "\n", "return", "+", "1", "\n", "case", "Float", ":", "v2", ",", "ok", ":=", "v2", ".", "(", "Float", ")", "\n", "if", "!", "ok", "{", "return", "-", "1", "\n", "}", "\n", "if", "v1", "==", "v2", "{", "return", "0", "\n", "}", "else", "if", "v1", "<", "v2", "{", "return", "-", "1", "\n", "}", "\n", "return", "+", "1", "\n", "}", "\n", "return", "-", "1", "\n", "}" ]
// CompareValues return 0 if values are equal, positive value if first value sorts after second, and negative otherwise.
[ "CompareValues", "return", "0", "if", "values", "are", "equal", "positive", "value", "if", "first", "value", "sorts", "after", "second", "and", "negative", "otherwise", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/nosql/value.go#L108-L179
train
cayleygraph/cayley
graph/iterator/fixed.go
NewFixed
func NewFixed(vals ...graph.Value) *Fixed { it := &Fixed{ uid: NextUID(), values: make([]graph.Value, 0, 20), } for _, v := range vals { it.Add(v) } return it }
go
func NewFixed(vals ...graph.Value) *Fixed { it := &Fixed{ uid: NextUID(), values: make([]graph.Value, 0, 20), } for _, v := range vals { it.Add(v) } return it }
[ "func", "NewFixed", "(", "vals", "...", "graph", ".", "Value", ")", "*", "Fixed", "{", "it", ":=", "&", "Fixed", "{", "uid", ":", "NextUID", "(", ")", ",", "values", ":", "make", "(", "[", "]", "graph", ".", "Value", ",", "0", ",", "20", ")", ",", "}", "\n", "for", "_", ",", "v", ":=", "range", "vals", "{", "it", ".", "Add", "(", "v", ")", "\n", "}", "\n", "return", "it", "\n", "}" ]
// Creates a new Fixed iterator with a custom comparator.
[ "Creates", "a", "new", "Fixed", "iterator", "with", "a", "custom", "comparator", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterator/fixed.go#L43-L52
train
cayleygraph/cayley
graph/iterator/fixed.go
Contains
func (it *Fixed) Contains(ctx context.Context, v graph.Value) bool { // Could be optimized by keeping it sorted or using a better datastructure. // However, for fixed iterators, which are by definition kind of tiny, this // isn't a big issue. graph.ContainsLogIn(it, v) vk := graph.ToKey(v) for _, x := range it.values { if graph.ToKey(x) == vk { it.result = x return graph.ContainsLogOut(it, v, true) } } return graph.ContainsLogOut(it, v, false) }
go
func (it *Fixed) Contains(ctx context.Context, v graph.Value) bool { // Could be optimized by keeping it sorted or using a better datastructure. // However, for fixed iterators, which are by definition kind of tiny, this // isn't a big issue. graph.ContainsLogIn(it, v) vk := graph.ToKey(v) for _, x := range it.values { if graph.ToKey(x) == vk { it.result = x return graph.ContainsLogOut(it, v, true) } } return graph.ContainsLogOut(it, v, false) }
[ "func", "(", "it", "*", "Fixed", ")", "Contains", "(", "ctx", "context", ".", "Context", ",", "v", "graph", ".", "Value", ")", "bool", "{", "// Could be optimized by keeping it sorted or using a better datastructure.", "// However, for fixed iterators, which are by definition kind of tiny, this", "// isn't a big issue.", "graph", ".", "ContainsLogIn", "(", "it", ",", "v", ")", "\n", "vk", ":=", "graph", ".", "ToKey", "(", "v", ")", "\n", "for", "_", ",", "x", ":=", "range", "it", ".", "values", "{", "if", "graph", ".", "ToKey", "(", "x", ")", "==", "vk", "{", "it", ".", "result", "=", "x", "\n", "return", "graph", ".", "ContainsLogOut", "(", "it", ",", "v", ",", "true", ")", "\n", "}", "\n", "}", "\n", "return", "graph", ".", "ContainsLogOut", "(", "it", ",", "v", ",", "false", ")", "\n", "}" ]
// Check if the passed value is equal to one of the values stored in the iterator.
[ "Check", "if", "the", "passed", "value", "is", "equal", "to", "one", "of", "the", "values", "stored", "in", "the", "iterator", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterator/fixed.go#L101-L114
train
cayleygraph/cayley
graph/iterator/fixed.go
Size
func (it *Fixed) Size() (int64, bool) { return int64(len(it.values)), true }
go
func (it *Fixed) Size() (int64, bool) { return int64(len(it.values)), true }
[ "func", "(", "it", "*", "Fixed", ")", "Size", "(", ")", "(", "int64", ",", "bool", ")", "{", "return", "int64", "(", "len", "(", "it", ".", "values", ")", ")", ",", "true", "\n", "}" ]
// Size is the number of values stored.
[ "Size", "is", "the", "number", "of", "values", "stored", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterator/fixed.go#L157-L159
train
cayleygraph/cayley
schema/loader.go
LoadToDepth
func (c *Config) LoadToDepth(ctx context.Context, qs graph.QuadStore, dst interface{}, depth int, ids ...quad.Value) error { if dst == nil { return fmt.Errorf("nil destination object") } var it graph.Iterator if len(ids) != 0 { fixed := iterator.NewFixed() for _, id := range ids { fixed.Add(qs.ValueOf(id)) } it = fixed } var rv reflect.Value if v, ok := dst.(reflect.Value); ok { rv = v } else { rv = reflect.ValueOf(dst) } return c.LoadIteratorToDepth(ctx, qs, rv, depth, it) }
go
func (c *Config) LoadToDepth(ctx context.Context, qs graph.QuadStore, dst interface{}, depth int, ids ...quad.Value) error { if dst == nil { return fmt.Errorf("nil destination object") } var it graph.Iterator if len(ids) != 0 { fixed := iterator.NewFixed() for _, id := range ids { fixed.Add(qs.ValueOf(id)) } it = fixed } var rv reflect.Value if v, ok := dst.(reflect.Value); ok { rv = v } else { rv = reflect.ValueOf(dst) } return c.LoadIteratorToDepth(ctx, qs, rv, depth, it) }
[ "func", "(", "c", "*", "Config", ")", "LoadToDepth", "(", "ctx", "context", ".", "Context", ",", "qs", "graph", ".", "QuadStore", ",", "dst", "interface", "{", "}", ",", "depth", "int", ",", "ids", "...", "quad", ".", "Value", ")", "error", "{", "if", "dst", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "var", "it", "graph", ".", "Iterator", "\n", "if", "len", "(", "ids", ")", "!=", "0", "{", "fixed", ":=", "iterator", ".", "NewFixed", "(", ")", "\n", "for", "_", ",", "id", ":=", "range", "ids", "{", "fixed", ".", "Add", "(", "qs", ".", "ValueOf", "(", "id", ")", ")", "\n", "}", "\n", "it", "=", "fixed", "\n", "}", "\n", "var", "rv", "reflect", ".", "Value", "\n", "if", "v", ",", "ok", ":=", "dst", ".", "(", "reflect", ".", "Value", ")", ";", "ok", "{", "rv", "=", "v", "\n", "}", "else", "{", "rv", "=", "reflect", ".", "ValueOf", "(", "dst", ")", "\n", "}", "\n", "return", "c", ".", "LoadIteratorToDepth", "(", "ctx", ",", "qs", ",", "rv", ",", "depth", ",", "it", ")", "\n", "}" ]
// LoadToDepth is the same as LoadTo, but stops at a specified depth. // Negative value means unlimited depth, and zero means top level only.
[ "LoadToDepth", "is", "the", "same", "as", "LoadTo", "but", "stops", "at", "a", "specified", "depth", ".", "Negative", "value", "means", "unlimited", "depth", "and", "zero", "means", "top", "level", "only", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/schema/loader.go#L98-L117
train
cayleygraph/cayley
schema/loader.go
LoadPathTo
func (c *Config) LoadPathTo(ctx context.Context, qs graph.QuadStore, dst interface{}, p *path.Path) error { return c.LoadIteratorTo(ctx, qs, reflect.ValueOf(dst), p.BuildIterator()) }
go
func (c *Config) LoadPathTo(ctx context.Context, qs graph.QuadStore, dst interface{}, p *path.Path) error { return c.LoadIteratorTo(ctx, qs, reflect.ValueOf(dst), p.BuildIterator()) }
[ "func", "(", "c", "*", "Config", ")", "LoadPathTo", "(", "ctx", "context", ".", "Context", ",", "qs", "graph", ".", "QuadStore", ",", "dst", "interface", "{", "}", ",", "p", "*", "path", ".", "Path", ")", "error", "{", "return", "c", ".", "LoadIteratorTo", "(", "ctx", ",", "qs", ",", "reflect", ".", "ValueOf", "(", "dst", ")", ",", "p", ".", "BuildIterator", "(", ")", ")", "\n", "}" ]
// LoadPathTo is the same as LoadTo, but starts loading objects from a given path.
[ "LoadPathTo", "is", "the", "same", "as", "LoadTo", "but", "starts", "loading", "objects", "from", "a", "given", "path", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/schema/loader.go#L120-L122
train
cayleygraph/cayley
schema/loader.go
LoadIteratorToDepth
func (c *Config) LoadIteratorToDepth(ctx context.Context, qs graph.QuadStore, dst reflect.Value, depth int, list graph.Iterator) error { if depth >= 0 { // 0 depth means "current level only" for user, but it's easier to make depth=0 a stop condition depth++ } l := c.newLoader(qs) return l.loadIteratorToDepth(ctx, dst, depth, list) }
go
func (c *Config) LoadIteratorToDepth(ctx context.Context, qs graph.QuadStore, dst reflect.Value, depth int, list graph.Iterator) error { if depth >= 0 { // 0 depth means "current level only" for user, but it's easier to make depth=0 a stop condition depth++ } l := c.newLoader(qs) return l.loadIteratorToDepth(ctx, dst, depth, list) }
[ "func", "(", "c", "*", "Config", ")", "LoadIteratorToDepth", "(", "ctx", "context", ".", "Context", ",", "qs", "graph", ".", "QuadStore", ",", "dst", "reflect", ".", "Value", ",", "depth", "int", ",", "list", "graph", ".", "Iterator", ")", "error", "{", "if", "depth", ">=", "0", "{", "// 0 depth means \"current level only\" for user, but it's easier to make depth=0 a stop condition", "depth", "++", "\n", "}", "\n", "l", ":=", "c", ".", "newLoader", "(", "qs", ")", "\n", "return", "l", ".", "loadIteratorToDepth", "(", "ctx", ",", "dst", ",", "depth", ",", "list", ")", "\n", "}" ]
// LoadIteratorToDepth is the same as LoadIteratorTo, but stops at a specified depth. // Negative value means unlimited depth, and zero means top level only.
[ "LoadIteratorToDepth", "is", "the", "same", "as", "LoadIteratorTo", "but", "stops", "at", "a", "specified", "depth", ".", "Negative", "value", "means", "unlimited", "depth", "and", "zero", "means", "top", "level", "only", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/schema/loader.go#L136-L143
train
cayleygraph/cayley
internal/decompressor/decompressor.go
New
func New(r io.Reader) (io.Reader, error) { br := bufio.NewReader(r) buf, err := br.Peek(3) if err != nil { return nil, err } switch { case bytes.Compare(buf[:2], []byte(gzipMagic)) == 0: return gzip.NewReader(br) case bytes.Compare(buf[:3], []byte(b2zipMagic)) == 0: return bzip2.NewReader(br), nil default: return br, nil } }
go
func New(r io.Reader) (io.Reader, error) { br := bufio.NewReader(r) buf, err := br.Peek(3) if err != nil { return nil, err } switch { case bytes.Compare(buf[:2], []byte(gzipMagic)) == 0: return gzip.NewReader(br) case bytes.Compare(buf[:3], []byte(b2zipMagic)) == 0: return bzip2.NewReader(br), nil default: return br, nil } }
[ "func", "New", "(", "r", "io", ".", "Reader", ")", "(", "io", ".", "Reader", ",", "error", ")", "{", "br", ":=", "bufio", ".", "NewReader", "(", "r", ")", "\n", "buf", ",", "err", ":=", "br", ".", "Peek", "(", "3", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "switch", "{", "case", "bytes", ".", "Compare", "(", "buf", "[", ":", "2", "]", ",", "[", "]", "byte", "(", "gzipMagic", ")", ")", "==", "0", ":", "return", "gzip", ".", "NewReader", "(", "br", ")", "\n", "case", "bytes", ".", "Compare", "(", "buf", "[", ":", "3", "]", ",", "[", "]", "byte", "(", "b2zipMagic", ")", ")", "==", "0", ":", "return", "bzip2", ".", "NewReader", "(", "br", ")", ",", "nil", "\n", "default", ":", "return", "br", ",", "nil", "\n", "}", "\n", "}" ]
// New detects the file type of an io.Reader between // bzip, gzip, or raw quad file.
[ "New", "detects", "the", "file", "type", "of", "an", "io", ".", "Reader", "between", "bzip", "gzip", "or", "raw", "quad", "file", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/internal/decompressor/decompressor.go#L32-L46
train
cayleygraph/cayley
graph/gaedatastore/config.go
LoadConf
func LoadConf(file string) (*Config, error) { config := &Config{} if file == "" { return config, nil } f, err := os.Open(file) if err != nil { return nil, fmt.Errorf("could not open config file %q: %v", file, err) } defer f.Close() dec := json.NewDecoder(f) err = dec.Decode(config) if err != nil { return nil, fmt.Errorf("could not parse config file %q: %v", file, err) } return config, nil }
go
func LoadConf(file string) (*Config, error) { config := &Config{} if file == "" { return config, nil } f, err := os.Open(file) if err != nil { return nil, fmt.Errorf("could not open config file %q: %v", file, err) } defer f.Close() dec := json.NewDecoder(f) err = dec.Decode(config) if err != nil { return nil, fmt.Errorf("could not parse config file %q: %v", file, err) } return config, nil }
[ "func", "LoadConf", "(", "file", "string", ")", "(", "*", "Config", ",", "error", ")", "{", "config", ":=", "&", "Config", "{", "}", "\n", "if", "file", "==", "\"", "\"", "{", "return", "config", ",", "nil", "\n", "}", "\n", "f", ",", "err", ":=", "os", ".", "Open", "(", "file", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "file", ",", "err", ")", "\n", "}", "\n", "defer", "f", ".", "Close", "(", ")", "\n\n", "dec", ":=", "json", ".", "NewDecoder", "(", "f", ")", "\n", "err", "=", "dec", ".", "Decode", "(", "config", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "file", ",", "err", ")", "\n", "}", "\n", "return", "config", ",", "nil", "\n", "}" ]
// Load reads a JSON-encoded config contained in the given file. A zero value // config is returned if the filename is empty.
[ "Load", "reads", "a", "JSON", "-", "encoded", "config", "contained", "in", "the", "given", "file", ".", "A", "zero", "value", "config", "is", "returned", "if", "the", "filename", "is", "empty", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/gaedatastore/config.go#L125-L142
train
cayleygraph/cayley
graph/iterate.go
Iterate
func Iterate(ctx context.Context, it Iterator) *IterateChain { if ctx == nil { ctx = context.Background() } return &IterateChain{ ctx: ctx, it: it, limit: -1, paths: true, optimize: true, } }
go
func Iterate(ctx context.Context, it Iterator) *IterateChain { if ctx == nil { ctx = context.Background() } return &IterateChain{ ctx: ctx, it: it, limit: -1, paths: true, optimize: true, } }
[ "func", "Iterate", "(", "ctx", "context", ".", "Context", ",", "it", "Iterator", ")", "*", "IterateChain", "{", "if", "ctx", "==", "nil", "{", "ctx", "=", "context", ".", "Background", "(", ")", "\n", "}", "\n", "return", "&", "IterateChain", "{", "ctx", ":", "ctx", ",", "it", ":", "it", ",", "limit", ":", "-", "1", ",", "paths", ":", "true", ",", "optimize", ":", "true", ",", "}", "\n", "}" ]
// Iterate is a set of helpers for iteration. Context may be used to cancel execution. // Iterator will be optimized and closed after execution. // // By default, iteration has no limit and includes sub-paths.
[ "Iterate", "is", "a", "set", "of", "helpers", "for", "iteration", ".", "Context", "may", "be", "used", "to", "cancel", "execution", ".", "Iterator", "will", "be", "optimized", "and", "closed", "after", "execution", ".", "By", "default", "iteration", "has", "no", "limit", "and", "includes", "sub", "-", "paths", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterate.go#L29-L38
train
cayleygraph/cayley
graph/iterate.go
Limit
func (c *IterateChain) Limit(n int) *IterateChain { c.limit = n return c }
go
func (c *IterateChain) Limit(n int) *IterateChain { c.limit = n return c }
[ "func", "(", "c", "*", "IterateChain", ")", "Limit", "(", "n", "int", ")", "*", "IterateChain", "{", "c", ".", "limit", "=", "n", "\n", "return", "c", "\n", "}" ]
// Limit limits a total number of results returned.
[ "Limit", "limits", "a", "total", "number", "of", "results", "returned", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterate.go#L92-L95
train
cayleygraph/cayley
graph/iterate.go
On
func (c *IterateChain) On(qs QuadStore) *IterateChain { c.qs = qs return c }
go
func (c *IterateChain) On(qs QuadStore) *IterateChain { c.qs = qs return c }
[ "func", "(", "c", "*", "IterateChain", ")", "On", "(", "qs", "QuadStore", ")", "*", "IterateChain", "{", "c", ".", "qs", "=", "qs", "\n", "return", "c", "\n", "}" ]
// On sets a default quad store for iteration. If qs was set, it may be omitted in other functions.
[ "On", "sets", "a", "default", "quad", "store", "for", "iteration", ".", "If", "qs", "was", "set", "it", "may", "be", "omitted", "in", "other", "functions", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterate.go#L105-L108
train
cayleygraph/cayley
graph/iterate.go
Each
func (c *IterateChain) Each(fnc func(Value)) error { c.start() defer c.end() done := c.ctx.Done() for c.next() { select { case <-done: return c.ctx.Err() default: } fnc(c.it.Result()) for c.nextPath() { select { case <-done: return c.ctx.Err() default: } fnc(c.it.Result()) } } return c.it.Err() }
go
func (c *IterateChain) Each(fnc func(Value)) error { c.start() defer c.end() done := c.ctx.Done() for c.next() { select { case <-done: return c.ctx.Err() default: } fnc(c.it.Result()) for c.nextPath() { select { case <-done: return c.ctx.Err() default: } fnc(c.it.Result()) } } return c.it.Err() }
[ "func", "(", "c", "*", "IterateChain", ")", "Each", "(", "fnc", "func", "(", "Value", ")", ")", "error", "{", "c", ".", "start", "(", ")", "\n", "defer", "c", ".", "end", "(", ")", "\n", "done", ":=", "c", ".", "ctx", ".", "Done", "(", ")", "\n\n", "for", "c", ".", "next", "(", ")", "{", "select", "{", "case", "<-", "done", ":", "return", "c", ".", "ctx", ".", "Err", "(", ")", "\n", "default", ":", "}", "\n", "fnc", "(", "c", ".", "it", ".", "Result", "(", ")", ")", "\n", "for", "c", ".", "nextPath", "(", ")", "{", "select", "{", "case", "<-", "done", ":", "return", "c", ".", "ctx", ".", "Err", "(", ")", "\n", "default", ":", "}", "\n", "fnc", "(", "c", ".", "it", ".", "Result", "(", ")", ")", "\n", "}", "\n", "}", "\n", "return", "c", ".", "it", ".", "Err", "(", ")", "\n", "}" ]
// Each will run a provided callback for each result of the iterator.
[ "Each", "will", "run", "a", "provided", "callback", "for", "each", "result", "of", "the", "iterator", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterate.go#L117-L139
train
cayleygraph/cayley
graph/iterate.go
First
func (c *IterateChain) First() (Value, error) { c.start() defer c.end() if !c.next() { return nil, c.it.Err() } return c.it.Result(), nil }
go
func (c *IterateChain) First() (Value, error) { c.start() defer c.end() if !c.next() { return nil, c.it.Err() } return c.it.Result(), nil }
[ "func", "(", "c", "*", "IterateChain", ")", "First", "(", ")", "(", "Value", ",", "error", ")", "{", "c", ".", "start", "(", ")", "\n", "defer", "c", ".", "end", "(", ")", "\n", "if", "!", "c", ".", "next", "(", ")", "{", "return", "nil", ",", "c", ".", "it", ".", "Err", "(", ")", "\n", "}", "\n", "return", "c", ".", "it", ".", "Result", "(", ")", ",", "nil", "\n", "}" ]
// First will return a first result of an iterator. It returns nil if iterator is empty.
[ "First", "will", "return", "a", "first", "result", "of", "an", "iterator", ".", "It", "returns", "nil", "if", "iterator", "is", "empty", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterate.go#L200-L207
train
cayleygraph/cayley
graph/iterate.go
Send
func (c *IterateChain) Send(out chan<- Value) error { c.start() defer c.end() done := c.ctx.Done() for c.next() { select { case <-done: return c.ctx.Err() case out <- c.it.Result(): } for c.nextPath() { select { case <-done: return c.ctx.Err() case out <- c.it.Result(): } } } return c.it.Err() }
go
func (c *IterateChain) Send(out chan<- Value) error { c.start() defer c.end() done := c.ctx.Done() for c.next() { select { case <-done: return c.ctx.Err() case out <- c.it.Result(): } for c.nextPath() { select { case <-done: return c.ctx.Err() case out <- c.it.Result(): } } } return c.it.Err() }
[ "func", "(", "c", "*", "IterateChain", ")", "Send", "(", "out", "chan", "<-", "Value", ")", "error", "{", "c", ".", "start", "(", ")", "\n", "defer", "c", ".", "end", "(", ")", "\n", "done", ":=", "c", ".", "ctx", ".", "Done", "(", ")", "\n", "for", "c", ".", "next", "(", ")", "{", "select", "{", "case", "<-", "done", ":", "return", "c", ".", "ctx", ".", "Err", "(", ")", "\n", "case", "out", "<-", "c", ".", "it", ".", "Result", "(", ")", ":", "}", "\n", "for", "c", ".", "nextPath", "(", ")", "{", "select", "{", "case", "<-", "done", ":", "return", "c", ".", "ctx", ".", "Err", "(", ")", "\n", "case", "out", "<-", "c", ".", "it", ".", "Result", "(", ")", ":", "}", "\n", "}", "\n", "}", "\n", "return", "c", ".", "it", ".", "Err", "(", ")", "\n", "}" ]
// Send will send each result of the iterator to the provided channel. // // Channel will NOT be closed when function returns.
[ "Send", "will", "send", "each", "result", "of", "the", "iterator", "to", "the", "provided", "channel", ".", "Channel", "will", "NOT", "be", "closed", "when", "function", "returns", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterate.go#L212-L231
train
cayleygraph/cayley
graph/iterate.go
TagEach
func (c *IterateChain) TagEach(fnc func(map[string]Value)) error { c.start() defer c.end() done := c.ctx.Done() mn := 0 for c.next() { select { case <-done: return c.ctx.Err() default: } tags := make(map[string]Value, mn) c.it.TagResults(tags) if n := len(tags); n > mn { mn = n } fnc(tags) for c.nextPath() { select { case <-done: return c.ctx.Err() default: } tags := make(map[string]Value, mn) c.it.TagResults(tags) if n := len(tags); n > mn { mn = n } fnc(tags) } } return c.it.Err() }
go
func (c *IterateChain) TagEach(fnc func(map[string]Value)) error { c.start() defer c.end() done := c.ctx.Done() mn := 0 for c.next() { select { case <-done: return c.ctx.Err() default: } tags := make(map[string]Value, mn) c.it.TagResults(tags) if n := len(tags); n > mn { mn = n } fnc(tags) for c.nextPath() { select { case <-done: return c.ctx.Err() default: } tags := make(map[string]Value, mn) c.it.TagResults(tags) if n := len(tags); n > mn { mn = n } fnc(tags) } } return c.it.Err() }
[ "func", "(", "c", "*", "IterateChain", ")", "TagEach", "(", "fnc", "func", "(", "map", "[", "string", "]", "Value", ")", ")", "error", "{", "c", ".", "start", "(", ")", "\n", "defer", "c", ".", "end", "(", ")", "\n", "done", ":=", "c", ".", "ctx", ".", "Done", "(", ")", "\n\n", "mn", ":=", "0", "\n", "for", "c", ".", "next", "(", ")", "{", "select", "{", "case", "<-", "done", ":", "return", "c", ".", "ctx", ".", "Err", "(", ")", "\n", "default", ":", "}", "\n", "tags", ":=", "make", "(", "map", "[", "string", "]", "Value", ",", "mn", ")", "\n", "c", ".", "it", ".", "TagResults", "(", "tags", ")", "\n", "if", "n", ":=", "len", "(", "tags", ")", ";", "n", ">", "mn", "{", "mn", "=", "n", "\n", "}", "\n", "fnc", "(", "tags", ")", "\n", "for", "c", ".", "nextPath", "(", ")", "{", "select", "{", "case", "<-", "done", ":", "return", "c", ".", "ctx", ".", "Err", "(", ")", "\n", "default", ":", "}", "\n", "tags", ":=", "make", "(", "map", "[", "string", "]", "Value", ",", "mn", ")", "\n", "c", ".", "it", ".", "TagResults", "(", "tags", ")", "\n", "if", "n", ":=", "len", "(", "tags", ")", ";", "n", ">", "mn", "{", "mn", "=", "n", "\n", "}", "\n", "fnc", "(", "tags", ")", "\n", "}", "\n", "}", "\n", "return", "c", ".", "it", ".", "Err", "(", ")", "\n", "}" ]
// TagEach will run a provided tag map callback for each result of the iterator.
[ "TagEach", "will", "run", "a", "provided", "tag", "map", "callback", "for", "each", "result", "of", "the", "iterator", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterate.go#L234-L267
train
cayleygraph/cayley
graph/iterate.go
EachValue
func (c *IterateChain) EachValue(qs QuadStore, fnc func(quad.Value)) error { if qs != nil { c.qs = qs } if c.qs == nil { return errNoQuadStore } // TODO(dennwc): batch NameOf? return c.Each(func(v Value) { if nv := c.qs.NameOf(v); nv != nil { fnc(nv) } }) }
go
func (c *IterateChain) EachValue(qs QuadStore, fnc func(quad.Value)) error { if qs != nil { c.qs = qs } if c.qs == nil { return errNoQuadStore } // TODO(dennwc): batch NameOf? return c.Each(func(v Value) { if nv := c.qs.NameOf(v); nv != nil { fnc(nv) } }) }
[ "func", "(", "c", "*", "IterateChain", ")", "EachValue", "(", "qs", "QuadStore", ",", "fnc", "func", "(", "quad", ".", "Value", ")", ")", "error", "{", "if", "qs", "!=", "nil", "{", "c", ".", "qs", "=", "qs", "\n", "}", "\n", "if", "c", ".", "qs", "==", "nil", "{", "return", "errNoQuadStore", "\n", "}", "\n", "// TODO(dennwc): batch NameOf?", "return", "c", ".", "Each", "(", "func", "(", "v", "Value", ")", "{", "if", "nv", ":=", "c", ".", "qs", ".", "NameOf", "(", "v", ")", ";", "nv", "!=", "nil", "{", "fnc", "(", "nv", ")", "\n", "}", "\n", "}", ")", "\n", "}" ]
// EachValue is an analog of Each, but it will additionally call NameOf // for each graph.Value before passing it to a callback.
[ "EachValue", "is", "an", "analog", "of", "Each", "but", "it", "will", "additionally", "call", "NameOf", "for", "each", "graph", ".", "Value", "before", "passing", "it", "to", "a", "callback", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterate.go#L273-L286
train
cayleygraph/cayley
graph/iterate.go
AllValues
func (c *IterateChain) AllValues(qs QuadStore) ([]quad.Value, error) { var out []quad.Value err := c.EachValue(qs, func(v quad.Value) { out = append(out, v) }) return out, err }
go
func (c *IterateChain) AllValues(qs QuadStore) ([]quad.Value, error) { var out []quad.Value err := c.EachValue(qs, func(v quad.Value) { out = append(out, v) }) return out, err }
[ "func", "(", "c", "*", "IterateChain", ")", "AllValues", "(", "qs", "QuadStore", ")", "(", "[", "]", "quad", ".", "Value", ",", "error", ")", "{", "var", "out", "[", "]", "quad", ".", "Value", "\n", "err", ":=", "c", ".", "EachValue", "(", "qs", ",", "func", "(", "v", "quad", ".", "Value", ")", "{", "out", "=", "append", "(", "out", ",", "v", ")", "\n", "}", ")", "\n", "return", "out", ",", "err", "\n", "}" ]
// AllValues is an analog of All, but it will additionally call NameOf // for each graph.Value before returning the results slice.
[ "AllValues", "is", "an", "analog", "of", "All", "but", "it", "will", "additionally", "call", "NameOf", "for", "each", "graph", ".", "Value", "before", "returning", "the", "results", "slice", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterate.go#L307-L313
train
cayleygraph/cayley
graph/iterate.go
FirstValue
func (c *IterateChain) FirstValue(qs QuadStore) (quad.Value, error) { if qs != nil { c.qs = qs } if c.qs == nil { return nil, errNoQuadStore } v, err := c.First() if err != nil || v == nil { return nil, err } // TODO: return an error from NameOf once we have it exposed return c.qs.NameOf(v), nil }
go
func (c *IterateChain) FirstValue(qs QuadStore) (quad.Value, error) { if qs != nil { c.qs = qs } if c.qs == nil { return nil, errNoQuadStore } v, err := c.First() if err != nil || v == nil { return nil, err } // TODO: return an error from NameOf once we have it exposed return c.qs.NameOf(v), nil }
[ "func", "(", "c", "*", "IterateChain", ")", "FirstValue", "(", "qs", "QuadStore", ")", "(", "quad", ".", "Value", ",", "error", ")", "{", "if", "qs", "!=", "nil", "{", "c", ".", "qs", "=", "qs", "\n", "}", "\n", "if", "c", ".", "qs", "==", "nil", "{", "return", "nil", ",", "errNoQuadStore", "\n", "}", "\n", "v", ",", "err", ":=", "c", ".", "First", "(", ")", "\n", "if", "err", "!=", "nil", "||", "v", "==", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "// TODO: return an error from NameOf once we have it exposed", "return", "c", ".", "qs", ".", "NameOf", "(", "v", ")", ",", "nil", "\n", "}" ]
// FirstValue is an analog of First, but it does lookup of a value in QuadStore.
[ "FirstValue", "is", "an", "analog", "of", "First", "but", "it", "does", "lookup", "of", "a", "value", "in", "QuadStore", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterate.go#L316-L329
train
cayleygraph/cayley
graph/iterate.go
SendValues
func (c *IterateChain) SendValues(qs QuadStore, out chan<- quad.Value) error { if qs != nil { c.qs = qs } if c.qs == nil { return errNoQuadStore } c.start() defer c.end() done := c.ctx.Done() send := func(v Value) error { nv := c.qs.NameOf(c.it.Result()) if nv == nil { return nil } select { case <-done: return c.ctx.Err() case out <- c.qs.NameOf(c.it.Result()): } return nil } for c.next() { if err := send(c.it.Result()); err != nil { return err } for c.nextPath() { if err := send(c.it.Result()); err != nil { return err } } } return c.it.Err() }
go
func (c *IterateChain) SendValues(qs QuadStore, out chan<- quad.Value) error { if qs != nil { c.qs = qs } if c.qs == nil { return errNoQuadStore } c.start() defer c.end() done := c.ctx.Done() send := func(v Value) error { nv := c.qs.NameOf(c.it.Result()) if nv == nil { return nil } select { case <-done: return c.ctx.Err() case out <- c.qs.NameOf(c.it.Result()): } return nil } for c.next() { if err := send(c.it.Result()); err != nil { return err } for c.nextPath() { if err := send(c.it.Result()); err != nil { return err } } } return c.it.Err() }
[ "func", "(", "c", "*", "IterateChain", ")", "SendValues", "(", "qs", "QuadStore", ",", "out", "chan", "<-", "quad", ".", "Value", ")", "error", "{", "if", "qs", "!=", "nil", "{", "c", ".", "qs", "=", "qs", "\n", "}", "\n", "if", "c", ".", "qs", "==", "nil", "{", "return", "errNoQuadStore", "\n", "}", "\n", "c", ".", "start", "(", ")", "\n", "defer", "c", ".", "end", "(", ")", "\n", "done", ":=", "c", ".", "ctx", ".", "Done", "(", ")", "\n", "send", ":=", "func", "(", "v", "Value", ")", "error", "{", "nv", ":=", "c", ".", "qs", ".", "NameOf", "(", "c", ".", "it", ".", "Result", "(", ")", ")", "\n", "if", "nv", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "select", "{", "case", "<-", "done", ":", "return", "c", ".", "ctx", ".", "Err", "(", ")", "\n", "case", "out", "<-", "c", ".", "qs", ".", "NameOf", "(", "c", ".", "it", ".", "Result", "(", ")", ")", ":", "}", "\n", "return", "nil", "\n", "}", "\n", "for", "c", ".", "next", "(", ")", "{", "if", "err", ":=", "send", "(", "c", ".", "it", ".", "Result", "(", ")", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "for", "c", ".", "nextPath", "(", ")", "{", "if", "err", ":=", "send", "(", "c", ".", "it", ".", "Result", "(", ")", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "c", ".", "it", ".", "Err", "(", ")", "\n", "}" ]
// SendValues is an analog of Send, but it will additionally call NameOf // for each graph.Value before sending it to a channel.
[ "SendValues", "is", "an", "analog", "of", "Send", "but", "it", "will", "additionally", "call", "NameOf", "for", "each", "graph", ".", "Value", "before", "sending", "it", "to", "a", "channel", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterate.go#L333-L366
train
cayleygraph/cayley
graph/iterate.go
TagValues
func (c *IterateChain) TagValues(qs QuadStore, fnc func(map[string]quad.Value)) error { if qs != nil { c.qs = qs } if c.qs == nil { return errNoQuadStore } return c.TagEach(func(m map[string]Value) { vm := make(map[string]quad.Value, len(m)) for k, v := range m { vm[k] = c.qs.NameOf(v) // TODO(dennwc): batch NameOf? } fnc(vm) }) }
go
func (c *IterateChain) TagValues(qs QuadStore, fnc func(map[string]quad.Value)) error { if qs != nil { c.qs = qs } if c.qs == nil { return errNoQuadStore } return c.TagEach(func(m map[string]Value) { vm := make(map[string]quad.Value, len(m)) for k, v := range m { vm[k] = c.qs.NameOf(v) // TODO(dennwc): batch NameOf? } fnc(vm) }) }
[ "func", "(", "c", "*", "IterateChain", ")", "TagValues", "(", "qs", "QuadStore", ",", "fnc", "func", "(", "map", "[", "string", "]", "quad", ".", "Value", ")", ")", "error", "{", "if", "qs", "!=", "nil", "{", "c", ".", "qs", "=", "qs", "\n", "}", "\n", "if", "c", ".", "qs", "==", "nil", "{", "return", "errNoQuadStore", "\n", "}", "\n", "return", "c", ".", "TagEach", "(", "func", "(", "m", "map", "[", "string", "]", "Value", ")", "{", "vm", ":=", "make", "(", "map", "[", "string", "]", "quad", ".", "Value", ",", "len", "(", "m", ")", ")", "\n", "for", "k", ",", "v", ":=", "range", "m", "{", "vm", "[", "k", "]", "=", "c", ".", "qs", ".", "NameOf", "(", "v", ")", "// TODO(dennwc): batch NameOf?", "\n", "}", "\n", "fnc", "(", "vm", ")", "\n", "}", ")", "\n", "}" ]
// TagValues is an analog of TagEach, but it will additionally call NameOf // for each graph.Value before passing the map to a callback.
[ "TagValues", "is", "an", "analog", "of", "TagEach", "but", "it", "will", "additionally", "call", "NameOf", "for", "each", "graph", ".", "Value", "before", "passing", "the", "map", "to", "a", "callback", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterate.go#L370-L384
train
cayleygraph/cayley
graph/iterator/skip.go
Next
func (it *Skip) Next(ctx context.Context) bool { graph.NextLogIn(it) for ; it.skipped < it.skip; it.skipped++ { if !it.primaryIt.Next(ctx) { return graph.NextLogOut(it, false) } } if it.primaryIt.Next(ctx) { return graph.NextLogOut(it, true) } return graph.NextLogOut(it, false) }
go
func (it *Skip) Next(ctx context.Context) bool { graph.NextLogIn(it) for ; it.skipped < it.skip; it.skipped++ { if !it.primaryIt.Next(ctx) { return graph.NextLogOut(it, false) } } if it.primaryIt.Next(ctx) { return graph.NextLogOut(it, true) } return graph.NextLogOut(it, false) }
[ "func", "(", "it", "*", "Skip", ")", "Next", "(", "ctx", "context", ".", "Context", ")", "bool", "{", "graph", ".", "NextLogIn", "(", "it", ")", "\n", "for", ";", "it", ".", "skipped", "<", "it", ".", "skip", ";", "it", ".", "skipped", "++", "{", "if", "!", "it", ".", "primaryIt", ".", "Next", "(", "ctx", ")", "{", "return", "graph", ".", "NextLogOut", "(", "it", ",", "false", ")", "\n", "}", "\n", "}", "\n", "if", "it", ".", "primaryIt", ".", "Next", "(", "ctx", ")", "{", "return", "graph", ".", "NextLogOut", "(", "it", ",", "true", ")", "\n", "}", "\n", "return", "graph", ".", "NextLogOut", "(", "it", ",", "false", ")", "\n", "}" ]
// Next advances the Skip iterator. It will skip all initial values // before returning actual result.
[ "Next", "advances", "the", "Skip", "iterator", ".", "It", "will", "skip", "all", "initial", "values", "before", "returning", "actual", "result", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterator/skip.go#L57-L68
train
cayleygraph/cayley
graph/iterator/skip.go
NextPath
func (it *Skip) NextPath(ctx context.Context) bool { for ; it.skipped < it.skip; it.skipped++ { if !it.primaryIt.NextPath(ctx) { return false } } return it.primaryIt.NextPath(ctx) }
go
func (it *Skip) NextPath(ctx context.Context) bool { for ; it.skipped < it.skip; it.skipped++ { if !it.primaryIt.NextPath(ctx) { return false } } return it.primaryIt.NextPath(ctx) }
[ "func", "(", "it", "*", "Skip", ")", "NextPath", "(", "ctx", "context", ".", "Context", ")", "bool", "{", "for", ";", "it", ".", "skipped", "<", "it", ".", "skip", ";", "it", ".", "skipped", "++", "{", "if", "!", "it", ".", "primaryIt", ".", "NextPath", "(", "ctx", ")", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "it", ".", "primaryIt", ".", "NextPath", "(", "ctx", ")", "\n", "}" ]
// NextPath checks whether there is another path. It will skip first paths // according to iterator parameter.
[ "NextPath", "checks", "whether", "there", "is", "another", "path", ".", "It", "will", "skip", "first", "paths", "according", "to", "iterator", "parameter", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterator/skip.go#L84-L91
train
cayleygraph/cayley
graph/iterator/not.go
SubIterators
func (it *Not) SubIterators() []graph.Iterator { return []graph.Iterator{it.primaryIt, it.allIt} }
go
func (it *Not) SubIterators() []graph.Iterator { return []graph.Iterator{it.primaryIt, it.allIt} }
[ "func", "(", "it", "*", "Not", ")", "SubIterators", "(", ")", "[", "]", "graph", ".", "Iterator", "{", "return", "[", "]", "graph", ".", "Iterator", "{", "it", ".", "primaryIt", ",", "it", ".", "allIt", "}", "\n", "}" ]
// SubIterators returns a slice of the sub iterators. // The first iterator is the primary iterator, for which the complement // is generated.
[ "SubIterators", "returns", "a", "slice", "of", "the", "sub", "iterators", ".", "The", "first", "iterator", "is", "the", "primary", "iterator", "for", "which", "the", "complement", "is", "generated", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterator/not.go#L63-L65
train
cayleygraph/cayley
graph/iterator/not.go
Next
func (it *Not) Next(ctx context.Context) bool { graph.NextLogIn(it) it.runstats.Next += 1 for it.allIt.Next(ctx) { if curr := it.allIt.Result(); !it.primaryIt.Contains(ctx, curr) { it.result = curr it.runstats.ContainsNext += 1 return graph.NextLogOut(it, true) } } it.err = it.allIt.Err() return graph.NextLogOut(it, false) }
go
func (it *Not) Next(ctx context.Context) bool { graph.NextLogIn(it) it.runstats.Next += 1 for it.allIt.Next(ctx) { if curr := it.allIt.Result(); !it.primaryIt.Contains(ctx, curr) { it.result = curr it.runstats.ContainsNext += 1 return graph.NextLogOut(it, true) } } it.err = it.allIt.Err() return graph.NextLogOut(it, false) }
[ "func", "(", "it", "*", "Not", ")", "Next", "(", "ctx", "context", ".", "Context", ")", "bool", "{", "graph", ".", "NextLogIn", "(", "it", ")", "\n", "it", ".", "runstats", ".", "Next", "+=", "1", "\n\n", "for", "it", ".", "allIt", ".", "Next", "(", "ctx", ")", "{", "if", "curr", ":=", "it", ".", "allIt", ".", "Result", "(", ")", ";", "!", "it", ".", "primaryIt", ".", "Contains", "(", "ctx", ",", "curr", ")", "{", "it", ".", "result", "=", "curr", "\n", "it", ".", "runstats", ".", "ContainsNext", "+=", "1", "\n", "return", "graph", ".", "NextLogOut", "(", "it", ",", "true", ")", "\n", "}", "\n", "}", "\n", "it", ".", "err", "=", "it", ".", "allIt", ".", "Err", "(", ")", "\n", "return", "graph", ".", "NextLogOut", "(", "it", ",", "false", ")", "\n", "}" ]
// Next advances the Not iterator. It returns whether there is another valid // new value. It fetches the next value of the all iterator which is not // contained by the primary iterator.
[ "Next", "advances", "the", "Not", "iterator", ".", "It", "returns", "whether", "there", "is", "another", "valid", "new", "value", ".", "It", "fetches", "the", "next", "value", "of", "the", "all", "iterator", "which", "is", "not", "contained", "by", "the", "primary", "iterator", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterator/not.go#L70-L83
train
cayleygraph/cayley
graph/iterator/not.go
Contains
func (it *Not) Contains(ctx context.Context, val graph.Value) bool { graph.ContainsLogIn(it, val) it.runstats.Contains += 1 if it.primaryIt.Contains(ctx, val) { return graph.ContainsLogOut(it, val, false) } it.err = it.primaryIt.Err() if it.err != nil { // Explicitly return 'false', since an error occurred. return false } it.result = val return graph.ContainsLogOut(it, val, true) }
go
func (it *Not) Contains(ctx context.Context, val graph.Value) bool { graph.ContainsLogIn(it, val) it.runstats.Contains += 1 if it.primaryIt.Contains(ctx, val) { return graph.ContainsLogOut(it, val, false) } it.err = it.primaryIt.Err() if it.err != nil { // Explicitly return 'false', since an error occurred. return false } it.result = val return graph.ContainsLogOut(it, val, true) }
[ "func", "(", "it", "*", "Not", ")", "Contains", "(", "ctx", "context", ".", "Context", ",", "val", "graph", ".", "Value", ")", "bool", "{", "graph", ".", "ContainsLogIn", "(", "it", ",", "val", ")", "\n", "it", ".", "runstats", ".", "Contains", "+=", "1", "\n\n", "if", "it", ".", "primaryIt", ".", "Contains", "(", "ctx", ",", "val", ")", "{", "return", "graph", ".", "ContainsLogOut", "(", "it", ",", "val", ",", "false", ")", "\n", "}", "\n\n", "it", ".", "err", "=", "it", ".", "primaryIt", ".", "Err", "(", ")", "\n", "if", "it", ".", "err", "!=", "nil", "{", "// Explicitly return 'false', since an error occurred.", "return", "false", "\n", "}", "\n\n", "it", ".", "result", "=", "val", "\n", "return", "graph", ".", "ContainsLogOut", "(", "it", ",", "val", ",", "true", ")", "\n", "}" ]
// Contains checks whether the passed value is part of the primary iterator's // complement. For a valid value, it updates the Result returned by the iterator // to the value itself.
[ "Contains", "checks", "whether", "the", "passed", "value", "is", "part", "of", "the", "primary", "iterator", "s", "complement", ".", "For", "a", "valid", "value", "it", "updates", "the", "Result", "returned", "by", "the", "iterator", "to", "the", "value", "itself", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterator/not.go#L96-L112
train
cayleygraph/cayley
graph/iterator/not.go
Close
func (it *Not) Close() error { err := it.primaryIt.Close() _err := it.allIt.Close() if _err != nil && err == nil { err = _err } return err }
go
func (it *Not) Close() error { err := it.primaryIt.Close() _err := it.allIt.Close() if _err != nil && err == nil { err = _err } return err }
[ "func", "(", "it", "*", "Not", ")", "Close", "(", ")", "error", "{", "err", ":=", "it", ".", "primaryIt", ".", "Close", "(", ")", "\n\n", "_err", ":=", "it", ".", "allIt", ".", "Close", "(", ")", "\n", "if", "_err", "!=", "nil", "&&", "err", "==", "nil", "{", "err", "=", "_err", "\n", "}", "\n\n", "return", "err", "\n", "}" ]
// Close closes the primary and all iterators. It closes all subiterators // it can, but returns the first error it encounters.
[ "Close", "closes", "the", "primary", "and", "all", "iterators", ".", "It", "closes", "all", "subiterators", "it", "can", "but", "returns", "the", "first", "error", "it", "encounters", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterator/not.go#L122-L131
train
cayleygraph/cayley
graph/memstore/quadstore.go
New
func New(quads ...quad.Quad) *QuadStore { qs := newQuadStore() for _, q := range quads { qs.AddQuad(q) } return qs }
go
func New(quads ...quad.Quad) *QuadStore { qs := newQuadStore() for _, q := range quads { qs.AddQuad(q) } return qs }
[ "func", "New", "(", "quads", "...", "quad", ".", "Quad", ")", "*", "QuadStore", "{", "qs", ":=", "newQuadStore", "(", ")", "\n", "for", "_", ",", "q", ":=", "range", "quads", "{", "qs", ".", "AddQuad", "(", "q", ")", "\n", "}", "\n", "return", "qs", "\n", "}" ]
// New creates a new in-memory quad store and loads provided quads.
[ "New", "creates", "a", "new", "in", "-", "memory", "quad", "store", "and", "loads", "provided", "quads", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/memstore/quadstore.go#L147-L153
train
cayleygraph/cayley
graph/memstore/quadstore.go
AddValue
func (qs *QuadStore) AddValue(v quad.Value) (int64, bool) { id, exists := qs.resolveVal(v, true) return id, !exists }
go
func (qs *QuadStore) AddValue(v quad.Value) (int64, bool) { id, exists := qs.resolveVal(v, true) return id, !exists }
[ "func", "(", "qs", "*", "QuadStore", ")", "AddValue", "(", "v", "quad", ".", "Value", ")", "(", "int64", ",", "bool", ")", "{", "id", ",", "exists", ":=", "qs", ".", "resolveVal", "(", "v", ",", "true", ")", "\n", "return", "id", ",", "!", "exists", "\n", "}" ]
// AddNode adds a value to quad store. It returns an id of the value. // False is returned as a second parameter if value exists already.
[ "AddNode", "adds", "a", "value", "to", "quad", "store", ".", "It", "returns", "an", "id", "of", "the", "value", ".", "False", "is", "returned", "as", "a", "second", "parameter", "if", "value", "exists", "already", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/memstore/quadstore.go#L265-L268
train
cayleygraph/cayley
graph/memstore/quadstore.go
AddQuad
func (qs *QuadStore) AddQuad(q quad.Quad) (int64, bool) { p, _ := qs.resolveQuad(q, true) if id := qs.quads[p]; id != 0 { return id, false } pr := &primitive{Quad: p} id := qs.addPrimitive(pr) qs.quads[p] = id for _, t := range qs.indexesForQuad(p) { t.Set(id, pr) } // TODO(barakmich): Add VIP indexing return id, true }
go
func (qs *QuadStore) AddQuad(q quad.Quad) (int64, bool) { p, _ := qs.resolveQuad(q, true) if id := qs.quads[p]; id != 0 { return id, false } pr := &primitive{Quad: p} id := qs.addPrimitive(pr) qs.quads[p] = id for _, t := range qs.indexesForQuad(p) { t.Set(id, pr) } // TODO(barakmich): Add VIP indexing return id, true }
[ "func", "(", "qs", "*", "QuadStore", ")", "AddQuad", "(", "q", "quad", ".", "Quad", ")", "(", "int64", ",", "bool", ")", "{", "p", ",", "_", ":=", "qs", ".", "resolveQuad", "(", "q", ",", "true", ")", "\n", "if", "id", ":=", "qs", ".", "quads", "[", "p", "]", ";", "id", "!=", "0", "{", "return", "id", ",", "false", "\n", "}", "\n", "pr", ":=", "&", "primitive", "{", "Quad", ":", "p", "}", "\n", "id", ":=", "qs", ".", "addPrimitive", "(", "pr", ")", "\n", "qs", ".", "quads", "[", "p", "]", "=", "id", "\n", "for", "_", ",", "t", ":=", "range", "qs", ".", "indexesForQuad", "(", "p", ")", "{", "t", ".", "Set", "(", "id", ",", "pr", ")", "\n", "}", "\n", "// TODO(barakmich): Add VIP indexing", "return", "id", ",", "true", "\n", "}" ]
// AddQuad adds a quad to quad store. It returns an id of the quad. // False is returned as a second parameter if quad exists already.
[ "AddQuad", "adds", "a", "quad", "to", "quad", "store", ".", "It", "returns", "an", "id", "of", "the", "quad", ".", "False", "is", "returned", "as", "a", "second", "parameter", "if", "quad", "exists", "already", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/memstore/quadstore.go#L284-L297
train
cayleygraph/cayley
graph/iterator/and_optimize.go
closeIteratorList
func closeIteratorList(its []graph.Iterator, except graph.Iterator) { for _, it := range its { if it != except { it.Close() } } }
go
func closeIteratorList(its []graph.Iterator, except graph.Iterator) { for _, it := range its { if it != except { it.Close() } } }
[ "func", "closeIteratorList", "(", "its", "[", "]", "graph", ".", "Iterator", ",", "except", "graph", ".", "Iterator", ")", "{", "for", "_", ",", "it", ":=", "range", "its", "{", "if", "it", "!=", "except", "{", "it", ".", "Close", "(", ")", "\n", "}", "\n", "}", "\n", "}" ]
// Closes a list of iterators, except the one passed in `except`. Closes all // of the iterators in the list if `except` is nil.
[ "Closes", "a", "list", "of", "iterators", "except", "the", "one", "passed", "in", "except", ".", "Closes", "all", "of", "the", "iterators", "in", "the", "list", "if", "except", "is", "nil", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterator/and_optimize.go#L119-L125
train
cayleygraph/cayley
graph/iterator/and_optimize.go
optimizeReplacement
func (*And) optimizeReplacement(its []graph.Iterator) graph.Iterator { // If we were created with no SubIterators, we're as good as Null. if len(its) == 0 { return NewNull() } if len(its) == 1 { // When there's only one iterator, there's only one choice. return its[0] } // If any of our subiterators, post-optimization, are also Null, then // there's no point in continuing the branch, we will have no results // and we are null as well. if hasAnyNullIterators(its) { return NewNull() } // If we have one useful iterator, use that. it := hasOneUsefulIterator(its) if it != nil { return it } return nil }
go
func (*And) optimizeReplacement(its []graph.Iterator) graph.Iterator { // If we were created with no SubIterators, we're as good as Null. if len(its) == 0 { return NewNull() } if len(its) == 1 { // When there's only one iterator, there's only one choice. return its[0] } // If any of our subiterators, post-optimization, are also Null, then // there's no point in continuing the branch, we will have no results // and we are null as well. if hasAnyNullIterators(its) { return NewNull() } // If we have one useful iterator, use that. it := hasOneUsefulIterator(its) if it != nil { return it } return nil }
[ "func", "(", "*", "And", ")", "optimizeReplacement", "(", "its", "[", "]", "graph", ".", "Iterator", ")", "graph", ".", "Iterator", "{", "// If we were created with no SubIterators, we're as good as Null.", "if", "len", "(", "its", ")", "==", "0", "{", "return", "NewNull", "(", ")", "\n", "}", "\n", "if", "len", "(", "its", ")", "==", "1", "{", "// When there's only one iterator, there's only one choice.", "return", "its", "[", "0", "]", "\n", "}", "\n", "// If any of our subiterators, post-optimization, are also Null, then", "// there's no point in continuing the branch, we will have no results", "// and we are null as well.", "if", "hasAnyNullIterators", "(", "its", ")", "{", "return", "NewNull", "(", ")", "\n", "}", "\n\n", "// If we have one useful iterator, use that.", "it", ":=", "hasOneUsefulIterator", "(", "its", ")", "\n", "if", "it", "!=", "nil", "{", "return", "it", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Find if there is a single subiterator which is a valid replacement for this // And.
[ "Find", "if", "there", "is", "a", "single", "subiterator", "which", "is", "a", "valid", "replacement", "for", "this", "And", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterator/and_optimize.go#L129-L151
train
cayleygraph/cayley
graph/iterator/and_optimize.go
hasAnyNullIterators
func hasAnyNullIterators(its []graph.Iterator) bool { for _, it := range its { if it.Type() == graph.Null { return true } } return false }
go
func hasAnyNullIterators(its []graph.Iterator) bool { for _, it := range its { if it.Type() == graph.Null { return true } } return false }
[ "func", "hasAnyNullIterators", "(", "its", "[", "]", "graph", ".", "Iterator", ")", "bool", "{", "for", "_", ",", "it", ":=", "range", "its", "{", "if", "it", ".", "Type", "(", ")", "==", "graph", ".", "Null", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// Check a list of iterators for any Null iterators.
[ "Check", "a", "list", "of", "iterators", "for", "any", "Null", "iterators", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterator/and_optimize.go#L289-L296
train
cayleygraph/cayley
graph/quadwriter.go
Unwrap
func Unwrap(qs QuadStore) QuadStore { if h, ok := qs.(*Handle); ok { return h.QuadStore } return qs }
go
func Unwrap(qs QuadStore) QuadStore { if h, ok := qs.(*Handle); ok { return h.QuadStore } return qs }
[ "func", "Unwrap", "(", "qs", "QuadStore", ")", "QuadStore", "{", "if", "h", ",", "ok", ":=", "qs", ".", "(", "*", "Handle", ")", ";", "ok", "{", "return", "h", ".", "QuadStore", "\n", "}", "\n", "return", "qs", "\n", "}" ]
// Unwrap returns an original QuadStore value if it was wrapped by Handle. // This prevents shadowing of optional interface implementations.
[ "Unwrap", "returns", "an", "original", "QuadStore", "value", "if", "it", "was", "wrapped", "by", "Handle", ".", "This", "prevents", "shadowing", "of", "optional", "interface", "implementations", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/quadwriter.go#L58-L63
train
cayleygraph/cayley
graph/quadwriter.go
IsQuadExist
func IsQuadExist(err error) bool { if err == ErrQuadExists { return true } de, ok := err.(*DeltaError) return ok && de.Err == ErrQuadExists }
go
func IsQuadExist(err error) bool { if err == ErrQuadExists { return true } de, ok := err.(*DeltaError) return ok && de.Err == ErrQuadExists }
[ "func", "IsQuadExist", "(", "err", "error", ")", "bool", "{", "if", "err", "==", "ErrQuadExists", "{", "return", "true", "\n", "}", "\n", "de", ",", "ok", ":=", "err", ".", "(", "*", "DeltaError", ")", "\n", "return", "ok", "&&", "de", ".", "Err", "==", "ErrQuadExists", "\n", "}" ]
// IsQuadExist returns whether an error is a DeltaError // with the Err field equal to ErrQuadExists.
[ "IsQuadExist", "returns", "whether", "an", "error", "is", "a", "DeltaError", "with", "the", "Err", "field", "equal", "to", "ErrQuadExists", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/quadwriter.go#L102-L108
train
cayleygraph/cayley
graph/quadwriter.go
IsQuadNotExist
func IsQuadNotExist(err error) bool { if err == ErrQuadNotExist { return true } de, ok := err.(*DeltaError) return ok && de.Err == ErrQuadNotExist }
go
func IsQuadNotExist(err error) bool { if err == ErrQuadNotExist { return true } de, ok := err.(*DeltaError) return ok && de.Err == ErrQuadNotExist }
[ "func", "IsQuadNotExist", "(", "err", "error", ")", "bool", "{", "if", "err", "==", "ErrQuadNotExist", "{", "return", "true", "\n", "}", "\n", "de", ",", "ok", ":=", "err", ".", "(", "*", "DeltaError", ")", "\n", "return", "ok", "&&", "de", ".", "Err", "==", "ErrQuadNotExist", "\n", "}" ]
// IsQuadNotExist returns whether an error is a DeltaError // with the Err field equal to ErrQuadNotExist.
[ "IsQuadNotExist", "returns", "whether", "an", "error", "is", "a", "DeltaError", "with", "the", "Err", "field", "equal", "to", "ErrQuadNotExist", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/quadwriter.go#L112-L118
train
cayleygraph/cayley
graph/quadwriter.go
IsInvalidAction
func IsInvalidAction(err error) bool { if err == ErrInvalidAction { return true } de, ok := err.(*DeltaError) return ok && de.Err == ErrInvalidAction }
go
func IsInvalidAction(err error) bool { if err == ErrInvalidAction { return true } de, ok := err.(*DeltaError) return ok && de.Err == ErrInvalidAction }
[ "func", "IsInvalidAction", "(", "err", "error", ")", "bool", "{", "if", "err", "==", "ErrInvalidAction", "{", "return", "true", "\n", "}", "\n", "de", ",", "ok", ":=", "err", ".", "(", "*", "DeltaError", ")", "\n", "return", "ok", "&&", "de", ".", "Err", "==", "ErrInvalidAction", "\n", "}" ]
// IsInvalidAction returns whether an error is a DeltaError // with the Err field equal to ErrInvalidAction.
[ "IsInvalidAction", "returns", "whether", "an", "error", "is", "a", "DeltaError", "with", "the", "Err", "field", "equal", "to", "ErrInvalidAction", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/quadwriter.go#L122-L128
train
cayleygraph/cayley
graph/quadwriter.go
NewTxWriter
func NewTxWriter(tx *Transaction, p Procedure) quad.Writer { if p == 0 { p = Add } return &txWriter{tx: tx, p: p} }
go
func NewTxWriter(tx *Transaction, p Procedure) quad.Writer { if p == 0 { p = Add } return &txWriter{tx: tx, p: p} }
[ "func", "NewTxWriter", "(", "tx", "*", "Transaction", ",", "p", "Procedure", ")", "quad", ".", "Writer", "{", "if", "p", "==", "0", "{", "p", "=", "Add", "\n", "}", "\n", "return", "&", "txWriter", "{", "tx", ":", "tx", ",", "p", ":", "p", "}", "\n", "}" ]
// NewTxWriter creates a writer that applies a given procedures for all quads in stream. // If procedure is zero, Add operation will be used.
[ "NewTxWriter", "creates", "a", "writer", "that", "applies", "a", "given", "procedures", "for", "all", "quads", "in", "stream", ".", "If", "procedure", "is", "zero", "Add", "operation", "will", "be", "used", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/quadwriter.go#L240-L245
train
cayleygraph/cayley
graph/quadwriter.go
NewResultReader
func NewResultReader(qs QuadStore, it Iterator) quad.ReadSkipCloser { if it == nil { it = qs.QuadsAllIterator() } return &quadReader{qs: qs, it: it} }
go
func NewResultReader(qs QuadStore, it Iterator) quad.ReadSkipCloser { if it == nil { it = qs.QuadsAllIterator() } return &quadReader{qs: qs, it: it} }
[ "func", "NewResultReader", "(", "qs", "QuadStore", ",", "it", "Iterator", ")", "quad", ".", "ReadSkipCloser", "{", "if", "it", "==", "nil", "{", "it", "=", "qs", ".", "QuadsAllIterator", "(", ")", "\n", "}", "\n", "return", "&", "quadReader", "{", "qs", ":", "qs", ",", "it", ":", "it", "}", "\n", "}" ]
// NewResultReader creates a quad reader for a given QuadStore and iterator. // If iterator is nil QuadsAllIterator will be used. // // Only quads returned by iterator's Result will be used. // // Iterator will be closed with the reader.
[ "NewResultReader", "creates", "a", "quad", "reader", "for", "a", "given", "QuadStore", "and", "iterator", ".", "If", "iterator", "is", "nil", "QuadsAllIterator", "will", "be", "used", ".", "Only", "quads", "returned", "by", "iterator", "s", "Result", "will", "be", "used", ".", "Iterator", "will", "be", "closed", "with", "the", "reader", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/quadwriter.go#L302-L307
train
cayleygraph/cayley
quad/value.go
HashOf
func HashOf(v Value) []byte { key := make([]byte, HashSize) HashTo(v, key) return key }
go
func HashOf(v Value) []byte { key := make([]byte, HashSize) HashTo(v, key) return key }
[ "func", "HashOf", "(", "v", "Value", ")", "[", "]", "byte", "{", "key", ":=", "make", "(", "[", "]", "byte", ",", "HashSize", ")", "\n", "HashTo", "(", "v", ",", "key", ")", "\n", "return", "key", "\n", "}" ]
// HashOf calculates a hash of value v.
[ "HashOf", "calculates", "a", "hash", "of", "value", "v", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/quad/value.go#L48-L52
train
cayleygraph/cayley
quad/value.go
HashTo
func HashTo(v Value, p []byte) { h := hashPool.Get().(hash.Hash) h.Reset() defer hashPool.Put(h) if len(p) < HashSize { panic("buffer too small to fit the hash") } if v != nil { // TODO(kortschak,dennwc) Remove dependence on String() method. h.Write([]byte(v.String())) } h.Sum(p[:0]) }
go
func HashTo(v Value, p []byte) { h := hashPool.Get().(hash.Hash) h.Reset() defer hashPool.Put(h) if len(p) < HashSize { panic("buffer too small to fit the hash") } if v != nil { // TODO(kortschak,dennwc) Remove dependence on String() method. h.Write([]byte(v.String())) } h.Sum(p[:0]) }
[ "func", "HashTo", "(", "v", "Value", ",", "p", "[", "]", "byte", ")", "{", "h", ":=", "hashPool", ".", "Get", "(", ")", ".", "(", "hash", ".", "Hash", ")", "\n", "h", ".", "Reset", "(", ")", "\n", "defer", "hashPool", ".", "Put", "(", "h", ")", "\n", "if", "len", "(", "p", ")", "<", "HashSize", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "v", "!=", "nil", "{", "// TODO(kortschak,dennwc) Remove dependence on String() method.", "h", ".", "Write", "(", "[", "]", "byte", "(", "v", ".", "String", "(", ")", ")", ")", "\n", "}", "\n", "h", ".", "Sum", "(", "p", "[", ":", "0", "]", ")", "\n", "}" ]
// HashTo calculates a hash of value v, storing it in a slice p.
[ "HashTo", "calculates", "a", "hash", "of", "value", "v", "storing", "it", "in", "a", "slice", "p", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/quad/value.go#L55-L67
train
cayleygraph/cayley
quad/value.go
AsValue
func AsValue(v interface{}) (out Value, ok bool) { if v == nil { return nil, true } switch v := v.(type) { case Value: out = v case string: out = String(v) case int: out = Int(v) case int8: out = Int(v) case int16: out = Int(v) case int32: out = Int(v) case int64: out = Int(v) case uint: out = Int(v) case uint8: out = Int(v) case uint16: out = Int(v) case uint32: out = Int(v) case uint64: out = Int(v) case float64: out = Float(v) case float32: out = Float(v) case bool: out = Bool(v) case time.Time: out = Time(v) default: return nil, false } return out, true }
go
func AsValue(v interface{}) (out Value, ok bool) { if v == nil { return nil, true } switch v := v.(type) { case Value: out = v case string: out = String(v) case int: out = Int(v) case int8: out = Int(v) case int16: out = Int(v) case int32: out = Int(v) case int64: out = Int(v) case uint: out = Int(v) case uint8: out = Int(v) case uint16: out = Int(v) case uint32: out = Int(v) case uint64: out = Int(v) case float64: out = Float(v) case float32: out = Float(v) case bool: out = Bool(v) case time.Time: out = Time(v) default: return nil, false } return out, true }
[ "func", "AsValue", "(", "v", "interface", "{", "}", ")", "(", "out", "Value", ",", "ok", "bool", ")", "{", "if", "v", "==", "nil", "{", "return", "nil", ",", "true", "\n", "}", "\n", "switch", "v", ":=", "v", ".", "(", "type", ")", "{", "case", "Value", ":", "out", "=", "v", "\n", "case", "string", ":", "out", "=", "String", "(", "v", ")", "\n", "case", "int", ":", "out", "=", "Int", "(", "v", ")", "\n", "case", "int8", ":", "out", "=", "Int", "(", "v", ")", "\n", "case", "int16", ":", "out", "=", "Int", "(", "v", ")", "\n", "case", "int32", ":", "out", "=", "Int", "(", "v", ")", "\n", "case", "int64", ":", "out", "=", "Int", "(", "v", ")", "\n", "case", "uint", ":", "out", "=", "Int", "(", "v", ")", "\n", "case", "uint8", ":", "out", "=", "Int", "(", "v", ")", "\n", "case", "uint16", ":", "out", "=", "Int", "(", "v", ")", "\n", "case", "uint32", ":", "out", "=", "Int", "(", "v", ")", "\n", "case", "uint64", ":", "out", "=", "Int", "(", "v", ")", "\n", "case", "float64", ":", "out", "=", "Float", "(", "v", ")", "\n", "case", "float32", ":", "out", "=", "Float", "(", "v", ")", "\n", "case", "bool", ":", "out", "=", "Bool", "(", "v", ")", "\n", "case", "time", ".", "Time", ":", "out", "=", "Time", "(", "v", ")", "\n", "default", ":", "return", "nil", ",", "false", "\n", "}", "\n", "return", "out", ",", "true", "\n", "}" ]
// AsValue converts native type into closest Value representation. // It returns false if type was not recognized.
[ "AsValue", "converts", "native", "type", "into", "closest", "Value", "representation", ".", "It", "returns", "false", "if", "type", "was", "not", "recognized", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/quad/value.go#L87-L128
train
cayleygraph/cayley
quad/value.go
ToString
func ToString(v Value) string { if s, ok := v.(String); ok { return string(s) } return StringOf(v) }
go
func ToString(v Value) string { if s, ok := v.(String); ok { return string(s) } return StringOf(v) }
[ "func", "ToString", "(", "v", "Value", ")", "string", "{", "if", "s", ",", "ok", ":=", "v", ".", "(", "String", ")", ";", "ok", "{", "return", "string", "(", "s", ")", "\n", "}", "\n", "return", "StringOf", "(", "v", ")", "\n", "}" ]
// ToString casts a values to String or falls back to StringOf.
[ "ToString", "casts", "a", "values", "to", "String", "or", "falls", "back", "to", "StringOf", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/quad/value.go#L153-L158
train
cayleygraph/cayley
quad/value.go
ParseValue
func (s TypedString) ParseValue() (Value, error) { fnc := knownConversions[s.Type.Full()] if fnc == nil { return s, nil } return fnc(string(s.Value)) }
go
func (s TypedString) ParseValue() (Value, error) { fnc := knownConversions[s.Type.Full()] if fnc == nil { return s, nil } return fnc(string(s.Value)) }
[ "func", "(", "s", "TypedString", ")", "ParseValue", "(", ")", "(", "Value", ",", "error", ")", "{", "fnc", ":=", "knownConversions", "[", "s", ".", "Type", ".", "Full", "(", ")", "]", "\n", "if", "fnc", "==", "nil", "{", "return", "s", ",", "nil", "\n", "}", "\n", "return", "fnc", "(", "string", "(", "s", ".", "Value", ")", ")", "\n", "}" ]
// ParseValue will try to parse underlying string value using registered functions. // // It will return unchanged value if suitable function is not available. // // Error will be returned if the type was recognizes, but parsing failed.
[ "ParseValue", "will", "try", "to", "parse", "underlying", "string", "value", "using", "registered", "functions", ".", "It", "will", "return", "unchanged", "value", "if", "suitable", "function", "is", "not", "available", ".", "Error", "will", "be", "returned", "if", "the", "type", "was", "recognizes", "but", "parsing", "failed", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/quad/value.go#L214-L220
train