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 list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
asdine/storm | finder.go | One | func (n *node) One(fieldName string, value interface{}, to interface{}) error {
sink, err := newFirstSink(n, to)
if err != nil {
return err
}
bucketName := sink.bucketName()
if bucketName == "" {
return ErrNoName
}
if fieldName == "" {
return ErrNotFound
}
ref := reflect.Indirect(sink.ref)
cfg, err :... | go | func (n *node) One(fieldName string, value interface{}, to interface{}) error {
sink, err := newFirstSink(n, to)
if err != nil {
return err
}
bucketName := sink.bucketName()
if bucketName == "" {
return ErrNoName
}
if fieldName == "" {
return ErrNotFound
}
ref := reflect.Indirect(sink.ref)
cfg, err :... | [
"func",
"(",
"n",
"*",
"node",
")",
"One",
"(",
"fieldName",
"string",
",",
"value",
"interface",
"{",
"}",
",",
"to",
"interface",
"{",
"}",
")",
"error",
"{",
"sink",
",",
"err",
":=",
"newFirstSink",
"(",
"n",
",",
"to",
")",
"\n",
"if",
"err"... | // One returns one record by the specified index | [
"One",
"returns",
"one",
"record",
"by",
"the",
"specified",
"index"
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/finder.go#L41-L90 | train |
asdine/storm | finder.go | AllByIndex | func (n *node) AllByIndex(fieldName string, to interface{}, options ...func(*index.Options)) error {
if fieldName == "" {
return n.All(to, options...)
}
ref := reflect.ValueOf(to)
if ref.Kind() != reflect.Ptr || ref.Elem().Kind() != reflect.Slice {
return ErrSlicePtrNeeded
}
typ := reflect.Indirect(ref).Ty... | go | func (n *node) AllByIndex(fieldName string, to interface{}, options ...func(*index.Options)) error {
if fieldName == "" {
return n.All(to, options...)
}
ref := reflect.ValueOf(to)
if ref.Kind() != reflect.Ptr || ref.Elem().Kind() != reflect.Slice {
return ErrSlicePtrNeeded
}
typ := reflect.Indirect(ref).Ty... | [
"func",
"(",
"n",
"*",
"node",
")",
"AllByIndex",
"(",
"fieldName",
"string",
",",
"to",
"interface",
"{",
"}",
",",
"options",
"...",
"func",
"(",
"*",
"index",
".",
"Options",
")",
")",
"error",
"{",
"if",
"fieldName",
"==",
"\"",
"\"",
"{",
"ret... | // AllByIndex gets all the records of a bucket that are indexed in the specified index | [
"AllByIndex",
"gets",
"all",
"the",
"records",
"of",
"a",
"bucket",
"that",
"are",
"indexed",
"in",
"the",
"specified",
"index"
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/finder.go#L213-L249 | train |
asdine/storm | finder.go | All | func (n *node) All(to interface{}, options ...func(*index.Options)) error {
opts := index.NewOptions()
for _, fn := range options {
fn(opts)
}
query := newQuery(n, nil).Limit(opts.Limit).Skip(opts.Skip)
if opts.Reverse {
query.Reverse()
}
err := query.Find(to)
if err != nil && err != ErrNotFound {
retur... | go | func (n *node) All(to interface{}, options ...func(*index.Options)) error {
opts := index.NewOptions()
for _, fn := range options {
fn(opts)
}
query := newQuery(n, nil).Limit(opts.Limit).Skip(opts.Skip)
if opts.Reverse {
query.Reverse()
}
err := query.Find(to)
if err != nil && err != ErrNotFound {
retur... | [
"func",
"(",
"n",
"*",
"node",
")",
"All",
"(",
"to",
"interface",
"{",
"}",
",",
"options",
"...",
"func",
"(",
"*",
"index",
".",
"Options",
")",
")",
"error",
"{",
"opts",
":=",
"index",
".",
"NewOptions",
"(",
")",
"\n",
"for",
"_",
",",
"f... | // All gets all the records of a bucket.
// If there are no records it returns no error and the 'to' parameter is set to an empty slice. | [
"All",
"gets",
"all",
"the",
"records",
"of",
"a",
"bucket",
".",
"If",
"there",
"are",
"no",
"records",
"it",
"returns",
"no",
"error",
"and",
"the",
"to",
"parameter",
"is",
"set",
"to",
"an",
"empty",
"slice",
"."
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/finder.go#L295-L317 | train |
asdine/storm | finder.go | Range | func (n *node) Range(fieldName string, min, max, to interface{}, options ...func(*index.Options)) error {
sink, err := newListSink(n, to)
if err != nil {
return err
}
bucketName := sink.bucketName()
if bucketName == "" {
return ErrNoName
}
ref := reflect.Indirect(reflect.New(sink.elemType))
cfg, err := ex... | go | func (n *node) Range(fieldName string, min, max, to interface{}, options ...func(*index.Options)) error {
sink, err := newListSink(n, to)
if err != nil {
return err
}
bucketName := sink.bucketName()
if bucketName == "" {
return ErrNoName
}
ref := reflect.Indirect(reflect.New(sink.elemType))
cfg, err := ex... | [
"func",
"(",
"n",
"*",
"node",
")",
"Range",
"(",
"fieldName",
"string",
",",
"min",
",",
"max",
",",
"to",
"interface",
"{",
"}",
",",
"options",
"...",
"func",
"(",
"*",
"index",
".",
"Options",
")",
")",
"error",
"{",
"sink",
",",
"err",
":=",... | // Range returns one or more records by the specified index within the specified range | [
"Range",
"returns",
"one",
"or",
"more",
"records",
"by",
"the",
"specified",
"index",
"within",
"the",
"specified",
"range"
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/finder.go#L320-L375 | train |
asdine/storm | finder.go | Prefix | func (n *node) Prefix(fieldName string, prefix string, to interface{}, options ...func(*index.Options)) error {
sink, err := newListSink(n, to)
if err != nil {
return err
}
bucketName := sink.bucketName()
if bucketName == "" {
return ErrNoName
}
ref := reflect.Indirect(reflect.New(sink.elemType))
cfg, err... | go | func (n *node) Prefix(fieldName string, prefix string, to interface{}, options ...func(*index.Options)) error {
sink, err := newListSink(n, to)
if err != nil {
return err
}
bucketName := sink.bucketName()
if bucketName == "" {
return ErrNoName
}
ref := reflect.Indirect(reflect.New(sink.elemType))
cfg, err... | [
"func",
"(",
"n",
"*",
"node",
")",
"Prefix",
"(",
"fieldName",
"string",
",",
"prefix",
"string",
",",
"to",
"interface",
"{",
"}",
",",
"options",
"...",
"func",
"(",
"*",
"index",
".",
"Options",
")",
")",
"error",
"{",
"sink",
",",
"err",
":=",... | // Prefix returns one or more records whose given field starts with the specified prefix. | [
"Prefix",
"returns",
"one",
"or",
"more",
"records",
"whose",
"given",
"field",
"starts",
"with",
"the",
"specified",
"prefix",
"."
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/finder.go#L411-L461 | train |
asdine/storm | finder.go | Count | func (n *node) Count(data interface{}) (int, error) {
return n.Select().Count(data)
} | go | func (n *node) Count(data interface{}) (int, error) {
return n.Select().Count(data)
} | [
"func",
"(",
"n",
"*",
"node",
")",
"Count",
"(",
"data",
"interface",
"{",
"}",
")",
"(",
"int",
",",
"error",
")",
"{",
"return",
"n",
".",
"Select",
"(",
")",
".",
"Count",
"(",
"data",
")",
"\n",
"}"
] | // Count counts all the records of a bucket | [
"Count",
"counts",
"all",
"the",
"records",
"of",
"a",
"bucket"
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/finder.go#L497-L499 | train |
asdine/storm | query.go | Select | func (n *node) Select(matchers ...q.Matcher) Query {
tree := q.And(matchers...)
return newQuery(n, tree)
} | go | func (n *node) Select(matchers ...q.Matcher) Query {
tree := q.And(matchers...)
return newQuery(n, tree)
} | [
"func",
"(",
"n",
"*",
"node",
")",
"Select",
"(",
"matchers",
"...",
"q",
".",
"Matcher",
")",
"Query",
"{",
"tree",
":=",
"q",
".",
"And",
"(",
"matchers",
"...",
")",
"\n",
"return",
"newQuery",
"(",
"n",
",",
"tree",
")",
"\n",
"}"
] | // Select a list of records that match a list of matchers. Doesn't use indexes. | [
"Select",
"a",
"list",
"of",
"records",
"that",
"match",
"a",
"list",
"of",
"matchers",
".",
"Doesn",
"t",
"use",
"indexes",
"."
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/query.go#L10-L13 | train |
asdine/storm | index/list.go | NewListIndex | func NewListIndex(parent *bolt.Bucket, indexName []byte) (*ListIndex, error) {
var err error
b := parent.Bucket(indexName)
if b == nil {
if !parent.Writable() {
return nil, ErrNotFound
}
b, err = parent.CreateBucket(indexName)
if err != nil {
return nil, err
}
}
ids, err := NewUniqueIndex(b, []byt... | go | func NewListIndex(parent *bolt.Bucket, indexName []byte) (*ListIndex, error) {
var err error
b := parent.Bucket(indexName)
if b == nil {
if !parent.Writable() {
return nil, ErrNotFound
}
b, err = parent.CreateBucket(indexName)
if err != nil {
return nil, err
}
}
ids, err := NewUniqueIndex(b, []byt... | [
"func",
"NewListIndex",
"(",
"parent",
"*",
"bolt",
".",
"Bucket",
",",
"indexName",
"[",
"]",
"byte",
")",
"(",
"*",
"ListIndex",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"b",
":=",
"parent",
".",
"Bucket",
"(",
"indexName",
")",
"\n",
... | // NewListIndex loads a ListIndex | [
"NewListIndex",
"loads",
"a",
"ListIndex"
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/index/list.go#L11-L34 | train |
asdine/storm | index/list.go | Add | func (idx *ListIndex) Add(newValue []byte, targetID []byte) error {
if newValue == nil || len(newValue) == 0 {
return ErrNilParam
}
if targetID == nil || len(targetID) == 0 {
return ErrNilParam
}
key := idx.IDs.Get(targetID)
if key != nil {
err := idx.IndexBucket.Delete(key)
if err != nil {
return err... | go | func (idx *ListIndex) Add(newValue []byte, targetID []byte) error {
if newValue == nil || len(newValue) == 0 {
return ErrNilParam
}
if targetID == nil || len(targetID) == 0 {
return ErrNilParam
}
key := idx.IDs.Get(targetID)
if key != nil {
err := idx.IndexBucket.Delete(key)
if err != nil {
return err... | [
"func",
"(",
"idx",
"*",
"ListIndex",
")",
"Add",
"(",
"newValue",
"[",
"]",
"byte",
",",
"targetID",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"newValue",
"==",
"nil",
"||",
"len",
"(",
"newValue",
")",
"==",
"0",
"{",
"return",
"ErrNilParam",
"\... | // Add a value to the list index | [
"Add",
"a",
"value",
"to",
"the",
"list",
"index"
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/index/list.go#L44-L78 | train |
asdine/storm | index/list.go | RemoveID | func (idx *ListIndex) RemoveID(targetID []byte) error {
value := idx.IDs.Get(targetID)
if value == nil {
return nil
}
err := idx.IndexBucket.Delete(value)
if err != nil {
return err
}
return idx.IDs.Remove(targetID)
} | go | func (idx *ListIndex) RemoveID(targetID []byte) error {
value := idx.IDs.Get(targetID)
if value == nil {
return nil
}
err := idx.IndexBucket.Delete(value)
if err != nil {
return err
}
return idx.IDs.Remove(targetID)
} | [
"func",
"(",
"idx",
"*",
"ListIndex",
")",
"RemoveID",
"(",
"targetID",
"[",
"]",
"byte",
")",
"error",
"{",
"value",
":=",
"idx",
".",
"IDs",
".",
"Get",
"(",
"targetID",
")",
"\n",
"if",
"value",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\... | // RemoveID removes an ID from the list index | [
"RemoveID",
"removes",
"an",
"ID",
"from",
"the",
"list",
"index"
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/index/list.go#L103-L115 | train |
asdine/storm | index/list.go | Get | func (idx *ListIndex) Get(value []byte) []byte {
c := idx.IndexBucket.Cursor()
prefix := generatePrefix(value)
for k, id := c.Seek(prefix); bytes.HasPrefix(k, prefix); k, id = c.Next() {
return id
}
return nil
} | go | func (idx *ListIndex) Get(value []byte) []byte {
c := idx.IndexBucket.Cursor()
prefix := generatePrefix(value)
for k, id := c.Seek(prefix); bytes.HasPrefix(k, prefix); k, id = c.Next() {
return id
}
return nil
} | [
"func",
"(",
"idx",
"*",
"ListIndex",
")",
"Get",
"(",
"value",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"c",
":=",
"idx",
".",
"IndexBucket",
".",
"Cursor",
"(",
")",
"\n",
"prefix",
":=",
"generatePrefix",
"(",
"value",
")",
"\n\n",
"for",
... | // Get the first ID corresponding to the given value | [
"Get",
"the",
"first",
"ID",
"corresponding",
"to",
"the",
"given",
"value"
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/index/list.go#L118-L127 | train |
asdine/storm | index/list.go | All | func (idx *ListIndex) All(value []byte, opts *Options) ([][]byte, error) {
var list [][]byte
c := idx.IndexBucket.Cursor()
cur := internal.Cursor{C: c, Reverse: opts != nil && opts.Reverse}
prefix := generatePrefix(value)
k, id := c.Seek(prefix)
if cur.Reverse {
var count int
kc := k
idc := id
for ; kc ... | go | func (idx *ListIndex) All(value []byte, opts *Options) ([][]byte, error) {
var list [][]byte
c := idx.IndexBucket.Cursor()
cur := internal.Cursor{C: c, Reverse: opts != nil && opts.Reverse}
prefix := generatePrefix(value)
k, id := c.Seek(prefix)
if cur.Reverse {
var count int
kc := k
idc := id
for ; kc ... | [
"func",
"(",
"idx",
"*",
"ListIndex",
")",
"All",
"(",
"value",
"[",
"]",
"byte",
",",
"opts",
"*",
"Options",
")",
"(",
"[",
"]",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"list",
"[",
"]",
"[",
"]",
"byte",
"\n",
"c",
":=",
"idx",
... | // All the IDs corresponding to the given value | [
"All",
"the",
"IDs",
"corresponding",
"to",
"the",
"given",
"value"
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/index/list.go#L130-L170 | train |
asdine/storm | node.go | From | func (n node) From(addend ...string) Node {
n.rootBucket = append(n.rootBucket, addend...)
return &n
} | go | func (n node) From(addend ...string) Node {
n.rootBucket = append(n.rootBucket, addend...)
return &n
} | [
"func",
"(",
"n",
"node",
")",
"From",
"(",
"addend",
"...",
"string",
")",
"Node",
"{",
"n",
".",
"rootBucket",
"=",
"append",
"(",
"n",
".",
"rootBucket",
",",
"addend",
"...",
")",
"\n",
"return",
"&",
"n",
"\n",
"}"
] | // From returns a new Storm Node with a new bucket root below the current.
// All DB operations on the new node will be executed relative to this bucket. | [
"From",
"returns",
"a",
"new",
"Storm",
"Node",
"with",
"a",
"new",
"bucket",
"root",
"below",
"the",
"current",
".",
"All",
"DB",
"operations",
"on",
"the",
"new",
"node",
"will",
"be",
"executed",
"relative",
"to",
"this",
"bucket",
"."
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/node.go#L65-L68 | train |
asdine/storm | node.go | WithTransaction | func (n node) WithTransaction(tx *bolt.Tx) Node {
n.tx = tx
return &n
} | go | func (n node) WithTransaction(tx *bolt.Tx) Node {
n.tx = tx
return &n
} | [
"func",
"(",
"n",
"node",
")",
"WithTransaction",
"(",
"tx",
"*",
"bolt",
".",
"Tx",
")",
"Node",
"{",
"n",
".",
"tx",
"=",
"tx",
"\n",
"return",
"&",
"n",
"\n",
"}"
] | // WithTransaction returns a new Storm Node that will use the given transaction. | [
"WithTransaction",
"returns",
"a",
"new",
"Storm",
"Node",
"that",
"will",
"use",
"the",
"given",
"transaction",
"."
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/node.go#L71-L74 | train |
asdine/storm | node.go | WithCodec | func (n node) WithCodec(codec codec.MarshalUnmarshaler) Node {
n.codec = codec
return &n
} | go | func (n node) WithCodec(codec codec.MarshalUnmarshaler) Node {
n.codec = codec
return &n
} | [
"func",
"(",
"n",
"node",
")",
"WithCodec",
"(",
"codec",
"codec",
".",
"MarshalUnmarshaler",
")",
"Node",
"{",
"n",
".",
"codec",
"=",
"codec",
"\n",
"return",
"&",
"n",
"\n",
"}"
] | // WithCodec returns a new Storm Node that will use the given Codec. | [
"WithCodec",
"returns",
"a",
"new",
"Storm",
"Node",
"that",
"will",
"use",
"the",
"given",
"Codec",
"."
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/node.go#L77-L80 | train |
asdine/storm | node.go | WithBatch | func (n node) WithBatch(enabled bool) Node {
n.batchMode = enabled
return &n
} | go | func (n node) WithBatch(enabled bool) Node {
n.batchMode = enabled
return &n
} | [
"func",
"(",
"n",
"node",
")",
"WithBatch",
"(",
"enabled",
"bool",
")",
"Node",
"{",
"n",
".",
"batchMode",
"=",
"enabled",
"\n",
"return",
"&",
"n",
"\n",
"}"
] | // WithBatch returns a new Storm Node with the batch mode enabled. | [
"WithBatch",
"returns",
"a",
"new",
"Storm",
"Node",
"with",
"the",
"batch",
"mode",
"enabled",
"."
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/node.go#L83-L86 | train |
asdine/storm | node.go | readWriteTx | func (n *node) readWriteTx(fn func(tx *bolt.Tx) error) error {
if n.tx != nil {
return fn(n.tx)
}
if n.batchMode {
return n.s.Bolt.Batch(func(tx *bolt.Tx) error {
return fn(tx)
})
}
return n.s.Bolt.Update(func(tx *bolt.Tx) error {
return fn(tx)
})
} | go | func (n *node) readWriteTx(fn func(tx *bolt.Tx) error) error {
if n.tx != nil {
return fn(n.tx)
}
if n.batchMode {
return n.s.Bolt.Batch(func(tx *bolt.Tx) error {
return fn(tx)
})
}
return n.s.Bolt.Update(func(tx *bolt.Tx) error {
return fn(tx)
})
} | [
"func",
"(",
"n",
"*",
"node",
")",
"readWriteTx",
"(",
"fn",
"func",
"(",
"tx",
"*",
"bolt",
".",
"Tx",
")",
"error",
")",
"error",
"{",
"if",
"n",
".",
"tx",
"!=",
"nil",
"{",
"return",
"fn",
"(",
"n",
".",
"tx",
")",
"\n",
"}",
"\n\n",
"... | // Detects if already in transaction or runs a read write transaction.
// Uses batch mode if enabled. | [
"Detects",
"if",
"already",
"in",
"transaction",
"or",
"runs",
"a",
"read",
"write",
"transaction",
".",
"Uses",
"batch",
"mode",
"if",
"enabled",
"."
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/node.go#L101-L115 | train |
asdine/storm | node.go | readTx | func (n *node) readTx(fn func(tx *bolt.Tx) error) error {
if n.tx != nil {
return fn(n.tx)
}
return n.s.Bolt.View(func(tx *bolt.Tx) error {
return fn(tx)
})
} | go | func (n *node) readTx(fn func(tx *bolt.Tx) error) error {
if n.tx != nil {
return fn(n.tx)
}
return n.s.Bolt.View(func(tx *bolt.Tx) error {
return fn(tx)
})
} | [
"func",
"(",
"n",
"*",
"node",
")",
"readTx",
"(",
"fn",
"func",
"(",
"tx",
"*",
"bolt",
".",
"Tx",
")",
"error",
")",
"error",
"{",
"if",
"n",
".",
"tx",
"!=",
"nil",
"{",
"return",
"fn",
"(",
"n",
".",
"tx",
")",
"\n",
"}",
"\n\n",
"retur... | // Detects if already in transaction or runs a read transaction. | [
"Detects",
"if",
"already",
"in",
"transaction",
"or",
"runs",
"a",
"read",
"transaction",
"."
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/node.go#L118-L126 | train |
asdine/storm | index/unique.go | NewUniqueIndex | func NewUniqueIndex(parent *bolt.Bucket, indexName []byte) (*UniqueIndex, error) {
var err error
b := parent.Bucket(indexName)
if b == nil {
if !parent.Writable() {
return nil, ErrNotFound
}
b, err = parent.CreateBucket(indexName)
if err != nil {
return nil, err
}
}
return &UniqueIndex{
IndexBuc... | go | func NewUniqueIndex(parent *bolt.Bucket, indexName []byte) (*UniqueIndex, error) {
var err error
b := parent.Bucket(indexName)
if b == nil {
if !parent.Writable() {
return nil, ErrNotFound
}
b, err = parent.CreateBucket(indexName)
if err != nil {
return nil, err
}
}
return &UniqueIndex{
IndexBuc... | [
"func",
"NewUniqueIndex",
"(",
"parent",
"*",
"bolt",
".",
"Bucket",
",",
"indexName",
"[",
"]",
"byte",
")",
"(",
"*",
"UniqueIndex",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"b",
":=",
"parent",
".",
"Bucket",
"(",
"indexName",
")",
"\n... | // NewUniqueIndex loads a UniqueIndex | [
"NewUniqueIndex",
"loads",
"a",
"UniqueIndex"
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/index/unique.go#L11-L28 | train |
asdine/storm | index/unique.go | Add | func (idx *UniqueIndex) Add(value []byte, targetID []byte) error {
if value == nil || len(value) == 0 {
return ErrNilParam
}
if targetID == nil || len(targetID) == 0 {
return ErrNilParam
}
exists := idx.IndexBucket.Get(value)
if exists != nil {
if bytes.Equal(exists, targetID) {
return nil
}
return ... | go | func (idx *UniqueIndex) Add(value []byte, targetID []byte) error {
if value == nil || len(value) == 0 {
return ErrNilParam
}
if targetID == nil || len(targetID) == 0 {
return ErrNilParam
}
exists := idx.IndexBucket.Get(value)
if exists != nil {
if bytes.Equal(exists, targetID) {
return nil
}
return ... | [
"func",
"(",
"idx",
"*",
"UniqueIndex",
")",
"Add",
"(",
"value",
"[",
"]",
"byte",
",",
"targetID",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"value",
"==",
"nil",
"||",
"len",
"(",
"value",
")",
"==",
"0",
"{",
"return",
"ErrNilParam",
"\n",
"... | // Add a value to the unique index | [
"Add",
"a",
"value",
"to",
"the",
"unique",
"index"
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/index/unique.go#L37-L54 | train |
asdine/storm | index/unique.go | RemoveID | func (idx *UniqueIndex) RemoveID(id []byte) error {
c := idx.IndexBucket.Cursor()
for val, ident := c.First(); val != nil; val, ident = c.Next() {
if bytes.Equal(ident, id) {
return idx.Remove(val)
}
}
return nil
} | go | func (idx *UniqueIndex) RemoveID(id []byte) error {
c := idx.IndexBucket.Cursor()
for val, ident := c.First(); val != nil; val, ident = c.Next() {
if bytes.Equal(ident, id) {
return idx.Remove(val)
}
}
return nil
} | [
"func",
"(",
"idx",
"*",
"UniqueIndex",
")",
"RemoveID",
"(",
"id",
"[",
"]",
"byte",
")",
"error",
"{",
"c",
":=",
"idx",
".",
"IndexBucket",
".",
"Cursor",
"(",
")",
"\n\n",
"for",
"val",
",",
"ident",
":=",
"c",
".",
"First",
"(",
")",
";",
... | // RemoveID removes an ID from the unique index | [
"RemoveID",
"removes",
"an",
"ID",
"from",
"the",
"unique",
"index"
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/index/unique.go#L62-L71 | train |
asdine/storm | index/unique.go | Get | func (idx *UniqueIndex) Get(value []byte) []byte {
return idx.IndexBucket.Get(value)
} | go | func (idx *UniqueIndex) Get(value []byte) []byte {
return idx.IndexBucket.Get(value)
} | [
"func",
"(",
"idx",
"*",
"UniqueIndex",
")",
"Get",
"(",
"value",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"return",
"idx",
".",
"IndexBucket",
".",
"Get",
"(",
"value",
")",
"\n",
"}"
] | // Get the id corresponding to the given value | [
"Get",
"the",
"id",
"corresponding",
"to",
"the",
"given",
"value"
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/index/unique.go#L74-L76 | train |
asdine/storm | index/unique.go | All | func (idx *UniqueIndex) All(value []byte, opts *Options) ([][]byte, error) {
id := idx.IndexBucket.Get(value)
if id != nil {
return [][]byte{id}, nil
}
return nil, nil
} | go | func (idx *UniqueIndex) All(value []byte, opts *Options) ([][]byte, error) {
id := idx.IndexBucket.Get(value)
if id != nil {
return [][]byte{id}, nil
}
return nil, nil
} | [
"func",
"(",
"idx",
"*",
"UniqueIndex",
")",
"All",
"(",
"value",
"[",
"]",
"byte",
",",
"opts",
"*",
"Options",
")",
"(",
"[",
"]",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"id",
":=",
"idx",
".",
"IndexBucket",
".",
"Get",
"(",
"value",
")",... | // All returns all the ids corresponding to the given value | [
"All",
"returns",
"all",
"the",
"ids",
"corresponding",
"to",
"the",
"given",
"value"
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/index/unique.go#L79-L86 | train |
asdine/storm | index/unique.go | first | func (idx *UniqueIndex) first() []byte {
c := idx.IndexBucket.Cursor()
for val, ident := c.First(); val != nil; val, ident = c.Next() {
return ident
}
return nil
} | go | func (idx *UniqueIndex) first() []byte {
c := idx.IndexBucket.Cursor()
for val, ident := c.First(); val != nil; val, ident = c.Next() {
return ident
}
return nil
} | [
"func",
"(",
"idx",
"*",
"UniqueIndex",
")",
"first",
"(",
")",
"[",
"]",
"byte",
"{",
"c",
":=",
"idx",
".",
"IndexBucket",
".",
"Cursor",
"(",
")",
"\n\n",
"for",
"val",
",",
"ident",
":=",
"c",
".",
"First",
"(",
")",
";",
"val",
"!=",
"nil"... | // first returns the first ID of this index | [
"first",
"returns",
"the",
"first",
"ID",
"of",
"this",
"index"
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/index/unique.go#L176-L183 | train |
asdine/storm | codec/protobuf/protobuf.go | Marshal | func (c protobufCodec) Marshal(v interface{}) ([]byte, error) {
message, ok := v.(proto.Message)
if !ok {
// toBytes() may need to encode non-protobuf type, if that occurs use json
return json.Codec.Marshal(v)
}
return proto.Marshal(message)
} | go | func (c protobufCodec) Marshal(v interface{}) ([]byte, error) {
message, ok := v.(proto.Message)
if !ok {
// toBytes() may need to encode non-protobuf type, if that occurs use json
return json.Codec.Marshal(v)
}
return proto.Marshal(message)
} | [
"func",
"(",
"c",
"protobufCodec",
")",
"Marshal",
"(",
"v",
"interface",
"{",
"}",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"message",
",",
"ok",
":=",
"v",
".",
"(",
"proto",
".",
"Message",
")",
"\n",
"if",
"!",
"ok",
"{",
"// toB... | // Encode value with protocol buffer.
// If type isn't a Protocol buffer Message, json encoder will be used instead. | [
"Encode",
"value",
"with",
"protocol",
"buffer",
".",
"If",
"type",
"isn",
"t",
"a",
"Protocol",
"buffer",
"Message",
"json",
"encoder",
"will",
"be",
"used",
"instead",
"."
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/codec/protobuf/protobuf.go#L23-L30 | train |
asdine/storm | storm.go | Open | func Open(path string, stormOptions ...func(*Options) error) (*DB, error) {
var err error
var opts Options
for _, option := range stormOptions {
if err = option(&opts); err != nil {
return nil, err
}
}
s := DB{
Bolt: opts.bolt,
}
n := node{
s: &s,
codec: opts.codec,
batchMode: op... | go | func Open(path string, stormOptions ...func(*Options) error) (*DB, error) {
var err error
var opts Options
for _, option := range stormOptions {
if err = option(&opts); err != nil {
return nil, err
}
}
s := DB{
Bolt: opts.bolt,
}
n := node{
s: &s,
codec: opts.codec,
batchMode: op... | [
"func",
"Open",
"(",
"path",
"string",
",",
"stormOptions",
"...",
"func",
"(",
"*",
"Options",
")",
"error",
")",
"(",
"*",
"DB",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"var",
"opts",
"Options",
"\n",
"for",
"_",
",",
"option",
":=... | // Open opens a database at the given path with optional Storm options. | [
"Open",
"opens",
"a",
"database",
"at",
"the",
"given",
"path",
"with",
"optional",
"Storm",
"options",
"."
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/storm.go#L22-L71 | train |
asdine/storm | storm.go | toBytes | func toBytes(key interface{}, codec codec.MarshalUnmarshaler) ([]byte, error) {
if key == nil {
return nil, nil
}
switch t := key.(type) {
case []byte:
return t, nil
case string:
return []byte(t), nil
case int:
return numbertob(int64(t))
case uint:
return numbertob(uint64(t))
case int8, int16, int32, ... | go | func toBytes(key interface{}, codec codec.MarshalUnmarshaler) ([]byte, error) {
if key == nil {
return nil, nil
}
switch t := key.(type) {
case []byte:
return t, nil
case string:
return []byte(t), nil
case int:
return numbertob(int64(t))
case uint:
return numbertob(uint64(t))
case int8, int16, int32, ... | [
"func",
"toBytes",
"(",
"key",
"interface",
"{",
"}",
",",
"codec",
"codec",
".",
"MarshalUnmarshaler",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"key",
"==",
"nil",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"switch",
"t",
... | // toBytes turns an interface into a slice of bytes | [
"toBytes",
"turns",
"an",
"interface",
"into",
"a",
"slice",
"of",
"bytes"
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/storm.go#L105-L123 | train |
asdine/storm | options.go | BoltOptions | func BoltOptions(mode os.FileMode, options *bolt.Options) func(*Options) error {
return func(opts *Options) error {
opts.boltMode = mode
opts.boltOptions = options
return nil
}
} | go | func BoltOptions(mode os.FileMode, options *bolt.Options) func(*Options) error {
return func(opts *Options) error {
opts.boltMode = mode
opts.boltOptions = options
return nil
}
} | [
"func",
"BoltOptions",
"(",
"mode",
"os",
".",
"FileMode",
",",
"options",
"*",
"bolt",
".",
"Options",
")",
"func",
"(",
"*",
"Options",
")",
"error",
"{",
"return",
"func",
"(",
"opts",
"*",
"Options",
")",
"error",
"{",
"opts",
".",
"boltMode",
"=... | // BoltOptions used to pass options to BoltDB. | [
"BoltOptions",
"used",
"to",
"pass",
"options",
"to",
"BoltDB",
"."
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/options.go#L12-L18 | train |
asdine/storm | options.go | Codec | func Codec(c codec.MarshalUnmarshaler) func(*Options) error {
return func(opts *Options) error {
opts.codec = c
return nil
}
} | go | func Codec(c codec.MarshalUnmarshaler) func(*Options) error {
return func(opts *Options) error {
opts.codec = c
return nil
}
} | [
"func",
"Codec",
"(",
"c",
"codec",
".",
"MarshalUnmarshaler",
")",
"func",
"(",
"*",
"Options",
")",
"error",
"{",
"return",
"func",
"(",
"opts",
"*",
"Options",
")",
"error",
"{",
"opts",
".",
"codec",
"=",
"c",
"\n",
"return",
"nil",
"\n",
"}",
... | // Codec used to set a custom encoder and decoder. The default is JSON. | [
"Codec",
"used",
"to",
"set",
"a",
"custom",
"encoder",
"and",
"decoder",
".",
"The",
"default",
"is",
"JSON",
"."
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/options.go#L21-L26 | train |
asdine/storm | options.go | Batch | func Batch() func(*Options) error {
return func(opts *Options) error {
opts.batchMode = true
return nil
}
} | go | func Batch() func(*Options) error {
return func(opts *Options) error {
opts.batchMode = true
return nil
}
} | [
"func",
"Batch",
"(",
")",
"func",
"(",
"*",
"Options",
")",
"error",
"{",
"return",
"func",
"(",
"opts",
"*",
"Options",
")",
"error",
"{",
"opts",
".",
"batchMode",
"=",
"true",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // Batch enables the use of batch instead of update for read-write transactions. | [
"Batch",
"enables",
"the",
"use",
"of",
"batch",
"instead",
"of",
"update",
"for",
"read",
"-",
"write",
"transactions",
"."
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/options.go#L29-L34 | train |
asdine/storm | options.go | Root | func Root(root ...string) func(*Options) error {
return func(opts *Options) error {
opts.rootBucket = root
return nil
}
} | go | func Root(root ...string) func(*Options) error {
return func(opts *Options) error {
opts.rootBucket = root
return nil
}
} | [
"func",
"Root",
"(",
"root",
"...",
"string",
")",
"func",
"(",
"*",
"Options",
")",
"error",
"{",
"return",
"func",
"(",
"opts",
"*",
"Options",
")",
"error",
"{",
"opts",
".",
"rootBucket",
"=",
"root",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"... | // Root used to set the root bucket. See also the From method. | [
"Root",
"used",
"to",
"set",
"the",
"root",
"bucket",
".",
"See",
"also",
"the",
"From",
"method",
"."
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/options.go#L37-L42 | train |
asdine/storm | options.go | Limit | func Limit(limit int) func(*index.Options) {
return func(opts *index.Options) {
opts.Limit = limit
}
} | go | func Limit(limit int) func(*index.Options) {
return func(opts *index.Options) {
opts.Limit = limit
}
} | [
"func",
"Limit",
"(",
"limit",
"int",
")",
"func",
"(",
"*",
"index",
".",
"Options",
")",
"{",
"return",
"func",
"(",
"opts",
"*",
"index",
".",
"Options",
")",
"{",
"opts",
".",
"Limit",
"=",
"limit",
"\n",
"}",
"\n",
"}"
] | // Limit sets the maximum number of records to return | [
"Limit",
"sets",
"the",
"maximum",
"number",
"of",
"records",
"to",
"return"
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/options.go#L55-L59 | train |
asdine/storm | options.go | Skip | func Skip(offset int) func(*index.Options) {
return func(opts *index.Options) {
opts.Skip = offset
}
} | go | func Skip(offset int) func(*index.Options) {
return func(opts *index.Options) {
opts.Skip = offset
}
} | [
"func",
"Skip",
"(",
"offset",
"int",
")",
"func",
"(",
"*",
"index",
".",
"Options",
")",
"{",
"return",
"func",
"(",
"opts",
"*",
"index",
".",
"Options",
")",
"{",
"opts",
".",
"Skip",
"=",
"offset",
"\n",
"}",
"\n",
"}"
] | // Skip sets the number of records to skip | [
"Skip",
"sets",
"the",
"number",
"of",
"records",
"to",
"skip"
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/options.go#L62-L66 | train |
asdine/storm | store.go | Init | func (n *node) Init(data interface{}) error {
v := reflect.ValueOf(data)
cfg, err := extract(&v)
if err != nil {
return err
}
return n.readWriteTx(func(tx *bolt.Tx) error {
return n.init(tx, cfg)
})
} | go | func (n *node) Init(data interface{}) error {
v := reflect.ValueOf(data)
cfg, err := extract(&v)
if err != nil {
return err
}
return n.readWriteTx(func(tx *bolt.Tx) error {
return n.init(tx, cfg)
})
} | [
"func",
"(",
"n",
"*",
"node",
")",
"Init",
"(",
"data",
"interface",
"{",
"}",
")",
"error",
"{",
"v",
":=",
"reflect",
".",
"ValueOf",
"(",
"data",
")",
"\n",
"cfg",
",",
"err",
":=",
"extract",
"(",
"&",
"v",
")",
"\n",
"if",
"err",
"!=",
... | // Init creates the indexes and buckets for a given structure | [
"Init",
"creates",
"the",
"indexes",
"and",
"buckets",
"for",
"a",
"given",
"structure"
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/store.go#L38-L48 | train |
asdine/storm | store.go | Save | func (n *node) Save(data interface{}) error {
ref := reflect.ValueOf(data)
if !ref.IsValid() || ref.Kind() != reflect.Ptr || ref.Elem().Kind() != reflect.Struct {
return ErrStructPtrNeeded
}
cfg, err := extract(&ref)
if err != nil {
return err
}
if cfg.ID.IsZero {
if !cfg.ID.IsInteger || !cfg.ID.Increme... | go | func (n *node) Save(data interface{}) error {
ref := reflect.ValueOf(data)
if !ref.IsValid() || ref.Kind() != reflect.Ptr || ref.Elem().Kind() != reflect.Struct {
return ErrStructPtrNeeded
}
cfg, err := extract(&ref)
if err != nil {
return err
}
if cfg.ID.IsZero {
if !cfg.ID.IsInteger || !cfg.ID.Increme... | [
"func",
"(",
"n",
"*",
"node",
")",
"Save",
"(",
"data",
"interface",
"{",
"}",
")",
"error",
"{",
"ref",
":=",
"reflect",
".",
"ValueOf",
"(",
"data",
")",
"\n\n",
"if",
"!",
"ref",
".",
"IsValid",
"(",
")",
"||",
"ref",
".",
"Kind",
"(",
")",... | // Save a structure | [
"Save",
"a",
"structure"
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/store.go#L138-L159 | train |
asdine/storm | store.go | Update | func (n *node) Update(data interface{}) error {
return n.update(data, func(ref *reflect.Value, current *reflect.Value, cfg *structConfig) error {
numfield := ref.NumField()
for i := 0; i < numfield; i++ {
f := ref.Field(i)
if ref.Type().Field(i).PkgPath != "" {
continue
}
zero := reflect.Zero(f.Typ... | go | func (n *node) Update(data interface{}) error {
return n.update(data, func(ref *reflect.Value, current *reflect.Value, cfg *structConfig) error {
numfield := ref.NumField()
for i := 0; i < numfield; i++ {
f := ref.Field(i)
if ref.Type().Field(i).PkgPath != "" {
continue
}
zero := reflect.Zero(f.Typ... | [
"func",
"(",
"n",
"*",
"node",
")",
"Update",
"(",
"data",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"n",
".",
"update",
"(",
"data",
",",
"func",
"(",
"ref",
"*",
"reflect",
".",
"Value",
",",
"current",
"*",
"reflect",
".",
"Value",
"... | // Update a structure | [
"Update",
"a",
"structure"
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/store.go#L258-L279 | train |
asdine/storm | store.go | UpdateField | func (n *node) UpdateField(data interface{}, fieldName string, value interface{}) error {
return n.update(data, func(ref *reflect.Value, current *reflect.Value, cfg *structConfig) error {
f := current.FieldByName(fieldName)
if !f.IsValid() {
return ErrNotFound
}
tf, _ := current.Type().FieldByName(fieldName... | go | func (n *node) UpdateField(data interface{}, fieldName string, value interface{}) error {
return n.update(data, func(ref *reflect.Value, current *reflect.Value, cfg *structConfig) error {
f := current.FieldByName(fieldName)
if !f.IsValid() {
return ErrNotFound
}
tf, _ := current.Type().FieldByName(fieldName... | [
"func",
"(",
"n",
"*",
"node",
")",
"UpdateField",
"(",
"data",
"interface",
"{",
"}",
",",
"fieldName",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"n",
".",
"update",
"(",
"data",
",",
"func",
"(",
"ref",
"*",
"ref... | // UpdateField updates a single field | [
"UpdateField",
"updates",
"a",
"single",
"field"
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/store.go#L282-L305 | train |
asdine/storm | store.go | Drop | func (n *node) Drop(data interface{}) error {
var bucketName string
v := reflect.ValueOf(data)
if v.Kind() != reflect.String {
info, err := extract(&v)
if err != nil {
return err
}
bucketName = info.Name
} else {
bucketName = v.Interface().(string)
}
return n.readWriteTx(func(tx *bolt.Tx) error {
... | go | func (n *node) Drop(data interface{}) error {
var bucketName string
v := reflect.ValueOf(data)
if v.Kind() != reflect.String {
info, err := extract(&v)
if err != nil {
return err
}
bucketName = info.Name
} else {
bucketName = v.Interface().(string)
}
return n.readWriteTx(func(tx *bolt.Tx) error {
... | [
"func",
"(",
"n",
"*",
"node",
")",
"Drop",
"(",
"data",
"interface",
"{",
"}",
")",
"error",
"{",
"var",
"bucketName",
"string",
"\n\n",
"v",
":=",
"reflect",
".",
"ValueOf",
"(",
"data",
")",
"\n",
"if",
"v",
".",
"Kind",
"(",
")",
"!=",
"refle... | // Drop a bucket | [
"Drop",
"a",
"bucket"
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/store.go#L342-L360 | train |
asdine/storm | store.go | DeleteStruct | func (n *node) DeleteStruct(data interface{}) error {
ref := reflect.ValueOf(data)
if !ref.IsValid() || ref.Kind() != reflect.Ptr || ref.Elem().Kind() != reflect.Struct {
return ErrStructPtrNeeded
}
cfg, err := extract(&ref)
if err != nil {
return err
}
id, err := toBytes(cfg.ID.Value.Interface(), n.codec... | go | func (n *node) DeleteStruct(data interface{}) error {
ref := reflect.ValueOf(data)
if !ref.IsValid() || ref.Kind() != reflect.Ptr || ref.Elem().Kind() != reflect.Struct {
return ErrStructPtrNeeded
}
cfg, err := extract(&ref)
if err != nil {
return err
}
id, err := toBytes(cfg.ID.Value.Interface(), n.codec... | [
"func",
"(",
"n",
"*",
"node",
")",
"DeleteStruct",
"(",
"data",
"interface",
"{",
"}",
")",
"error",
"{",
"ref",
":=",
"reflect",
".",
"ValueOf",
"(",
"data",
")",
"\n\n",
"if",
"!",
"ref",
".",
"IsValid",
"(",
")",
"||",
"ref",
".",
"Kind",
"("... | // DeleteStruct deletes a structure from the associated bucket | [
"DeleteStruct",
"deletes",
"a",
"structure",
"from",
"the",
"associated",
"bucket"
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/store.go#L372-L392 | train |
asdine/storm | kv.go | SetBytes | func (n *node) SetBytes(bucketName string, key interface{}, value []byte) error {
if key == nil {
return ErrNilParam
}
id, err := toBytes(key, n.codec)
if err != nil {
return err
}
return n.readWriteTx(func(tx *bolt.Tx) error {
return n.setBytes(tx, bucketName, id, value)
})
} | go | func (n *node) SetBytes(bucketName string, key interface{}, value []byte) error {
if key == nil {
return ErrNilParam
}
id, err := toBytes(key, n.codec)
if err != nil {
return err
}
return n.readWriteTx(func(tx *bolt.Tx) error {
return n.setBytes(tx, bucketName, id, value)
})
} | [
"func",
"(",
"n",
"*",
"node",
")",
"SetBytes",
"(",
"bucketName",
"string",
",",
"key",
"interface",
"{",
"}",
",",
"value",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"key",
"==",
"nil",
"{",
"return",
"ErrNilParam",
"\n",
"}",
"\n\n",
"id",
",",... | // SetBytes sets a raw value into a bucket. | [
"SetBytes",
"sets",
"a",
"raw",
"value",
"into",
"a",
"bucket",
"."
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/kv.go#L61-L74 | train |
asdine/storm | kv.go | Get | func (n *node) Get(bucketName string, key interface{}, to interface{}) error {
ref := reflect.ValueOf(to)
if !ref.IsValid() || ref.Kind() != reflect.Ptr {
return ErrPtrNeeded
}
id, err := toBytes(key, n.codec)
if err != nil {
return err
}
return n.readTx(func(tx *bolt.Tx) error {
raw, err := n.getBytes(... | go | func (n *node) Get(bucketName string, key interface{}, to interface{}) error {
ref := reflect.ValueOf(to)
if !ref.IsValid() || ref.Kind() != reflect.Ptr {
return ErrPtrNeeded
}
id, err := toBytes(key, n.codec)
if err != nil {
return err
}
return n.readTx(func(tx *bolt.Tx) error {
raw, err := n.getBytes(... | [
"func",
"(",
"n",
"*",
"node",
")",
"Get",
"(",
"bucketName",
"string",
",",
"key",
"interface",
"{",
"}",
",",
"to",
"interface",
"{",
"}",
")",
"error",
"{",
"ref",
":=",
"reflect",
".",
"ValueOf",
"(",
"to",
")",
"\n\n",
"if",
"!",
"ref",
".",... | // Get a value from a bucket | [
"Get",
"a",
"value",
"from",
"a",
"bucket"
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/kv.go#L92-L112 | train |
asdine/storm | kv.go | Delete | func (n *node) Delete(bucketName string, key interface{}) error {
id, err := toBytes(key, n.codec)
if err != nil {
return err
}
return n.readWriteTx(func(tx *bolt.Tx) error {
return n.delete(tx, bucketName, id)
})
} | go | func (n *node) Delete(bucketName string, key interface{}) error {
id, err := toBytes(key, n.codec)
if err != nil {
return err
}
return n.readWriteTx(func(tx *bolt.Tx) error {
return n.delete(tx, bucketName, id)
})
} | [
"func",
"(",
"n",
"*",
"node",
")",
"Delete",
"(",
"bucketName",
"string",
",",
"key",
"interface",
"{",
"}",
")",
"error",
"{",
"id",
",",
"err",
":=",
"toBytes",
"(",
"key",
",",
"n",
".",
"codec",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"r... | // Delete deletes a key from a bucket | [
"Delete",
"deletes",
"a",
"key",
"from",
"a",
"bucket"
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/kv.go#L129-L138 | train |
asdine/storm | kv.go | KeyExists | func (n *node) KeyExists(bucketName string, key interface{}) (bool, error) {
id, err := toBytes(key, n.codec)
if err != nil {
return false, err
}
var exists bool
return exists, n.readTx(func(tx *bolt.Tx) error {
bucket := n.GetBucket(tx, bucketName)
if bucket == nil {
return ErrNotFound
}
v := bucke... | go | func (n *node) KeyExists(bucketName string, key interface{}) (bool, error) {
id, err := toBytes(key, n.codec)
if err != nil {
return false, err
}
var exists bool
return exists, n.readTx(func(tx *bolt.Tx) error {
bucket := n.GetBucket(tx, bucketName)
if bucket == nil {
return ErrNotFound
}
v := bucke... | [
"func",
"(",
"n",
"*",
"node",
")",
"KeyExists",
"(",
"bucketName",
"string",
",",
"key",
"interface",
"{",
"}",
")",
"(",
"bool",
",",
"error",
")",
"{",
"id",
",",
"err",
":=",
"toBytes",
"(",
"key",
",",
"n",
".",
"codec",
")",
"\n",
"if",
"... | // KeyExists reports the presence of a key in a bucket. | [
"KeyExists",
"reports",
"the",
"presence",
"of",
"a",
"key",
"in",
"a",
"bucket",
"."
] | e0f77eada154c7c2670527a8566d3c045880224f | https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/kv.go#L150-L170 | train |
gorilla/sessions | store.go | save | func (s *FilesystemStore) save(session *Session) error {
encoded, err := securecookie.EncodeMulti(session.Name(), session.Values,
s.Codecs...)
if err != nil {
return err
}
filename := filepath.Join(s.path, "session_"+session.ID)
fileMutex.Lock()
defer fileMutex.Unlock()
return ioutil.WriteFile(filename, []by... | go | func (s *FilesystemStore) save(session *Session) error {
encoded, err := securecookie.EncodeMulti(session.Name(), session.Values,
s.Codecs...)
if err != nil {
return err
}
filename := filepath.Join(s.path, "session_"+session.ID)
fileMutex.Lock()
defer fileMutex.Unlock()
return ioutil.WriteFile(filename, []by... | [
"func",
"(",
"s",
"*",
"FilesystemStore",
")",
"save",
"(",
"session",
"*",
"Session",
")",
"error",
"{",
"encoded",
",",
"err",
":=",
"securecookie",
".",
"EncodeMulti",
"(",
"session",
".",
"Name",
"(",
")",
",",
"session",
".",
"Values",
",",
"s",
... | // save writes encoded session.Values to a file. | [
"save",
"writes",
"encoded",
"session",
".",
"Values",
"to",
"a",
"file",
"."
] | 12bd4761fc66ac946e16fcc2a32b1e0b066f6177 | https://github.com/gorilla/sessions/blob/12bd4761fc66ac946e16fcc2a32b1e0b066f6177/store.go#L255-L265 | train |
gorilla/sessions | store.go | erase | func (s *FilesystemStore) erase(session *Session) error {
filename := filepath.Join(s.path, "session_"+session.ID)
fileMutex.RLock()
defer fileMutex.RUnlock()
err := os.Remove(filename)
return err
} | go | func (s *FilesystemStore) erase(session *Session) error {
filename := filepath.Join(s.path, "session_"+session.ID)
fileMutex.RLock()
defer fileMutex.RUnlock()
err := os.Remove(filename)
return err
} | [
"func",
"(",
"s",
"*",
"FilesystemStore",
")",
"erase",
"(",
"session",
"*",
"Session",
")",
"error",
"{",
"filename",
":=",
"filepath",
".",
"Join",
"(",
"s",
".",
"path",
",",
"\"",
"\"",
"+",
"session",
".",
"ID",
")",
"\n\n",
"fileMutex",
".",
... | // delete session file | [
"delete",
"session",
"file"
] | 12bd4761fc66ac946e16fcc2a32b1e0b066f6177 | https://github.com/gorilla/sessions/blob/12bd4761fc66ac946e16fcc2a32b1e0b066f6177/store.go#L284-L292 | train |
gorilla/sessions | sessions.go | GetRegistry | func GetRegistry(r *http.Request) *Registry {
var ctx = r.Context()
registry := ctx.Value(registryKey)
if registry != nil {
return registry.(*Registry)
}
newRegistry := &Registry{
request: r,
sessions: make(map[string]sessionInfo),
}
*r = *r.WithContext(context.WithValue(ctx, registryKey, newRegistry))
r... | go | func GetRegistry(r *http.Request) *Registry {
var ctx = r.Context()
registry := ctx.Value(registryKey)
if registry != nil {
return registry.(*Registry)
}
newRegistry := &Registry{
request: r,
sessions: make(map[string]sessionInfo),
}
*r = *r.WithContext(context.WithValue(ctx, registryKey, newRegistry))
r... | [
"func",
"GetRegistry",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"*",
"Registry",
"{",
"var",
"ctx",
"=",
"r",
".",
"Context",
"(",
")",
"\n",
"registry",
":=",
"ctx",
".",
"Value",
"(",
"registryKey",
")",
"\n",
"if",
"registry",
"!=",
"nil",
"{... | // GetRegistry returns a registry instance for the current request. | [
"GetRegistry",
"returns",
"a",
"registry",
"instance",
"for",
"the",
"current",
"request",
"."
] | 12bd4761fc66ac946e16fcc2a32b1e0b066f6177 | https://github.com/gorilla/sessions/blob/12bd4761fc66ac946e16fcc2a32b1e0b066f6177/sessions.go#L109-L121 | train |
gorilla/sessions | sessions.go | Get | func (s *Registry) Get(store Store, name string) (session *Session, err error) {
if !isCookieNameValid(name) {
return nil, fmt.Errorf("sessions: invalid character in cookie name: %s", name)
}
if info, ok := s.sessions[name]; ok {
session, err = info.s, info.e
} else {
session, err = store.New(s.request, name)... | go | func (s *Registry) Get(store Store, name string) (session *Session, err error) {
if !isCookieNameValid(name) {
return nil, fmt.Errorf("sessions: invalid character in cookie name: %s", name)
}
if info, ok := s.sessions[name]; ok {
session, err = info.s, info.e
} else {
session, err = store.New(s.request, name)... | [
"func",
"(",
"s",
"*",
"Registry",
")",
"Get",
"(",
"store",
"Store",
",",
"name",
"string",
")",
"(",
"session",
"*",
"Session",
",",
"err",
"error",
")",
"{",
"if",
"!",
"isCookieNameValid",
"(",
"name",
")",
"{",
"return",
"nil",
",",
"fmt",
"."... | // Get registers and returns a session for the given name and session store.
//
// It returns a new session if there are no sessions registered for the name. | [
"Get",
"registers",
"and",
"returns",
"a",
"session",
"for",
"the",
"given",
"name",
"and",
"session",
"store",
".",
"It",
"returns",
"a",
"new",
"session",
"if",
"there",
"are",
"no",
"sessions",
"registered",
"for",
"the",
"name",
"."
] | 12bd4761fc66ac946e16fcc2a32b1e0b066f6177 | https://github.com/gorilla/sessions/blob/12bd4761fc66ac946e16fcc2a32b1e0b066f6177/sessions.go#L132-L145 | train |
gorilla/sessions | sessions.go | Save | func (s *Registry) Save(w http.ResponseWriter) error {
var errMulti MultiError
for name, info := range s.sessions {
session := info.s
if session.store == nil {
errMulti = append(errMulti, fmt.Errorf(
"sessions: missing store for session %q", name))
} else if err := session.store.Save(s.request, w, sessio... | go | func (s *Registry) Save(w http.ResponseWriter) error {
var errMulti MultiError
for name, info := range s.sessions {
session := info.s
if session.store == nil {
errMulti = append(errMulti, fmt.Errorf(
"sessions: missing store for session %q", name))
} else if err := session.store.Save(s.request, w, sessio... | [
"func",
"(",
"s",
"*",
"Registry",
")",
"Save",
"(",
"w",
"http",
".",
"ResponseWriter",
")",
"error",
"{",
"var",
"errMulti",
"MultiError",
"\n",
"for",
"name",
",",
"info",
":=",
"range",
"s",
".",
"sessions",
"{",
"session",
":=",
"info",
".",
"s"... | // Save saves all sessions registered for the current request. | [
"Save",
"saves",
"all",
"sessions",
"registered",
"for",
"the",
"current",
"request",
"."
] | 12bd4761fc66ac946e16fcc2a32b1e0b066f6177 | https://github.com/gorilla/sessions/blob/12bd4761fc66ac946e16fcc2a32b1e0b066f6177/sessions.go#L148-L164 | train |
gorilla/sessions | sessions.go | Save | func Save(r *http.Request, w http.ResponseWriter) error {
return GetRegistry(r).Save(w)
} | go | func Save(r *http.Request, w http.ResponseWriter) error {
return GetRegistry(r).Save(w)
} | [
"func",
"Save",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"w",
"http",
".",
"ResponseWriter",
")",
"error",
"{",
"return",
"GetRegistry",
"(",
"r",
")",
".",
"Save",
"(",
"w",
")",
"\n",
"}"
] | // Save saves all sessions used during the current request. | [
"Save",
"saves",
"all",
"sessions",
"used",
"during",
"the",
"current",
"request",
"."
] | 12bd4761fc66ac946e16fcc2a32b1e0b066f6177 | https://github.com/gorilla/sessions/blob/12bd4761fc66ac946e16fcc2a32b1e0b066f6177/sessions.go#L173-L175 | train |
gorilla/sessions | cookie_go111.go | newCookieFromOptions | func newCookieFromOptions(name, value string, options *Options) *http.Cookie {
return &http.Cookie{
Name: name,
Value: value,
Path: options.Path,
Domain: options.Domain,
MaxAge: options.MaxAge,
Secure: options.Secure,
HttpOnly: options.HttpOnly,
SameSite: options.SameSite,
}
} | go | func newCookieFromOptions(name, value string, options *Options) *http.Cookie {
return &http.Cookie{
Name: name,
Value: value,
Path: options.Path,
Domain: options.Domain,
MaxAge: options.MaxAge,
Secure: options.Secure,
HttpOnly: options.HttpOnly,
SameSite: options.SameSite,
}
} | [
"func",
"newCookieFromOptions",
"(",
"name",
",",
"value",
"string",
",",
"options",
"*",
"Options",
")",
"*",
"http",
".",
"Cookie",
"{",
"return",
"&",
"http",
".",
"Cookie",
"{",
"Name",
":",
"name",
",",
"Value",
":",
"value",
",",
"Path",
":",
"... | // newCookieFromOptions returns an http.Cookie with the options set. | [
"newCookieFromOptions",
"returns",
"an",
"http",
".",
"Cookie",
"with",
"the",
"options",
"set",
"."
] | 12bd4761fc66ac946e16fcc2a32b1e0b066f6177 | https://github.com/gorilla/sessions/blob/12bd4761fc66ac946e16fcc2a32b1e0b066f6177/cookie_go111.go#L8-L20 | train |
nfnt/resize | ycc.go | SubImage | func (p *ycc) SubImage(r image.Rectangle) image.Image {
r = r.Intersect(p.Rect)
if r.Empty() {
return &ycc{SubsampleRatio: p.SubsampleRatio}
}
i := p.PixOffset(r.Min.X, r.Min.Y)
return &ycc{
Pix: p.Pix[i:],
Stride: p.Stride,
Rect: r,
SubsampleRatio: p.SubsampleRatio,
}
} | go | func (p *ycc) SubImage(r image.Rectangle) image.Image {
r = r.Intersect(p.Rect)
if r.Empty() {
return &ycc{SubsampleRatio: p.SubsampleRatio}
}
i := p.PixOffset(r.Min.X, r.Min.Y)
return &ycc{
Pix: p.Pix[i:],
Stride: p.Stride,
Rect: r,
SubsampleRatio: p.SubsampleRatio,
}
} | [
"func",
"(",
"p",
"*",
"ycc",
")",
"SubImage",
"(",
"r",
"image",
".",
"Rectangle",
")",
"image",
".",
"Image",
"{",
"r",
"=",
"r",
".",
"Intersect",
"(",
"p",
".",
"Rect",
")",
"\n",
"if",
"r",
".",
"Empty",
"(",
")",
"{",
"return",
"&",
"yc... | // SubImage returns an image representing the portion of the image p visible
// through r. The returned value shares pixels with the original image. | [
"SubImage",
"returns",
"an",
"image",
"representing",
"the",
"portion",
"of",
"the",
"image",
"p",
"visible",
"through",
"r",
".",
"The",
"returned",
"value",
"shares",
"pixels",
"with",
"the",
"original",
"image",
"."
] | 83c6a9932646f83e3267f353373d47347b6036b2 | https://github.com/nfnt/resize/blob/83c6a9932646f83e3267f353373d47347b6036b2/ycc.go#L70-L82 | train |
nfnt/resize | ycc.go | newYCC | func newYCC(r image.Rectangle, s image.YCbCrSubsampleRatio) *ycc {
w, h := r.Dx(), r.Dy()
buf := make([]uint8, 3*w*h)
return &ycc{Pix: buf, Stride: 3 * w, Rect: r, SubsampleRatio: s}
} | go | func newYCC(r image.Rectangle, s image.YCbCrSubsampleRatio) *ycc {
w, h := r.Dx(), r.Dy()
buf := make([]uint8, 3*w*h)
return &ycc{Pix: buf, Stride: 3 * w, Rect: r, SubsampleRatio: s}
} | [
"func",
"newYCC",
"(",
"r",
"image",
".",
"Rectangle",
",",
"s",
"image",
".",
"YCbCrSubsampleRatio",
")",
"*",
"ycc",
"{",
"w",
",",
"h",
":=",
"r",
".",
"Dx",
"(",
")",
",",
"r",
".",
"Dy",
"(",
")",
"\n",
"buf",
":=",
"make",
"(",
"[",
"]"... | // newYCC returns a new ycc with the given bounds and subsample ratio. | [
"newYCC",
"returns",
"a",
"new",
"ycc",
"with",
"the",
"given",
"bounds",
"and",
"subsample",
"ratio",
"."
] | 83c6a9932646f83e3267f353373d47347b6036b2 | https://github.com/nfnt/resize/blob/83c6a9932646f83e3267f353373d47347b6036b2/ycc.go#L85-L89 | train |
nfnt/resize | ycc.go | YCbCr | func (p *ycc) YCbCr() *image.YCbCr {
ycbcr := image.NewYCbCr(p.Rect, p.SubsampleRatio)
switch ycbcr.SubsampleRatio {
case ycbcrSubsampleRatio422:
return p.ycbcr422(ycbcr)
case ycbcrSubsampleRatio420:
return p.ycbcr420(ycbcr)
case ycbcrSubsampleRatio440:
return p.ycbcr440(ycbcr)
case ycbcrSubsampleRatio444:
... | go | func (p *ycc) YCbCr() *image.YCbCr {
ycbcr := image.NewYCbCr(p.Rect, p.SubsampleRatio)
switch ycbcr.SubsampleRatio {
case ycbcrSubsampleRatio422:
return p.ycbcr422(ycbcr)
case ycbcrSubsampleRatio420:
return p.ycbcr420(ycbcr)
case ycbcrSubsampleRatio440:
return p.ycbcr440(ycbcr)
case ycbcrSubsampleRatio444:
... | [
"func",
"(",
"p",
"*",
"ycc",
")",
"YCbCr",
"(",
")",
"*",
"image",
".",
"YCbCr",
"{",
"ycbcr",
":=",
"image",
".",
"NewYCbCr",
"(",
"p",
".",
"Rect",
",",
"p",
".",
"SubsampleRatio",
")",
"\n",
"switch",
"ycbcr",
".",
"SubsampleRatio",
"{",
"case"... | // YCbCr converts ycc to a YCbCr image with the same subsample ratio
// as the YCbCr image that ycc was generated from. | [
"YCbCr",
"converts",
"ycc",
"to",
"a",
"YCbCr",
"image",
"with",
"the",
"same",
"subsample",
"ratio",
"as",
"the",
"YCbCr",
"image",
"that",
"ycc",
"was",
"generated",
"from",
"."
] | 83c6a9932646f83e3267f353373d47347b6036b2 | https://github.com/nfnt/resize/blob/83c6a9932646f83e3267f353373d47347b6036b2/ycc.go#L104-L121 | train |
nfnt/resize | ycc.go | imageYCbCrToYCC | func imageYCbCrToYCC(in *image.YCbCr) *ycc {
w, h := in.Rect.Dx(), in.Rect.Dy()
p := ycc{
Pix: make([]uint8, 3*w*h),
Stride: 3 * w,
Rect: image.Rect(0, 0, w, h),
SubsampleRatio: in.SubsampleRatio,
}
switch in.SubsampleRatio {
case ycbcrSubsampleRatio422:
return convertToYCC42... | go | func imageYCbCrToYCC(in *image.YCbCr) *ycc {
w, h := in.Rect.Dx(), in.Rect.Dy()
p := ycc{
Pix: make([]uint8, 3*w*h),
Stride: 3 * w,
Rect: image.Rect(0, 0, w, h),
SubsampleRatio: in.SubsampleRatio,
}
switch in.SubsampleRatio {
case ycbcrSubsampleRatio422:
return convertToYCC42... | [
"func",
"imageYCbCrToYCC",
"(",
"in",
"*",
"image",
".",
"YCbCr",
")",
"*",
"ycc",
"{",
"w",
",",
"h",
":=",
"in",
".",
"Rect",
".",
"Dx",
"(",
")",
",",
"in",
".",
"Rect",
".",
"Dy",
"(",
")",
"\n",
"p",
":=",
"ycc",
"{",
"Pix",
":",
"make... | // imageYCbCrToYCC converts a YCbCr image to a ycc image for resizing. | [
"imageYCbCrToYCC",
"converts",
"a",
"YCbCr",
"image",
"to",
"a",
"ycc",
"image",
"for",
"resizing",
"."
] | 83c6a9932646f83e3267f353373d47347b6036b2 | https://github.com/nfnt/resize/blob/83c6a9932646f83e3267f353373d47347b6036b2/ycc.go#L124-L147 | train |
nfnt/resize | thumbnail.go | Thumbnail | func Thumbnail(maxWidth, maxHeight uint, img image.Image, interp InterpolationFunction) image.Image {
origBounds := img.Bounds()
origWidth := uint(origBounds.Dx())
origHeight := uint(origBounds.Dy())
newWidth, newHeight := origWidth, origHeight
// Return original image if it have same or smaller size as constrain... | go | func Thumbnail(maxWidth, maxHeight uint, img image.Image, interp InterpolationFunction) image.Image {
origBounds := img.Bounds()
origWidth := uint(origBounds.Dx())
origHeight := uint(origBounds.Dy())
newWidth, newHeight := origWidth, origHeight
// Return original image if it have same or smaller size as constrain... | [
"func",
"Thumbnail",
"(",
"maxWidth",
",",
"maxHeight",
"uint",
",",
"img",
"image",
".",
"Image",
",",
"interp",
"InterpolationFunction",
")",
"image",
".",
"Image",
"{",
"origBounds",
":=",
"img",
".",
"Bounds",
"(",
")",
"\n",
"origWidth",
":=",
"uint",... | // Thumbnail will downscale provided image to max width and height preserving
// original aspect ratio and using the interpolation function interp.
// It will return original image, without processing it, if original sizes
// are already smaller than provided constraints. | [
"Thumbnail",
"will",
"downscale",
"provided",
"image",
"to",
"max",
"width",
"and",
"height",
"preserving",
"original",
"aspect",
"ratio",
"and",
"using",
"the",
"interpolation",
"function",
"interp",
".",
"It",
"will",
"return",
"original",
"image",
"without",
... | 83c6a9932646f83e3267f353373d47347b6036b2 | https://github.com/nfnt/resize/blob/83c6a9932646f83e3267f353373d47347b6036b2/thumbnail.go#L27-L55 | train |
nfnt/resize | resize.go | kernel | func (i InterpolationFunction) kernel() (int, func(float64) float64) {
switch i {
case Bilinear:
return 2, linear
case Bicubic:
return 4, cubic
case MitchellNetravali:
return 4, mitchellnetravali
case Lanczos2:
return 4, lanczos2
case Lanczos3:
return 6, lanczos3
default:
// Default to NearestNeighbo... | go | func (i InterpolationFunction) kernel() (int, func(float64) float64) {
switch i {
case Bilinear:
return 2, linear
case Bicubic:
return 4, cubic
case MitchellNetravali:
return 4, mitchellnetravali
case Lanczos2:
return 4, lanczos2
case Lanczos3:
return 6, lanczos3
default:
// Default to NearestNeighbo... | [
"func",
"(",
"i",
"InterpolationFunction",
")",
"kernel",
"(",
")",
"(",
"int",
",",
"func",
"(",
"float64",
")",
"float64",
")",
"{",
"switch",
"i",
"{",
"case",
"Bilinear",
":",
"return",
"2",
",",
"linear",
"\n",
"case",
"Bicubic",
":",
"return",
... | // kernal, returns an InterpolationFunctions taps and kernel. | [
"kernal",
"returns",
"an",
"InterpolationFunctions",
"taps",
"and",
"kernel",
"."
] | 83c6a9932646f83e3267f353373d47347b6036b2 | https://github.com/nfnt/resize/blob/83c6a9932646f83e3267f353373d47347b6036b2/resize.go#L55-L71 | train |
nfnt/resize | resize.go | calcFactors | func calcFactors(width, height uint, oldWidth, oldHeight float64) (scaleX, scaleY float64) {
if width == 0 {
if height == 0 {
scaleX = 1.0
scaleY = 1.0
} else {
scaleY = oldHeight / float64(height)
scaleX = scaleY
}
} else {
scaleX = oldWidth / float64(width)
if height == 0 {
scaleY = scaleX
... | go | func calcFactors(width, height uint, oldWidth, oldHeight float64) (scaleX, scaleY float64) {
if width == 0 {
if height == 0 {
scaleX = 1.0
scaleY = 1.0
} else {
scaleY = oldHeight / float64(height)
scaleX = scaleY
}
} else {
scaleX = oldWidth / float64(width)
if height == 0 {
scaleY = scaleX
... | [
"func",
"calcFactors",
"(",
"width",
",",
"height",
"uint",
",",
"oldWidth",
",",
"oldHeight",
"float64",
")",
"(",
"scaleX",
",",
"scaleY",
"float64",
")",
"{",
"if",
"width",
"==",
"0",
"{",
"if",
"height",
"==",
"0",
"{",
"scaleX",
"=",
"1.0",
"\n... | // Calculates scaling factors using old and new image dimensions. | [
"Calculates",
"scaling",
"factors",
"using",
"old",
"and",
"new",
"image",
"dimensions",
"."
] | 83c6a9932646f83e3267f353373d47347b6036b2 | https://github.com/nfnt/resize/blob/83c6a9932646f83e3267f353373d47347b6036b2/resize.go#L593-L611 | train |
gliderlabs/ssh | server.go | Shutdown | func (srv *Server) Shutdown(ctx context.Context) error {
srv.mu.Lock()
lnerr := srv.closeListenersLocked()
srv.closeDoneChanLocked()
srv.mu.Unlock()
finished := make(chan struct{}, 1)
go func() {
srv.listenerWg.Wait()
srv.connWg.Wait()
finished <- struct{}{}
}()
select {
case <-ctx.Done():
return ctx... | go | func (srv *Server) Shutdown(ctx context.Context) error {
srv.mu.Lock()
lnerr := srv.closeListenersLocked()
srv.closeDoneChanLocked()
srv.mu.Unlock()
finished := make(chan struct{}, 1)
go func() {
srv.listenerWg.Wait()
srv.connWg.Wait()
finished <- struct{}{}
}()
select {
case <-ctx.Done():
return ctx... | [
"func",
"(",
"srv",
"*",
"Server",
")",
"Shutdown",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"srv",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"lnerr",
":=",
"srv",
".",
"closeListenersLocked",
"(",
")",
"\n",
"srv",
".",
"closeDoneChan... | // Shutdown gracefully shuts down the server without interrupting any
// active connections. Shutdown works by first closing all open
// listeners, and then waiting indefinitely for connections to close.
// If the provided context expires before the shutdown is complete,
// then the context's error is returned. | [
"Shutdown",
"gracefully",
"shuts",
"down",
"the",
"server",
"without",
"interrupting",
"any",
"active",
"connections",
".",
"Shutdown",
"works",
"by",
"first",
"closing",
"all",
"open",
"listeners",
"and",
"then",
"waiting",
"indefinitely",
"for",
"connections",
"... | a9daacccc9f1368e52f390591d908470cee477d2 | https://github.com/gliderlabs/ssh/blob/a9daacccc9f1368e52f390591d908470cee477d2/server.go#L154-L173 | train |
gliderlabs/ssh | server.go | Serve | func (srv *Server) Serve(l net.Listener) error {
srv.ensureHandlers()
defer l.Close()
if err := srv.ensureHostSigner(); err != nil {
return err
}
if srv.Handler == nil {
srv.Handler = DefaultHandler
}
if srv.channelHandlers == nil {
srv.channelHandlers = map[string]channelHandler{
"session": sessio... | go | func (srv *Server) Serve(l net.Listener) error {
srv.ensureHandlers()
defer l.Close()
if err := srv.ensureHostSigner(); err != nil {
return err
}
if srv.Handler == nil {
srv.Handler = DefaultHandler
}
if srv.channelHandlers == nil {
srv.channelHandlers = map[string]channelHandler{
"session": sessio... | [
"func",
"(",
"srv",
"*",
"Server",
")",
"Serve",
"(",
"l",
"net",
".",
"Listener",
")",
"error",
"{",
"srv",
".",
"ensureHandlers",
"(",
")",
"\n",
"defer",
"l",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
":=",
"srv",
".",
"ensureHostSigner",
"(",
... | // Serve accepts incoming connections on the Listener l, creating a new
// connection goroutine for each. The connection goroutines read requests and then
// calls srv.Handler to handle sessions.
//
// Serve always returns a non-nil error. | [
"Serve",
"accepts",
"incoming",
"connections",
"on",
"the",
"Listener",
"l",
"creating",
"a",
"new",
"connection",
"goroutine",
"for",
"each",
".",
"The",
"connection",
"goroutines",
"read",
"requests",
"and",
"then",
"calls",
"srv",
".",
"Handler",
"to",
"han... | a9daacccc9f1368e52f390591d908470cee477d2 | https://github.com/gliderlabs/ssh/blob/a9daacccc9f1368e52f390591d908470cee477d2/server.go#L180-L223 | train |
gliderlabs/ssh | ssh.go | Serve | func Serve(l net.Listener, handler Handler, options ...Option) error {
srv := &Server{Handler: handler}
for _, option := range options {
if err := srv.SetOption(option); err != nil {
return err
}
}
return srv.Serve(l)
} | go | func Serve(l net.Listener, handler Handler, options ...Option) error {
srv := &Server{Handler: handler}
for _, option := range options {
if err := srv.SetOption(option); err != nil {
return err
}
}
return srv.Serve(l)
} | [
"func",
"Serve",
"(",
"l",
"net",
".",
"Listener",
",",
"handler",
"Handler",
",",
"options",
"...",
"Option",
")",
"error",
"{",
"srv",
":=",
"&",
"Server",
"{",
"Handler",
":",
"handler",
"}",
"\n",
"for",
"_",
",",
"option",
":=",
"range",
"option... | // Serve accepts incoming SSH connections on the listener l, creating a new
// connection goroutine for each. The connection goroutines read requests and
// then calls handler to handle sessions. Handler is typically nil, in which
// case the DefaultHandler is used. | [
"Serve",
"accepts",
"incoming",
"SSH",
"connections",
"on",
"the",
"listener",
"l",
"creating",
"a",
"new",
"connection",
"goroutine",
"for",
"each",
".",
"The",
"connection",
"goroutines",
"read",
"requests",
"and",
"then",
"calls",
"handler",
"to",
"handle",
... | a9daacccc9f1368e52f390591d908470cee477d2 | https://github.com/gliderlabs/ssh/blob/a9daacccc9f1368e52f390591d908470cee477d2/ssh.go#L84-L92 | train |
gliderlabs/ssh | ssh.go | ListenAndServe | func ListenAndServe(addr string, handler Handler, options ...Option) error {
srv := &Server{Addr: addr, Handler: handler}
for _, option := range options {
if err := srv.SetOption(option); err != nil {
return err
}
}
return srv.ListenAndServe()
} | go | func ListenAndServe(addr string, handler Handler, options ...Option) error {
srv := &Server{Addr: addr, Handler: handler}
for _, option := range options {
if err := srv.SetOption(option); err != nil {
return err
}
}
return srv.ListenAndServe()
} | [
"func",
"ListenAndServe",
"(",
"addr",
"string",
",",
"handler",
"Handler",
",",
"options",
"...",
"Option",
")",
"error",
"{",
"srv",
":=",
"&",
"Server",
"{",
"Addr",
":",
"addr",
",",
"Handler",
":",
"handler",
"}",
"\n",
"for",
"_",
",",
"option",
... | // ListenAndServe listens on the TCP network address addr and then calls Serve
// with handler to handle sessions on incoming connections. Handler is typically
// nil, in which case the DefaultHandler is used. | [
"ListenAndServe",
"listens",
"on",
"the",
"TCP",
"network",
"address",
"addr",
"and",
"then",
"calls",
"Serve",
"with",
"handler",
"to",
"handle",
"sessions",
"on",
"incoming",
"connections",
".",
"Handler",
"is",
"typically",
"nil",
"in",
"which",
"case",
"th... | a9daacccc9f1368e52f390591d908470cee477d2 | https://github.com/gliderlabs/ssh/blob/a9daacccc9f1368e52f390591d908470cee477d2/ssh.go#L97-L105 | train |
gliderlabs/ssh | ssh.go | KeysEqual | func KeysEqual(ak, bk PublicKey) bool {
//avoid panic if one of the keys is nil, return false instead
if ak == nil || bk == nil {
return false
}
a := ak.Marshal()
b := bk.Marshal()
return (len(a) == len(b) && subtle.ConstantTimeCompare(a, b) == 1)
} | go | func KeysEqual(ak, bk PublicKey) bool {
//avoid panic if one of the keys is nil, return false instead
if ak == nil || bk == nil {
return false
}
a := ak.Marshal()
b := bk.Marshal()
return (len(a) == len(b) && subtle.ConstantTimeCompare(a, b) == 1)
} | [
"func",
"KeysEqual",
"(",
"ak",
",",
"bk",
"PublicKey",
")",
"bool",
"{",
"//avoid panic if one of the keys is nil, return false instead",
"if",
"ak",
"==",
"nil",
"||",
"bk",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"a",
":=",
"ak",
".",
"Mar... | // KeysEqual is constant time compare of the keys to avoid timing attacks. | [
"KeysEqual",
"is",
"constant",
"time",
"compare",
"of",
"the",
"keys",
"to",
"avoid",
"timing",
"attacks",
"."
] | a9daacccc9f1368e52f390591d908470cee477d2 | https://github.com/gliderlabs/ssh/blob/a9daacccc9f1368e52f390591d908470cee477d2/ssh.go#L113-L123 | train |
gliderlabs/ssh | options.go | PasswordAuth | func PasswordAuth(fn PasswordHandler) Option {
return func(srv *Server) error {
srv.PasswordHandler = fn
return nil
}
} | go | func PasswordAuth(fn PasswordHandler) Option {
return func(srv *Server) error {
srv.PasswordHandler = fn
return nil
}
} | [
"func",
"PasswordAuth",
"(",
"fn",
"PasswordHandler",
")",
"Option",
"{",
"return",
"func",
"(",
"srv",
"*",
"Server",
")",
"error",
"{",
"srv",
".",
"PasswordHandler",
"=",
"fn",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // PasswordAuth returns a functional option that sets PasswordHandler on the server. | [
"PasswordAuth",
"returns",
"a",
"functional",
"option",
"that",
"sets",
"PasswordHandler",
"on",
"the",
"server",
"."
] | a9daacccc9f1368e52f390591d908470cee477d2 | https://github.com/gliderlabs/ssh/blob/a9daacccc9f1368e52f390591d908470cee477d2/options.go#L10-L15 | train |
gliderlabs/ssh | options.go | PublicKeyAuth | func PublicKeyAuth(fn PublicKeyHandler) Option {
return func(srv *Server) error {
srv.PublicKeyHandler = fn
return nil
}
} | go | func PublicKeyAuth(fn PublicKeyHandler) Option {
return func(srv *Server) error {
srv.PublicKeyHandler = fn
return nil
}
} | [
"func",
"PublicKeyAuth",
"(",
"fn",
"PublicKeyHandler",
")",
"Option",
"{",
"return",
"func",
"(",
"srv",
"*",
"Server",
")",
"error",
"{",
"srv",
".",
"PublicKeyHandler",
"=",
"fn",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // PublicKeyAuth returns a functional option that sets PublicKeyHandler on the server. | [
"PublicKeyAuth",
"returns",
"a",
"functional",
"option",
"that",
"sets",
"PublicKeyHandler",
"on",
"the",
"server",
"."
] | a9daacccc9f1368e52f390591d908470cee477d2 | https://github.com/gliderlabs/ssh/blob/a9daacccc9f1368e52f390591d908470cee477d2/options.go#L18-L23 | train |
gliderlabs/ssh | options.go | HostKeyFile | func HostKeyFile(filepath string) Option {
return func(srv *Server) error {
pemBytes, err := ioutil.ReadFile(filepath)
if err != nil {
return err
}
signer, err := gossh.ParsePrivateKey(pemBytes)
if err != nil {
return err
}
srv.AddHostKey(signer)
return nil
}
} | go | func HostKeyFile(filepath string) Option {
return func(srv *Server) error {
pemBytes, err := ioutil.ReadFile(filepath)
if err != nil {
return err
}
signer, err := gossh.ParsePrivateKey(pemBytes)
if err != nil {
return err
}
srv.AddHostKey(signer)
return nil
}
} | [
"func",
"HostKeyFile",
"(",
"filepath",
"string",
")",
"Option",
"{",
"return",
"func",
"(",
"srv",
"*",
"Server",
")",
"error",
"{",
"pemBytes",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"filepath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
... | // HostKeyFile returns a functional option that adds HostSigners to the server
// from a PEM file at filepath. | [
"HostKeyFile",
"returns",
"a",
"functional",
"option",
"that",
"adds",
"HostSigners",
"to",
"the",
"server",
"from",
"a",
"PEM",
"file",
"at",
"filepath",
"."
] | a9daacccc9f1368e52f390591d908470cee477d2 | https://github.com/gliderlabs/ssh/blob/a9daacccc9f1368e52f390591d908470cee477d2/options.go#L27-L43 | train |
gliderlabs/ssh | options.go | HostKeyPEM | func HostKeyPEM(bytes []byte) Option {
return func(srv *Server) error {
signer, err := gossh.ParsePrivateKey(bytes)
if err != nil {
return err
}
srv.AddHostKey(signer)
return nil
}
} | go | func HostKeyPEM(bytes []byte) Option {
return func(srv *Server) error {
signer, err := gossh.ParsePrivateKey(bytes)
if err != nil {
return err
}
srv.AddHostKey(signer)
return nil
}
} | [
"func",
"HostKeyPEM",
"(",
"bytes",
"[",
"]",
"byte",
")",
"Option",
"{",
"return",
"func",
"(",
"srv",
"*",
"Server",
")",
"error",
"{",
"signer",
",",
"err",
":=",
"gossh",
".",
"ParsePrivateKey",
"(",
"bytes",
")",
"\n",
"if",
"err",
"!=",
"nil",
... | // HostKeyPEM returns a functional option that adds HostSigners to the server
// from a PEM file as bytes. | [
"HostKeyPEM",
"returns",
"a",
"functional",
"option",
"that",
"adds",
"HostSigners",
"to",
"the",
"server",
"from",
"a",
"PEM",
"file",
"as",
"bytes",
"."
] | a9daacccc9f1368e52f390591d908470cee477d2 | https://github.com/gliderlabs/ssh/blob/a9daacccc9f1368e52f390591d908470cee477d2/options.go#L47-L58 | train |
gliderlabs/ssh | options.go | NoPty | func NoPty() Option {
return func(srv *Server) error {
srv.PtyCallback = func(ctx Context, pty Pty) bool {
return false
}
return nil
}
} | go | func NoPty() Option {
return func(srv *Server) error {
srv.PtyCallback = func(ctx Context, pty Pty) bool {
return false
}
return nil
}
} | [
"func",
"NoPty",
"(",
")",
"Option",
"{",
"return",
"func",
"(",
"srv",
"*",
"Server",
")",
"error",
"{",
"srv",
".",
"PtyCallback",
"=",
"func",
"(",
"ctx",
"Context",
",",
"pty",
"Pty",
")",
"bool",
"{",
"return",
"false",
"\n",
"}",
"\n",
"retur... | // NoPty returns a functional option that sets PtyCallback to return false,
// denying PTY requests. | [
"NoPty",
"returns",
"a",
"functional",
"option",
"that",
"sets",
"PtyCallback",
"to",
"return",
"false",
"denying",
"PTY",
"requests",
"."
] | a9daacccc9f1368e52f390591d908470cee477d2 | https://github.com/gliderlabs/ssh/blob/a9daacccc9f1368e52f390591d908470cee477d2/options.go#L62-L69 | train |
gliderlabs/ssh | options.go | WrapConn | func WrapConn(fn ConnCallback) Option {
return func(srv *Server) error {
srv.ConnCallback = fn
return nil
}
} | go | func WrapConn(fn ConnCallback) Option {
return func(srv *Server) error {
srv.ConnCallback = fn
return nil
}
} | [
"func",
"WrapConn",
"(",
"fn",
"ConnCallback",
")",
"Option",
"{",
"return",
"func",
"(",
"srv",
"*",
"Server",
")",
"error",
"{",
"srv",
".",
"ConnCallback",
"=",
"fn",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // WrapConn returns a functional option that sets ConnCallback on the server. | [
"WrapConn",
"returns",
"a",
"functional",
"option",
"that",
"sets",
"ConnCallback",
"on",
"the",
"server",
"."
] | a9daacccc9f1368e52f390591d908470cee477d2 | https://github.com/gliderlabs/ssh/blob/a9daacccc9f1368e52f390591d908470cee477d2/options.go#L72-L77 | train |
gliderlabs/ssh | context.go | applyConnMetadata | func applyConnMetadata(ctx Context, conn gossh.ConnMetadata) {
if ctx.Value(ContextKeySessionID) != nil {
return
}
ctx.SetValue(ContextKeySessionID, hex.EncodeToString(conn.SessionID()))
ctx.SetValue(ContextKeyClientVersion, string(conn.ClientVersion()))
ctx.SetValue(ContextKeyServerVersion, string(conn.ServerVe... | go | func applyConnMetadata(ctx Context, conn gossh.ConnMetadata) {
if ctx.Value(ContextKeySessionID) != nil {
return
}
ctx.SetValue(ContextKeySessionID, hex.EncodeToString(conn.SessionID()))
ctx.SetValue(ContextKeyClientVersion, string(conn.ClientVersion()))
ctx.SetValue(ContextKeyServerVersion, string(conn.ServerVe... | [
"func",
"applyConnMetadata",
"(",
"ctx",
"Context",
",",
"conn",
"gossh",
".",
"ConnMetadata",
")",
"{",
"if",
"ctx",
".",
"Value",
"(",
"ContextKeySessionID",
")",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"ctx",
".",
"SetValue",
"(",
"ContextKeySessio... | // this is separate from newContext because we will get ConnMetadata
// at different points so it needs to be applied separately | [
"this",
"is",
"separate",
"from",
"newContext",
"because",
"we",
"will",
"get",
"ConnMetadata",
"at",
"different",
"points",
"so",
"it",
"needs",
"to",
"be",
"applied",
"separately"
] | a9daacccc9f1368e52f390591d908470cee477d2 | https://github.com/gliderlabs/ssh/blob/a9daacccc9f1368e52f390591d908470cee477d2/context.go#L110-L120 | train |
gliderlabs/ssh | agent.go | NewAgentListener | func NewAgentListener() (net.Listener, error) {
dir, err := ioutil.TempDir("", agentTempDir)
if err != nil {
return nil, err
}
l, err := net.Listen("unix", path.Join(dir, agentListenFile))
if err != nil {
return nil, err
}
return l, nil
} | go | func NewAgentListener() (net.Listener, error) {
dir, err := ioutil.TempDir("", agentTempDir)
if err != nil {
return nil, err
}
l, err := net.Listen("unix", path.Join(dir, agentListenFile))
if err != nil {
return nil, err
}
return l, nil
} | [
"func",
"NewAgentListener",
"(",
")",
"(",
"net",
".",
"Listener",
",",
"error",
")",
"{",
"dir",
",",
"err",
":=",
"ioutil",
".",
"TempDir",
"(",
"\"",
"\"",
",",
"agentTempDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err... | // NewAgentListener sets up a temporary Unix socket that can be communicated
// to the session environment and used for forwarding connections. | [
"NewAgentListener",
"sets",
"up",
"a",
"temporary",
"Unix",
"socket",
"that",
"can",
"be",
"communicated",
"to",
"the",
"session",
"environment",
"and",
"used",
"for",
"forwarding",
"connections",
"."
] | a9daacccc9f1368e52f390591d908470cee477d2 | https://github.com/gliderlabs/ssh/blob/a9daacccc9f1368e52f390591d908470cee477d2/agent.go#L38-L48 | train |
gliderlabs/ssh | agent.go | ForwardAgentConnections | func ForwardAgentConnections(l net.Listener, s Session) {
sshConn := s.Context().Value(ContextKeyConn).(gossh.Conn)
for {
conn, err := l.Accept()
if err != nil {
return
}
go func(conn net.Conn) {
defer conn.Close()
channel, reqs, err := sshConn.OpenChannel(agentChannelType, nil)
if err != nil {
... | go | func ForwardAgentConnections(l net.Listener, s Session) {
sshConn := s.Context().Value(ContextKeyConn).(gossh.Conn)
for {
conn, err := l.Accept()
if err != nil {
return
}
go func(conn net.Conn) {
defer conn.Close()
channel, reqs, err := sshConn.OpenChannel(agentChannelType, nil)
if err != nil {
... | [
"func",
"ForwardAgentConnections",
"(",
"l",
"net",
".",
"Listener",
",",
"s",
"Session",
")",
"{",
"sshConn",
":=",
"s",
".",
"Context",
"(",
")",
".",
"Value",
"(",
"ContextKeyConn",
")",
".",
"(",
"gossh",
".",
"Conn",
")",
"\n",
"for",
"{",
"conn... | // ForwardAgentConnections takes connections from a listener to proxy into the
// session on the OpenSSH channel for agent connections. It blocks and services
// connections until the listener stop accepting. | [
"ForwardAgentConnections",
"takes",
"connections",
"from",
"a",
"listener",
"to",
"proxy",
"into",
"the",
"session",
"on",
"the",
"OpenSSH",
"channel",
"for",
"agent",
"connections",
".",
"It",
"blocks",
"and",
"services",
"connections",
"until",
"the",
"listener"... | a9daacccc9f1368e52f390591d908470cee477d2 | https://github.com/gliderlabs/ssh/blob/a9daacccc9f1368e52f390591d908470cee477d2/agent.go#L53-L83 | train |
aarzilli/nucular | masterwindow.go | PopupOpen | func (mw *masterWindowCommon) PopupOpen(title string, flags WindowFlags, rect rect.Rect, scale bool, updateFn UpdateFn) {
go func() {
mw.ctx.mw.Lock()
defer mw.ctx.mw.Unlock()
mw.ctx.popupOpen(title, flags, rect, scale, updateFn)
mw.ctx.mw.Changed()
}()
} | go | func (mw *masterWindowCommon) PopupOpen(title string, flags WindowFlags, rect rect.Rect, scale bool, updateFn UpdateFn) {
go func() {
mw.ctx.mw.Lock()
defer mw.ctx.mw.Unlock()
mw.ctx.popupOpen(title, flags, rect, scale, updateFn)
mw.ctx.mw.Changed()
}()
} | [
"func",
"(",
"mw",
"*",
"masterWindowCommon",
")",
"PopupOpen",
"(",
"title",
"string",
",",
"flags",
"WindowFlags",
",",
"rect",
"rect",
".",
"Rect",
",",
"scale",
"bool",
",",
"updateFn",
"UpdateFn",
")",
"{",
"go",
"func",
"(",
")",
"{",
"mw",
".",
... | // Opens a popup window inside win. Will return true until the
// popup window is closed.
// The contents of the popup window will be updated by updateFn | [
"Opens",
"a",
"popup",
"window",
"inside",
"win",
".",
"Will",
"return",
"true",
"until",
"the",
"popup",
"window",
"is",
"closed",
".",
"The",
"contents",
"of",
"the",
"popup",
"window",
"will",
"be",
"updated",
"by",
"updateFn"
] | 64ec1eba91814ebb417978927206070dd1fc44e1 | https://github.com/aarzilli/nucular/blob/64ec1eba91814ebb417978927206070dd1fc44e1/masterwindow.go#L134-L141 | train |
aarzilli/nucular | masterwindow.go | drawChanged | func (w *masterWindowCommon) drawChanged() bool {
contextAllCommands(w.ctx)
w.ctx.Reset()
cmds := w.ctx.cmds
if len(cmds) != len(w.prevCmds) {
return true
}
for i := range cmds {
if cmds[i].Kind != w.prevCmds[i].Kind {
return true
}
cmd := &cmds[i]
pcmd := &w.prevCmds[i]
switch cmds[i].Kind {... | go | func (w *masterWindowCommon) drawChanged() bool {
contextAllCommands(w.ctx)
w.ctx.Reset()
cmds := w.ctx.cmds
if len(cmds) != len(w.prevCmds) {
return true
}
for i := range cmds {
if cmds[i].Kind != w.prevCmds[i].Kind {
return true
}
cmd := &cmds[i]
pcmd := &w.prevCmds[i]
switch cmds[i].Kind {... | [
"func",
"(",
"w",
"*",
"masterWindowCommon",
")",
"drawChanged",
"(",
")",
"bool",
"{",
"contextAllCommands",
"(",
"w",
".",
"ctx",
")",
"\n",
"w",
".",
"ctx",
".",
"Reset",
"(",
")",
"\n\n",
"cmds",
":=",
"w",
".",
"ctx",
".",
"cmds",
"\n\n",
"if"... | // compares cmds to the last draw frame, returns true if there is a change | [
"compares",
"cmds",
"to",
"the",
"last",
"draw",
"frame",
"returns",
"true",
"if",
"there",
"is",
"a",
"change"
] | 64ec1eba91814ebb417978927206070dd1fc44e1 | https://github.com/aarzilli/nucular/blob/64ec1eba91814ebb417978927206070dd1fc44e1/masterwindow.go#L191-L255 | train |
aarzilli/nucular | shiny.go | NewMasterWindowSize | func NewMasterWindowSize(flags WindowFlags, title string, sz image.Point, updatefn UpdateFn) MasterWindow {
ctx := &context{}
wnd := &masterWindow{}
wnd.masterWindowCommonInit(ctx, flags, updatefn, wnd)
wnd.Title = title
wnd.initialSize = sz
clipboardMu.Lock()
if !clipboardStarted {
clipboardStarted = true
... | go | func NewMasterWindowSize(flags WindowFlags, title string, sz image.Point, updatefn UpdateFn) MasterWindow {
ctx := &context{}
wnd := &masterWindow{}
wnd.masterWindowCommonInit(ctx, flags, updatefn, wnd)
wnd.Title = title
wnd.initialSize = sz
clipboardMu.Lock()
if !clipboardStarted {
clipboardStarted = true
... | [
"func",
"NewMasterWindowSize",
"(",
"flags",
"WindowFlags",
",",
"title",
"string",
",",
"sz",
"image",
".",
"Point",
",",
"updatefn",
"UpdateFn",
")",
"MasterWindow",
"{",
"ctx",
":=",
"&",
"context",
"{",
"}",
"\n",
"wnd",
":=",
"&",
"masterWindow",
"{",... | // Creates new master window | [
"Creates",
"new",
"master",
"window"
] | 64ec1eba91814ebb417978927206070dd1fc44e1 | https://github.com/aarzilli/nucular/blob/64ec1eba91814ebb417978927206070dd1fc44e1/shiny.go#L52-L69 | train |
aarzilli/nucular | shiny.go | Close | func (mw *masterWindow) Close() {
mw.wnd.Send(lifecycle.Event{From: lifecycle.StageAlive, To: lifecycle.StageDead})
} | go | func (mw *masterWindow) Close() {
mw.wnd.Send(lifecycle.Event{From: lifecycle.StageAlive, To: lifecycle.StageDead})
} | [
"func",
"(",
"mw",
"*",
"masterWindow",
")",
"Close",
"(",
")",
"{",
"mw",
".",
"wnd",
".",
"Send",
"(",
"lifecycle",
".",
"Event",
"{",
"From",
":",
"lifecycle",
".",
"StageAlive",
",",
"To",
":",
"lifecycle",
".",
"StageDead",
"}",
")",
"\n",
"}"... | // Programmatically closes window. | [
"Programmatically",
"closes",
"window",
"."
] | 64ec1eba91814ebb417978927206070dd1fc44e1 | https://github.com/aarzilli/nucular/blob/64ec1eba91814ebb417978927206070dd1fc44e1/shiny.go#L293-L295 | train |
aarzilli/nucular | shiny.go | Closed | func (mw *masterWindow) Closed() bool {
mw.uilock.Lock()
defer mw.uilock.Unlock()
return mw.closing
} | go | func (mw *masterWindow) Closed() bool {
mw.uilock.Lock()
defer mw.uilock.Unlock()
return mw.closing
} | [
"func",
"(",
"mw",
"*",
"masterWindow",
")",
"Closed",
"(",
")",
"bool",
"{",
"mw",
".",
"uilock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"mw",
".",
"uilock",
".",
"Unlock",
"(",
")",
"\n",
"return",
"mw",
".",
"closing",
"\n",
"}"
] | // Returns true if the window is closed. | [
"Returns",
"true",
"if",
"the",
"window",
"is",
"closed",
"."
] | 64ec1eba91814ebb417978927206070dd1fc44e1 | https://github.com/aarzilli/nucular/blob/64ec1eba91814ebb417978927206070dd1fc44e1/shiny.go#L298-L302 | train |
aarzilli/nucular | text.go | Delete | func (edit *TextEditor) Delete(where int, len int) {
/* delete characters while updating undo */
edit.makeundoDelete(where, len)
edit.Buffer = strDeleteText(edit.Buffer, where, len)
edit.HasPreferredX = false
} | go | func (edit *TextEditor) Delete(where int, len int) {
/* delete characters while updating undo */
edit.makeundoDelete(where, len)
edit.Buffer = strDeleteText(edit.Buffer, where, len)
edit.HasPreferredX = false
} | [
"func",
"(",
"edit",
"*",
"TextEditor",
")",
"Delete",
"(",
"where",
"int",
",",
"len",
"int",
")",
"{",
"/* delete characters while updating undo */",
"edit",
".",
"makeundoDelete",
"(",
"where",
",",
"len",
")",
"\n\n",
"edit",
".",
"Buffer",
"=",
"strDele... | // Deletes a chunk of text in the editor. | [
"Deletes",
"a",
"chunk",
"of",
"text",
"in",
"the",
"editor",
"."
] | 64ec1eba91814ebb417978927206070dd1fc44e1 | https://github.com/aarzilli/nucular/blob/64ec1eba91814ebb417978927206070dd1fc44e1/text.go#L460-L466 | train |
aarzilli/nucular | text.go | DeleteSelection | func (edit *TextEditor) DeleteSelection() {
/* delete the section */
edit.clamp()
if edit.hasSelection() {
if edit.SelectStart < edit.SelectEnd {
edit.Delete(edit.SelectStart, edit.SelectEnd-edit.SelectStart)
edit.Cursor = edit.SelectStart
edit.SelectEnd = edit.Cursor
} else {
edit.Delete(edit.Selec... | go | func (edit *TextEditor) DeleteSelection() {
/* delete the section */
edit.clamp()
if edit.hasSelection() {
if edit.SelectStart < edit.SelectEnd {
edit.Delete(edit.SelectStart, edit.SelectEnd-edit.SelectStart)
edit.Cursor = edit.SelectStart
edit.SelectEnd = edit.Cursor
} else {
edit.Delete(edit.Selec... | [
"func",
"(",
"edit",
"*",
"TextEditor",
")",
"DeleteSelection",
"(",
")",
"{",
"/* delete the section */",
"edit",
".",
"clamp",
"(",
")",
"\n\n",
"if",
"edit",
".",
"hasSelection",
"(",
")",
"{",
"if",
"edit",
".",
"SelectStart",
"<",
"edit",
".",
"Sele... | // Deletes selection. | [
"Deletes",
"selection",
"."
] | 64ec1eba91814ebb417978927206070dd1fc44e1 | https://github.com/aarzilli/nucular/blob/64ec1eba91814ebb417978927206070dd1fc44e1/text.go#L469-L486 | train |
aarzilli/nucular | text.go | tonl | func (state *TextEditor) tonl(start int, dir int) int {
sz := len(state.Buffer)
i := start
if i < 0 {
return 0
}
if i >= sz {
i = sz - 1
}
for ; (i >= 0) && (i < sz); i += dir {
c := state.Buffer[i]
if c == '\n' {
if dir >= 0 {
return i
} else {
return i + 1
}
}
}
if dir < 0 {
re... | go | func (state *TextEditor) tonl(start int, dir int) int {
sz := len(state.Buffer)
i := start
if i < 0 {
return 0
}
if i >= sz {
i = sz - 1
}
for ; (i >= 0) && (i < sz); i += dir {
c := state.Buffer[i]
if c == '\n' {
if dir >= 0 {
return i
} else {
return i + 1
}
}
}
if dir < 0 {
re... | [
"func",
"(",
"state",
"*",
"TextEditor",
")",
"tonl",
"(",
"start",
"int",
",",
"dir",
"int",
")",
"int",
"{",
"sz",
":=",
"len",
"(",
"state",
".",
"Buffer",
")",
"\n\n",
"i",
":=",
"start",
"\n",
"if",
"i",
"<",
"0",
"{",
"return",
"0",
"\n",... | // Moves to the beginning or end of a line | [
"Moves",
"to",
"the",
"beginning",
"or",
"end",
"of",
"a",
"line"
] | 64ec1eba91814ebb417978927206070dd1fc44e1 | https://github.com/aarzilli/nucular/blob/64ec1eba91814ebb417978927206070dd1fc44e1/text.go#L519-L545 | train |
aarzilli/nucular | text.go | towd | func (state *TextEditor) towd(start int, dir int, dontForceAdvance bool) int {
first := (dir < 0)
notfirst := !first
var i int
for i = start; (i >= 0) && (i < len(state.Buffer)); i += dir {
c := state.Buffer[i]
if !(unicode.IsLetter(c) || unicode.IsDigit(c) || (c == '_')) {
if !first && !dontForceAdvance {
... | go | func (state *TextEditor) towd(start int, dir int, dontForceAdvance bool) int {
first := (dir < 0)
notfirst := !first
var i int
for i = start; (i >= 0) && (i < len(state.Buffer)); i += dir {
c := state.Buffer[i]
if !(unicode.IsLetter(c) || unicode.IsDigit(c) || (c == '_')) {
if !first && !dontForceAdvance {
... | [
"func",
"(",
"state",
"*",
"TextEditor",
")",
"towd",
"(",
"start",
"int",
",",
"dir",
"int",
",",
"dontForceAdvance",
"bool",
")",
"int",
"{",
"first",
":=",
"(",
"dir",
"<",
"0",
")",
"\n",
"notfirst",
":=",
"!",
"first",
"\n",
"var",
"i",
"int",... | // Moves to the beginning or end of an alphanumerically delimited word | [
"Moves",
"to",
"the",
"beginning",
"or",
"end",
"of",
"an",
"alphanumerically",
"delimited",
"word"
] | 64ec1eba91814ebb417978927206070dd1fc44e1 | https://github.com/aarzilli/nucular/blob/64ec1eba91814ebb417978927206070dd1fc44e1/text.go#L548-L566 | train |
aarzilli/nucular | text.go | tospc | func (state *TextEditor) tospc(start int, dir int) int {
return state.tof(start, dir, unicode.IsSpace)
} | go | func (state *TextEditor) tospc(start int, dir int) int {
return state.tof(start, dir, unicode.IsSpace)
} | [
"func",
"(",
"state",
"*",
"TextEditor",
")",
"tospc",
"(",
"start",
"int",
",",
"dir",
"int",
")",
"int",
"{",
"return",
"state",
".",
"tof",
"(",
"start",
",",
"dir",
",",
"unicode",
".",
"IsSpace",
")",
"\n",
"}"
] | // Moves to the beginning or end of a space delimited word | [
"Moves",
"to",
"the",
"beginning",
"or",
"end",
"of",
"a",
"space",
"delimited",
"word"
] | 64ec1eba91814ebb417978927206070dd1fc44e1 | https://github.com/aarzilli/nucular/blob/64ec1eba91814ebb417978927206070dd1fc44e1/text.go#L569-L571 | train |
aarzilli/nucular | text.go | tof | func (state *TextEditor) tof(start int, dir int, f func(rune) bool) int {
first := (dir < 0)
notfirst := !first
var i int
for i = start; (i >= 0) && (i < len(state.Buffer)); i += dir {
c := state.Buffer[i]
if f(c) {
if !first {
i++
}
break
}
first = notfirst
}
if i < 0 {
i = 0
}
return i
... | go | func (state *TextEditor) tof(start int, dir int, f func(rune) bool) int {
first := (dir < 0)
notfirst := !first
var i int
for i = start; (i >= 0) && (i < len(state.Buffer)); i += dir {
c := state.Buffer[i]
if f(c) {
if !first {
i++
}
break
}
first = notfirst
}
if i < 0 {
i = 0
}
return i
... | [
"func",
"(",
"state",
"*",
"TextEditor",
")",
"tof",
"(",
"start",
"int",
",",
"dir",
"int",
",",
"f",
"func",
"(",
"rune",
")",
"bool",
")",
"int",
"{",
"first",
":=",
"(",
"dir",
"<",
"0",
")",
"\n",
"notfirst",
":=",
"!",
"first",
"\n",
"var... | // Moves to the first position where f returns true | [
"Moves",
"to",
"the",
"first",
"position",
"where",
"f",
"returns",
"true"
] | 64ec1eba91814ebb417978927206070dd1fc44e1 | https://github.com/aarzilli/nucular/blob/64ec1eba91814ebb417978927206070dd1fc44e1/text.go#L574-L592 | train |
aarzilli/nucular | text.go | tofp | func (state *TextEditor) tofp(start int, dir int) int {
first := (dir < 0)
notfirst := !first
var i int
for i = start; (i >= 0) && (i < len(state.Buffer)); i += dir {
c := state.Buffer[i]
if !(unicode.IsLetter(c) || unicode.IsDigit(c) || (c == '_') || (c == '-') || (c == '+') || (c == '/') || (c == '=') || (c =... | go | func (state *TextEditor) tofp(start int, dir int) int {
first := (dir < 0)
notfirst := !first
var i int
for i = start; (i >= 0) && (i < len(state.Buffer)); i += dir {
c := state.Buffer[i]
if !(unicode.IsLetter(c) || unicode.IsDigit(c) || (c == '_') || (c == '-') || (c == '+') || (c == '/') || (c == '=') || (c =... | [
"func",
"(",
"state",
"*",
"TextEditor",
")",
"tofp",
"(",
"start",
"int",
",",
"dir",
"int",
")",
"int",
"{",
"first",
":=",
"(",
"dir",
"<",
"0",
")",
"\n",
"notfirst",
":=",
"!",
"first",
"\n",
"var",
"i",
"int",
"\n",
"for",
"i",
"=",
"star... | // Moves to the beginning or end of something that looks like a file path | [
"Moves",
"to",
"the",
"beginning",
"or",
"end",
"of",
"something",
"that",
"looks",
"like",
"a",
"file",
"path"
] | 64ec1eba91814ebb417978927206070dd1fc44e1 | https://github.com/aarzilli/nucular/blob/64ec1eba91814ebb417978927206070dd1fc44e1/text.go#L595-L614 | train |
aarzilli/nucular | text.go | Paste | func (edit *TextEditor) Paste(ctext string) {
if edit.Flags&EditReadOnly != 0 {
return
}
/* if there's a selection, the paste should delete it */
edit.clamp()
edit.DeleteSelection()
text := []rune(ctext)
edit.Buffer = strInsertText(edit.Buffer, edit.Cursor, text)
edit.makeundoInsert(edit.Cursor, len(text... | go | func (edit *TextEditor) Paste(ctext string) {
if edit.Flags&EditReadOnly != 0 {
return
}
/* if there's a selection, the paste should delete it */
edit.clamp()
edit.DeleteSelection()
text := []rune(ctext)
edit.Buffer = strInsertText(edit.Buffer, edit.Cursor, text)
edit.makeundoInsert(edit.Cursor, len(text... | [
"func",
"(",
"edit",
"*",
"TextEditor",
")",
"Paste",
"(",
"ctext",
"string",
")",
"{",
"if",
"edit",
".",
"Flags",
"&",
"EditReadOnly",
"!=",
"0",
"{",
"return",
"\n",
"}",
"\n\n",
"/* if there's a selection, the paste should delete it */",
"edit",
".",
"clam... | // Paste from clipboard | [
"Paste",
"from",
"clipboard"
] | 64ec1eba91814ebb417978927206070dd1fc44e1 | https://github.com/aarzilli/nucular/blob/64ec1eba91814ebb417978927206070dd1fc44e1/text.go#L641-L658 | train |
aarzilli/nucular | text.go | Edit | func (edit *TextEditor) Edit(win *Window) EditEvents {
edit.init(win)
if edit.Maxlen > 0 {
if len(edit.Buffer) > edit.Maxlen {
edit.Buffer = edit.Buffer[:edit.Maxlen]
}
}
if edit.Flags&EditNoCursor != 0 {
edit.Cursor = len(edit.Buffer)
}
if edit.Flags&EditSelectable == 0 {
edit.SelectStart = edit.Curs... | go | func (edit *TextEditor) Edit(win *Window) EditEvents {
edit.init(win)
if edit.Maxlen > 0 {
if len(edit.Buffer) > edit.Maxlen {
edit.Buffer = edit.Buffer[:edit.Maxlen]
}
}
if edit.Flags&EditNoCursor != 0 {
edit.Cursor = len(edit.Buffer)
}
if edit.Flags&EditSelectable == 0 {
edit.SelectStart = edit.Curs... | [
"func",
"(",
"edit",
"*",
"TextEditor",
")",
"Edit",
"(",
"win",
"*",
"Window",
")",
"EditEvents",
"{",
"edit",
".",
"init",
"(",
"win",
")",
"\n",
"if",
"edit",
".",
"Maxlen",
">",
"0",
"{",
"if",
"len",
"(",
"edit",
".",
"Buffer",
")",
">",
"... | // Adds text editor edit to win.
// Initial contents of the text editor will be set to text. If
// alwaysSet is specified the contents of the editor will be reset
// to text. | [
"Adds",
"text",
"editor",
"edit",
"to",
"win",
".",
"Initial",
"contents",
"of",
"the",
"text",
"editor",
"will",
"be",
"set",
"to",
"text",
".",
"If",
"alwaysSet",
"is",
"specified",
"the",
"contents",
"of",
"the",
"editor",
"will",
"be",
"reset",
"to",... | 64ec1eba91814ebb417978927206070dd1fc44e1 | https://github.com/aarzilli/nucular/blob/64ec1eba91814ebb417978927206070dd1fc44e1/text.go#L1780-L1835 | train |
aarzilli/nucular | context.go | SetColor | func (r *myRGBAPainter) SetColor(c color.Color) {
r.cr, r.cg, r.cb, r.ca = c.RGBA()
} | go | func (r *myRGBAPainter) SetColor(c color.Color) {
r.cr, r.cg, r.cb, r.ca = c.RGBA()
} | [
"func",
"(",
"r",
"*",
"myRGBAPainter",
")",
"SetColor",
"(",
"c",
"color",
".",
"Color",
")",
"{",
"r",
".",
"cr",
",",
"r",
".",
"cg",
",",
"r",
".",
"cb",
",",
"r",
".",
"ca",
"=",
"c",
".",
"RGBA",
"(",
")",
"\n",
"}"
] | // SetColor sets the color to paint the spans. | [
"SetColor",
"sets",
"the",
"color",
"to",
"paint",
"the",
"spans",
"."
] | 64ec1eba91814ebb417978927206070dd1fc44e1 | https://github.com/aarzilli/nucular/blob/64ec1eba91814ebb417978927206070dd1fc44e1/context.go#L724-L726 | train |
aarzilli/nucular | nucular.go | MenubarBegin | func (win *Window) MenubarBegin() {
layout := win.layout
layout.Menu.X = layout.AtX
layout.Menu.Y = layout.Bounds.Y + layout.HeaderH
layout.Menu.W = layout.Width
layout.Menu.Offset = *layout.Offset
layout.Offset.Y = 0
} | go | func (win *Window) MenubarBegin() {
layout := win.layout
layout.Menu.X = layout.AtX
layout.Menu.Y = layout.Bounds.Y + layout.HeaderH
layout.Menu.W = layout.Width
layout.Menu.Offset = *layout.Offset
layout.Offset.Y = 0
} | [
"func",
"(",
"win",
"*",
"Window",
")",
"MenubarBegin",
"(",
")",
"{",
"layout",
":=",
"win",
".",
"layout",
"\n\n",
"layout",
".",
"Menu",
".",
"X",
"=",
"layout",
".",
"AtX",
"\n",
"layout",
".",
"Menu",
".",
"Y",
"=",
"layout",
".",
"Bounds",
... | // MenubarBegin adds a menubar to the current window.
// A menubar is an area displayed at the top of the window that is unaffected by scrolling.
// Remember to call MenubarEnd when you are done adding elements to the menubar. | [
"MenubarBegin",
"adds",
"a",
"menubar",
"to",
"the",
"current",
"window",
".",
"A",
"menubar",
"is",
"an",
"area",
"displayed",
"at",
"the",
"top",
"of",
"the",
"window",
"that",
"is",
"unaffected",
"by",
"scrolling",
".",
"Remember",
"to",
"call",
"Menuba... | 64ec1eba91814ebb417978927206070dd1fc44e1 | https://github.com/aarzilli/nucular/blob/64ec1eba91814ebb417978927206070dd1fc44e1/nucular.go#L704-L712 | train |
aarzilli/nucular | nucular.go | MenubarEnd | func (win *Window) MenubarEnd() {
layout := win.layout
layout.Menu.H = layout.AtY - layout.Menu.Y
layout.Clip.Y = layout.Bounds.Y + layout.HeaderH + layout.Menu.H + layout.Row.Height
layout.Height -= layout.Menu.H
*layout.Offset = layout.Menu.Offset
layout.Clip.H -= layout.Menu.H + layout.Row.Height
layout.AtY ... | go | func (win *Window) MenubarEnd() {
layout := win.layout
layout.Menu.H = layout.AtY - layout.Menu.Y
layout.Clip.Y = layout.Bounds.Y + layout.HeaderH + layout.Menu.H + layout.Row.Height
layout.Height -= layout.Menu.H
*layout.Offset = layout.Menu.Offset
layout.Clip.H -= layout.Menu.H + layout.Row.Height
layout.AtY ... | [
"func",
"(",
"win",
"*",
"Window",
")",
"MenubarEnd",
"(",
")",
"{",
"layout",
":=",
"win",
".",
"layout",
"\n\n",
"layout",
".",
"Menu",
".",
"H",
"=",
"layout",
".",
"AtY",
"-",
"layout",
".",
"Menu",
".",
"Y",
"\n",
"layout",
".",
"Clip",
".",... | // MenubarEnd signals that all widgets have been added to the menubar. | [
"MenubarEnd",
"signals",
"that",
"all",
"widgets",
"have",
"been",
"added",
"to",
"the",
"menubar",
"."
] | 64ec1eba91814ebb417978927206070dd1fc44e1 | https://github.com/aarzilli/nucular/blob/64ec1eba91814ebb417978927206070dd1fc44e1/nucular.go#L745-L755 | train |
aarzilli/nucular | nucular.go | LayoutReserveRow | func (win *Window) LayoutReserveRow(height int, num int) {
win.LayoutReserveRowScaled(win.ctx.scale(height), num)
} | go | func (win *Window) LayoutReserveRow(height int, num int) {
win.LayoutReserveRowScaled(win.ctx.scale(height), num)
} | [
"func",
"(",
"win",
"*",
"Window",
")",
"LayoutReserveRow",
"(",
"height",
"int",
",",
"num",
"int",
")",
"{",
"win",
".",
"LayoutReserveRowScaled",
"(",
"win",
".",
"ctx",
".",
"scale",
"(",
"height",
")",
",",
"num",
")",
"\n",
"}"
] | // Reserves space for num rows of the specified height at the bottom
// of the panel.
// If a row of height == 0 is inserted it will take reserved space
// into account. | [
"Reserves",
"space",
"for",
"num",
"rows",
"of",
"the",
"specified",
"height",
"at",
"the",
"bottom",
"of",
"the",
"panel",
".",
"If",
"a",
"row",
"of",
"height",
"==",
"0",
"is",
"inserted",
"it",
"will",
"take",
"reserved",
"space",
"into",
"account",
... | 64ec1eba91814ebb417978927206070dd1fc44e1 | https://github.com/aarzilli/nucular/blob/64ec1eba91814ebb417978927206070dd1fc44e1/nucular.go#L995-L997 | train |
aarzilli/nucular | nucular.go | LayoutReserveRowScaled | func (win *Window) LayoutReserveRowScaled(height int, num int) {
win.layout.ReservedHeight += height*num + win.style().Spacing.Y*num
} | go | func (win *Window) LayoutReserveRowScaled(height int, num int) {
win.layout.ReservedHeight += height*num + win.style().Spacing.Y*num
} | [
"func",
"(",
"win",
"*",
"Window",
")",
"LayoutReserveRowScaled",
"(",
"height",
"int",
",",
"num",
"int",
")",
"{",
"win",
".",
"layout",
".",
"ReservedHeight",
"+=",
"height",
"*",
"num",
"+",
"win",
".",
"style",
"(",
")",
".",
"Spacing",
".",
"Y"... | // Like LayoutReserveRow but with a scaled height. | [
"Like",
"LayoutReserveRow",
"but",
"with",
"a",
"scaled",
"height",
"."
] | 64ec1eba91814ebb417978927206070dd1fc44e1 | https://github.com/aarzilli/nucular/blob/64ec1eba91814ebb417978927206070dd1fc44e1/nucular.go#L1000-L1002 | train |
aarzilli/nucular | nucular.go | RowScaled | func (win *Window) RowScaled(height int) *rowConstructor {
win.rowCtor.height = height
return &win.rowCtor
} | go | func (win *Window) RowScaled(height int) *rowConstructor {
win.rowCtor.height = height
return &win.rowCtor
} | [
"func",
"(",
"win",
"*",
"Window",
")",
"RowScaled",
"(",
"height",
"int",
")",
"*",
"rowConstructor",
"{",
"win",
".",
"rowCtor",
".",
"height",
"=",
"height",
"\n",
"return",
"&",
"win",
".",
"rowCtor",
"\n",
"}"
] | // Same as Row but with scaled units. | [
"Same",
"as",
"Row",
"but",
"with",
"scaled",
"units",
"."
] | 64ec1eba91814ebb417978927206070dd1fc44e1 | https://github.com/aarzilli/nucular/blob/64ec1eba91814ebb417978927206070dd1fc44e1/nucular.go#L1014-L1017 | train |
aarzilli/nucular | nucular.go | Dynamic | func (ctr *rowConstructor) Dynamic(cols int) {
rowLayoutCtr(ctr.win, ctr.height, cols, 0)
} | go | func (ctr *rowConstructor) Dynamic(cols int) {
rowLayoutCtr(ctr.win, ctr.height, cols, 0)
} | [
"func",
"(",
"ctr",
"*",
"rowConstructor",
")",
"Dynamic",
"(",
"cols",
"int",
")",
"{",
"rowLayoutCtr",
"(",
"ctr",
".",
"win",
",",
"ctr",
".",
"height",
",",
"cols",
",",
"0",
")",
"\n",
"}"
] | // Starts new row that has cols columns of equal width that automatically
// resize to fill the available space. | [
"Starts",
"new",
"row",
"that",
"has",
"cols",
"columns",
"of",
"equal",
"width",
"that",
"automatically",
"resize",
"to",
"fill",
"the",
"available",
"space",
"."
] | 64ec1eba91814ebb417978927206070dd1fc44e1 | https://github.com/aarzilli/nucular/blob/64ec1eba91814ebb417978927206070dd1fc44e1/nucular.go#L1026-L1028 | train |
aarzilli/nucular | nucular.go | Ratio | func (ctr *rowConstructor) Ratio(ratio ...float64) {
layout := ctr.win.layout
panelLayout(ctr.win.ctx, ctr.win, ctr.height, len(ratio), 0)
/* calculate width of undefined widget ratios */
r := 0.0
n_undef := 0
layout.Row.Ratio = ratio
for i := range ratio {
if ratio[i] < 0.0 {
n_undef++
} else {
r += ... | go | func (ctr *rowConstructor) Ratio(ratio ...float64) {
layout := ctr.win.layout
panelLayout(ctr.win.ctx, ctr.win, ctr.height, len(ratio), 0)
/* calculate width of undefined widget ratios */
r := 0.0
n_undef := 0
layout.Row.Ratio = ratio
for i := range ratio {
if ratio[i] < 0.0 {
n_undef++
} else {
r += ... | [
"func",
"(",
"ctr",
"*",
"rowConstructor",
")",
"Ratio",
"(",
"ratio",
"...",
"float64",
")",
"{",
"layout",
":=",
"ctr",
".",
"win",
".",
"layout",
"\n",
"panelLayout",
"(",
"ctr",
".",
"win",
".",
"ctx",
",",
"ctr",
".",
"win",
",",
"ctr",
".",
... | // Starts new row with a fixed number of columns of width proportional
// to the size of the window. | [
"Starts",
"new",
"row",
"with",
"a",
"fixed",
"number",
"of",
"columns",
"of",
"width",
"proportional",
"to",
"the",
"size",
"of",
"the",
"window",
"."
] | 64ec1eba91814ebb417978927206070dd1fc44e1 | https://github.com/aarzilli/nucular/blob/64ec1eba91814ebb417978927206070dd1fc44e1/nucular.go#L1032-L1059 | train |
aarzilli/nucular | nucular.go | StaticScaled | func (ctr *rowConstructor) StaticScaled(width ...int) {
layout := ctr.win.layout
cnt := 0
if len(width) == 0 {
if len(layout.Row.WidthArr) == 0 {
cnt = layout.Cnt
} else {
cnt = ctr.win.lastLayoutCnt + 1
ctr.win.lastLayoutCnt = cnt
}
}
panelLayout(ctr.win.ctx, ctr.win, ctr.height, len(width), cnt... | go | func (ctr *rowConstructor) StaticScaled(width ...int) {
layout := ctr.win.layout
cnt := 0
if len(width) == 0 {
if len(layout.Row.WidthArr) == 0 {
cnt = layout.Cnt
} else {
cnt = ctr.win.lastLayoutCnt + 1
ctr.win.lastLayoutCnt = cnt
}
}
panelLayout(ctr.win.ctx, ctr.win, ctr.height, len(width), cnt... | [
"func",
"(",
"ctr",
"*",
"rowConstructor",
")",
"StaticScaled",
"(",
"width",
"...",
"int",
")",
"{",
"layout",
":=",
"ctr",
".",
"win",
".",
"layout",
"\n\n",
"cnt",
":=",
"0",
"\n\n",
"if",
"len",
"(",
"width",
")",
"==",
"0",
"{",
"if",
"len",
... | // Like Static but with scaled sizes. | [
"Like",
"Static",
"but",
"with",
"scaled",
"sizes",
"."
] | 64ec1eba91814ebb417978927206070dd1fc44e1 | https://github.com/aarzilli/nucular/blob/64ec1eba91814ebb417978927206070dd1fc44e1/nucular.go#L1106-L1130 | train |
aarzilli/nucular | nucular.go | LayoutResetStatic | func (win *Window) LayoutResetStatic(width ...int) {
for i := range width {
width[i] = win.ctx.scale(width[i])
}
win.LayoutResetStaticScaled(width...)
} | go | func (win *Window) LayoutResetStatic(width ...int) {
for i := range width {
width[i] = win.ctx.scale(width[i])
}
win.LayoutResetStaticScaled(width...)
} | [
"func",
"(",
"win",
"*",
"Window",
")",
"LayoutResetStatic",
"(",
"width",
"...",
"int",
")",
"{",
"for",
"i",
":=",
"range",
"width",
"{",
"width",
"[",
"i",
"]",
"=",
"win",
".",
"ctx",
".",
"scale",
"(",
"width",
"[",
"i",
"]",
")",
"\n",
"}... | // Reset static row | [
"Reset",
"static",
"row"
] | 64ec1eba91814ebb417978927206070dd1fc44e1 | https://github.com/aarzilli/nucular/blob/64ec1eba91814ebb417978927206070dd1fc44e1/nucular.go#L1133-L1138 | train |
aarzilli/nucular | nucular.go | SpaceBeginRatio | func (ctr *rowConstructor) SpaceBeginRatio(widget_count int) {
layout := ctr.win.layout
panelLayout(ctr.win.ctx, ctr.win, ctr.height, widget_count, 0)
layout.Row.Type = layoutDynamicFree
layout.Row.Ratio = nil
layout.Row.ItemWidth = 0
layout.Row.ItemRatio = 0.0
layout.Row.ItemOffset = 0
layout.Row.Filled = 0
} | go | func (ctr *rowConstructor) SpaceBeginRatio(widget_count int) {
layout := ctr.win.layout
panelLayout(ctr.win.ctx, ctr.win, ctr.height, widget_count, 0)
layout.Row.Type = layoutDynamicFree
layout.Row.Ratio = nil
layout.Row.ItemWidth = 0
layout.Row.ItemRatio = 0.0
layout.Row.ItemOffset = 0
layout.Row.Filled = 0
} | [
"func",
"(",
"ctr",
"*",
"rowConstructor",
")",
"SpaceBeginRatio",
"(",
"widget_count",
"int",
")",
"{",
"layout",
":=",
"ctr",
".",
"win",
".",
"layout",
"\n",
"panelLayout",
"(",
"ctr",
".",
"win",
".",
"ctx",
",",
"ctr",
".",
"win",
",",
"ctr",
".... | // Starts new row that will contain widget_count widgets.
// The size and position of widgets inside this row will be specified
// by callling LayoutSpacePushRatio. | [
"Starts",
"new",
"row",
"that",
"will",
"contain",
"widget_count",
"widgets",
".",
"The",
"size",
"and",
"position",
"of",
"widgets",
"inside",
"this",
"row",
"will",
"be",
"specified",
"by",
"callling",
"LayoutSpacePushRatio",
"."
] | 64ec1eba91814ebb417978927206070dd1fc44e1 | https://github.com/aarzilli/nucular/blob/64ec1eba91814ebb417978927206070dd1fc44e1/nucular.go#L1184-L1194 | train |
aarzilli/nucular | nucular.go | LayoutSetWidth | func (win *Window) LayoutSetWidth(width int) {
layout := win.layout
if layout.Row.Type != layoutStatic || len(layout.Row.WidthArr) > 0 {
panic(WrongLayoutErr)
}
layout.Row.Index2++
layout.Row.CalcMaxWidth = false
layout.Row.ItemWidth = win.ctx.scale(width)
} | go | func (win *Window) LayoutSetWidth(width int) {
layout := win.layout
if layout.Row.Type != layoutStatic || len(layout.Row.WidthArr) > 0 {
panic(WrongLayoutErr)
}
layout.Row.Index2++
layout.Row.CalcMaxWidth = false
layout.Row.ItemWidth = win.ctx.scale(width)
} | [
"func",
"(",
"win",
"*",
"Window",
")",
"LayoutSetWidth",
"(",
"width",
"int",
")",
"{",
"layout",
":=",
"win",
".",
"layout",
"\n",
"if",
"layout",
".",
"Row",
".",
"Type",
"!=",
"layoutStatic",
"||",
"len",
"(",
"layout",
".",
"Row",
".",
"WidthArr... | // LayoutSetWidth adds a new column with the specified width to a static
// layout. | [
"LayoutSetWidth",
"adds",
"a",
"new",
"column",
"with",
"the",
"specified",
"width",
"to",
"a",
"static",
"layout",
"."
] | 64ec1eba91814ebb417978927206070dd1fc44e1 | https://github.com/aarzilli/nucular/blob/64ec1eba91814ebb417978927206070dd1fc44e1/nucular.go#L1198-L1206 | train |
aarzilli/nucular | nucular.go | LayoutFitWidth | func (win *Window) LayoutFitWidth(id int, minwidth int) {
layout := win.layout
if layout.Row.Type != layoutStatic || len(layout.Row.WidthArr) > 0 {
panic(WrongLayoutErr)
}
if win.adjust == nil {
win.adjust = make(map[int]map[int]*adjustCol)
}
adjust, ok := win.adjust[layout.Cnt]
if !ok {
adjust = make(map[... | go | func (win *Window) LayoutFitWidth(id int, minwidth int) {
layout := win.layout
if layout.Row.Type != layoutStatic || len(layout.Row.WidthArr) > 0 {
panic(WrongLayoutErr)
}
if win.adjust == nil {
win.adjust = make(map[int]map[int]*adjustCol)
}
adjust, ok := win.adjust[layout.Cnt]
if !ok {
adjust = make(map[... | [
"func",
"(",
"win",
"*",
"Window",
")",
"LayoutFitWidth",
"(",
"id",
"int",
",",
"minwidth",
"int",
")",
"{",
"layout",
":=",
"win",
".",
"layout",
"\n",
"if",
"layout",
".",
"Row",
".",
"Type",
"!=",
"layoutStatic",
"||",
"len",
"(",
"layout",
".",
... | // LayoutFitWidth adds a new column to a static layout.
// The width of the column will be large enough to fit the largest widget
// exactly. The largest widget will only be calculated once per id, if the
// dataset changes the id should change. | [
"LayoutFitWidth",
"adds",
"a",
"new",
"column",
"to",
"a",
"static",
"layout",
".",
"The",
"width",
"of",
"the",
"column",
"will",
"be",
"large",
"enough",
"to",
"fit",
"the",
"largest",
"widget",
"exactly",
".",
"The",
"largest",
"widget",
"will",
"only",... | 64ec1eba91814ebb417978927206070dd1fc44e1 | https://github.com/aarzilli/nucular/blob/64ec1eba91814ebb417978927206070dd1fc44e1/nucular.go#L1224-L1254 | train |
aarzilli/nucular | nucular.go | LayoutSpacePushScaled | func (win *Window) LayoutSpacePushScaled(rect rect.Rect) {
if win.layout.Row.Type != layoutStaticFree {
panic(WrongLayoutErr)
}
win.layout.Row.Item = rect
} | go | func (win *Window) LayoutSpacePushScaled(rect rect.Rect) {
if win.layout.Row.Type != layoutStaticFree {
panic(WrongLayoutErr)
}
win.layout.Row.Item = rect
} | [
"func",
"(",
"win",
"*",
"Window",
")",
"LayoutSpacePushScaled",
"(",
"rect",
"rect",
".",
"Rect",
")",
"{",
"if",
"win",
".",
"layout",
".",
"Row",
".",
"Type",
"!=",
"layoutStaticFree",
"{",
"panic",
"(",
"WrongLayoutErr",
")",
"\n",
"}",
"\n",
"win"... | // Like LayoutSpacePush but with scaled units | [
"Like",
"LayoutSpacePush",
"but",
"with",
"scaled",
"units"
] | 64ec1eba91814ebb417978927206070dd1fc44e1 | https://github.com/aarzilli/nucular/blob/64ec1eba91814ebb417978927206070dd1fc44e1/nucular.go#L1271-L1276 | train |
aarzilli/nucular | nucular.go | WidgetBounds | func (win *Window) WidgetBounds() rect.Rect {
var bounds rect.Rect
win.layoutPeek(&bounds)
return bounds
} | go | func (win *Window) WidgetBounds() rect.Rect {
var bounds rect.Rect
win.layoutPeek(&bounds)
return bounds
} | [
"func",
"(",
"win",
"*",
"Window",
")",
"WidgetBounds",
"(",
")",
"rect",
".",
"Rect",
"{",
"var",
"bounds",
"rect",
".",
"Rect",
"\n",
"win",
".",
"layoutPeek",
"(",
"&",
"bounds",
")",
"\n",
"return",
"bounds",
"\n",
"}"
] | // Returns the position and size of the next widget that will be
// added to the current row.
// Note that the return value is in scaled units. | [
"Returns",
"the",
"position",
"and",
"size",
"of",
"the",
"next",
"widget",
"that",
"will",
"be",
"added",
"to",
"the",
"current",
"row",
".",
"Note",
"that",
"the",
"return",
"value",
"is",
"in",
"scaled",
"units",
"."
] | 64ec1eba91814ebb417978927206070dd1fc44e1 | https://github.com/aarzilli/nucular/blob/64ec1eba91814ebb417978927206070dd1fc44e1/nucular.go#L1307-L1311 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.