repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
dropbox/godropbox | sync2/boundedrwlock.go | WakeAtomic | func (wait *rwwait) WakeAtomic() bool {
swapped := atomic.CompareAndSwapInt32(&wait.alive, 1, 0)
if !swapped {
// They've moved on.
return false
}
wait.wake <- true
return true
} | go | func (wait *rwwait) WakeAtomic() bool {
swapped := atomic.CompareAndSwapInt32(&wait.alive, 1, 0)
if !swapped {
// They've moved on.
return false
}
wait.wake <- true
return true
} | [
"func",
"(",
"wait",
"*",
"rwwait",
")",
"WakeAtomic",
"(",
")",
"bool",
"{",
"swapped",
":=",
"atomic",
".",
"CompareAndSwapInt32",
"(",
"&",
"wait",
".",
"alive",
",",
"1",
",",
"0",
")",
"\n",
"if",
"!",
"swapped",
"{",
"// They've moved on.",
"return",
"false",
"\n",
"}",
"\n",
"wait",
".",
"wake",
"<-",
"true",
"\n",
"return",
"true",
"\n",
"}"
] | // Signal the wait to wake.
//
// Returns true of the waiter got the signal, false if the waiter timed out
// before we could deliver the signal. | [
"Signal",
"the",
"wait",
"to",
"wake",
".",
"Returns",
"true",
"of",
"the",
"waiter",
"got",
"the",
"signal",
"false",
"if",
"the",
"waiter",
"timed",
"out",
"before",
"we",
"could",
"deliver",
"the",
"signal",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/sync2/boundedrwlock.go#L210-L218 | train |
dropbox/godropbox | database/binlog/xid_event.go | Parse | func (p *XidEventParser) Parse(raw *RawV4Event) (Event, error) {
xe := &XidEvent{
Event: raw,
}
// For convenience, we'll interpret the bytes as little endian, our
// dominate computing (intel) platform.
_, err := readLittleEndian(raw.VariableLengthData(), &xe.xid)
if err != nil {
return raw, errors.Wrap(err, "Failed to read xid")
}
return xe, nil
} | go | func (p *XidEventParser) Parse(raw *RawV4Event) (Event, error) {
xe := &XidEvent{
Event: raw,
}
// For convenience, we'll interpret the bytes as little endian, our
// dominate computing (intel) platform.
_, err := readLittleEndian(raw.VariableLengthData(), &xe.xid)
if err != nil {
return raw, errors.Wrap(err, "Failed to read xid")
}
return xe, nil
} | [
"func",
"(",
"p",
"*",
"XidEventParser",
")",
"Parse",
"(",
"raw",
"*",
"RawV4Event",
")",
"(",
"Event",
",",
"error",
")",
"{",
"xe",
":=",
"&",
"XidEvent",
"{",
"Event",
":",
"raw",
",",
"}",
"\n\n",
"// For convenience, we'll interpret the bytes as little endian, our",
"// dominate computing (intel) platform.",
"_",
",",
"err",
":=",
"readLittleEndian",
"(",
"raw",
".",
"VariableLengthData",
"(",
")",
",",
"&",
"xe",
".",
"xid",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"raw",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"xe",
",",
"nil",
"\n",
"}"
] | // XidEventParser's Parse processes a raw xid event into a XidEvent. | [
"XidEventParser",
"s",
"Parse",
"processes",
"a",
"raw",
"xid",
"event",
"into",
"a",
"XidEvent",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/binlog/xid_event.go#L50-L63 | train |
dropbox/godropbox | memcache/mock_client.go | Get | func (c *MockClient) Get(key string) GetResponse {
c.mutex.Lock()
defer c.mutex.Unlock()
return c.getHelper(key)
} | go | func (c *MockClient) Get(key string) GetResponse {
c.mutex.Lock()
defer c.mutex.Unlock()
return c.getHelper(key)
} | [
"func",
"(",
"c",
"*",
"MockClient",
")",
"Get",
"(",
"key",
"string",
")",
"GetResponse",
"{",
"c",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"c",
".",
"getHelper",
"(",
"key",
")",
"\n",
"}"
] | // This retrieves a single entry from memcache. | [
"This",
"retrieves",
"a",
"single",
"entry",
"from",
"memcache",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/mock_client.go#L58-L63 | train |
dropbox/godropbox | memcache/mock_client.go | GetMulti | func (c *MockClient) GetMulti(keys []string) map[string]GetResponse {
c.mutex.Lock()
defer c.mutex.Unlock()
res := make(map[string]GetResponse)
for _, key := range keys {
res[key] = c.getHelper(key)
}
return res
} | go | func (c *MockClient) GetMulti(keys []string) map[string]GetResponse {
c.mutex.Lock()
defer c.mutex.Unlock()
res := make(map[string]GetResponse)
for _, key := range keys {
res[key] = c.getHelper(key)
}
return res
} | [
"func",
"(",
"c",
"*",
"MockClient",
")",
"GetMulti",
"(",
"keys",
"[",
"]",
"string",
")",
"map",
"[",
"string",
"]",
"GetResponse",
"{",
"c",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"res",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"GetResponse",
")",
"\n",
"for",
"_",
",",
"key",
":=",
"range",
"keys",
"{",
"res",
"[",
"key",
"]",
"=",
"c",
".",
"getHelper",
"(",
"key",
")",
"\n",
"}",
"\n",
"return",
"res",
"\n",
"}"
] | // Batch version of the Get method. | [
"Batch",
"version",
"of",
"the",
"Get",
"method",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/mock_client.go#L66-L75 | train |
dropbox/godropbox | memcache/mock_client.go | Delete | func (c *MockClient) Delete(key string) MutateResponse {
c.mutex.Lock()
defer c.mutex.Unlock()
if c.forceFailEverything {
return NewMutateResponse(
key,
StatusInternalError,
0)
}
_, ok := c.data[key]
if !ok {
return NewMutateResponse(
key,
StatusKeyNotFound,
0)
}
delete(c.data, key)
return NewMutateResponse(
key,
StatusNoError,
0)
} | go | func (c *MockClient) Delete(key string) MutateResponse {
c.mutex.Lock()
defer c.mutex.Unlock()
if c.forceFailEverything {
return NewMutateResponse(
key,
StatusInternalError,
0)
}
_, ok := c.data[key]
if !ok {
return NewMutateResponse(
key,
StatusKeyNotFound,
0)
}
delete(c.data, key)
return NewMutateResponse(
key,
StatusNoError,
0)
} | [
"func",
"(",
"c",
"*",
"MockClient",
")",
"Delete",
"(",
"key",
"string",
")",
"MutateResponse",
"{",
"c",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"c",
".",
"forceFailEverything",
"{",
"return",
"NewMutateResponse",
"(",
"key",
",",
"StatusInternalError",
",",
"0",
")",
"\n",
"}",
"\n\n",
"_",
",",
"ok",
":=",
"c",
".",
"data",
"[",
"key",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"NewMutateResponse",
"(",
"key",
",",
"StatusKeyNotFound",
",",
"0",
")",
"\n",
"}",
"\n\n",
"delete",
"(",
"c",
".",
"data",
",",
"key",
")",
"\n\n",
"return",
"NewMutateResponse",
"(",
"key",
",",
"StatusNoError",
",",
"0",
")",
"\n",
"}"
] | // This deletes a single entry from memcache. | [
"This",
"deletes",
"a",
"single",
"entry",
"from",
"memcache",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/mock_client.go#L235-L260 | train |
dropbox/godropbox | memcache/mock_client.go | Append | func (c *MockClient) Append(key string, value []byte) MutateResponse {
return NewMutateErrorResponse(key, errors.Newf("Append not implemented"))
} | go | func (c *MockClient) Append(key string, value []byte) MutateResponse {
return NewMutateErrorResponse(key, errors.Newf("Append not implemented"))
} | [
"func",
"(",
"c",
"*",
"MockClient",
")",
"Append",
"(",
"key",
"string",
",",
"value",
"[",
"]",
"byte",
")",
"MutateResponse",
"{",
"return",
"NewMutateErrorResponse",
"(",
"key",
",",
"errors",
".",
"Newf",
"(",
"\"",
"\"",
")",
")",
"\n",
"}"
] | // This appends the value bytes to the end of an existing entry. Note that
// this does not allow you to extend past the item limit. | [
"This",
"appends",
"the",
"value",
"bytes",
"to",
"the",
"end",
"of",
"an",
"existing",
"entry",
".",
"Note",
"that",
"this",
"does",
"not",
"allow",
"you",
"to",
"extend",
"past",
"the",
"item",
"limit",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/mock_client.go#L274-L276 | train |
dropbox/godropbox | memcache/mock_client.go | Flush | func (c *MockClient) Flush(expiration uint32) Response {
c.mutex.Lock()
defer c.mutex.Unlock()
// TODO(patrick): Use expiration argument
c.data = make(map[string]*Item)
return NewResponse(StatusNoError)
} | go | func (c *MockClient) Flush(expiration uint32) Response {
c.mutex.Lock()
defer c.mutex.Unlock()
// TODO(patrick): Use expiration argument
c.data = make(map[string]*Item)
return NewResponse(StatusNoError)
} | [
"func",
"(",
"c",
"*",
"MockClient",
")",
"Flush",
"(",
"expiration",
"uint32",
")",
"Response",
"{",
"c",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// TODO(patrick): Use expiration argument",
"c",
".",
"data",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"Item",
")",
"\n",
"return",
"NewResponse",
"(",
"StatusNoError",
")",
"\n",
"}"
] | // This invalidates all existing cache items after expiration number of
// seconds. | [
"This",
"invalidates",
"all",
"existing",
"cache",
"items",
"after",
"expiration",
"number",
"of",
"seconds",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/mock_client.go#L395-L402 | train |
dropbox/godropbox | memcache/mock_client.go | Stat | func (c *MockClient) Stat(statsKey string) StatResponse {
return NewStatErrorResponse(errors.Newf("Stat not implemented"), nil)
} | go | func (c *MockClient) Stat(statsKey string) StatResponse {
return NewStatErrorResponse(errors.Newf("Stat not implemented"), nil)
} | [
"func",
"(",
"c",
"*",
"MockClient",
")",
"Stat",
"(",
"statsKey",
"string",
")",
"StatResponse",
"{",
"return",
"NewStatErrorResponse",
"(",
"errors",
".",
"Newf",
"(",
"\"",
"\"",
")",
",",
"nil",
")",
"\n",
"}"
] | // This requests the server statistics. When the key is an empty string,
// the server will respond with a "default" set of statistics information. | [
"This",
"requests",
"the",
"server",
"statistics",
".",
"When",
"the",
"key",
"is",
"an",
"empty",
"string",
"the",
"server",
"will",
"respond",
"with",
"a",
"default",
"set",
"of",
"statistics",
"information",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/mock_client.go#L406-L408 | train |
dropbox/godropbox | net2/ip.go | MyHostname | func MyHostname() string {
myHostnameOnce.Do(func() {
var err error
myHostname, err = os.Hostname()
if err != nil {
log.Fatal(err)
}
})
return myHostname
} | go | func MyHostname() string {
myHostnameOnce.Do(func() {
var err error
myHostname, err = os.Hostname()
if err != nil {
log.Fatal(err)
}
})
return myHostname
} | [
"func",
"MyHostname",
"(",
")",
"string",
"{",
"myHostnameOnce",
".",
"Do",
"(",
"func",
"(",
")",
"{",
"var",
"err",
"error",
"\n",
"myHostname",
",",
"err",
"=",
"os",
".",
"Hostname",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatal",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
")",
"\n",
"return",
"myHostname",
"\n",
"}"
] | // Like os.Hostname but caches first successful result, making it cheap to call it
// over and over.
// It will also crash whole process if fetching Hostname fails! | [
"Like",
"os",
".",
"Hostname",
"but",
"caches",
"first",
"successful",
"result",
"making",
"it",
"cheap",
"to",
"call",
"it",
"over",
"and",
"over",
".",
"It",
"will",
"also",
"crash",
"whole",
"process",
"if",
"fetching",
"Hostname",
"fails!"
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/net2/ip.go#L19-L28 | train |
dropbox/godropbox | database/binlog/event_reader.go | IsRetryableError | func IsRetryableError(err error) bool {
if err == io.EOF {
return true
}
if _, ok := err.(*FailedToOpenFileError); ok {
return true
}
return false
} | go | func IsRetryableError(err error) bool {
if err == io.EOF {
return true
}
if _, ok := err.(*FailedToOpenFileError); ok {
return true
}
return false
} | [
"func",
"IsRetryableError",
"(",
"err",
"error",
")",
"bool",
"{",
"if",
"err",
"==",
"io",
".",
"EOF",
"{",
"return",
"true",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"err",
".",
"(",
"*",
"FailedToOpenFileError",
")",
";",
"ok",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] | // This returns true if the error returned by the event parser is retryable. | [
"This",
"returns",
"true",
"if",
"the",
"error",
"returned",
"by",
"the",
"event",
"parser",
"is",
"retryable",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/binlog/event_reader.go#L52-L61 | train |
dropbox/godropbox | database/sqlbuilder/statement.go | String | func (q *selectStatementImpl) String(database string) (sql string, err error) {
if !validIdentifierName(database) {
return "", errors.New("Invalid database name specified")
}
buf := new(bytes.Buffer)
_, _ = buf.WriteString("SELECT ")
if err = writeComment(q.comment, buf); err != nil {
return
}
if q.distinct {
_, _ = buf.WriteString("DISTINCT ")
}
if q.projections == nil || len(q.projections) == 0 {
return "", errors.Newf(
"No column selected. Generated sql: %s",
buf.String())
}
for i, col := range q.projections {
if i > 0 {
_ = buf.WriteByte(',')
}
if col == nil {
return "", errors.Newf(
"nil column selected. Generated sql: %s",
buf.String())
}
if err = col.SerializeSqlForColumnList(buf); err != nil {
return
}
}
_, _ = buf.WriteString(" FROM ")
if q.table == nil {
return "", errors.Newf("nil table. Generated sql: %s", buf.String())
}
if err = q.table.SerializeSql(database, buf); err != nil {
return
}
if q.where != nil {
_, _ = buf.WriteString(" WHERE ")
if err = q.where.SerializeSql(buf); err != nil {
return
}
}
if q.group != nil {
_, _ = buf.WriteString(" GROUP BY ")
if err = q.group.SerializeSql(buf); err != nil {
return
}
}
if q.order != nil {
_, _ = buf.WriteString(" ORDER BY ")
if err = q.order.SerializeSql(buf); err != nil {
return
}
}
if q.limit >= 0 {
if q.offset >= 0 {
_, _ = buf.WriteString(fmt.Sprintf(" LIMIT %d, %d", q.offset, q.limit))
} else {
_, _ = buf.WriteString(fmt.Sprintf(" LIMIT %d", q.limit))
}
}
if q.forUpdate {
_, _ = buf.WriteString(" FOR UPDATE")
} else if q.withSharedLock {
_, _ = buf.WriteString(" LOCK IN SHARE MODE")
}
return buf.String(), nil
} | go | func (q *selectStatementImpl) String(database string) (sql string, err error) {
if !validIdentifierName(database) {
return "", errors.New("Invalid database name specified")
}
buf := new(bytes.Buffer)
_, _ = buf.WriteString("SELECT ")
if err = writeComment(q.comment, buf); err != nil {
return
}
if q.distinct {
_, _ = buf.WriteString("DISTINCT ")
}
if q.projections == nil || len(q.projections) == 0 {
return "", errors.Newf(
"No column selected. Generated sql: %s",
buf.String())
}
for i, col := range q.projections {
if i > 0 {
_ = buf.WriteByte(',')
}
if col == nil {
return "", errors.Newf(
"nil column selected. Generated sql: %s",
buf.String())
}
if err = col.SerializeSqlForColumnList(buf); err != nil {
return
}
}
_, _ = buf.WriteString(" FROM ")
if q.table == nil {
return "", errors.Newf("nil table. Generated sql: %s", buf.String())
}
if err = q.table.SerializeSql(database, buf); err != nil {
return
}
if q.where != nil {
_, _ = buf.WriteString(" WHERE ")
if err = q.where.SerializeSql(buf); err != nil {
return
}
}
if q.group != nil {
_, _ = buf.WriteString(" GROUP BY ")
if err = q.group.SerializeSql(buf); err != nil {
return
}
}
if q.order != nil {
_, _ = buf.WriteString(" ORDER BY ")
if err = q.order.SerializeSql(buf); err != nil {
return
}
}
if q.limit >= 0 {
if q.offset >= 0 {
_, _ = buf.WriteString(fmt.Sprintf(" LIMIT %d, %d", q.offset, q.limit))
} else {
_, _ = buf.WriteString(fmt.Sprintf(" LIMIT %d", q.limit))
}
}
if q.forUpdate {
_, _ = buf.WriteString(" FOR UPDATE")
} else if q.withSharedLock {
_, _ = buf.WriteString(" LOCK IN SHARE MODE")
}
return buf.String(), nil
} | [
"func",
"(",
"q",
"*",
"selectStatementImpl",
")",
"String",
"(",
"database",
"string",
")",
"(",
"sql",
"string",
",",
"err",
"error",
")",
"{",
"if",
"!",
"validIdentifierName",
"(",
"database",
")",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"buf",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n",
"_",
",",
"_",
"=",
"buf",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n\n",
"if",
"err",
"=",
"writeComment",
"(",
"q",
".",
"comment",
",",
"buf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"q",
".",
"distinct",
"{",
"_",
",",
"_",
"=",
"buf",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"q",
".",
"projections",
"==",
"nil",
"||",
"len",
"(",
"q",
".",
"projections",
")",
"==",
"0",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Newf",
"(",
"\"",
"\"",
",",
"buf",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n\n",
"for",
"i",
",",
"col",
":=",
"range",
"q",
".",
"projections",
"{",
"if",
"i",
">",
"0",
"{",
"_",
"=",
"buf",
".",
"WriteByte",
"(",
"','",
")",
"\n",
"}",
"\n",
"if",
"col",
"==",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Newf",
"(",
"\"",
"\"",
",",
"buf",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"if",
"err",
"=",
"col",
".",
"SerializeSqlForColumnList",
"(",
"buf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n\n",
"_",
",",
"_",
"=",
"buf",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"if",
"q",
".",
"table",
"==",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Newf",
"(",
"\"",
"\"",
",",
"buf",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"if",
"err",
"=",
"q",
".",
"table",
".",
"SerializeSql",
"(",
"database",
",",
"buf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"q",
".",
"where",
"!=",
"nil",
"{",
"_",
",",
"_",
"=",
"buf",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"=",
"q",
".",
"where",
".",
"SerializeSql",
"(",
"buf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"q",
".",
"group",
"!=",
"nil",
"{",
"_",
",",
"_",
"=",
"buf",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"=",
"q",
".",
"group",
".",
"SerializeSql",
"(",
"buf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"q",
".",
"order",
"!=",
"nil",
"{",
"_",
",",
"_",
"=",
"buf",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"=",
"q",
".",
"order",
".",
"SerializeSql",
"(",
"buf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"q",
".",
"limit",
">=",
"0",
"{",
"if",
"q",
".",
"offset",
">=",
"0",
"{",
"_",
",",
"_",
"=",
"buf",
".",
"WriteString",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"q",
".",
"offset",
",",
"q",
".",
"limit",
")",
")",
"\n",
"}",
"else",
"{",
"_",
",",
"_",
"=",
"buf",
".",
"WriteString",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"q",
".",
"limit",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"q",
".",
"forUpdate",
"{",
"_",
",",
"_",
"=",
"buf",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"q",
".",
"withSharedLock",
"{",
"_",
",",
"_",
"=",
"buf",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"buf",
".",
"String",
"(",
")",
",",
"nil",
"\n",
"}"
] | // Return the properly escaped SQL statement, against the specified database | [
"Return",
"the",
"properly",
"escaped",
"SQL",
"statement",
"against",
"the",
"specified",
"database"
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/sqlbuilder/statement.go#L386-L466 | train |
dropbox/godropbox | database/sqlbuilder/statement.go | AddReadLock | func (s *lockStatementImpl) AddReadLock(t *Table) LockStatement {
s.locks = append(s.locks, tableLock{t: t, w: false})
return s
} | go | func (s *lockStatementImpl) AddReadLock(t *Table) LockStatement {
s.locks = append(s.locks, tableLock{t: t, w: false})
return s
} | [
"func",
"(",
"s",
"*",
"lockStatementImpl",
")",
"AddReadLock",
"(",
"t",
"*",
"Table",
")",
"LockStatement",
"{",
"s",
".",
"locks",
"=",
"append",
"(",
"s",
".",
"locks",
",",
"tableLock",
"{",
"t",
":",
"t",
",",
"w",
":",
"false",
"}",
")",
"\n",
"return",
"s",
"\n",
"}"
] | // AddReadLock takes read lock on the table. | [
"AddReadLock",
"takes",
"read",
"lock",
"on",
"the",
"table",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/sqlbuilder/statement.go#L899-L902 | train |
dropbox/godropbox | database/sqlbuilder/statement.go | AddWriteLock | func (s *lockStatementImpl) AddWriteLock(t *Table) LockStatement {
s.locks = append(s.locks, tableLock{t: t, w: true})
return s
} | go | func (s *lockStatementImpl) AddWriteLock(t *Table) LockStatement {
s.locks = append(s.locks, tableLock{t: t, w: true})
return s
} | [
"func",
"(",
"s",
"*",
"lockStatementImpl",
")",
"AddWriteLock",
"(",
"t",
"*",
"Table",
")",
"LockStatement",
"{",
"s",
".",
"locks",
"=",
"append",
"(",
"s",
".",
"locks",
",",
"tableLock",
"{",
"t",
":",
"t",
",",
"w",
":",
"true",
"}",
")",
"\n",
"return",
"s",
"\n",
"}"
] | // AddWriteLock takes write lock on the table. | [
"AddWriteLock",
"takes",
"write",
"lock",
"on",
"the",
"table",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/sqlbuilder/statement.go#L905-L908 | train |
dropbox/godropbox | database/sqlbuilder/statement.go | NewGtidNextStatement | func NewGtidNextStatement(sid []byte, gno uint64) GtidNextStatement {
return >idNextStatementImpl{
sid: sid,
gno: gno,
}
} | go | func NewGtidNextStatement(sid []byte, gno uint64) GtidNextStatement {
return >idNextStatementImpl{
sid: sid,
gno: gno,
}
} | [
"func",
"NewGtidNextStatement",
"(",
"sid",
"[",
"]",
"byte",
",",
"gno",
"uint64",
")",
"GtidNextStatement",
"{",
"return",
"&",
"gtidNextStatementImpl",
"{",
"sid",
":",
"sid",
",",
"gno",
":",
"gno",
",",
"}",
"\n",
"}"
] | // Set GTID_NEXT statement returns a SQL statement that can be used to explicitly set the next GTID. | [
"Set",
"GTID_NEXT",
"statement",
"returns",
"a",
"SQL",
"statement",
"that",
"can",
"be",
"used",
"to",
"explicitly",
"set",
"the",
"next",
"GTID",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/sqlbuilder/statement.go#L959-L964 | train |
dropbox/godropbox | database/binlog/gtid_log_event.go | Parse | func (p *GtidLogEventParser) Parse(raw *RawV4Event) (Event, error) {
gle := &GtidLogEvent{
Event: raw,
}
if len(raw.VariableLengthData()) > 0 {
return raw, errors.New("GTID binlog event larger than expected size")
}
data := raw.FixedLengthData()
var commitData uint8
data, err := readLittleEndian(data, &commitData)
if err != nil {
return raw, errors.Wrap(err, "Failed to read commit flag")
}
if commitData == 0 {
gle.commit = false
} else if commitData == 1 {
gle.commit = true
} else {
return raw, errors.Newf("Commit data is not 0 or 1: %d", commitData)
}
data, err = readLittleEndian(data, &gle.sid)
if err != nil {
return raw, errors.Wrap(err, "Failed to read sid")
}
data, err = readLittleEndian(data, &gle.gno)
if err != nil {
return raw, errors.Wrap(err, "Failed to read GNO")
}
return gle, nil
} | go | func (p *GtidLogEventParser) Parse(raw *RawV4Event) (Event, error) {
gle := &GtidLogEvent{
Event: raw,
}
if len(raw.VariableLengthData()) > 0 {
return raw, errors.New("GTID binlog event larger than expected size")
}
data := raw.FixedLengthData()
var commitData uint8
data, err := readLittleEndian(data, &commitData)
if err != nil {
return raw, errors.Wrap(err, "Failed to read commit flag")
}
if commitData == 0 {
gle.commit = false
} else if commitData == 1 {
gle.commit = true
} else {
return raw, errors.Newf("Commit data is not 0 or 1: %d", commitData)
}
data, err = readLittleEndian(data, &gle.sid)
if err != nil {
return raw, errors.Wrap(err, "Failed to read sid")
}
data, err = readLittleEndian(data, &gle.gno)
if err != nil {
return raw, errors.Wrap(err, "Failed to read GNO")
}
return gle, nil
} | [
"func",
"(",
"p",
"*",
"GtidLogEventParser",
")",
"Parse",
"(",
"raw",
"*",
"RawV4Event",
")",
"(",
"Event",
",",
"error",
")",
"{",
"gle",
":=",
"&",
"GtidLogEvent",
"{",
"Event",
":",
"raw",
",",
"}",
"\n\n",
"if",
"len",
"(",
"raw",
".",
"VariableLengthData",
"(",
")",
")",
">",
"0",
"{",
"return",
"raw",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"data",
":=",
"raw",
".",
"FixedLengthData",
"(",
")",
"\n\n",
"var",
"commitData",
"uint8",
"\n",
"data",
",",
"err",
":=",
"readLittleEndian",
"(",
"data",
",",
"&",
"commitData",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"raw",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"commitData",
"==",
"0",
"{",
"gle",
".",
"commit",
"=",
"false",
"\n",
"}",
"else",
"if",
"commitData",
"==",
"1",
"{",
"gle",
".",
"commit",
"=",
"true",
"\n",
"}",
"else",
"{",
"return",
"raw",
",",
"errors",
".",
"Newf",
"(",
"\"",
"\"",
",",
"commitData",
")",
"\n",
"}",
"\n\n",
"data",
",",
"err",
"=",
"readLittleEndian",
"(",
"data",
",",
"&",
"gle",
".",
"sid",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"raw",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"data",
",",
"err",
"=",
"readLittleEndian",
"(",
"data",
",",
"&",
"gle",
".",
"gno",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"raw",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"gle",
",",
"nil",
"\n",
"}"
] | // GtidLogEventParser's Parse processes a raw gtid log event into a GtidLogEvent. | [
"GtidLogEventParser",
"s",
"Parse",
"processes",
"a",
"raw",
"gtid",
"log",
"event",
"into",
"a",
"GtidLogEvent",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/binlog/gtid_log_event.go#L53-L88 | train |
dropbox/godropbox | resource_pool/multi_resource_pool.go | NewMultiResourcePool | func NewMultiResourcePool(
options Options,
createPool func(Options) ResourcePool) ResourcePool {
if createPool == nil {
createPool = NewSimpleResourcePool
}
return &multiResourcePool{
options: options,
createPool: createPool,
rwMutex: sync.RWMutex{},
isLameDuck: false,
locationPools: make(map[string]ResourcePool),
}
} | go | func NewMultiResourcePool(
options Options,
createPool func(Options) ResourcePool) ResourcePool {
if createPool == nil {
createPool = NewSimpleResourcePool
}
return &multiResourcePool{
options: options,
createPool: createPool,
rwMutex: sync.RWMutex{},
isLameDuck: false,
locationPools: make(map[string]ResourcePool),
}
} | [
"func",
"NewMultiResourcePool",
"(",
"options",
"Options",
",",
"createPool",
"func",
"(",
"Options",
")",
"ResourcePool",
")",
"ResourcePool",
"{",
"if",
"createPool",
"==",
"nil",
"{",
"createPool",
"=",
"NewSimpleResourcePool",
"\n",
"}",
"\n\n",
"return",
"&",
"multiResourcePool",
"{",
"options",
":",
"options",
",",
"createPool",
":",
"createPool",
",",
"rwMutex",
":",
"sync",
".",
"RWMutex",
"{",
"}",
",",
"isLameDuck",
":",
"false",
",",
"locationPools",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"ResourcePool",
")",
",",
"}",
"\n",
"}"
] | // This returns a MultiResourcePool, which manages multiple
// resource location entries. The handles to each resource location
// entry acts independently.
//
// When createPool is nil, NewSimpleResourcePool is used as default. | [
"This",
"returns",
"a",
"MultiResourcePool",
"which",
"manages",
"multiple",
"resource",
"location",
"entries",
".",
"The",
"handles",
"to",
"each",
"resource",
"location",
"entry",
"acts",
"independently",
".",
"When",
"createPool",
"is",
"nil",
"NewSimpleResourcePool",
"is",
"used",
"as",
"default",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/resource_pool/multi_resource_pool.go#L30-L45 | train |
dropbox/godropbox | database/sqltypes/sqltypes.go | String | func (v Value) String() string {
if v.Inner == nil {
return ""
}
return string(v.Inner.raw())
} | go | func (v Value) String() string {
if v.Inner == nil {
return ""
}
return string(v.Inner.raw())
} | [
"func",
"(",
"v",
"Value",
")",
"String",
"(",
")",
"string",
"{",
"if",
"v",
".",
"Inner",
"==",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"string",
"(",
"v",
".",
"Inner",
".",
"raw",
"(",
")",
")",
"\n",
"}"
] | // String returns the raw value as a string | [
"String",
"returns",
"the",
"raw",
"value",
"as",
"a",
"string"
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/sqltypes/sqltypes.go#L87-L92 | train |
dropbox/godropbox | database/sqltypes/sqltypes.go | EncodeSql | func (v Value) EncodeSql(b encoding2.BinaryWriter) {
if v.Inner == nil {
if _, err := b.Write(nullstr); err != nil {
panic(err)
}
} else {
v.Inner.encodeSql(b)
}
} | go | func (v Value) EncodeSql(b encoding2.BinaryWriter) {
if v.Inner == nil {
if _, err := b.Write(nullstr); err != nil {
panic(err)
}
} else {
v.Inner.encodeSql(b)
}
} | [
"func",
"(",
"v",
"Value",
")",
"EncodeSql",
"(",
"b",
"encoding2",
".",
"BinaryWriter",
")",
"{",
"if",
"v",
".",
"Inner",
"==",
"nil",
"{",
"if",
"_",
",",
"err",
":=",
"b",
".",
"Write",
"(",
"nullstr",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"v",
".",
"Inner",
".",
"encodeSql",
"(",
"b",
")",
"\n",
"}",
"\n",
"}"
] | // EncodeSql encodes the value into an SQL statement. Can be binary. | [
"EncodeSql",
"encodes",
"the",
"value",
"into",
"an",
"SQL",
"statement",
".",
"Can",
"be",
"binary",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/sqltypes/sqltypes.go#L95-L103 | train |
dropbox/godropbox | database/sqltypes/sqltypes.go | EncodeAscii | func (v Value) EncodeAscii(b encoding2.BinaryWriter) {
if v.Inner == nil {
if _, err := b.Write(nullstr); err != nil {
panic(err)
}
} else {
v.Inner.encodeAscii(b)
}
} | go | func (v Value) EncodeAscii(b encoding2.BinaryWriter) {
if v.Inner == nil {
if _, err := b.Write(nullstr); err != nil {
panic(err)
}
} else {
v.Inner.encodeAscii(b)
}
} | [
"func",
"(",
"v",
"Value",
")",
"EncodeAscii",
"(",
"b",
"encoding2",
".",
"BinaryWriter",
")",
"{",
"if",
"v",
".",
"Inner",
"==",
"nil",
"{",
"if",
"_",
",",
"err",
":=",
"b",
".",
"Write",
"(",
"nullstr",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"v",
".",
"Inner",
".",
"encodeAscii",
"(",
"b",
")",
"\n",
"}",
"\n",
"}"
] | // EncodeAscii encodes the value using 7-bit clean ascii bytes. | [
"EncodeAscii",
"encodes",
"the",
"value",
"using",
"7",
"-",
"bit",
"clean",
"ascii",
"bytes",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/sqltypes/sqltypes.go#L106-L114 | train |
dropbox/godropbox | database/sqltypes/sqltypes.go | MarshalBinary | func (v Value) MarshalBinary() ([]byte, error) {
if v.IsNull() {
return []byte{byte(NullType)}, nil
}
return v.Inner.MarshalBinary()
} | go | func (v Value) MarshalBinary() ([]byte, error) {
if v.IsNull() {
return []byte{byte(NullType)}, nil
}
return v.Inner.MarshalBinary()
} | [
"func",
"(",
"v",
"Value",
")",
"MarshalBinary",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"v",
".",
"IsNull",
"(",
")",
"{",
"return",
"[",
"]",
"byte",
"{",
"byte",
"(",
"NullType",
")",
"}",
",",
"nil",
"\n",
"}",
"\n",
"return",
"v",
".",
"Inner",
".",
"MarshalBinary",
"(",
")",
"\n",
"}"
] | // MarshalBinary helps implement BinaryMarshaler interface for Value. | [
"MarshalBinary",
"helps",
"implement",
"BinaryMarshaler",
"interface",
"for",
"Value",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/sqltypes/sqltypes.go#L117-L122 | train |
dropbox/godropbox | database/sqltypes/sqltypes.go | UnmarshalBinary | func (v *Value) UnmarshalBinary(data []byte) error {
reader := bytes.NewReader(data)
b, err := reader.ReadByte()
if err != nil {
return err
}
typ := ValueType(b)
if typ == NullType {
*v = Value{}
return nil
}
length, err := binary.ReadUvarint(reader)
if err != nil {
return err
}
raw := make([]byte, length)
n, err := reader.Read(raw)
if err != nil {
return err
}
if uint64(n) != length {
return errors.Newf("Not enough bytes to read Value")
}
switch typ {
case NumericType:
*v = Value{Numeric(raw)}
case FractionalType:
*v = Value{Fractional(raw)}
case StringType:
*v = Value{String{raw, false}}
case UTF8StringType:
*v = Value{String{raw, true}}
default:
return errors.Newf("Unknown type %d", int(typ))
}
return nil
} | go | func (v *Value) UnmarshalBinary(data []byte) error {
reader := bytes.NewReader(data)
b, err := reader.ReadByte()
if err != nil {
return err
}
typ := ValueType(b)
if typ == NullType {
*v = Value{}
return nil
}
length, err := binary.ReadUvarint(reader)
if err != nil {
return err
}
raw := make([]byte, length)
n, err := reader.Read(raw)
if err != nil {
return err
}
if uint64(n) != length {
return errors.Newf("Not enough bytes to read Value")
}
switch typ {
case NumericType:
*v = Value{Numeric(raw)}
case FractionalType:
*v = Value{Fractional(raw)}
case StringType:
*v = Value{String{raw, false}}
case UTF8StringType:
*v = Value{String{raw, true}}
default:
return errors.Newf("Unknown type %d", int(typ))
}
return nil
} | [
"func",
"(",
"v",
"*",
"Value",
")",
"UnmarshalBinary",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"reader",
":=",
"bytes",
".",
"NewReader",
"(",
"data",
")",
"\n\n",
"b",
",",
"err",
":=",
"reader",
".",
"ReadByte",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"typ",
":=",
"ValueType",
"(",
"b",
")",
"\n",
"if",
"typ",
"==",
"NullType",
"{",
"*",
"v",
"=",
"Value",
"{",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"length",
",",
"err",
":=",
"binary",
".",
"ReadUvarint",
"(",
"reader",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"raw",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"length",
")",
"\n",
"n",
",",
"err",
":=",
"reader",
".",
"Read",
"(",
"raw",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"uint64",
"(",
"n",
")",
"!=",
"length",
"{",
"return",
"errors",
".",
"Newf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"switch",
"typ",
"{",
"case",
"NumericType",
":",
"*",
"v",
"=",
"Value",
"{",
"Numeric",
"(",
"raw",
")",
"}",
"\n",
"case",
"FractionalType",
":",
"*",
"v",
"=",
"Value",
"{",
"Fractional",
"(",
"raw",
")",
"}",
"\n",
"case",
"StringType",
":",
"*",
"v",
"=",
"Value",
"{",
"String",
"{",
"raw",
",",
"false",
"}",
"}",
"\n",
"case",
"UTF8StringType",
":",
"*",
"v",
"=",
"Value",
"{",
"String",
"{",
"raw",
",",
"true",
"}",
"}",
"\n",
"default",
":",
"return",
"errors",
".",
"Newf",
"(",
"\"",
"\"",
",",
"int",
"(",
"typ",
")",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // UnmarshalBinary helps implement BinaryUnmarshaler interface for Value. | [
"UnmarshalBinary",
"helps",
"implement",
"BinaryUnmarshaler",
"interface",
"for",
"Value",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/sqltypes/sqltypes.go#L125-L168 | train |
dropbox/godropbox | database/sqltypes/sqltypes.go | ConvertAssignRowNullable | func ConvertAssignRowNullable(row []Value, dest ...interface{}) error {
if len(row) != len(dest) {
return errors.Newf(
"# of row entries %d does not match # of destinations %d",
len(row),
len(dest))
}
if row == nil {
return nil
}
for i := 0; i < len(row); i++ {
if row[i].IsNull() {
continue
}
err := ConvertAssign(row[i], dest[i])
if err != nil {
return err
}
}
return nil
} | go | func ConvertAssignRowNullable(row []Value, dest ...interface{}) error {
if len(row) != len(dest) {
return errors.Newf(
"# of row entries %d does not match # of destinations %d",
len(row),
len(dest))
}
if row == nil {
return nil
}
for i := 0; i < len(row); i++ {
if row[i].IsNull() {
continue
}
err := ConvertAssign(row[i], dest[i])
if err != nil {
return err
}
}
return nil
} | [
"func",
"ConvertAssignRowNullable",
"(",
"row",
"[",
"]",
"Value",
",",
"dest",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"len",
"(",
"row",
")",
"!=",
"len",
"(",
"dest",
")",
"{",
"return",
"errors",
".",
"Newf",
"(",
"\"",
"\"",
",",
"len",
"(",
"row",
")",
",",
"len",
"(",
"dest",
")",
")",
"\n",
"}",
"\n\n",
"if",
"row",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"row",
")",
";",
"i",
"++",
"{",
"if",
"row",
"[",
"i",
"]",
".",
"IsNull",
"(",
")",
"{",
"continue",
"\n",
"}",
"\n\n",
"err",
":=",
"ConvertAssign",
"(",
"row",
"[",
"i",
"]",
",",
"dest",
"[",
"i",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // ConverAssignRowNullable is the same as ConvertAssignRow except that it allows
// nil as a value for the row or any of the row values. In thoses cases, the
// corresponding values are ignored. | [
"ConverAssignRowNullable",
"is",
"the",
"same",
"as",
"ConvertAssignRow",
"except",
"that",
"it",
"allows",
"nil",
"as",
"a",
"value",
"for",
"the",
"row",
"or",
"any",
"of",
"the",
"row",
"values",
".",
"In",
"thoses",
"cases",
"the",
"corresponding",
"values",
"are",
"ignored",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/sqltypes/sqltypes.go#L268-L292 | train |
dropbox/godropbox | database/sqltypes/sqltypes.go | ConvertAssignDefault | func ConvertAssignDefault(src Value, dest interface{}, defaultValue interface{}) error {
if src.IsNull() {
// This is not the most efficient way of doing things, but it's certainly cleaner
v, err := BuildValue(defaultValue)
if err != nil {
return err
}
return ConvertAssign(v, dest)
}
return ConvertAssign(src, dest)
} | go | func ConvertAssignDefault(src Value, dest interface{}, defaultValue interface{}) error {
if src.IsNull() {
// This is not the most efficient way of doing things, but it's certainly cleaner
v, err := BuildValue(defaultValue)
if err != nil {
return err
}
return ConvertAssign(v, dest)
}
return ConvertAssign(src, dest)
} | [
"func",
"ConvertAssignDefault",
"(",
"src",
"Value",
",",
"dest",
"interface",
"{",
"}",
",",
"defaultValue",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"src",
".",
"IsNull",
"(",
")",
"{",
"// This is not the most efficient way of doing things, but it's certainly cleaner",
"v",
",",
"err",
":=",
"BuildValue",
"(",
"defaultValue",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"ConvertAssign",
"(",
"v",
",",
"dest",
")",
"\n",
"}",
"\n",
"return",
"ConvertAssign",
"(",
"src",
",",
"dest",
")",
"\n",
"}"
] | // ConvertAssign, but with support for default values | [
"ConvertAssign",
"but",
"with",
"support",
"for",
"default",
"values"
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/sqltypes/sqltypes.go#L420-L430 | train |
dropbox/godropbox | database/sqltypes/sqltypes.go | Uint64EncodeSql | func Uint64EncodeSql(b encoding2.BinaryWriter, num uint64) {
numVal, _ := BuildValue(num)
numVal.EncodeSql(b)
} | go | func Uint64EncodeSql(b encoding2.BinaryWriter, num uint64) {
numVal, _ := BuildValue(num)
numVal.EncodeSql(b)
} | [
"func",
"Uint64EncodeSql",
"(",
"b",
"encoding2",
".",
"BinaryWriter",
",",
"num",
"uint64",
")",
"{",
"numVal",
",",
"_",
":=",
"BuildValue",
"(",
"num",
")",
"\n",
"numVal",
".",
"EncodeSql",
"(",
"b",
")",
"\n",
"}"
] | // Helper function for converting a uint64 to a string suitable for SQL. | [
"Helper",
"function",
"for",
"converting",
"a",
"uint64",
"to",
"a",
"string",
"suitable",
"for",
"SQL",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/sqltypes/sqltypes.go#L555-L558 | train |
dropbox/godropbox | container/bitvector/bitvector.go | NewBitVector | func NewBitVector(data []byte, length int) *BitVector {
return &BitVector{
data: data,
length: length,
}
} | go | func NewBitVector(data []byte, length int) *BitVector {
return &BitVector{
data: data,
length: length,
}
} | [
"func",
"NewBitVector",
"(",
"data",
"[",
"]",
"byte",
",",
"length",
"int",
")",
"*",
"BitVector",
"{",
"return",
"&",
"BitVector",
"{",
"data",
":",
"data",
",",
"length",
":",
"length",
",",
"}",
"\n",
"}"
] | // NewBitVector creates and initializes a new bit vector with length
// elements, using data as its initial contents. | [
"NewBitVector",
"creates",
"and",
"initializes",
"a",
"new",
"bit",
"vector",
"with",
"length",
"elements",
"using",
"data",
"as",
"its",
"initial",
"contents",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/container/bitvector/bitvector.go#L16-L21 | train |
dropbox/godropbox | container/bitvector/bitvector.go | bytesLength | func (vector *BitVector) bytesLength() int {
lastBitIndex := vector.length - 1
lastByteIndex := lastBitIndex >> 3
return lastByteIndex + 1
} | go | func (vector *BitVector) bytesLength() int {
lastBitIndex := vector.length - 1
lastByteIndex := lastBitIndex >> 3
return lastByteIndex + 1
} | [
"func",
"(",
"vector",
"*",
"BitVector",
")",
"bytesLength",
"(",
")",
"int",
"{",
"lastBitIndex",
":=",
"vector",
".",
"length",
"-",
"1",
"\n",
"lastByteIndex",
":=",
"lastBitIndex",
">>",
"3",
"\n",
"return",
"lastByteIndex",
"+",
"1",
"\n",
"}"
] | // Returns the minimum number of bytes needed for storing the bit vector. | [
"Returns",
"the",
"minimum",
"number",
"of",
"bytes",
"needed",
"for",
"storing",
"the",
"bit",
"vector",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/container/bitvector/bitvector.go#L64-L68 | train |
dropbox/godropbox | container/bitvector/bitvector.go | indexAssert | func (vector *BitVector) indexAssert(i int) {
if i < 0 || i >= vector.length {
panic("Attempted to access element outside buffer")
}
} | go | func (vector *BitVector) indexAssert(i int) {
if i < 0 || i >= vector.length {
panic("Attempted to access element outside buffer")
}
} | [
"func",
"(",
"vector",
"*",
"BitVector",
")",
"indexAssert",
"(",
"i",
"int",
")",
"{",
"if",
"i",
"<",
"0",
"||",
"i",
">=",
"vector",
".",
"length",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
] | // Panics if the given index is not within the bounds of the bit vector. | [
"Panics",
"if",
"the",
"given",
"index",
"is",
"not",
"within",
"the",
"bounds",
"of",
"the",
"bit",
"vector",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/container/bitvector/bitvector.go#L71-L75 | train |
dropbox/godropbox | container/bitvector/bitvector.go | Append | func (vector *BitVector) Append(bit byte) {
index := uint32(vector.length)
vector.length++
if vector.bytesLength() > len(vector.data) {
vector.data = append(vector.data, 0)
}
byteIndex := index >> 3
byteOffset := index % 8
oldByte := vector.data[byteIndex]
var newByte byte
if bit == 1 {
newByte = oldByte | 1<<byteOffset
} else {
// Set all bits except the byteOffset
mask := byte(^(1 << byteOffset))
newByte = oldByte & mask
}
vector.data[byteIndex] = newByte
} | go | func (vector *BitVector) Append(bit byte) {
index := uint32(vector.length)
vector.length++
if vector.bytesLength() > len(vector.data) {
vector.data = append(vector.data, 0)
}
byteIndex := index >> 3
byteOffset := index % 8
oldByte := vector.data[byteIndex]
var newByte byte
if bit == 1 {
newByte = oldByte | 1<<byteOffset
} else {
// Set all bits except the byteOffset
mask := byte(^(1 << byteOffset))
newByte = oldByte & mask
}
vector.data[byteIndex] = newByte
} | [
"func",
"(",
"vector",
"*",
"BitVector",
")",
"Append",
"(",
"bit",
"byte",
")",
"{",
"index",
":=",
"uint32",
"(",
"vector",
".",
"length",
")",
"\n",
"vector",
".",
"length",
"++",
"\n\n",
"if",
"vector",
".",
"bytesLength",
"(",
")",
">",
"len",
"(",
"vector",
".",
"data",
")",
"{",
"vector",
".",
"data",
"=",
"append",
"(",
"vector",
".",
"data",
",",
"0",
")",
"\n",
"}",
"\n\n",
"byteIndex",
":=",
"index",
">>",
"3",
"\n",
"byteOffset",
":=",
"index",
"%",
"8",
"\n",
"oldByte",
":=",
"vector",
".",
"data",
"[",
"byteIndex",
"]",
"\n",
"var",
"newByte",
"byte",
"\n",
"if",
"bit",
"==",
"1",
"{",
"newByte",
"=",
"oldByte",
"|",
"1",
"<<",
"byteOffset",
"\n",
"}",
"else",
"{",
"// Set all bits except the byteOffset",
"mask",
":=",
"byte",
"(",
"^",
"(",
"1",
"<<",
"byteOffset",
")",
")",
"\n",
"newByte",
"=",
"oldByte",
"&",
"mask",
"\n",
"}",
"\n\n",
"vector",
".",
"data",
"[",
"byteIndex",
"]",
"=",
"newByte",
"\n",
"}"
] | // Append adds a bit to the end of a bit vector. | [
"Append",
"adds",
"a",
"bit",
"to",
"the",
"end",
"of",
"a",
"bit",
"vector",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/container/bitvector/bitvector.go#L78-L99 | train |
dropbox/godropbox | container/bitvector/bitvector.go | Element | func (vector *BitVector) Element(i int) byte {
vector.indexAssert(i)
byteIndex := i >> 3
byteOffset := uint32(i % 8)
b := vector.data[byteIndex]
// Check the offset bit
return (b >> byteOffset) & 1
} | go | func (vector *BitVector) Element(i int) byte {
vector.indexAssert(i)
byteIndex := i >> 3
byteOffset := uint32(i % 8)
b := vector.data[byteIndex]
// Check the offset bit
return (b >> byteOffset) & 1
} | [
"func",
"(",
"vector",
"*",
"BitVector",
")",
"Element",
"(",
"i",
"int",
")",
"byte",
"{",
"vector",
".",
"indexAssert",
"(",
"i",
")",
"\n",
"byteIndex",
":=",
"i",
">>",
"3",
"\n",
"byteOffset",
":=",
"uint32",
"(",
"i",
"%",
"8",
")",
"\n",
"b",
":=",
"vector",
".",
"data",
"[",
"byteIndex",
"]",
"\n",
"// Check the offset bit",
"return",
"(",
"b",
">>",
"byteOffset",
")",
"&",
"1",
"\n",
"}"
] | // Element returns the bit in the ith index of the bit vector.
// Returned value is either 1 or 0. | [
"Element",
"returns",
"the",
"bit",
"in",
"the",
"ith",
"index",
"of",
"the",
"bit",
"vector",
".",
"Returned",
"value",
"is",
"either",
"1",
"or",
"0",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/container/bitvector/bitvector.go#L103-L110 | train |
dropbox/godropbox | container/bitvector/bitvector.go | Set | func (vector *BitVector) Set(bit byte, index int) {
vector.indexAssert(index)
byteIndex := uint32(index >> 3)
byteOffset := uint32(index % 8)
oldByte := vector.data[byteIndex]
var newByte byte
if bit == 1 {
// turn on the byteOffset'th bit
newByte = oldByte | 1<<byteOffset
} else {
// turn off the byteOffset'th bit
removeMask := byte(^(1 << byteOffset))
newByte = oldByte & removeMask
}
vector.data[byteIndex] = newByte
} | go | func (vector *BitVector) Set(bit byte, index int) {
vector.indexAssert(index)
byteIndex := uint32(index >> 3)
byteOffset := uint32(index % 8)
oldByte := vector.data[byteIndex]
var newByte byte
if bit == 1 {
// turn on the byteOffset'th bit
newByte = oldByte | 1<<byteOffset
} else {
// turn off the byteOffset'th bit
removeMask := byte(^(1 << byteOffset))
newByte = oldByte & removeMask
}
vector.data[byteIndex] = newByte
} | [
"func",
"(",
"vector",
"*",
"BitVector",
")",
"Set",
"(",
"bit",
"byte",
",",
"index",
"int",
")",
"{",
"vector",
".",
"indexAssert",
"(",
"index",
")",
"\n",
"byteIndex",
":=",
"uint32",
"(",
"index",
">>",
"3",
")",
"\n",
"byteOffset",
":=",
"uint32",
"(",
"index",
"%",
"8",
")",
"\n\n",
"oldByte",
":=",
"vector",
".",
"data",
"[",
"byteIndex",
"]",
"\n\n",
"var",
"newByte",
"byte",
"\n",
"if",
"bit",
"==",
"1",
"{",
"// turn on the byteOffset'th bit",
"newByte",
"=",
"oldByte",
"|",
"1",
"<<",
"byteOffset",
"\n",
"}",
"else",
"{",
"// turn off the byteOffset'th bit",
"removeMask",
":=",
"byte",
"(",
"^",
"(",
"1",
"<<",
"byteOffset",
")",
")",
"\n",
"newByte",
"=",
"oldByte",
"&",
"removeMask",
"\n",
"}",
"\n",
"vector",
".",
"data",
"[",
"byteIndex",
"]",
"=",
"newByte",
"\n",
"}"
] | // Set changes the bit in the ith index of the bit vector to the value specified in
// bit. | [
"Set",
"changes",
"the",
"bit",
"in",
"the",
"ith",
"index",
"of",
"the",
"bit",
"vector",
"to",
"the",
"value",
"specified",
"in",
"bit",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/container/bitvector/bitvector.go#L114-L131 | train |
dropbox/godropbox | container/bitvector/bitvector.go | Insert | func (vector *BitVector) Insert(bit byte, index int) {
vector.indexAssert(index)
vector.length++
// Append an additional byte if necessary.
if vector.bytesLength() > len(vector.data) {
vector.data = append(vector.data, 0)
}
byteIndex := uint32(index >> 3)
byteOffset := uint32(index % 8)
var bitToInsert byte
if bit == 1 {
bitToInsert = 1 << byteOffset
}
oldByte := vector.data[byteIndex]
// This bit will need to be shifted into the next byte
leftoverBit := (oldByte & 0x80) >> 7
// Make masks to pull off the bits below and above byteOffset
// This mask has the byteOffset lowest bits set.
bottomMask := byte((1 << byteOffset) - 1)
// This mask has the 8 - byteOffset top bits set.
topMask := ^bottomMask
top := (oldByte & topMask) << 1
newByte := bitToInsert | (oldByte & bottomMask) | top
vector.data[byteIndex] = newByte
// Shift the rest of the bytes in the slice one higher, append
// the leftoverBit obtained above.
shiftHigher(leftoverBit, vector.data[byteIndex+1:])
} | go | func (vector *BitVector) Insert(bit byte, index int) {
vector.indexAssert(index)
vector.length++
// Append an additional byte if necessary.
if vector.bytesLength() > len(vector.data) {
vector.data = append(vector.data, 0)
}
byteIndex := uint32(index >> 3)
byteOffset := uint32(index % 8)
var bitToInsert byte
if bit == 1 {
bitToInsert = 1 << byteOffset
}
oldByte := vector.data[byteIndex]
// This bit will need to be shifted into the next byte
leftoverBit := (oldByte & 0x80) >> 7
// Make masks to pull off the bits below and above byteOffset
// This mask has the byteOffset lowest bits set.
bottomMask := byte((1 << byteOffset) - 1)
// This mask has the 8 - byteOffset top bits set.
topMask := ^bottomMask
top := (oldByte & topMask) << 1
newByte := bitToInsert | (oldByte & bottomMask) | top
vector.data[byteIndex] = newByte
// Shift the rest of the bytes in the slice one higher, append
// the leftoverBit obtained above.
shiftHigher(leftoverBit, vector.data[byteIndex+1:])
} | [
"func",
"(",
"vector",
"*",
"BitVector",
")",
"Insert",
"(",
"bit",
"byte",
",",
"index",
"int",
")",
"{",
"vector",
".",
"indexAssert",
"(",
"index",
")",
"\n",
"vector",
".",
"length",
"++",
"\n\n",
"// Append an additional byte if necessary.",
"if",
"vector",
".",
"bytesLength",
"(",
")",
">",
"len",
"(",
"vector",
".",
"data",
")",
"{",
"vector",
".",
"data",
"=",
"append",
"(",
"vector",
".",
"data",
",",
"0",
")",
"\n",
"}",
"\n\n",
"byteIndex",
":=",
"uint32",
"(",
"index",
">>",
"3",
")",
"\n",
"byteOffset",
":=",
"uint32",
"(",
"index",
"%",
"8",
")",
"\n",
"var",
"bitToInsert",
"byte",
"\n",
"if",
"bit",
"==",
"1",
"{",
"bitToInsert",
"=",
"1",
"<<",
"byteOffset",
"\n",
"}",
"\n\n",
"oldByte",
":=",
"vector",
".",
"data",
"[",
"byteIndex",
"]",
"\n",
"// This bit will need to be shifted into the next byte",
"leftoverBit",
":=",
"(",
"oldByte",
"&",
"0x80",
")",
">>",
"7",
"\n",
"// Make masks to pull off the bits below and above byteOffset",
"// This mask has the byteOffset lowest bits set.",
"bottomMask",
":=",
"byte",
"(",
"(",
"1",
"<<",
"byteOffset",
")",
"-",
"1",
")",
"\n",
"// This mask has the 8 - byteOffset top bits set.",
"topMask",
":=",
"^",
"bottomMask",
"\n",
"top",
":=",
"(",
"oldByte",
"&",
"topMask",
")",
"<<",
"1",
"\n",
"newByte",
":=",
"bitToInsert",
"|",
"(",
"oldByte",
"&",
"bottomMask",
")",
"|",
"top",
"\n\n",
"vector",
".",
"data",
"[",
"byteIndex",
"]",
"=",
"newByte",
"\n",
"// Shift the rest of the bytes in the slice one higher, append",
"// the leftoverBit obtained above.",
"shiftHigher",
"(",
"leftoverBit",
",",
"vector",
".",
"data",
"[",
"byteIndex",
"+",
"1",
":",
"]",
")",
"\n",
"}"
] | // Insert inserts bit into the supplied index of the bit vector. All
// bits in positions greater than or equal to index before the call will
// be shifted up by one. | [
"Insert",
"inserts",
"bit",
"into",
"the",
"supplied",
"index",
"of",
"the",
"bit",
"vector",
".",
"All",
"bits",
"in",
"positions",
"greater",
"than",
"or",
"equal",
"to",
"index",
"before",
"the",
"call",
"will",
"be",
"shifted",
"up",
"by",
"one",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/container/bitvector/bitvector.go#L136-L167 | train |
dropbox/godropbox | container/bitvector/bitvector.go | Delete | func (vector *BitVector) Delete(index int) {
vector.indexAssert(index)
vector.length--
byteIndex := uint32(index >> 3)
byteOffset := uint32(index % 8)
oldByte := vector.data[byteIndex]
// Shift all the bytes above the byte we're modifying, return the
// leftover bit to include in the byte we're modifying.
bit := shiftLower(0, vector.data[byteIndex+1:])
// Modify oldByte.
// At a high level, we want to select the bits above byteOffset,
// and shift them down by one, removing the bit at byteOffset.
// This selects the bottom bits
bottomMask := byte((1 << byteOffset) - 1)
// This selects the top (8 - byteOffset - 1) bits
topMask := byte(^((1 << (byteOffset + 1)) - 1))
// newTop is the top bits, shifted down one, combined with the leftover bit from shifting
// the other bytes.
newTop := (oldByte&topMask)>>1 | (bit << 7)
// newByte takes the bottom bits and combines with the new top.
newByte := (bottomMask & oldByte) | newTop
vector.data[byteIndex] = newByte
// The desired length is the byte index of the last element plus one,
// where the byte index of the last element is the bit index of the last
// element divided by 8.
byteLength := vector.bytesLength()
if byteLength < len(vector.data) {
vector.data = vector.data[:byteLength]
}
} | go | func (vector *BitVector) Delete(index int) {
vector.indexAssert(index)
vector.length--
byteIndex := uint32(index >> 3)
byteOffset := uint32(index % 8)
oldByte := vector.data[byteIndex]
// Shift all the bytes above the byte we're modifying, return the
// leftover bit to include in the byte we're modifying.
bit := shiftLower(0, vector.data[byteIndex+1:])
// Modify oldByte.
// At a high level, we want to select the bits above byteOffset,
// and shift them down by one, removing the bit at byteOffset.
// This selects the bottom bits
bottomMask := byte((1 << byteOffset) - 1)
// This selects the top (8 - byteOffset - 1) bits
topMask := byte(^((1 << (byteOffset + 1)) - 1))
// newTop is the top bits, shifted down one, combined with the leftover bit from shifting
// the other bytes.
newTop := (oldByte&topMask)>>1 | (bit << 7)
// newByte takes the bottom bits and combines with the new top.
newByte := (bottomMask & oldByte) | newTop
vector.data[byteIndex] = newByte
// The desired length is the byte index of the last element plus one,
// where the byte index of the last element is the bit index of the last
// element divided by 8.
byteLength := vector.bytesLength()
if byteLength < len(vector.data) {
vector.data = vector.data[:byteLength]
}
} | [
"func",
"(",
"vector",
"*",
"BitVector",
")",
"Delete",
"(",
"index",
"int",
")",
"{",
"vector",
".",
"indexAssert",
"(",
"index",
")",
"\n",
"vector",
".",
"length",
"--",
"\n",
"byteIndex",
":=",
"uint32",
"(",
"index",
">>",
"3",
")",
"\n",
"byteOffset",
":=",
"uint32",
"(",
"index",
"%",
"8",
")",
"\n\n",
"oldByte",
":=",
"vector",
".",
"data",
"[",
"byteIndex",
"]",
"\n\n",
"// Shift all the bytes above the byte we're modifying, return the",
"// leftover bit to include in the byte we're modifying.",
"bit",
":=",
"shiftLower",
"(",
"0",
",",
"vector",
".",
"data",
"[",
"byteIndex",
"+",
"1",
":",
"]",
")",
"\n\n",
"// Modify oldByte.",
"// At a high level, we want to select the bits above byteOffset,",
"// and shift them down by one, removing the bit at byteOffset.",
"// This selects the bottom bits",
"bottomMask",
":=",
"byte",
"(",
"(",
"1",
"<<",
"byteOffset",
")",
"-",
"1",
")",
"\n",
"// This selects the top (8 - byteOffset - 1) bits",
"topMask",
":=",
"byte",
"(",
"^",
"(",
"(",
"1",
"<<",
"(",
"byteOffset",
"+",
"1",
")",
")",
"-",
"1",
")",
")",
"\n",
"// newTop is the top bits, shifted down one, combined with the leftover bit from shifting",
"// the other bytes.",
"newTop",
":=",
"(",
"oldByte",
"&",
"topMask",
")",
">>",
"1",
"|",
"(",
"bit",
"<<",
"7",
")",
"\n",
"// newByte takes the bottom bits and combines with the new top.",
"newByte",
":=",
"(",
"bottomMask",
"&",
"oldByte",
")",
"|",
"newTop",
"\n",
"vector",
".",
"data",
"[",
"byteIndex",
"]",
"=",
"newByte",
"\n\n",
"// The desired length is the byte index of the last element plus one,",
"// where the byte index of the last element is the bit index of the last",
"// element divided by 8.",
"byteLength",
":=",
"vector",
".",
"bytesLength",
"(",
")",
"\n",
"if",
"byteLength",
"<",
"len",
"(",
"vector",
".",
"data",
")",
"{",
"vector",
".",
"data",
"=",
"vector",
".",
"data",
"[",
":",
"byteLength",
"]",
"\n",
"}",
"\n",
"}"
] | // Delete removes the bit in the supplied index of the bit vector. All
// bits in positions greater than or equal to index before the call will
// be shifted down by one. | [
"Delete",
"removes",
"the",
"bit",
"in",
"the",
"supplied",
"index",
"of",
"the",
"bit",
"vector",
".",
"All",
"bits",
"in",
"positions",
"greater",
"than",
"or",
"equal",
"to",
"index",
"before",
"the",
"call",
"will",
"be",
"shifted",
"down",
"by",
"one",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/container/bitvector/bitvector.go#L172-L206 | train |
dropbox/godropbox | sort2/sort.go | Less | func (s UintSlice) Less(i, j int) bool {
return s[i] < s[j]
} | go | func (s UintSlice) Less(i, j int) bool {
return s[i] < s[j]
} | [
"func",
"(",
"s",
"UintSlice",
")",
"Less",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"s",
"[",
"i",
"]",
"<",
"s",
"[",
"j",
"]",
"\n",
"}"
] | // Less reports whether the element with
// index i should sort before the element with index j in the UintSlice. | [
"Less",
"reports",
"whether",
"the",
"element",
"with",
"index",
"i",
"should",
"sort",
"before",
"the",
"element",
"with",
"index",
"j",
"in",
"the",
"UintSlice",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/sort2/sort.go#L23-L25 | train |
dropbox/godropbox | sort2/sort.go | Swap | func (s UintSlice) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
} | go | func (s UintSlice) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
} | [
"func",
"(",
"s",
"UintSlice",
")",
"Swap",
"(",
"i",
",",
"j",
"int",
")",
"{",
"s",
"[",
"i",
"]",
",",
"s",
"[",
"j",
"]",
"=",
"s",
"[",
"j",
"]",
",",
"s",
"[",
"i",
"]",
"\n",
"}"
] | // Swap swaps the positions of the elements indices i and j of the UintSlice. | [
"Swap",
"swaps",
"the",
"positions",
"of",
"the",
"elements",
"indices",
"i",
"and",
"j",
"of",
"the",
"UintSlice",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/sort2/sort.go#L28-L30 | train |
dropbox/godropbox | sort2/sort.go | Less | func (s Uint32Slice) Less(i, j int) bool {
return s[i] < s[j]
} | go | func (s Uint32Slice) Less(i, j int) bool {
return s[i] < s[j]
} | [
"func",
"(",
"s",
"Uint32Slice",
")",
"Less",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"s",
"[",
"i",
"]",
"<",
"s",
"[",
"j",
"]",
"\n",
"}"
] | // Less reports whether the element with
// index i should sort before the element with index j in the Uint32Slice. | [
"Less",
"reports",
"whether",
"the",
"element",
"with",
"index",
"i",
"should",
"sort",
"before",
"the",
"element",
"with",
"index",
"j",
"in",
"the",
"Uint32Slice",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/sort2/sort.go#L89-L91 | train |
dropbox/godropbox | sort2/sort.go | Swap | func (s Uint32Slice) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
} | go | func (s Uint32Slice) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
} | [
"func",
"(",
"s",
"Uint32Slice",
")",
"Swap",
"(",
"i",
",",
"j",
"int",
")",
"{",
"s",
"[",
"i",
"]",
",",
"s",
"[",
"j",
"]",
"=",
"s",
"[",
"j",
"]",
",",
"s",
"[",
"i",
"]",
"\n",
"}"
] | // Swap swaps the positions of the elements indices i and j of the Uint32Slice. | [
"Swap",
"swaps",
"the",
"positions",
"of",
"the",
"elements",
"indices",
"i",
"and",
"j",
"of",
"the",
"Uint32Slice",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/sort2/sort.go#L94-L96 | train |
dropbox/godropbox | sort2/sort.go | Less | func (s Uint16Slice) Less(i, j int) bool {
return s[i] < s[j]
} | go | func (s Uint16Slice) Less(i, j int) bool {
return s[i] < s[j]
} | [
"func",
"(",
"s",
"Uint16Slice",
")",
"Less",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"s",
"[",
"i",
"]",
"<",
"s",
"[",
"j",
"]",
"\n",
"}"
] | // Less reports whether the element with
// index i should sort before the element with index j in the Uint16Slice. | [
"Less",
"reports",
"whether",
"the",
"element",
"with",
"index",
"i",
"should",
"sort",
"before",
"the",
"element",
"with",
"index",
"j",
"in",
"the",
"Uint16Slice",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/sort2/sort.go#L122-L124 | train |
dropbox/godropbox | sort2/sort.go | Swap | func (s Uint16Slice) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
} | go | func (s Uint16Slice) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
} | [
"func",
"(",
"s",
"Uint16Slice",
")",
"Swap",
"(",
"i",
",",
"j",
"int",
")",
"{",
"s",
"[",
"i",
"]",
",",
"s",
"[",
"j",
"]",
"=",
"s",
"[",
"j",
"]",
",",
"s",
"[",
"i",
"]",
"\n",
"}"
] | // Swap swaps the positions of the elements indices i and j of the Uint16Slice. | [
"Swap",
"swaps",
"the",
"positions",
"of",
"the",
"elements",
"indices",
"i",
"and",
"j",
"of",
"the",
"Uint16Slice",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/sort2/sort.go#L127-L129 | train |
dropbox/godropbox | sort2/sort.go | Less | func (s Uint8Slice) Less(i, j int) bool {
return s[i] < s[j]
} | go | func (s Uint8Slice) Less(i, j int) bool {
return s[i] < s[j]
} | [
"func",
"(",
"s",
"Uint8Slice",
")",
"Less",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"s",
"[",
"i",
"]",
"<",
"s",
"[",
"j",
"]",
"\n",
"}"
] | // Less reports whether the element with
// index i should sort before the element with index j in the Uint8Slice. | [
"Less",
"reports",
"whether",
"the",
"element",
"with",
"index",
"i",
"should",
"sort",
"before",
"the",
"element",
"with",
"index",
"j",
"in",
"the",
"Uint8Slice",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/sort2/sort.go#L155-L157 | train |
dropbox/godropbox | sort2/sort.go | Swap | func (s Uint8Slice) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
} | go | func (s Uint8Slice) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
} | [
"func",
"(",
"s",
"Uint8Slice",
")",
"Swap",
"(",
"i",
",",
"j",
"int",
")",
"{",
"s",
"[",
"i",
"]",
",",
"s",
"[",
"j",
"]",
"=",
"s",
"[",
"j",
"]",
",",
"s",
"[",
"i",
"]",
"\n",
"}"
] | // Swap swaps the positions of the elements indices i and j of the Uint8Slice | [
"Swap",
"swaps",
"the",
"positions",
"of",
"the",
"elements",
"indices",
"i",
"and",
"j",
"of",
"the",
"Uint8Slice"
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/sort2/sort.go#L160-L162 | train |
dropbox/godropbox | sort2/sort.go | Less | func (s Int32Slice) Less(i, j int) bool {
return s[i] < s[j]
} | go | func (s Int32Slice) Less(i, j int) bool {
return s[i] < s[j]
} | [
"func",
"(",
"s",
"Int32Slice",
")",
"Less",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"s",
"[",
"i",
"]",
"<",
"s",
"[",
"j",
"]",
"\n",
"}"
] | // Less reports whether the element with
// index i should sort before the element with index j in the Int32Slice. | [
"Less",
"reports",
"whether",
"the",
"element",
"with",
"index",
"i",
"should",
"sort",
"before",
"the",
"element",
"with",
"index",
"j",
"in",
"the",
"Int32Slice",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/sort2/sort.go#L221-L223 | train |
dropbox/godropbox | sort2/sort.go | Swap | func (s Int32Slice) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
} | go | func (s Int32Slice) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
} | [
"func",
"(",
"s",
"Int32Slice",
")",
"Swap",
"(",
"i",
",",
"j",
"int",
")",
"{",
"s",
"[",
"i",
"]",
",",
"s",
"[",
"j",
"]",
"=",
"s",
"[",
"j",
"]",
",",
"s",
"[",
"i",
"]",
"\n",
"}"
] | // Swap swaps the positions of the elements indices i and j of the Int32Slice | [
"Swap",
"swaps",
"the",
"positions",
"of",
"the",
"elements",
"indices",
"i",
"and",
"j",
"of",
"the",
"Int32Slice"
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/sort2/sort.go#L226-L228 | train |
dropbox/godropbox | sort2/sort.go | Less | func (s Int16Slice) Less(i, j int) bool {
return s[i] < s[j]
} | go | func (s Int16Slice) Less(i, j int) bool {
return s[i] < s[j]
} | [
"func",
"(",
"s",
"Int16Slice",
")",
"Less",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"s",
"[",
"i",
"]",
"<",
"s",
"[",
"j",
"]",
"\n",
"}"
] | // Less reports whether the element with
// index i should sort before the element with index j in the Int16Slice. | [
"Less",
"reports",
"whether",
"the",
"element",
"with",
"index",
"i",
"should",
"sort",
"before",
"the",
"element",
"with",
"index",
"j",
"in",
"the",
"Int16Slice",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/sort2/sort.go#L254-L256 | train |
dropbox/godropbox | sort2/sort.go | Swap | func (s Int16Slice) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
} | go | func (s Int16Slice) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
} | [
"func",
"(",
"s",
"Int16Slice",
")",
"Swap",
"(",
"i",
",",
"j",
"int",
")",
"{",
"s",
"[",
"i",
"]",
",",
"s",
"[",
"j",
"]",
"=",
"s",
"[",
"j",
"]",
",",
"s",
"[",
"i",
"]",
"\n",
"}"
] | // Swap swaps the positions of the elements indices i and j of the Int16Slice. | [
"Swap",
"swaps",
"the",
"positions",
"of",
"the",
"elements",
"indices",
"i",
"and",
"j",
"of",
"the",
"Int16Slice",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/sort2/sort.go#L259-L261 | train |
dropbox/godropbox | sort2/sort.go | Less | func (s Int8Slice) Less(i, j int) bool {
return s[i] < s[j]
} | go | func (s Int8Slice) Less(i, j int) bool {
return s[i] < s[j]
} | [
"func",
"(",
"s",
"Int8Slice",
")",
"Less",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"s",
"[",
"i",
"]",
"<",
"s",
"[",
"j",
"]",
"\n",
"}"
] | // Less reports whether the element with
// index i should sort before the element with index j in the Int8Slice. | [
"Less",
"reports",
"whether",
"the",
"element",
"with",
"index",
"i",
"should",
"sort",
"before",
"the",
"element",
"with",
"index",
"j",
"in",
"the",
"Int8Slice",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/sort2/sort.go#L287-L289 | train |
dropbox/godropbox | sort2/sort.go | Swap | func (s Int8Slice) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
} | go | func (s Int8Slice) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
} | [
"func",
"(",
"s",
"Int8Slice",
")",
"Swap",
"(",
"i",
",",
"j",
"int",
")",
"{",
"s",
"[",
"i",
"]",
",",
"s",
"[",
"j",
"]",
"=",
"s",
"[",
"j",
"]",
",",
"s",
"[",
"i",
"]",
"\n",
"}"
] | // Swap swaps the positions of the elements indices i and j of the Int8Slice. | [
"Swap",
"swaps",
"the",
"positions",
"of",
"the",
"elements",
"indices",
"i",
"and",
"j",
"of",
"the",
"Int8Slice",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/sort2/sort.go#L292-L294 | train |
dropbox/godropbox | sort2/sort.go | Less | func (s Float32Slice) Less(i, j int) bool {
return s[i] < s[j]
} | go | func (s Float32Slice) Less(i, j int) bool {
return s[i] < s[j]
} | [
"func",
"(",
"s",
"Float32Slice",
")",
"Less",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"s",
"[",
"i",
"]",
"<",
"s",
"[",
"j",
"]",
"\n",
"}"
] | // Less reports whether the element with
// index i should sort before the element with index j in the Float32Slice. | [
"Less",
"reports",
"whether",
"the",
"element",
"with",
"index",
"i",
"should",
"sort",
"before",
"the",
"element",
"with",
"index",
"j",
"in",
"the",
"Float32Slice",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/sort2/sort.go#L320-L322 | train |
dropbox/godropbox | sort2/sort.go | Swap | func (s Float32Slice) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
} | go | func (s Float32Slice) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
} | [
"func",
"(",
"s",
"Float32Slice",
")",
"Swap",
"(",
"i",
",",
"j",
"int",
")",
"{",
"s",
"[",
"i",
"]",
",",
"s",
"[",
"j",
"]",
"=",
"s",
"[",
"j",
"]",
",",
"s",
"[",
"i",
"]",
"\n",
"}"
] | // Swap swaps the positions of the elements indices i and j of the Float32Slice. | [
"Swap",
"swaps",
"the",
"positions",
"of",
"the",
"elements",
"indices",
"i",
"and",
"j",
"of",
"the",
"Float32Slice",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/sort2/sort.go#L325-L327 | train |
dropbox/godropbox | sort2/sort.go | Less | func (s Float64Slice) Less(i, j int) bool {
return s[i] < s[j]
} | go | func (s Float64Slice) Less(i, j int) bool {
return s[i] < s[j]
} | [
"func",
"(",
"s",
"Float64Slice",
")",
"Less",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"s",
"[",
"i",
"]",
"<",
"s",
"[",
"j",
"]",
"\n",
"}"
] | // Less reports whether the element with
// index i should sort before the element with index j in the Float64Slice. | [
"Less",
"reports",
"whether",
"the",
"element",
"with",
"index",
"i",
"should",
"sort",
"before",
"the",
"element",
"with",
"index",
"j",
"in",
"the",
"Float64Slice",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/sort2/sort.go#L353-L355 | train |
dropbox/godropbox | sort2/sort.go | Swap | func (s Float64Slice) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
} | go | func (s Float64Slice) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
} | [
"func",
"(",
"s",
"Float64Slice",
")",
"Swap",
"(",
"i",
",",
"j",
"int",
")",
"{",
"s",
"[",
"i",
"]",
",",
"s",
"[",
"j",
"]",
"=",
"s",
"[",
"j",
"]",
",",
"s",
"[",
"i",
"]",
"\n",
"}"
] | // Swap swaps the positions of the elements indices i and j of the Float64Slice. | [
"Swap",
"swaps",
"the",
"positions",
"of",
"the",
"elements",
"indices",
"i",
"and",
"j",
"of",
"the",
"Float64Slice",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/sort2/sort.go#L358-L360 | train |
dropbox/godropbox | sort2/sort.go | Swap | func (s ByteArraySlice) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
} | go | func (s ByteArraySlice) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
} | [
"func",
"(",
"s",
"ByteArraySlice",
")",
"Swap",
"(",
"i",
",",
"j",
"int",
")",
"{",
"s",
"[",
"i",
"]",
",",
"s",
"[",
"j",
"]",
"=",
"s",
"[",
"j",
"]",
",",
"s",
"[",
"i",
"]",
"\n",
"}"
] | // Swap swaps the positions of the elements indices i and j of the ByteArraySlice. | [
"Swap",
"swaps",
"the",
"positions",
"of",
"the",
"elements",
"indices",
"i",
"and",
"j",
"of",
"the",
"ByteArraySlice",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/sort2/sort.go#L391-L393 | train |
dropbox/godropbox | sort2/sort.go | Less | func (s TimeSlice) Less(i, j int) bool {
return s[i].Before(s[j])
} | go | func (s TimeSlice) Less(i, j int) bool {
return s[i].Before(s[j])
} | [
"func",
"(",
"s",
"TimeSlice",
")",
"Less",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"s",
"[",
"i",
"]",
".",
"Before",
"(",
"s",
"[",
"j",
"]",
")",
"\n",
"}"
] | // Less reports whether the element with
// index i should sort before the element with index j in the TimeSlice. | [
"Less",
"reports",
"whether",
"the",
"element",
"with",
"index",
"i",
"should",
"sort",
"before",
"the",
"element",
"with",
"index",
"j",
"in",
"the",
"TimeSlice",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/sort2/sort.go#L419-L421 | train |
dropbox/godropbox | sort2/sort.go | Swap | func (s TimeSlice) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
} | go | func (s TimeSlice) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
} | [
"func",
"(",
"s",
"TimeSlice",
")",
"Swap",
"(",
"i",
",",
"j",
"int",
")",
"{",
"s",
"[",
"i",
"]",
",",
"s",
"[",
"j",
"]",
"=",
"s",
"[",
"j",
"]",
",",
"s",
"[",
"i",
"]",
"\n",
"}"
] | // Swap swaps the positions of the elements indices i and j of the TimeSlice. | [
"Swap",
"swaps",
"the",
"positions",
"of",
"the",
"elements",
"indices",
"i",
"and",
"j",
"of",
"the",
"TimeSlice",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/sort2/sort.go#L424-L426 | train |
dropbox/godropbox | hash2/checksum.go | ValidateMd5Checksum | func ValidateMd5Checksum(data []byte, sum []byte) bool {
ourSum := ComputeMd5Checksum(data)
return bytes.Equal(ourSum, sum)
} | go | func ValidateMd5Checksum(data []byte, sum []byte) bool {
ourSum := ComputeMd5Checksum(data)
return bytes.Equal(ourSum, sum)
} | [
"func",
"ValidateMd5Checksum",
"(",
"data",
"[",
"]",
"byte",
",",
"sum",
"[",
"]",
"byte",
")",
"bool",
"{",
"ourSum",
":=",
"ComputeMd5Checksum",
"(",
"data",
")",
"\n",
"return",
"bytes",
".",
"Equal",
"(",
"ourSum",
",",
"sum",
")",
"\n",
"}"
] | // This returns true iff the data matches the provided checksum. | [
"This",
"returns",
"true",
"iff",
"the",
"data",
"matches",
"the",
"provided",
"checksum",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/hash2/checksum.go#L20-L23 | train |
dropbox/godropbox | memcache/responses.go | NewGetErrorResponse | func NewGetErrorResponse(key string, err error) GetResponse {
resp := &genericResponse{
err: err,
allowNotFound: true,
}
resp.item.Key = key
return resp
} | go | func NewGetErrorResponse(key string, err error) GetResponse {
resp := &genericResponse{
err: err,
allowNotFound: true,
}
resp.item.Key = key
return resp
} | [
"func",
"NewGetErrorResponse",
"(",
"key",
"string",
",",
"err",
"error",
")",
"GetResponse",
"{",
"resp",
":=",
"&",
"genericResponse",
"{",
"err",
":",
"err",
",",
"allowNotFound",
":",
"true",
",",
"}",
"\n",
"resp",
".",
"item",
".",
"Key",
"=",
"key",
"\n",
"return",
"resp",
"\n",
"}"
] | // This creates a GetResponse from an error. | [
"This",
"creates",
"a",
"GetResponse",
"from",
"an",
"error",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/responses.go#L130-L137 | train |
dropbox/godropbox | memcache/responses.go | NewGetResponse | func NewGetResponse(
key string,
status ResponseStatus,
flags uint32,
value []byte,
version uint64) GetResponse {
resp := &genericResponse{
status: status,
allowNotFound: true,
}
resp.item.Key = key
if status == StatusNoError {
if value == nil {
resp.item.Value = []byte{}
} else {
resp.item.Value = value
}
resp.item.Flags = flags
resp.item.DataVersionId = version
}
return resp
} | go | func NewGetResponse(
key string,
status ResponseStatus,
flags uint32,
value []byte,
version uint64) GetResponse {
resp := &genericResponse{
status: status,
allowNotFound: true,
}
resp.item.Key = key
if status == StatusNoError {
if value == nil {
resp.item.Value = []byte{}
} else {
resp.item.Value = value
}
resp.item.Flags = flags
resp.item.DataVersionId = version
}
return resp
} | [
"func",
"NewGetResponse",
"(",
"key",
"string",
",",
"status",
"ResponseStatus",
",",
"flags",
"uint32",
",",
"value",
"[",
"]",
"byte",
",",
"version",
"uint64",
")",
"GetResponse",
"{",
"resp",
":=",
"&",
"genericResponse",
"{",
"status",
":",
"status",
",",
"allowNotFound",
":",
"true",
",",
"}",
"\n",
"resp",
".",
"item",
".",
"Key",
"=",
"key",
"\n",
"if",
"status",
"==",
"StatusNoError",
"{",
"if",
"value",
"==",
"nil",
"{",
"resp",
".",
"item",
".",
"Value",
"=",
"[",
"]",
"byte",
"{",
"}",
"\n",
"}",
"else",
"{",
"resp",
".",
"item",
".",
"Value",
"=",
"value",
"\n",
"}",
"\n",
"resp",
".",
"item",
".",
"Flags",
"=",
"flags",
"\n",
"resp",
".",
"item",
".",
"DataVersionId",
"=",
"version",
"\n",
"}",
"\n",
"return",
"resp",
"\n",
"}"
] | // This creates a normal GetResponse. | [
"This",
"creates",
"a",
"normal",
"GetResponse",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/responses.go#L140-L162 | train |
dropbox/godropbox | memcache/responses.go | NewMutateErrorResponse | func NewMutateErrorResponse(key string, err error) MutateResponse {
resp := &genericResponse{
err: err,
}
resp.item.Key = key
return resp
} | go | func NewMutateErrorResponse(key string, err error) MutateResponse {
resp := &genericResponse{
err: err,
}
resp.item.Key = key
return resp
} | [
"func",
"NewMutateErrorResponse",
"(",
"key",
"string",
",",
"err",
"error",
")",
"MutateResponse",
"{",
"resp",
":=",
"&",
"genericResponse",
"{",
"err",
":",
"err",
",",
"}",
"\n",
"resp",
".",
"item",
".",
"Key",
"=",
"key",
"\n",
"return",
"resp",
"\n",
"}"
] | // This creates a MutateResponse from an error. | [
"This",
"creates",
"a",
"MutateResponse",
"from",
"an",
"error",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/responses.go#L165-L171 | train |
dropbox/godropbox | memcache/responses.go | NewMutateResponse | func NewMutateResponse(
key string,
status ResponseStatus,
version uint64) MutateResponse {
resp := &genericResponse{
status: status,
}
resp.item.Key = key
if status == StatusNoError {
resp.item.DataVersionId = version
}
return resp
} | go | func NewMutateResponse(
key string,
status ResponseStatus,
version uint64) MutateResponse {
resp := &genericResponse{
status: status,
}
resp.item.Key = key
if status == StatusNoError {
resp.item.DataVersionId = version
}
return resp
} | [
"func",
"NewMutateResponse",
"(",
"key",
"string",
",",
"status",
"ResponseStatus",
",",
"version",
"uint64",
")",
"MutateResponse",
"{",
"resp",
":=",
"&",
"genericResponse",
"{",
"status",
":",
"status",
",",
"}",
"\n",
"resp",
".",
"item",
".",
"Key",
"=",
"key",
"\n",
"if",
"status",
"==",
"StatusNoError",
"{",
"resp",
".",
"item",
".",
"DataVersionId",
"=",
"version",
"\n",
"}",
"\n",
"return",
"resp",
"\n",
"}"
] | // This creates a normal MutateResponse. | [
"This",
"creates",
"a",
"normal",
"MutateResponse",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/responses.go#L174-L187 | train |
dropbox/godropbox | memcache/responses.go | NewCountErrorResponse | func NewCountErrorResponse(key string, err error) CountResponse {
resp := &genericResponse{
err: err,
}
resp.item.Key = key
return resp
} | go | func NewCountErrorResponse(key string, err error) CountResponse {
resp := &genericResponse{
err: err,
}
resp.item.Key = key
return resp
} | [
"func",
"NewCountErrorResponse",
"(",
"key",
"string",
",",
"err",
"error",
")",
"CountResponse",
"{",
"resp",
":=",
"&",
"genericResponse",
"{",
"err",
":",
"err",
",",
"}",
"\n",
"resp",
".",
"item",
".",
"Key",
"=",
"key",
"\n",
"return",
"resp",
"\n",
"}"
] | // This creates a CountResponse from an error. | [
"This",
"creates",
"a",
"CountResponse",
"from",
"an",
"error",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/responses.go#L190-L196 | train |
dropbox/godropbox | memcache/responses.go | NewCountResponse | func NewCountResponse(
key string,
status ResponseStatus,
count uint64) CountResponse {
resp := &genericResponse{
status: status,
}
resp.item.Key = key
if status == StatusNoError {
resp.count = count
}
return resp
} | go | func NewCountResponse(
key string,
status ResponseStatus,
count uint64) CountResponse {
resp := &genericResponse{
status: status,
}
resp.item.Key = key
if status == StatusNoError {
resp.count = count
}
return resp
} | [
"func",
"NewCountResponse",
"(",
"key",
"string",
",",
"status",
"ResponseStatus",
",",
"count",
"uint64",
")",
"CountResponse",
"{",
"resp",
":=",
"&",
"genericResponse",
"{",
"status",
":",
"status",
",",
"}",
"\n",
"resp",
".",
"item",
".",
"Key",
"=",
"key",
"\n",
"if",
"status",
"==",
"StatusNoError",
"{",
"resp",
".",
"count",
"=",
"count",
"\n",
"}",
"\n",
"return",
"resp",
"\n",
"}"
] | // This creates a normal CountResponse. | [
"This",
"creates",
"a",
"normal",
"CountResponse",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/responses.go#L199-L212 | train |
dropbox/godropbox | memcache/responses.go | NewVersionErrorResponse | func NewVersionErrorResponse(
err error,
versions map[int]string) VersionResponse {
return &genericResponse{
err: err,
versions: versions,
}
} | go | func NewVersionErrorResponse(
err error,
versions map[int]string) VersionResponse {
return &genericResponse{
err: err,
versions: versions,
}
} | [
"func",
"NewVersionErrorResponse",
"(",
"err",
"error",
",",
"versions",
"map",
"[",
"int",
"]",
"string",
")",
"VersionResponse",
"{",
"return",
"&",
"genericResponse",
"{",
"err",
":",
"err",
",",
"versions",
":",
"versions",
",",
"}",
"\n",
"}"
] | // This creates a VersionResponse from an error. | [
"This",
"creates",
"a",
"VersionResponse",
"from",
"an",
"error",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/responses.go#L215-L222 | train |
dropbox/godropbox | memcache/responses.go | NewVersionResponse | func NewVersionResponse(
status ResponseStatus,
versions map[int]string) VersionResponse {
resp := &genericResponse{
status: status,
versions: versions,
}
return resp
} | go | func NewVersionResponse(
status ResponseStatus,
versions map[int]string) VersionResponse {
resp := &genericResponse{
status: status,
versions: versions,
}
return resp
} | [
"func",
"NewVersionResponse",
"(",
"status",
"ResponseStatus",
",",
"versions",
"map",
"[",
"int",
"]",
"string",
")",
"VersionResponse",
"{",
"resp",
":=",
"&",
"genericResponse",
"{",
"status",
":",
"status",
",",
"versions",
":",
"versions",
",",
"}",
"\n",
"return",
"resp",
"\n",
"}"
] | // This creates a normal VersionResponse. | [
"This",
"creates",
"a",
"normal",
"VersionResponse",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/responses.go#L225-L234 | train |
dropbox/godropbox | memcache/responses.go | NewStatErrorResponse | func NewStatErrorResponse(
err error,
entries map[int](map[string]string)) StatResponse {
return &genericResponse{
err: err,
statEntries: entries,
}
} | go | func NewStatErrorResponse(
err error,
entries map[int](map[string]string)) StatResponse {
return &genericResponse{
err: err,
statEntries: entries,
}
} | [
"func",
"NewStatErrorResponse",
"(",
"err",
"error",
",",
"entries",
"map",
"[",
"int",
"]",
"(",
"map",
"[",
"string",
"]",
"string",
")",
")",
"StatResponse",
"{",
"return",
"&",
"genericResponse",
"{",
"err",
":",
"err",
",",
"statEntries",
":",
"entries",
",",
"}",
"\n",
"}"
] | // This creates a StatResponse from an error. | [
"This",
"creates",
"a",
"StatResponse",
"from",
"an",
"error",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/responses.go#L237-L244 | train |
dropbox/godropbox | memcache/responses.go | NewStatResponse | func NewStatResponse(
status ResponseStatus,
entries map[int](map[string]string)) StatResponse {
resp := &genericResponse{
status: status,
statEntries: entries,
}
return resp
} | go | func NewStatResponse(
status ResponseStatus,
entries map[int](map[string]string)) StatResponse {
resp := &genericResponse{
status: status,
statEntries: entries,
}
return resp
} | [
"func",
"NewStatResponse",
"(",
"status",
"ResponseStatus",
",",
"entries",
"map",
"[",
"int",
"]",
"(",
"map",
"[",
"string",
"]",
"string",
")",
")",
"StatResponse",
"{",
"resp",
":=",
"&",
"genericResponse",
"{",
"status",
":",
"status",
",",
"statEntries",
":",
"entries",
",",
"}",
"\n",
"return",
"resp",
"\n",
"}"
] | // This creates a normal StatResponse. | [
"This",
"creates",
"a",
"normal",
"StatResponse",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/responses.go#L247-L256 | train |
dropbox/godropbox | memcache/base_shard_manager.go | Init | func (m *BaseShardManager) Init(
shardFunc func(key string, numShard int) (shard int),
logError func(err error),
logInfo func(v ...interface{}),
options net2.ConnectionOptions) {
m.InitWithPool(
shardFunc,
logError,
logInfo,
net2.NewMultiConnectionPool(options))
} | go | func (m *BaseShardManager) Init(
shardFunc func(key string, numShard int) (shard int),
logError func(err error),
logInfo func(v ...interface{}),
options net2.ConnectionOptions) {
m.InitWithPool(
shardFunc,
logError,
logInfo,
net2.NewMultiConnectionPool(options))
} | [
"func",
"(",
"m",
"*",
"BaseShardManager",
")",
"Init",
"(",
"shardFunc",
"func",
"(",
"key",
"string",
",",
"numShard",
"int",
")",
"(",
"shard",
"int",
")",
",",
"logError",
"func",
"(",
"err",
"error",
")",
",",
"logInfo",
"func",
"(",
"v",
"...",
"interface",
"{",
"}",
")",
",",
"options",
"net2",
".",
"ConnectionOptions",
")",
"{",
"m",
".",
"InitWithPool",
"(",
"shardFunc",
",",
"logError",
",",
"logInfo",
",",
"net2",
".",
"NewMultiConnectionPool",
"(",
"options",
")",
")",
"\n",
"}"
] | // Initializes the BaseShardManager. | [
"Initializes",
"the",
"BaseShardManager",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/base_shard_manager.go#L48-L59 | train |
dropbox/godropbox | memcache/base_shard_manager.go | UpdateShardStates | func (m *BaseShardManager) UpdateShardStates(shardStates []ShardState) {
newAddrs := set.NewSet()
for _, state := range shardStates {
newAddrs.Add(state.Address)
}
m.rwMutex.Lock()
defer m.rwMutex.Unlock()
oldAddrs := set.NewSet()
for _, state := range m.shardStates {
oldAddrs.Add(state.Address)
}
for address := range set.Subtract(newAddrs, oldAddrs).Iter() {
if err := m.pool.Register("tcp", address.(string)); err != nil {
m.logError(err)
}
}
for address := range set.Subtract(oldAddrs, newAddrs).Iter() {
if err := m.pool.Unregister("tcp", address.(string)); err != nil {
m.logError(err)
}
}
m.shardStates = shardStates
} | go | func (m *BaseShardManager) UpdateShardStates(shardStates []ShardState) {
newAddrs := set.NewSet()
for _, state := range shardStates {
newAddrs.Add(state.Address)
}
m.rwMutex.Lock()
defer m.rwMutex.Unlock()
oldAddrs := set.NewSet()
for _, state := range m.shardStates {
oldAddrs.Add(state.Address)
}
for address := range set.Subtract(newAddrs, oldAddrs).Iter() {
if err := m.pool.Register("tcp", address.(string)); err != nil {
m.logError(err)
}
}
for address := range set.Subtract(oldAddrs, newAddrs).Iter() {
if err := m.pool.Unregister("tcp", address.(string)); err != nil {
m.logError(err)
}
}
m.shardStates = shardStates
} | [
"func",
"(",
"m",
"*",
"BaseShardManager",
")",
"UpdateShardStates",
"(",
"shardStates",
"[",
"]",
"ShardState",
")",
"{",
"newAddrs",
":=",
"set",
".",
"NewSet",
"(",
")",
"\n",
"for",
"_",
",",
"state",
":=",
"range",
"shardStates",
"{",
"newAddrs",
".",
"Add",
"(",
"state",
".",
"Address",
")",
"\n",
"}",
"\n\n",
"m",
".",
"rwMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"rwMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"oldAddrs",
":=",
"set",
".",
"NewSet",
"(",
")",
"\n",
"for",
"_",
",",
"state",
":=",
"range",
"m",
".",
"shardStates",
"{",
"oldAddrs",
".",
"Add",
"(",
"state",
".",
"Address",
")",
"\n",
"}",
"\n\n",
"for",
"address",
":=",
"range",
"set",
".",
"Subtract",
"(",
"newAddrs",
",",
"oldAddrs",
")",
".",
"Iter",
"(",
")",
"{",
"if",
"err",
":=",
"m",
".",
"pool",
".",
"Register",
"(",
"\"",
"\"",
",",
"address",
".",
"(",
"string",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"m",
".",
"logError",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"address",
":=",
"range",
"set",
".",
"Subtract",
"(",
"oldAddrs",
",",
"newAddrs",
")",
".",
"Iter",
"(",
")",
"{",
"if",
"err",
":=",
"m",
".",
"pool",
".",
"Unregister",
"(",
"\"",
"\"",
",",
"address",
".",
"(",
"string",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"m",
".",
"logError",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"m",
".",
"shardStates",
"=",
"shardStates",
"\n",
"}"
] | // This updates the shard manager to use new shard states. | [
"This",
"updates",
"the",
"shard",
"manager",
"to",
"use",
"new",
"shard",
"states",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/base_shard_manager.go#L76-L103 | train |
dropbox/godropbox | memcache/base_shard_manager.go | getShardsForSentinelsLocked | func (m *BaseShardManager) getShardsForSentinelsLocked(
keys []string) map[int]*ShardMapping {
numShards := len(m.shardStates)
results := make(map[int]*ShardMapping)
for _, key := range keys {
shardId := m.getShardId(key, numShards)
entry, inMap := results[shardId]
if !inMap {
entry = &ShardMapping{}
if shardId != -1 {
state := m.shardStates[shardId]
if state.State == ActiveServer ||
state.State == WriteOnlyServer ||
state.State == WarmUpServer {
m.fillEntryWithConnection(state.Address, entry)
// During WARM_UP state, we do try to write sentinels to
// memcache but any failures are ignored. We run memcache
// server in this mode for sometime to prime our memcache
// and warm up memcache server.
if state.State == WarmUpServer {
entry.WarmingUp = true
}
} else {
connSkippedByAddr.Add(state.Address, 1)
}
}
entry.Keys = make([]string, 0, 1)
results[shardId] = entry
}
entry.Keys = append(entry.Keys, key)
}
return results
} | go | func (m *BaseShardManager) getShardsForSentinelsLocked(
keys []string) map[int]*ShardMapping {
numShards := len(m.shardStates)
results := make(map[int]*ShardMapping)
for _, key := range keys {
shardId := m.getShardId(key, numShards)
entry, inMap := results[shardId]
if !inMap {
entry = &ShardMapping{}
if shardId != -1 {
state := m.shardStates[shardId]
if state.State == ActiveServer ||
state.State == WriteOnlyServer ||
state.State == WarmUpServer {
m.fillEntryWithConnection(state.Address, entry)
// During WARM_UP state, we do try to write sentinels to
// memcache but any failures are ignored. We run memcache
// server in this mode for sometime to prime our memcache
// and warm up memcache server.
if state.State == WarmUpServer {
entry.WarmingUp = true
}
} else {
connSkippedByAddr.Add(state.Address, 1)
}
}
entry.Keys = make([]string, 0, 1)
results[shardId] = entry
}
entry.Keys = append(entry.Keys, key)
}
return results
} | [
"func",
"(",
"m",
"*",
"BaseShardManager",
")",
"getShardsForSentinelsLocked",
"(",
"keys",
"[",
"]",
"string",
")",
"map",
"[",
"int",
"]",
"*",
"ShardMapping",
"{",
"numShards",
":=",
"len",
"(",
"m",
".",
"shardStates",
")",
"\n",
"results",
":=",
"make",
"(",
"map",
"[",
"int",
"]",
"*",
"ShardMapping",
")",
"\n\n",
"for",
"_",
",",
"key",
":=",
"range",
"keys",
"{",
"shardId",
":=",
"m",
".",
"getShardId",
"(",
"key",
",",
"numShards",
")",
"\n\n",
"entry",
",",
"inMap",
":=",
"results",
"[",
"shardId",
"]",
"\n",
"if",
"!",
"inMap",
"{",
"entry",
"=",
"&",
"ShardMapping",
"{",
"}",
"\n",
"if",
"shardId",
"!=",
"-",
"1",
"{",
"state",
":=",
"m",
".",
"shardStates",
"[",
"shardId",
"]",
"\n",
"if",
"state",
".",
"State",
"==",
"ActiveServer",
"||",
"state",
".",
"State",
"==",
"WriteOnlyServer",
"||",
"state",
".",
"State",
"==",
"WarmUpServer",
"{",
"m",
".",
"fillEntryWithConnection",
"(",
"state",
".",
"Address",
",",
"entry",
")",
"\n\n",
"// During WARM_UP state, we do try to write sentinels to",
"// memcache but any failures are ignored. We run memcache",
"// server in this mode for sometime to prime our memcache",
"// and warm up memcache server.",
"if",
"state",
".",
"State",
"==",
"WarmUpServer",
"{",
"entry",
".",
"WarmingUp",
"=",
"true",
"\n",
"}",
"\n",
"}",
"else",
"{",
"connSkippedByAddr",
".",
"Add",
"(",
"state",
".",
"Address",
",",
"1",
")",
"\n",
"}",
"\n",
"}",
"\n",
"entry",
".",
"Keys",
"=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"1",
")",
"\n",
"results",
"[",
"shardId",
"]",
"=",
"entry",
"\n",
"}",
"\n",
"entry",
".",
"Keys",
"=",
"append",
"(",
"entry",
".",
"Keys",
",",
"key",
")",
"\n",
"}",
"\n\n",
"return",
"results",
"\n",
"}"
] | // This method assumes that m.rwMutex is locked. | [
"This",
"method",
"assumes",
"that",
"m",
".",
"rwMutex",
"is",
"locked",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/base_shard_manager.go#L213-L251 | train |
dropbox/godropbox | cinterop/buffered_work.go | readBuffer | func readBuffer(copyTo chan<- []byte, socketRead io.ReadCloser, batchSize int, workSize int) {
defer close(copyTo)
for {
batch := make([]byte, batchSize)
size, err := socketRead.Read(batch)
if err == nil && workSize != 0 && size%workSize != 0 {
var lsize int
lsize, err = io.ReadFull(
socketRead,
batch[size:size+workSize-(size%workSize)])
size += lsize
}
if size > 0 {
if err != nil && workSize != 0 {
size -= (size % workSize)
}
copyTo <- batch[:size]
}
if err != nil {
if err != io.EOF {
log.Print("Error encountered in readBuffer:", err)
}
return
}
}
} | go | func readBuffer(copyTo chan<- []byte, socketRead io.ReadCloser, batchSize int, workSize int) {
defer close(copyTo)
for {
batch := make([]byte, batchSize)
size, err := socketRead.Read(batch)
if err == nil && workSize != 0 && size%workSize != 0 {
var lsize int
lsize, err = io.ReadFull(
socketRead,
batch[size:size+workSize-(size%workSize)])
size += lsize
}
if size > 0 {
if err != nil && workSize != 0 {
size -= (size % workSize)
}
copyTo <- batch[:size]
}
if err != nil {
if err != io.EOF {
log.Print("Error encountered in readBuffer:", err)
}
return
}
}
} | [
"func",
"readBuffer",
"(",
"copyTo",
"chan",
"<-",
"[",
"]",
"byte",
",",
"socketRead",
"io",
".",
"ReadCloser",
",",
"batchSize",
"int",
",",
"workSize",
"int",
")",
"{",
"defer",
"close",
"(",
"copyTo",
")",
"\n",
"for",
"{",
"batch",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"batchSize",
")",
"\n",
"size",
",",
"err",
":=",
"socketRead",
".",
"Read",
"(",
"batch",
")",
"\n",
"if",
"err",
"==",
"nil",
"&&",
"workSize",
"!=",
"0",
"&&",
"size",
"%",
"workSize",
"!=",
"0",
"{",
"var",
"lsize",
"int",
"\n",
"lsize",
",",
"err",
"=",
"io",
".",
"ReadFull",
"(",
"socketRead",
",",
"batch",
"[",
"size",
":",
"size",
"+",
"workSize",
"-",
"(",
"size",
"%",
"workSize",
")",
"]",
")",
"\n",
"size",
"+=",
"lsize",
"\n",
"}",
"\n",
"if",
"size",
">",
"0",
"{",
"if",
"err",
"!=",
"nil",
"&&",
"workSize",
"!=",
"0",
"{",
"size",
"-=",
"(",
"size",
"%",
"workSize",
")",
"\n",
"}",
"\n",
"copyTo",
"<-",
"batch",
"[",
":",
"size",
"]",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"err",
"!=",
"io",
".",
"EOF",
"{",
"log",
".",
"Print",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // this reads in a loop from socketRead putting batchSize bytes of work to copyTo until
// the socketRead is empty. Will always block until a full workSize of units have been copied | [
"this",
"reads",
"in",
"a",
"loop",
"from",
"socketRead",
"putting",
"batchSize",
"bytes",
"of",
"work",
"to",
"copyTo",
"until",
"the",
"socketRead",
"is",
"empty",
".",
"Will",
"always",
"block",
"until",
"a",
"full",
"workSize",
"of",
"units",
"have",
"been",
"copied"
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/cinterop/buffered_work.go#L11-L36 | train |
dropbox/godropbox | cinterop/buffered_work.go | writeBuffer | func writeBuffer(copyFrom <-chan []byte, socketWrite io.Writer) {
for buf := range copyFrom {
if len(buf) > 0 {
size, err := socketWrite.Write(buf)
if err != nil {
log.Print("Error encountered in writeBuffer:", err)
return
} else if size != len(buf) {
panic(errors.New("Short Write: io.Writer not compliant"))
}
}
}
} | go | func writeBuffer(copyFrom <-chan []byte, socketWrite io.Writer) {
for buf := range copyFrom {
if len(buf) > 0 {
size, err := socketWrite.Write(buf)
if err != nil {
log.Print("Error encountered in writeBuffer:", err)
return
} else if size != len(buf) {
panic(errors.New("Short Write: io.Writer not compliant"))
}
}
}
} | [
"func",
"writeBuffer",
"(",
"copyFrom",
"<-",
"chan",
"[",
"]",
"byte",
",",
"socketWrite",
"io",
".",
"Writer",
")",
"{",
"for",
"buf",
":=",
"range",
"copyFrom",
"{",
"if",
"len",
"(",
"buf",
")",
">",
"0",
"{",
"size",
",",
"err",
":=",
"socketWrite",
".",
"Write",
"(",
"buf",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Print",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"else",
"if",
"size",
"!=",
"len",
"(",
"buf",
")",
"{",
"panic",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // this simply copies data from the chan to the socketWrite writer | [
"this",
"simply",
"copies",
"data",
"from",
"the",
"chan",
"to",
"the",
"socketWrite",
"writer"
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/cinterop/buffered_work.go#L39-L51 | train |
dropbox/godropbox | time2/time2.go | TimeToFloat | func TimeToFloat(t time.Time) float64 {
return float64(t.Unix()) + (float64(t.Nanosecond()) / 1e9)
} | go | func TimeToFloat(t time.Time) float64 {
return float64(t.Unix()) + (float64(t.Nanosecond()) / 1e9)
} | [
"func",
"TimeToFloat",
"(",
"t",
"time",
".",
"Time",
")",
"float64",
"{",
"return",
"float64",
"(",
"t",
".",
"Unix",
"(",
")",
")",
"+",
"(",
"float64",
"(",
"t",
".",
"Nanosecond",
"(",
")",
")",
"/",
"1e9",
")",
"\n",
"}"
] | // Convert Time to epoch seconds with subsecond precision. | [
"Convert",
"Time",
"to",
"epoch",
"seconds",
"with",
"subsecond",
"precision",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/time2/time2.go#L11-L13 | train |
gopherjs/gopherjs | nosync/mutex.go | Lock | func (rw *RWMutex) Lock() {
if rw.readLockCounter != 0 || rw.writeLocked {
panic("nosync: mutex is already locked")
}
rw.writeLocked = true
} | go | func (rw *RWMutex) Lock() {
if rw.readLockCounter != 0 || rw.writeLocked {
panic("nosync: mutex is already locked")
}
rw.writeLocked = true
} | [
"func",
"(",
"rw",
"*",
"RWMutex",
")",
"Lock",
"(",
")",
"{",
"if",
"rw",
".",
"readLockCounter",
"!=",
"0",
"||",
"rw",
".",
"writeLocked",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"rw",
".",
"writeLocked",
"=",
"true",
"\n",
"}"
] | // Lock locks m for writing. It is a run-time error if rw is already locked for reading or writing. | [
"Lock",
"locks",
"m",
"for",
"writing",
".",
"It",
"is",
"a",
"run",
"-",
"time",
"error",
"if",
"rw",
"is",
"already",
"locked",
"for",
"reading",
"or",
"writing",
"."
] | 3e4dfb77656c424b6d1196a4d5fed0fcf63677cc | https://github.com/gopherjs/gopherjs/blob/3e4dfb77656c424b6d1196a4d5fed0fcf63677cc/nosync/mutex.go#L31-L36 | train |
gopherjs/gopherjs | nosync/mutex.go | Add | func (wg *WaitGroup) Add(delta int) {
wg.counter += delta
if wg.counter < 0 {
panic("sync: negative WaitGroup counter")
}
} | go | func (wg *WaitGroup) Add(delta int) {
wg.counter += delta
if wg.counter < 0 {
panic("sync: negative WaitGroup counter")
}
} | [
"func",
"(",
"wg",
"*",
"WaitGroup",
")",
"Add",
"(",
"delta",
"int",
")",
"{",
"wg",
".",
"counter",
"+=",
"delta",
"\n",
"if",
"wg",
".",
"counter",
"<",
"0",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
] | // Add adds delta, which may be negative, to the WaitGroup If the counter goes negative, Add panics. | [
"Add",
"adds",
"delta",
"which",
"may",
"be",
"negative",
"to",
"the",
"WaitGroup",
"If",
"the",
"counter",
"goes",
"negative",
"Add",
"panics",
"."
] | 3e4dfb77656c424b6d1196a4d5fed0fcf63677cc | https://github.com/gopherjs/gopherjs/blob/3e4dfb77656c424b6d1196a4d5fed0fcf63677cc/nosync/mutex.go#L68-L73 | train |
gopherjs/gopherjs | compiler/natives/src/sync/sync.go | runtime_nanotime | func runtime_nanotime() int64 {
const millisecond = 1000000
return js.Global.Get("Date").New().Call("getTime").Int64() * millisecond
} | go | func runtime_nanotime() int64 {
const millisecond = 1000000
return js.Global.Get("Date").New().Call("getTime").Int64() * millisecond
} | [
"func",
"runtime_nanotime",
"(",
")",
"int64",
"{",
"const",
"millisecond",
"=",
"1000000",
"\n",
"return",
"js",
".",
"Global",
".",
"Get",
"(",
"\"",
"\"",
")",
".",
"New",
"(",
")",
".",
"Call",
"(",
"\"",
"\"",
")",
".",
"Int64",
"(",
")",
"*",
"millisecond",
"\n",
"}"
] | // Copy of time.runtimeNano. | [
"Copy",
"of",
"time",
".",
"runtimeNano",
"."
] | 3e4dfb77656c424b6d1196a4d5fed0fcf63677cc | https://github.com/gopherjs/gopherjs/blob/3e4dfb77656c424b6d1196a4d5fed0fcf63677cc/compiler/natives/src/sync/sync.go#L72-L75 | train |
gopherjs/gopherjs | nosync/map.go | Load | func (m *Map) Load(key interface{}) (value interface{}, ok bool) {
value, ok = m.m[key]
return value, ok
} | go | func (m *Map) Load(key interface{}) (value interface{}, ok bool) {
value, ok = m.m[key]
return value, ok
} | [
"func",
"(",
"m",
"*",
"Map",
")",
"Load",
"(",
"key",
"interface",
"{",
"}",
")",
"(",
"value",
"interface",
"{",
"}",
",",
"ok",
"bool",
")",
"{",
"value",
",",
"ok",
"=",
"m",
".",
"m",
"[",
"key",
"]",
"\n",
"return",
"value",
",",
"ok",
"\n",
"}"
] | // Load returns the value stored in the map for a key, or nil if no
// value is present.
// The ok result indicates whether value was found in the map. | [
"Load",
"returns",
"the",
"value",
"stored",
"in",
"the",
"map",
"for",
"a",
"key",
"or",
"nil",
"if",
"no",
"value",
"is",
"present",
".",
"The",
"ok",
"result",
"indicates",
"whether",
"value",
"was",
"found",
"in",
"the",
"map",
"."
] | 3e4dfb77656c424b6d1196a4d5fed0fcf63677cc | https://github.com/gopherjs/gopherjs/blob/3e4dfb77656c424b6d1196a4d5fed0fcf63677cc/nosync/map.go#L16-L19 | train |
gopherjs/gopherjs | nosync/map.go | Store | func (m *Map) Store(key, value interface{}) {
if m.m == nil {
m.m = make(map[interface{}]interface{})
}
m.m[key] = value
} | go | func (m *Map) Store(key, value interface{}) {
if m.m == nil {
m.m = make(map[interface{}]interface{})
}
m.m[key] = value
} | [
"func",
"(",
"m",
"*",
"Map",
")",
"Store",
"(",
"key",
",",
"value",
"interface",
"{",
"}",
")",
"{",
"if",
"m",
".",
"m",
"==",
"nil",
"{",
"m",
".",
"m",
"=",
"make",
"(",
"map",
"[",
"interface",
"{",
"}",
"]",
"interface",
"{",
"}",
")",
"\n",
"}",
"\n",
"m",
".",
"m",
"[",
"key",
"]",
"=",
"value",
"\n",
"}"
] | // Store sets the value for a key. | [
"Store",
"sets",
"the",
"value",
"for",
"a",
"key",
"."
] | 3e4dfb77656c424b6d1196a4d5fed0fcf63677cc | https://github.com/gopherjs/gopherjs/blob/3e4dfb77656c424b6d1196a4d5fed0fcf63677cc/nosync/map.go#L22-L27 | train |
gopherjs/gopherjs | nosync/map.go | LoadOrStore | func (m *Map) LoadOrStore(key, value interface{}) (actual interface{}, loaded bool) {
if value, ok := m.m[key]; ok {
return value, true
}
if m.m == nil {
m.m = make(map[interface{}]interface{})
}
m.m[key] = value
return value, false
} | go | func (m *Map) LoadOrStore(key, value interface{}) (actual interface{}, loaded bool) {
if value, ok := m.m[key]; ok {
return value, true
}
if m.m == nil {
m.m = make(map[interface{}]interface{})
}
m.m[key] = value
return value, false
} | [
"func",
"(",
"m",
"*",
"Map",
")",
"LoadOrStore",
"(",
"key",
",",
"value",
"interface",
"{",
"}",
")",
"(",
"actual",
"interface",
"{",
"}",
",",
"loaded",
"bool",
")",
"{",
"if",
"value",
",",
"ok",
":=",
"m",
".",
"m",
"[",
"key",
"]",
";",
"ok",
"{",
"return",
"value",
",",
"true",
"\n",
"}",
"\n",
"if",
"m",
".",
"m",
"==",
"nil",
"{",
"m",
".",
"m",
"=",
"make",
"(",
"map",
"[",
"interface",
"{",
"}",
"]",
"interface",
"{",
"}",
")",
"\n",
"}",
"\n",
"m",
".",
"m",
"[",
"key",
"]",
"=",
"value",
"\n",
"return",
"value",
",",
"false",
"\n",
"}"
] | // LoadOrStore returns the existing value for the key if present.
// Otherwise, it stores and returns the given value.
// The loaded result is true if the value was loaded, false if stored. | [
"LoadOrStore",
"returns",
"the",
"existing",
"value",
"for",
"the",
"key",
"if",
"present",
".",
"Otherwise",
"it",
"stores",
"and",
"returns",
"the",
"given",
"value",
".",
"The",
"loaded",
"result",
"is",
"true",
"if",
"the",
"value",
"was",
"loaded",
"false",
"if",
"stored",
"."
] | 3e4dfb77656c424b6d1196a4d5fed0fcf63677cc | https://github.com/gopherjs/gopherjs/blob/3e4dfb77656c424b6d1196a4d5fed0fcf63677cc/nosync/map.go#L32-L41 | train |
gopherjs/gopherjs | js/js.go | MakeFunc | func MakeFunc(fn func(this *Object, arguments []*Object) interface{}) *Object {
return Global.Call("$makeFunc", InternalObject(fn))
} | go | func MakeFunc(fn func(this *Object, arguments []*Object) interface{}) *Object {
return Global.Call("$makeFunc", InternalObject(fn))
} | [
"func",
"MakeFunc",
"(",
"fn",
"func",
"(",
"this",
"*",
"Object",
",",
"arguments",
"[",
"]",
"*",
"Object",
")",
"interface",
"{",
"}",
")",
"*",
"Object",
"{",
"return",
"Global",
".",
"Call",
"(",
"\"",
"\"",
",",
"InternalObject",
"(",
"fn",
")",
")",
"\n",
"}"
] | // MakeFunc wraps a function and gives access to the values of JavaScript's "this" and "arguments" keywords. | [
"MakeFunc",
"wraps",
"a",
"function",
"and",
"gives",
"access",
"to",
"the",
"values",
"of",
"JavaScript",
"s",
"this",
"and",
"arguments",
"keywords",
"."
] | 3e4dfb77656c424b6d1196a4d5fed0fcf63677cc | https://github.com/gopherjs/gopherjs/blob/3e4dfb77656c424b6d1196a4d5fed0fcf63677cc/js/js.go#L115-L117 | train |
gopherjs/gopherjs | js/js.go | Keys | func Keys(o *Object) []string {
if o == nil || o == Undefined {
return nil
}
a := Global.Get("Object").Call("keys", o)
s := make([]string, a.Length())
for i := 0; i < a.Length(); i++ {
s[i] = a.Index(i).String()
}
return s
} | go | func Keys(o *Object) []string {
if o == nil || o == Undefined {
return nil
}
a := Global.Get("Object").Call("keys", o)
s := make([]string, a.Length())
for i := 0; i < a.Length(); i++ {
s[i] = a.Index(i).String()
}
return s
} | [
"func",
"Keys",
"(",
"o",
"*",
"Object",
")",
"[",
"]",
"string",
"{",
"if",
"o",
"==",
"nil",
"||",
"o",
"==",
"Undefined",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"a",
":=",
"Global",
".",
"Get",
"(",
"\"",
"\"",
")",
".",
"Call",
"(",
"\"",
"\"",
",",
"o",
")",
"\n",
"s",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"a",
".",
"Length",
"(",
")",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"a",
".",
"Length",
"(",
")",
";",
"i",
"++",
"{",
"s",
"[",
"i",
"]",
"=",
"a",
".",
"Index",
"(",
"i",
")",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] | // Keys returns the keys of the given JavaScript object. | [
"Keys",
"returns",
"the",
"keys",
"of",
"the",
"given",
"JavaScript",
"object",
"."
] | 3e4dfb77656c424b6d1196a4d5fed0fcf63677cc | https://github.com/gopherjs/gopherjs/blob/3e4dfb77656c424b6d1196a4d5fed0fcf63677cc/js/js.go#L120-L130 | train |
gopherjs/gopherjs | js/js.go | MakeWrapper | func MakeWrapper(i interface{}) *Object {
v := InternalObject(i)
o := Global.Get("Object").New()
o.Set("__internal_object__", v)
methods := v.Get("constructor").Get("methods")
for i := 0; i < methods.Length(); i++ {
m := methods.Index(i)
if m.Get("pkg").String() != "" { // not exported
continue
}
o.Set(m.Get("name").String(), func(args ...*Object) *Object {
return Global.Call("$externalizeFunction", v.Get(m.Get("prop").String()), m.Get("typ"), true).Call("apply", v, args)
})
}
return o
} | go | func MakeWrapper(i interface{}) *Object {
v := InternalObject(i)
o := Global.Get("Object").New()
o.Set("__internal_object__", v)
methods := v.Get("constructor").Get("methods")
for i := 0; i < methods.Length(); i++ {
m := methods.Index(i)
if m.Get("pkg").String() != "" { // not exported
continue
}
o.Set(m.Get("name").String(), func(args ...*Object) *Object {
return Global.Call("$externalizeFunction", v.Get(m.Get("prop").String()), m.Get("typ"), true).Call("apply", v, args)
})
}
return o
} | [
"func",
"MakeWrapper",
"(",
"i",
"interface",
"{",
"}",
")",
"*",
"Object",
"{",
"v",
":=",
"InternalObject",
"(",
"i",
")",
"\n",
"o",
":=",
"Global",
".",
"Get",
"(",
"\"",
"\"",
")",
".",
"New",
"(",
")",
"\n",
"o",
".",
"Set",
"(",
"\"",
"\"",
",",
"v",
")",
"\n",
"methods",
":=",
"v",
".",
"Get",
"(",
"\"",
"\"",
")",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"methods",
".",
"Length",
"(",
")",
";",
"i",
"++",
"{",
"m",
":=",
"methods",
".",
"Index",
"(",
"i",
")",
"\n",
"if",
"m",
".",
"Get",
"(",
"\"",
"\"",
")",
".",
"String",
"(",
")",
"!=",
"\"",
"\"",
"{",
"// not exported",
"continue",
"\n",
"}",
"\n",
"o",
".",
"Set",
"(",
"m",
".",
"Get",
"(",
"\"",
"\"",
")",
".",
"String",
"(",
")",
",",
"func",
"(",
"args",
"...",
"*",
"Object",
")",
"*",
"Object",
"{",
"return",
"Global",
".",
"Call",
"(",
"\"",
"\"",
",",
"v",
".",
"Get",
"(",
"m",
".",
"Get",
"(",
"\"",
"\"",
")",
".",
"String",
"(",
")",
")",
",",
"m",
".",
"Get",
"(",
"\"",
"\"",
")",
",",
"true",
")",
".",
"Call",
"(",
"\"",
"\"",
",",
"v",
",",
"args",
")",
"\n",
"}",
")",
"\n",
"}",
"\n",
"return",
"o",
"\n",
"}"
] | // MakeWrapper creates a JavaScript object which has wrappers for the exported methods of i. Use explicit getter and setter methods to expose struct fields to JavaScript. | [
"MakeWrapper",
"creates",
"a",
"JavaScript",
"object",
"which",
"has",
"wrappers",
"for",
"the",
"exported",
"methods",
"of",
"i",
".",
"Use",
"explicit",
"getter",
"and",
"setter",
"methods",
"to",
"expose",
"struct",
"fields",
"to",
"JavaScript",
"."
] | 3e4dfb77656c424b6d1196a4d5fed0fcf63677cc | https://github.com/gopherjs/gopherjs/blob/3e4dfb77656c424b6d1196a4d5fed0fcf63677cc/js/js.go#L133-L148 | train |
gopherjs/gopherjs | js/js.go | NewArrayBuffer | func NewArrayBuffer(b []byte) *Object {
slice := InternalObject(b)
offset := slice.Get("$offset").Int()
length := slice.Get("$length").Int()
return slice.Get("$array").Get("buffer").Call("slice", offset, offset+length)
} | go | func NewArrayBuffer(b []byte) *Object {
slice := InternalObject(b)
offset := slice.Get("$offset").Int()
length := slice.Get("$length").Int()
return slice.Get("$array").Get("buffer").Call("slice", offset, offset+length)
} | [
"func",
"NewArrayBuffer",
"(",
"b",
"[",
"]",
"byte",
")",
"*",
"Object",
"{",
"slice",
":=",
"InternalObject",
"(",
"b",
")",
"\n",
"offset",
":=",
"slice",
".",
"Get",
"(",
"\"",
"\"",
")",
".",
"Int",
"(",
")",
"\n",
"length",
":=",
"slice",
".",
"Get",
"(",
"\"",
"\"",
")",
".",
"Int",
"(",
")",
"\n",
"return",
"slice",
".",
"Get",
"(",
"\"",
"\"",
")",
".",
"Get",
"(",
"\"",
"\"",
")",
".",
"Call",
"(",
"\"",
"\"",
",",
"offset",
",",
"offset",
"+",
"length",
")",
"\n",
"}"
] | // NewArrayBuffer creates a JavaScript ArrayBuffer from a byte slice. | [
"NewArrayBuffer",
"creates",
"a",
"JavaScript",
"ArrayBuffer",
"from",
"a",
"byte",
"slice",
"."
] | 3e4dfb77656c424b6d1196a4d5fed0fcf63677cc | https://github.com/gopherjs/gopherjs/blob/3e4dfb77656c424b6d1196a4d5fed0fcf63677cc/js/js.go#L151-L156 | train |
gopherjs/gopherjs | compiler/natives/src/internal/poll/fd_poll.go | runtime_Semacquire | func runtime_Semacquire(s *uint32) {
if *s == 0 {
ch := make(chan bool)
semWaiters[s] = append(semWaiters[s], ch)
<-ch
}
*s--
} | go | func runtime_Semacquire(s *uint32) {
if *s == 0 {
ch := make(chan bool)
semWaiters[s] = append(semWaiters[s], ch)
<-ch
}
*s--
} | [
"func",
"runtime_Semacquire",
"(",
"s",
"*",
"uint32",
")",
"{",
"if",
"*",
"s",
"==",
"0",
"{",
"ch",
":=",
"make",
"(",
"chan",
"bool",
")",
"\n",
"semWaiters",
"[",
"s",
"]",
"=",
"append",
"(",
"semWaiters",
"[",
"s",
"]",
",",
"ch",
")",
"\n",
"<-",
"ch",
"\n",
"}",
"\n",
"*",
"s",
"--",
"\n",
"}"
] | // Copy of sync.runtime_Semacquire. | [
"Copy",
"of",
"sync",
".",
"runtime_Semacquire",
"."
] | 3e4dfb77656c424b6d1196a4d5fed0fcf63677cc | https://github.com/gopherjs/gopherjs/blob/3e4dfb77656c424b6d1196a4d5fed0fcf63677cc/compiler/natives/src/internal/poll/fd_poll.go#L60-L67 | train |
gopherjs/gopherjs | compiler/natives/src/internal/poll/fd_poll.go | runtime_Semrelease | func runtime_Semrelease(s *uint32) {
*s++
w := semWaiters[s]
if len(w) == 0 {
return
}
ch := w[0]
w = w[1:]
semWaiters[s] = w
if len(w) == 0 {
delete(semWaiters, s)
}
ch <- true
} | go | func runtime_Semrelease(s *uint32) {
*s++
w := semWaiters[s]
if len(w) == 0 {
return
}
ch := w[0]
w = w[1:]
semWaiters[s] = w
if len(w) == 0 {
delete(semWaiters, s)
}
ch <- true
} | [
"func",
"runtime_Semrelease",
"(",
"s",
"*",
"uint32",
")",
"{",
"*",
"s",
"++",
"\n\n",
"w",
":=",
"semWaiters",
"[",
"s",
"]",
"\n",
"if",
"len",
"(",
"w",
")",
"==",
"0",
"{",
"return",
"\n",
"}",
"\n\n",
"ch",
":=",
"w",
"[",
"0",
"]",
"\n",
"w",
"=",
"w",
"[",
"1",
":",
"]",
"\n",
"semWaiters",
"[",
"s",
"]",
"=",
"w",
"\n",
"if",
"len",
"(",
"w",
")",
"==",
"0",
"{",
"delete",
"(",
"semWaiters",
",",
"s",
")",
"\n",
"}",
"\n\n",
"ch",
"<-",
"true",
"\n",
"}"
] | // Copy of sync.runtime_Semrelease. | [
"Copy",
"of",
"sync",
".",
"runtime_Semrelease",
"."
] | 3e4dfb77656c424b6d1196a4d5fed0fcf63677cc | https://github.com/gopherjs/gopherjs/blob/3e4dfb77656c424b6d1196a4d5fed0fcf63677cc/compiler/natives/src/internal/poll/fd_poll.go#L70-L86 | train |
gopherjs/gopherjs | build/build.go | excludeExecutable | func excludeExecutable(goFiles []string) []string {
var s []string
for _, f := range goFiles {
if strings.HasPrefix(f, "executable_") {
continue
}
s = append(s, f)
}
return s
} | go | func excludeExecutable(goFiles []string) []string {
var s []string
for _, f := range goFiles {
if strings.HasPrefix(f, "executable_") {
continue
}
s = append(s, f)
}
return s
} | [
"func",
"excludeExecutable",
"(",
"goFiles",
"[",
"]",
"string",
")",
"[",
"]",
"string",
"{",
"var",
"s",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"goFiles",
"{",
"if",
"strings",
".",
"HasPrefix",
"(",
"f",
",",
"\"",
"\"",
")",
"{",
"continue",
"\n",
"}",
"\n",
"s",
"=",
"append",
"(",
"s",
",",
"f",
")",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] | // excludeExecutable excludes all executable implementation .go files.
// They have "executable_" prefix. | [
"excludeExecutable",
"excludes",
"all",
"executable",
"implementation",
".",
"go",
"files",
".",
"They",
"have",
"executable_",
"prefix",
"."
] | 3e4dfb77656c424b6d1196a4d5fed0fcf63677cc | https://github.com/gopherjs/gopherjs/blob/3e4dfb77656c424b6d1196a4d5fed0fcf63677cc/build/build.go#L205-L214 | train |
gopherjs/gopherjs | build/build.go | exclude | func exclude(files []string, exclude ...string) []string {
var s []string
Outer:
for _, f := range files {
for _, e := range exclude {
if f == e {
continue Outer
}
}
s = append(s, f)
}
return s
} | go | func exclude(files []string, exclude ...string) []string {
var s []string
Outer:
for _, f := range files {
for _, e := range exclude {
if f == e {
continue Outer
}
}
s = append(s, f)
}
return s
} | [
"func",
"exclude",
"(",
"files",
"[",
"]",
"string",
",",
"exclude",
"...",
"string",
")",
"[",
"]",
"string",
"{",
"var",
"s",
"[",
"]",
"string",
"\n",
"Outer",
":",
"for",
"_",
",",
"f",
":=",
"range",
"files",
"{",
"for",
"_",
",",
"e",
":=",
"range",
"exclude",
"{",
"if",
"f",
"==",
"e",
"{",
"continue",
"Outer",
"\n",
"}",
"\n",
"}",
"\n",
"s",
"=",
"append",
"(",
"s",
",",
"f",
")",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] | // exclude returns files, excluding specified files. | [
"exclude",
"returns",
"files",
"excluding",
"specified",
"files",
"."
] | 3e4dfb77656c424b6d1196a4d5fed0fcf63677cc | https://github.com/gopherjs/gopherjs/blob/3e4dfb77656c424b6d1196a4d5fed0fcf63677cc/build/build.go#L217-L229 | train |
gopherjs/gopherjs | build/build.go | ImportDir | func ImportDir(dir string, mode build.ImportMode, installSuffix string, buildTags []string) (*PackageData, error) {
bctx := NewBuildContext(installSuffix, buildTags)
pkg, err := bctx.ImportDir(dir, mode)
if err != nil {
return nil, err
}
jsFiles, err := jsFilesFromDir(bctx, pkg.Dir)
if err != nil {
return nil, err
}
return &PackageData{Package: pkg, JSFiles: jsFiles}, nil
} | go | func ImportDir(dir string, mode build.ImportMode, installSuffix string, buildTags []string) (*PackageData, error) {
bctx := NewBuildContext(installSuffix, buildTags)
pkg, err := bctx.ImportDir(dir, mode)
if err != nil {
return nil, err
}
jsFiles, err := jsFilesFromDir(bctx, pkg.Dir)
if err != nil {
return nil, err
}
return &PackageData{Package: pkg, JSFiles: jsFiles}, nil
} | [
"func",
"ImportDir",
"(",
"dir",
"string",
",",
"mode",
"build",
".",
"ImportMode",
",",
"installSuffix",
"string",
",",
"buildTags",
"[",
"]",
"string",
")",
"(",
"*",
"PackageData",
",",
"error",
")",
"{",
"bctx",
":=",
"NewBuildContext",
"(",
"installSuffix",
",",
"buildTags",
")",
"\n",
"pkg",
",",
"err",
":=",
"bctx",
".",
"ImportDir",
"(",
"dir",
",",
"mode",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"jsFiles",
",",
"err",
":=",
"jsFilesFromDir",
"(",
"bctx",
",",
"pkg",
".",
"Dir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"PackageData",
"{",
"Package",
":",
"pkg",
",",
"JSFiles",
":",
"jsFiles",
"}",
",",
"nil",
"\n",
"}"
] | // ImportDir is like Import but processes the Go package found in the named
// directory. | [
"ImportDir",
"is",
"like",
"Import",
"but",
"processes",
"the",
"Go",
"package",
"found",
"in",
"the",
"named",
"directory",
"."
] | 3e4dfb77656c424b6d1196a4d5fed0fcf63677cc | https://github.com/gopherjs/gopherjs/blob/3e4dfb77656c424b6d1196a4d5fed0fcf63677cc/build/build.go#L233-L246 | train |
gopherjs/gopherjs | build/build.go | hasGopathPrefix | func hasGopathPrefix(file, gopath string) (hasGopathPrefix bool, prefixLen int) {
gopathWorkspaces := filepath.SplitList(gopath)
for _, gopathWorkspace := range gopathWorkspaces {
gopathWorkspace = filepath.Clean(gopathWorkspace)
if strings.HasPrefix(file, gopathWorkspace) {
return true, len(gopathWorkspace)
}
}
return false, 0
} | go | func hasGopathPrefix(file, gopath string) (hasGopathPrefix bool, prefixLen int) {
gopathWorkspaces := filepath.SplitList(gopath)
for _, gopathWorkspace := range gopathWorkspaces {
gopathWorkspace = filepath.Clean(gopathWorkspace)
if strings.HasPrefix(file, gopathWorkspace) {
return true, len(gopathWorkspace)
}
}
return false, 0
} | [
"func",
"hasGopathPrefix",
"(",
"file",
",",
"gopath",
"string",
")",
"(",
"hasGopathPrefix",
"bool",
",",
"prefixLen",
"int",
")",
"{",
"gopathWorkspaces",
":=",
"filepath",
".",
"SplitList",
"(",
"gopath",
")",
"\n",
"for",
"_",
",",
"gopathWorkspace",
":=",
"range",
"gopathWorkspaces",
"{",
"gopathWorkspace",
"=",
"filepath",
".",
"Clean",
"(",
"gopathWorkspace",
")",
"\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"file",
",",
"gopathWorkspace",
")",
"{",
"return",
"true",
",",
"len",
"(",
"gopathWorkspace",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
",",
"0",
"\n",
"}"
] | // hasGopathPrefix returns true and the length of the matched GOPATH workspace,
// iff file has a prefix that matches one of the GOPATH workspaces. | [
"hasGopathPrefix",
"returns",
"true",
"and",
"the",
"length",
"of",
"the",
"matched",
"GOPATH",
"workspace",
"iff",
"file",
"has",
"a",
"prefix",
"that",
"matches",
"one",
"of",
"the",
"GOPATH",
"workspaces",
"."
] | 3e4dfb77656c424b6d1196a4d5fed0fcf63677cc | https://github.com/gopherjs/gopherjs/blob/3e4dfb77656c424b6d1196a4d5fed0fcf63677cc/build/build.go#L843-L852 | train |
gopherjs/gopherjs | internal/sysutil/sysutil.go | RlimitStack | func RlimitStack() (cur uint64, err error) {
var r unix.Rlimit
err = unix.Getrlimit(unix.RLIMIT_STACK, &r)
return uint64(r.Cur), err // Type conversion because Cur is one of uint64, int64 depending on unix flavor.
} | go | func RlimitStack() (cur uint64, err error) {
var r unix.Rlimit
err = unix.Getrlimit(unix.RLIMIT_STACK, &r)
return uint64(r.Cur), err // Type conversion because Cur is one of uint64, int64 depending on unix flavor.
} | [
"func",
"RlimitStack",
"(",
")",
"(",
"cur",
"uint64",
",",
"err",
"error",
")",
"{",
"var",
"r",
"unix",
".",
"Rlimit",
"\n",
"err",
"=",
"unix",
".",
"Getrlimit",
"(",
"unix",
".",
"RLIMIT_STACK",
",",
"&",
"r",
")",
"\n",
"return",
"uint64",
"(",
"r",
".",
"Cur",
")",
",",
"err",
"// Type conversion because Cur is one of uint64, int64 depending on unix flavor.",
"\n",
"}"
] | // RlimitStack reports the current stack size limit in bytes. | [
"RlimitStack",
"reports",
"the",
"current",
"stack",
"size",
"limit",
"in",
"bytes",
"."
] | 3e4dfb77656c424b6d1196a4d5fed0fcf63677cc | https://github.com/gopherjs/gopherjs/blob/3e4dfb77656c424b6d1196a4d5fed0fcf63677cc/internal/sysutil/sysutil.go#L9-L13 | train |
gopherjs/gopherjs | compiler/natives/src/syscall/js/js.go | convertArgs | func convertArgs(args ...interface{}) []interface{} {
newArgs := []interface{}{}
for _, arg := range args {
v := ValueOf(arg)
newArgs = append(newArgs, v.internal())
}
return newArgs
} | go | func convertArgs(args ...interface{}) []interface{} {
newArgs := []interface{}{}
for _, arg := range args {
v := ValueOf(arg)
newArgs = append(newArgs, v.internal())
}
return newArgs
} | [
"func",
"convertArgs",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"[",
"]",
"interface",
"{",
"}",
"{",
"newArgs",
":=",
"[",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"for",
"_",
",",
"arg",
":=",
"range",
"args",
"{",
"v",
":=",
"ValueOf",
"(",
"arg",
")",
"\n",
"newArgs",
"=",
"append",
"(",
"newArgs",
",",
"v",
".",
"internal",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"newArgs",
"\n",
"}"
] | // convertArgs converts arguments into values for GopherJS arguments. | [
"convertArgs",
"converts",
"arguments",
"into",
"values",
"for",
"GopherJS",
"arguments",
"."
] | 3e4dfb77656c424b6d1196a4d5fed0fcf63677cc | https://github.com/gopherjs/gopherjs/blob/3e4dfb77656c424b6d1196a4d5fed0fcf63677cc/compiler/natives/src/syscall/js/js.go#L171-L178 | train |
gopherjs/gopherjs | compiler/natives/src/net/net.go | bytesEqual | func bytesEqual(x, y []byte) bool {
if len(x) != len(y) {
return false
}
for i, b := range x {
if b != y[i] {
return false
}
}
return true
} | go | func bytesEqual(x, y []byte) bool {
if len(x) != len(y) {
return false
}
for i, b := range x {
if b != y[i] {
return false
}
}
return true
} | [
"func",
"bytesEqual",
"(",
"x",
",",
"y",
"[",
"]",
"byte",
")",
"bool",
"{",
"if",
"len",
"(",
"x",
")",
"!=",
"len",
"(",
"y",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"for",
"i",
",",
"b",
":=",
"range",
"x",
"{",
"if",
"b",
"!=",
"y",
"[",
"i",
"]",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // Copy of bytes.Equal. | [
"Copy",
"of",
"bytes",
".",
"Equal",
"."
] | 3e4dfb77656c424b6d1196a4d5fed0fcf63677cc | https://github.com/gopherjs/gopherjs/blob/3e4dfb77656c424b6d1196a4d5fed0fcf63677cc/compiler/natives/src/net/net.go#L45-L55 | train |
gopherjs/gopherjs | compiler/natives/src/net/net.go | bytesIndexByte | func bytesIndexByte(s []byte, c byte) int {
for i, b := range s {
if b == c {
return i
}
}
return -1
} | go | func bytesIndexByte(s []byte, c byte) int {
for i, b := range s {
if b == c {
return i
}
}
return -1
} | [
"func",
"bytesIndexByte",
"(",
"s",
"[",
"]",
"byte",
",",
"c",
"byte",
")",
"int",
"{",
"for",
"i",
",",
"b",
":=",
"range",
"s",
"{",
"if",
"b",
"==",
"c",
"{",
"return",
"i",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"-",
"1",
"\n",
"}"
] | // Copy of bytes.IndexByte. | [
"Copy",
"of",
"bytes",
".",
"IndexByte",
"."
] | 3e4dfb77656c424b6d1196a4d5fed0fcf63677cc | https://github.com/gopherjs/gopherjs/blob/3e4dfb77656c424b6d1196a4d5fed0fcf63677cc/compiler/natives/src/net/net.go#L58-L65 | train |
gopherjs/gopherjs | tool.go | handleError | func handleError(err error, options *gbuild.Options, browserErrors *bytes.Buffer) int {
switch err := err.(type) {
case nil:
return 0
case compiler.ErrorList:
for _, entry := range err {
printError(entry, options, browserErrors)
}
return 1
case *exec.ExitError:
return err.Sys().(syscall.WaitStatus).ExitStatus()
default:
printError(err, options, browserErrors)
return 1
}
} | go | func handleError(err error, options *gbuild.Options, browserErrors *bytes.Buffer) int {
switch err := err.(type) {
case nil:
return 0
case compiler.ErrorList:
for _, entry := range err {
printError(entry, options, browserErrors)
}
return 1
case *exec.ExitError:
return err.Sys().(syscall.WaitStatus).ExitStatus()
default:
printError(err, options, browserErrors)
return 1
}
} | [
"func",
"handleError",
"(",
"err",
"error",
",",
"options",
"*",
"gbuild",
".",
"Options",
",",
"browserErrors",
"*",
"bytes",
".",
"Buffer",
")",
"int",
"{",
"switch",
"err",
":=",
"err",
".",
"(",
"type",
")",
"{",
"case",
"nil",
":",
"return",
"0",
"\n",
"case",
"compiler",
".",
"ErrorList",
":",
"for",
"_",
",",
"entry",
":=",
"range",
"err",
"{",
"printError",
"(",
"entry",
",",
"options",
",",
"browserErrors",
")",
"\n",
"}",
"\n",
"return",
"1",
"\n",
"case",
"*",
"exec",
".",
"ExitError",
":",
"return",
"err",
".",
"Sys",
"(",
")",
".",
"(",
"syscall",
".",
"WaitStatus",
")",
".",
"ExitStatus",
"(",
")",
"\n",
"default",
":",
"printError",
"(",
"err",
",",
"options",
",",
"browserErrors",
")",
"\n",
"return",
"1",
"\n",
"}",
"\n",
"}"
] | // handleError handles err and returns an appropriate exit code.
// If browserErrors is non-nil, errors are written for presentation in browser. | [
"handleError",
"handles",
"err",
"and",
"returns",
"an",
"appropriate",
"exit",
"code",
".",
"If",
"browserErrors",
"is",
"non",
"-",
"nil",
"errors",
"are",
"written",
"for",
"presentation",
"in",
"browser",
"."
] | 3e4dfb77656c424b6d1196a4d5fed0fcf63677cc | https://github.com/gopherjs/gopherjs/blob/3e4dfb77656c424b6d1196a4d5fed0fcf63677cc/tool.go#L698-L713 | train |
gopherjs/gopherjs | tool.go | printError | func printError(err error, options *gbuild.Options, browserErrors *bytes.Buffer) {
e := sprintError(err)
options.PrintError("%s\n", e)
if browserErrors != nil {
fmt.Fprintln(browserErrors, `console.error("`+template.JSEscapeString(e)+`");`)
}
} | go | func printError(err error, options *gbuild.Options, browserErrors *bytes.Buffer) {
e := sprintError(err)
options.PrintError("%s\n", e)
if browserErrors != nil {
fmt.Fprintln(browserErrors, `console.error("`+template.JSEscapeString(e)+`");`)
}
} | [
"func",
"printError",
"(",
"err",
"error",
",",
"options",
"*",
"gbuild",
".",
"Options",
",",
"browserErrors",
"*",
"bytes",
".",
"Buffer",
")",
"{",
"e",
":=",
"sprintError",
"(",
"err",
")",
"\n",
"options",
".",
"PrintError",
"(",
"\"",
"\\n",
"\"",
",",
"e",
")",
"\n",
"if",
"browserErrors",
"!=",
"nil",
"{",
"fmt",
".",
"Fprintln",
"(",
"browserErrors",
",",
"`console.error(\"`",
"+",
"template",
".",
"JSEscapeString",
"(",
"e",
")",
"+",
"`\");`",
")",
"\n",
"}",
"\n",
"}"
] | // printError prints err to Stderr with options. If browserErrors is non-nil, errors are also written for presentation in browser. | [
"printError",
"prints",
"err",
"to",
"Stderr",
"with",
"options",
".",
"If",
"browserErrors",
"is",
"non",
"-",
"nil",
"errors",
"are",
"also",
"written",
"for",
"presentation",
"in",
"browser",
"."
] | 3e4dfb77656c424b6d1196a4d5fed0fcf63677cc | https://github.com/gopherjs/gopherjs/blob/3e4dfb77656c424b6d1196a4d5fed0fcf63677cc/tool.go#L716-L722 | train |
gopherjs/gopherjs | tool.go | sprintError | func sprintError(err error) string {
makeRel := func(name string) string {
if relname, err := filepath.Rel(currentDirectory, name); err == nil {
return relname
}
return name
}
switch e := err.(type) {
case *scanner.Error:
return fmt.Sprintf("%s:%d:%d: %s", makeRel(e.Pos.Filename), e.Pos.Line, e.Pos.Column, e.Msg)
case types.Error:
pos := e.Fset.Position(e.Pos)
return fmt.Sprintf("%s:%d:%d: %s", makeRel(pos.Filename), pos.Line, pos.Column, e.Msg)
default:
return fmt.Sprintf("%s", e)
}
} | go | func sprintError(err error) string {
makeRel := func(name string) string {
if relname, err := filepath.Rel(currentDirectory, name); err == nil {
return relname
}
return name
}
switch e := err.(type) {
case *scanner.Error:
return fmt.Sprintf("%s:%d:%d: %s", makeRel(e.Pos.Filename), e.Pos.Line, e.Pos.Column, e.Msg)
case types.Error:
pos := e.Fset.Position(e.Pos)
return fmt.Sprintf("%s:%d:%d: %s", makeRel(pos.Filename), pos.Line, pos.Column, e.Msg)
default:
return fmt.Sprintf("%s", e)
}
} | [
"func",
"sprintError",
"(",
"err",
"error",
")",
"string",
"{",
"makeRel",
":=",
"func",
"(",
"name",
"string",
")",
"string",
"{",
"if",
"relname",
",",
"err",
":=",
"filepath",
".",
"Rel",
"(",
"currentDirectory",
",",
"name",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"relname",
"\n",
"}",
"\n",
"return",
"name",
"\n",
"}",
"\n\n",
"switch",
"e",
":=",
"err",
".",
"(",
"type",
")",
"{",
"case",
"*",
"scanner",
".",
"Error",
":",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"makeRel",
"(",
"e",
".",
"Pos",
".",
"Filename",
")",
",",
"e",
".",
"Pos",
".",
"Line",
",",
"e",
".",
"Pos",
".",
"Column",
",",
"e",
".",
"Msg",
")",
"\n",
"case",
"types",
".",
"Error",
":",
"pos",
":=",
"e",
".",
"Fset",
".",
"Position",
"(",
"e",
".",
"Pos",
")",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"makeRel",
"(",
"pos",
".",
"Filename",
")",
",",
"pos",
".",
"Line",
",",
"pos",
".",
"Column",
",",
"e",
".",
"Msg",
")",
"\n",
"default",
":",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"e",
")",
"\n",
"}",
"\n",
"}"
] | // sprintError returns an annotated error string without trailing newline. | [
"sprintError",
"returns",
"an",
"annotated",
"error",
"string",
"without",
"trailing",
"newline",
"."
] | 3e4dfb77656c424b6d1196a4d5fed0fcf63677cc | https://github.com/gopherjs/gopherjs/blob/3e4dfb77656c424b6d1196a4d5fed0fcf63677cc/tool.go#L725-L742 | train |
gopherjs/gopherjs | tool.go | runNode | func runNode(script string, args []string, dir string, quiet bool) error {
var allArgs []string
if b, _ := strconv.ParseBool(os.Getenv("SOURCE_MAP_SUPPORT")); os.Getenv("SOURCE_MAP_SUPPORT") == "" || b {
allArgs = []string{"--require", "source-map-support/register"}
if err := exec.Command("node", "--require", "source-map-support/register", "--eval", "").Run(); err != nil {
if !quiet {
fmt.Fprintln(os.Stderr, "gopherjs: Source maps disabled. Install source-map-support module for nice stack traces. See https://github.com/gopherjs/gopherjs#gopherjs-run-gopherjs-test.")
}
allArgs = []string{}
}
}
if runtime.GOOS != "windows" {
// We've seen issues with stack space limits causing
// recursion-heavy standard library tests to fail (e.g., see
// https://github.com/gopherjs/gopherjs/pull/669#issuecomment-319319483).
//
// There are two separate limits in non-Windows environments:
//
// - OS process limit
// - Node.js (V8) limit
//
// GopherJS fetches the current OS process limit, and sets the
// Node.js limit to the same value. So both limits are kept in sync
// and can be controlled by setting OS process limit. E.g.:
//
// ulimit -s 10000 && gopherjs test
//
cur, err := sysutil.RlimitStack()
if err != nil {
return fmt.Errorf("failed to get stack size limit: %v", err)
}
allArgs = append(allArgs, fmt.Sprintf("--stack_size=%v", cur/1000)) // Convert from bytes to KB.
}
allArgs = append(allArgs, script)
allArgs = append(allArgs, args...)
node := exec.Command("node", allArgs...)
node.Dir = dir
node.Stdin = os.Stdin
node.Stdout = os.Stdout
node.Stderr = os.Stderr
err := node.Run()
if _, ok := err.(*exec.ExitError); err != nil && !ok {
err = fmt.Errorf("could not run Node.js: %s", err.Error())
}
return err
} | go | func runNode(script string, args []string, dir string, quiet bool) error {
var allArgs []string
if b, _ := strconv.ParseBool(os.Getenv("SOURCE_MAP_SUPPORT")); os.Getenv("SOURCE_MAP_SUPPORT") == "" || b {
allArgs = []string{"--require", "source-map-support/register"}
if err := exec.Command("node", "--require", "source-map-support/register", "--eval", "").Run(); err != nil {
if !quiet {
fmt.Fprintln(os.Stderr, "gopherjs: Source maps disabled. Install source-map-support module for nice stack traces. See https://github.com/gopherjs/gopherjs#gopherjs-run-gopherjs-test.")
}
allArgs = []string{}
}
}
if runtime.GOOS != "windows" {
// We've seen issues with stack space limits causing
// recursion-heavy standard library tests to fail (e.g., see
// https://github.com/gopherjs/gopherjs/pull/669#issuecomment-319319483).
//
// There are two separate limits in non-Windows environments:
//
// - OS process limit
// - Node.js (V8) limit
//
// GopherJS fetches the current OS process limit, and sets the
// Node.js limit to the same value. So both limits are kept in sync
// and can be controlled by setting OS process limit. E.g.:
//
// ulimit -s 10000 && gopherjs test
//
cur, err := sysutil.RlimitStack()
if err != nil {
return fmt.Errorf("failed to get stack size limit: %v", err)
}
allArgs = append(allArgs, fmt.Sprintf("--stack_size=%v", cur/1000)) // Convert from bytes to KB.
}
allArgs = append(allArgs, script)
allArgs = append(allArgs, args...)
node := exec.Command("node", allArgs...)
node.Dir = dir
node.Stdin = os.Stdin
node.Stdout = os.Stdout
node.Stderr = os.Stderr
err := node.Run()
if _, ok := err.(*exec.ExitError); err != nil && !ok {
err = fmt.Errorf("could not run Node.js: %s", err.Error())
}
return err
} | [
"func",
"runNode",
"(",
"script",
"string",
",",
"args",
"[",
"]",
"string",
",",
"dir",
"string",
",",
"quiet",
"bool",
")",
"error",
"{",
"var",
"allArgs",
"[",
"]",
"string",
"\n",
"if",
"b",
",",
"_",
":=",
"strconv",
".",
"ParseBool",
"(",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
")",
";",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
"==",
"\"",
"\"",
"||",
"b",
"{",
"allArgs",
"=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
"\n",
"if",
"err",
":=",
"exec",
".",
"Command",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
".",
"Run",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"if",
"!",
"quiet",
"{",
"fmt",
".",
"Fprintln",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"allArgs",
"=",
"[",
"]",
"string",
"{",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"runtime",
".",
"GOOS",
"!=",
"\"",
"\"",
"{",
"// We've seen issues with stack space limits causing",
"// recursion-heavy standard library tests to fail (e.g., see",
"// https://github.com/gopherjs/gopherjs/pull/669#issuecomment-319319483).",
"//",
"// There are two separate limits in non-Windows environments:",
"//",
"// -\tOS process limit",
"// -\tNode.js (V8) limit",
"//",
"// GopherJS fetches the current OS process limit, and sets the",
"// Node.js limit to the same value. So both limits are kept in sync",
"// and can be controlled by setting OS process limit. E.g.:",
"//",
"// \tulimit -s 10000 && gopherjs test",
"//",
"cur",
",",
"err",
":=",
"sysutil",
".",
"RlimitStack",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"allArgs",
"=",
"append",
"(",
"allArgs",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"cur",
"/",
"1000",
")",
")",
"// Convert from bytes to KB.",
"\n",
"}",
"\n\n",
"allArgs",
"=",
"append",
"(",
"allArgs",
",",
"script",
")",
"\n",
"allArgs",
"=",
"append",
"(",
"allArgs",
",",
"args",
"...",
")",
"\n\n",
"node",
":=",
"exec",
".",
"Command",
"(",
"\"",
"\"",
",",
"allArgs",
"...",
")",
"\n",
"node",
".",
"Dir",
"=",
"dir",
"\n",
"node",
".",
"Stdin",
"=",
"os",
".",
"Stdin",
"\n",
"node",
".",
"Stdout",
"=",
"os",
".",
"Stdout",
"\n",
"node",
".",
"Stderr",
"=",
"os",
".",
"Stderr",
"\n",
"err",
":=",
"node",
".",
"Run",
"(",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"err",
".",
"(",
"*",
"exec",
".",
"ExitError",
")",
";",
"err",
"!=",
"nil",
"&&",
"!",
"ok",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // runNode runs script with args using Node.js in directory dir.
// If dir is empty string, current directory is used. | [
"runNode",
"runs",
"script",
"with",
"args",
"using",
"Node",
".",
"js",
"in",
"directory",
"dir",
".",
"If",
"dir",
"is",
"empty",
"string",
"current",
"directory",
"is",
"used",
"."
] | 3e4dfb77656c424b6d1196a4d5fed0fcf63677cc | https://github.com/gopherjs/gopherjs/blob/3e4dfb77656c424b6d1196a4d5fed0fcf63677cc/tool.go#L746-L794 | train |
disintegration/imaging | tools.go | New | func New(width, height int, fillColor color.Color) *image.NRGBA {
if width <= 0 || height <= 0 {
return &image.NRGBA{}
}
c := color.NRGBAModel.Convert(fillColor).(color.NRGBA)
if (c == color.NRGBA{0, 0, 0, 0}) {
return image.NewNRGBA(image.Rect(0, 0, width, height))
}
return &image.NRGBA{
Pix: bytes.Repeat([]byte{c.R, c.G, c.B, c.A}, width*height),
Stride: 4 * width,
Rect: image.Rect(0, 0, width, height),
}
} | go | func New(width, height int, fillColor color.Color) *image.NRGBA {
if width <= 0 || height <= 0 {
return &image.NRGBA{}
}
c := color.NRGBAModel.Convert(fillColor).(color.NRGBA)
if (c == color.NRGBA{0, 0, 0, 0}) {
return image.NewNRGBA(image.Rect(0, 0, width, height))
}
return &image.NRGBA{
Pix: bytes.Repeat([]byte{c.R, c.G, c.B, c.A}, width*height),
Stride: 4 * width,
Rect: image.Rect(0, 0, width, height),
}
} | [
"func",
"New",
"(",
"width",
",",
"height",
"int",
",",
"fillColor",
"color",
".",
"Color",
")",
"*",
"image",
".",
"NRGBA",
"{",
"if",
"width",
"<=",
"0",
"||",
"height",
"<=",
"0",
"{",
"return",
"&",
"image",
".",
"NRGBA",
"{",
"}",
"\n",
"}",
"\n\n",
"c",
":=",
"color",
".",
"NRGBAModel",
".",
"Convert",
"(",
"fillColor",
")",
".",
"(",
"color",
".",
"NRGBA",
")",
"\n",
"if",
"(",
"c",
"==",
"color",
".",
"NRGBA",
"{",
"0",
",",
"0",
",",
"0",
",",
"0",
"}",
")",
"{",
"return",
"image",
".",
"NewNRGBA",
"(",
"image",
".",
"Rect",
"(",
"0",
",",
"0",
",",
"width",
",",
"height",
")",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"image",
".",
"NRGBA",
"{",
"Pix",
":",
"bytes",
".",
"Repeat",
"(",
"[",
"]",
"byte",
"{",
"c",
".",
"R",
",",
"c",
".",
"G",
",",
"c",
".",
"B",
",",
"c",
".",
"A",
"}",
",",
"width",
"*",
"height",
")",
",",
"Stride",
":",
"4",
"*",
"width",
",",
"Rect",
":",
"image",
".",
"Rect",
"(",
"0",
",",
"0",
",",
"width",
",",
"height",
")",
",",
"}",
"\n",
"}"
] | // New creates a new image with the specified width and height, and fills it with the specified color. | [
"New",
"creates",
"a",
"new",
"image",
"with",
"the",
"specified",
"width",
"and",
"height",
"and",
"fills",
"it",
"with",
"the",
"specified",
"color",
"."
] | 061e8a750a4db9667cdf9e2af7f4029ba506cb3b | https://github.com/disintegration/imaging/blob/061e8a750a4db9667cdf9e2af7f4029ba506cb3b/tools.go#L11-L26 | train |
disintegration/imaging | tools.go | Clone | func Clone(img image.Image) *image.NRGBA {
src := newScanner(img)
dst := image.NewNRGBA(image.Rect(0, 0, src.w, src.h))
size := src.w * 4
parallel(0, src.h, func(ys <-chan int) {
for y := range ys {
i := y * dst.Stride
src.scan(0, y, src.w, y+1, dst.Pix[i:i+size])
}
})
return dst
} | go | func Clone(img image.Image) *image.NRGBA {
src := newScanner(img)
dst := image.NewNRGBA(image.Rect(0, 0, src.w, src.h))
size := src.w * 4
parallel(0, src.h, func(ys <-chan int) {
for y := range ys {
i := y * dst.Stride
src.scan(0, y, src.w, y+1, dst.Pix[i:i+size])
}
})
return dst
} | [
"func",
"Clone",
"(",
"img",
"image",
".",
"Image",
")",
"*",
"image",
".",
"NRGBA",
"{",
"src",
":=",
"newScanner",
"(",
"img",
")",
"\n",
"dst",
":=",
"image",
".",
"NewNRGBA",
"(",
"image",
".",
"Rect",
"(",
"0",
",",
"0",
",",
"src",
".",
"w",
",",
"src",
".",
"h",
")",
")",
"\n",
"size",
":=",
"src",
".",
"w",
"*",
"4",
"\n",
"parallel",
"(",
"0",
",",
"src",
".",
"h",
",",
"func",
"(",
"ys",
"<-",
"chan",
"int",
")",
"{",
"for",
"y",
":=",
"range",
"ys",
"{",
"i",
":=",
"y",
"*",
"dst",
".",
"Stride",
"\n",
"src",
".",
"scan",
"(",
"0",
",",
"y",
",",
"src",
".",
"w",
",",
"y",
"+",
"1",
",",
"dst",
".",
"Pix",
"[",
"i",
":",
"i",
"+",
"size",
"]",
")",
"\n",
"}",
"\n",
"}",
")",
"\n",
"return",
"dst",
"\n",
"}"
] | // Clone returns a copy of the given image. | [
"Clone",
"returns",
"a",
"copy",
"of",
"the",
"given",
"image",
"."
] | 061e8a750a4db9667cdf9e2af7f4029ba506cb3b | https://github.com/disintegration/imaging/blob/061e8a750a4db9667cdf9e2af7f4029ba506cb3b/tools.go#L29-L40 | train |
disintegration/imaging | tools.go | Crop | func Crop(img image.Image, rect image.Rectangle) *image.NRGBA {
r := rect.Intersect(img.Bounds()).Sub(img.Bounds().Min)
if r.Empty() {
return &image.NRGBA{}
}
src := newScanner(img)
dst := image.NewNRGBA(image.Rect(0, 0, r.Dx(), r.Dy()))
rowSize := r.Dx() * 4
parallel(r.Min.Y, r.Max.Y, func(ys <-chan int) {
for y := range ys {
i := (y - r.Min.Y) * dst.Stride
src.scan(r.Min.X, y, r.Max.X, y+1, dst.Pix[i:i+rowSize])
}
})
return dst
} | go | func Crop(img image.Image, rect image.Rectangle) *image.NRGBA {
r := rect.Intersect(img.Bounds()).Sub(img.Bounds().Min)
if r.Empty() {
return &image.NRGBA{}
}
src := newScanner(img)
dst := image.NewNRGBA(image.Rect(0, 0, r.Dx(), r.Dy()))
rowSize := r.Dx() * 4
parallel(r.Min.Y, r.Max.Y, func(ys <-chan int) {
for y := range ys {
i := (y - r.Min.Y) * dst.Stride
src.scan(r.Min.X, y, r.Max.X, y+1, dst.Pix[i:i+rowSize])
}
})
return dst
} | [
"func",
"Crop",
"(",
"img",
"image",
".",
"Image",
",",
"rect",
"image",
".",
"Rectangle",
")",
"*",
"image",
".",
"NRGBA",
"{",
"r",
":=",
"rect",
".",
"Intersect",
"(",
"img",
".",
"Bounds",
"(",
")",
")",
".",
"Sub",
"(",
"img",
".",
"Bounds",
"(",
")",
".",
"Min",
")",
"\n",
"if",
"r",
".",
"Empty",
"(",
")",
"{",
"return",
"&",
"image",
".",
"NRGBA",
"{",
"}",
"\n",
"}",
"\n",
"src",
":=",
"newScanner",
"(",
"img",
")",
"\n",
"dst",
":=",
"image",
".",
"NewNRGBA",
"(",
"image",
".",
"Rect",
"(",
"0",
",",
"0",
",",
"r",
".",
"Dx",
"(",
")",
",",
"r",
".",
"Dy",
"(",
")",
")",
")",
"\n",
"rowSize",
":=",
"r",
".",
"Dx",
"(",
")",
"*",
"4",
"\n",
"parallel",
"(",
"r",
".",
"Min",
".",
"Y",
",",
"r",
".",
"Max",
".",
"Y",
",",
"func",
"(",
"ys",
"<-",
"chan",
"int",
")",
"{",
"for",
"y",
":=",
"range",
"ys",
"{",
"i",
":=",
"(",
"y",
"-",
"r",
".",
"Min",
".",
"Y",
")",
"*",
"dst",
".",
"Stride",
"\n",
"src",
".",
"scan",
"(",
"r",
".",
"Min",
".",
"X",
",",
"y",
",",
"r",
".",
"Max",
".",
"X",
",",
"y",
"+",
"1",
",",
"dst",
".",
"Pix",
"[",
"i",
":",
"i",
"+",
"rowSize",
"]",
")",
"\n",
"}",
"\n",
"}",
")",
"\n",
"return",
"dst",
"\n",
"}"
] | // Crop cuts out a rectangular region with the specified bounds
// from the image and returns the cropped image. | [
"Crop",
"cuts",
"out",
"a",
"rectangular",
"region",
"with",
"the",
"specified",
"bounds",
"from",
"the",
"image",
"and",
"returns",
"the",
"cropped",
"image",
"."
] | 061e8a750a4db9667cdf9e2af7f4029ba506cb3b | https://github.com/disintegration/imaging/blob/061e8a750a4db9667cdf9e2af7f4029ba506cb3b/tools.go#L94-L109 | train |
disintegration/imaging | tools.go | CropAnchor | func CropAnchor(img image.Image, width, height int, anchor Anchor) *image.NRGBA {
srcBounds := img.Bounds()
pt := anchorPt(srcBounds, width, height, anchor)
r := image.Rect(0, 0, width, height).Add(pt)
b := srcBounds.Intersect(r)
return Crop(img, b)
} | go | func CropAnchor(img image.Image, width, height int, anchor Anchor) *image.NRGBA {
srcBounds := img.Bounds()
pt := anchorPt(srcBounds, width, height, anchor)
r := image.Rect(0, 0, width, height).Add(pt)
b := srcBounds.Intersect(r)
return Crop(img, b)
} | [
"func",
"CropAnchor",
"(",
"img",
"image",
".",
"Image",
",",
"width",
",",
"height",
"int",
",",
"anchor",
"Anchor",
")",
"*",
"image",
".",
"NRGBA",
"{",
"srcBounds",
":=",
"img",
".",
"Bounds",
"(",
")",
"\n",
"pt",
":=",
"anchorPt",
"(",
"srcBounds",
",",
"width",
",",
"height",
",",
"anchor",
")",
"\n",
"r",
":=",
"image",
".",
"Rect",
"(",
"0",
",",
"0",
",",
"width",
",",
"height",
")",
".",
"Add",
"(",
"pt",
")",
"\n",
"b",
":=",
"srcBounds",
".",
"Intersect",
"(",
"r",
")",
"\n",
"return",
"Crop",
"(",
"img",
",",
"b",
")",
"\n",
"}"
] | // CropAnchor cuts out a rectangular region with the specified size
// from the image using the specified anchor point and returns the cropped image. | [
"CropAnchor",
"cuts",
"out",
"a",
"rectangular",
"region",
"with",
"the",
"specified",
"size",
"from",
"the",
"image",
"using",
"the",
"specified",
"anchor",
"point",
"and",
"returns",
"the",
"cropped",
"image",
"."
] | 061e8a750a4db9667cdf9e2af7f4029ba506cb3b | https://github.com/disintegration/imaging/blob/061e8a750a4db9667cdf9e2af7f4029ba506cb3b/tools.go#L113-L119 | train |
disintegration/imaging | tools.go | CropCenter | func CropCenter(img image.Image, width, height int) *image.NRGBA {
return CropAnchor(img, width, height, Center)
} | go | func CropCenter(img image.Image, width, height int) *image.NRGBA {
return CropAnchor(img, width, height, Center)
} | [
"func",
"CropCenter",
"(",
"img",
"image",
".",
"Image",
",",
"width",
",",
"height",
"int",
")",
"*",
"image",
".",
"NRGBA",
"{",
"return",
"CropAnchor",
"(",
"img",
",",
"width",
",",
"height",
",",
"Center",
")",
"\n",
"}"
] | // CropCenter cuts out a rectangular region with the specified size
// from the center of the image and returns the cropped image. | [
"CropCenter",
"cuts",
"out",
"a",
"rectangular",
"region",
"with",
"the",
"specified",
"size",
"from",
"the",
"center",
"of",
"the",
"image",
"and",
"returns",
"the",
"cropped",
"image",
"."
] | 061e8a750a4db9667cdf9e2af7f4029ba506cb3b | https://github.com/disintegration/imaging/blob/061e8a750a4db9667cdf9e2af7f4029ba506cb3b/tools.go#L123-L125 | train |
disintegration/imaging | tools.go | Paste | func Paste(background, img image.Image, pos image.Point) *image.NRGBA {
dst := Clone(background)
pos = pos.Sub(background.Bounds().Min)
pasteRect := image.Rectangle{Min: pos, Max: pos.Add(img.Bounds().Size())}
interRect := pasteRect.Intersect(dst.Bounds())
if interRect.Empty() {
return dst
}
src := newScanner(img)
parallel(interRect.Min.Y, interRect.Max.Y, func(ys <-chan int) {
for y := range ys {
x1 := interRect.Min.X - pasteRect.Min.X
x2 := interRect.Max.X - pasteRect.Min.X
y1 := y - pasteRect.Min.Y
y2 := y1 + 1
i1 := y*dst.Stride + interRect.Min.X*4
i2 := i1 + interRect.Dx()*4
src.scan(x1, y1, x2, y2, dst.Pix[i1:i2])
}
})
return dst
} | go | func Paste(background, img image.Image, pos image.Point) *image.NRGBA {
dst := Clone(background)
pos = pos.Sub(background.Bounds().Min)
pasteRect := image.Rectangle{Min: pos, Max: pos.Add(img.Bounds().Size())}
interRect := pasteRect.Intersect(dst.Bounds())
if interRect.Empty() {
return dst
}
src := newScanner(img)
parallel(interRect.Min.Y, interRect.Max.Y, func(ys <-chan int) {
for y := range ys {
x1 := interRect.Min.X - pasteRect.Min.X
x2 := interRect.Max.X - pasteRect.Min.X
y1 := y - pasteRect.Min.Y
y2 := y1 + 1
i1 := y*dst.Stride + interRect.Min.X*4
i2 := i1 + interRect.Dx()*4
src.scan(x1, y1, x2, y2, dst.Pix[i1:i2])
}
})
return dst
} | [
"func",
"Paste",
"(",
"background",
",",
"img",
"image",
".",
"Image",
",",
"pos",
"image",
".",
"Point",
")",
"*",
"image",
".",
"NRGBA",
"{",
"dst",
":=",
"Clone",
"(",
"background",
")",
"\n",
"pos",
"=",
"pos",
".",
"Sub",
"(",
"background",
".",
"Bounds",
"(",
")",
".",
"Min",
")",
"\n",
"pasteRect",
":=",
"image",
".",
"Rectangle",
"{",
"Min",
":",
"pos",
",",
"Max",
":",
"pos",
".",
"Add",
"(",
"img",
".",
"Bounds",
"(",
")",
".",
"Size",
"(",
")",
")",
"}",
"\n",
"interRect",
":=",
"pasteRect",
".",
"Intersect",
"(",
"dst",
".",
"Bounds",
"(",
")",
")",
"\n",
"if",
"interRect",
".",
"Empty",
"(",
")",
"{",
"return",
"dst",
"\n",
"}",
"\n",
"src",
":=",
"newScanner",
"(",
"img",
")",
"\n",
"parallel",
"(",
"interRect",
".",
"Min",
".",
"Y",
",",
"interRect",
".",
"Max",
".",
"Y",
",",
"func",
"(",
"ys",
"<-",
"chan",
"int",
")",
"{",
"for",
"y",
":=",
"range",
"ys",
"{",
"x1",
":=",
"interRect",
".",
"Min",
".",
"X",
"-",
"pasteRect",
".",
"Min",
".",
"X",
"\n",
"x2",
":=",
"interRect",
".",
"Max",
".",
"X",
"-",
"pasteRect",
".",
"Min",
".",
"X",
"\n",
"y1",
":=",
"y",
"-",
"pasteRect",
".",
"Min",
".",
"Y",
"\n",
"y2",
":=",
"y1",
"+",
"1",
"\n",
"i1",
":=",
"y",
"*",
"dst",
".",
"Stride",
"+",
"interRect",
".",
"Min",
".",
"X",
"*",
"4",
"\n",
"i2",
":=",
"i1",
"+",
"interRect",
".",
"Dx",
"(",
")",
"*",
"4",
"\n",
"src",
".",
"scan",
"(",
"x1",
",",
"y1",
",",
"x2",
",",
"y2",
",",
"dst",
".",
"Pix",
"[",
"i1",
":",
"i2",
"]",
")",
"\n",
"}",
"\n",
"}",
")",
"\n",
"return",
"dst",
"\n",
"}"
] | // Paste pastes the img image to the background image at the specified position and returns the combined image. | [
"Paste",
"pastes",
"the",
"img",
"image",
"to",
"the",
"background",
"image",
"at",
"the",
"specified",
"position",
"and",
"returns",
"the",
"combined",
"image",
"."
] | 061e8a750a4db9667cdf9e2af7f4029ba506cb3b | https://github.com/disintegration/imaging/blob/061e8a750a4db9667cdf9e2af7f4029ba506cb3b/tools.go#L128-L149 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.