repo stringlengths 5 67 | path stringlengths 4 218 | func_name stringlengths 0 151 | original_string stringlengths 52 373k | language stringclasses 6 values | code stringlengths 52 373k | code_tokens listlengths 10 512 | docstring stringlengths 3 47.2k | docstring_tokens listlengths 3 234 | sha stringlengths 40 40 | url stringlengths 85 339 | partition stringclasses 3 values |
|---|---|---|---|---|---|---|---|---|---|---|---|
dropbox/godropbox | lockstore/map.go | NewLockingMap | func NewLockingMap(options LockingMapOptions) LockingMap {
return &lockingMap{
lock: &sync.RWMutex{},
keyLocker: New(options.LockStoreOptions),
data: make(map[string]interface{}),
checkFunc: options.ValueCheckFunc,
}
} | go | func NewLockingMap(options LockingMapOptions) LockingMap {
return &lockingMap{
lock: &sync.RWMutex{},
keyLocker: New(options.LockStoreOptions),
data: make(map[string]interface{}),
checkFunc: options.ValueCheckFunc,
}
} | [
"func",
"NewLockingMap",
"(",
"options",
"LockingMapOptions",
")",
"LockingMap",
"{",
"return",
"&",
"lockingMap",
"{",
"lock",
":",
"&",
"sync",
".",
"RWMutex",
"{",
"}",
",",
"keyLocker",
":",
"New",
"(",
"options",
".",
"LockStoreOptions",
")",
",",
"data",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
",",
"checkFunc",
":",
"options",
".",
"ValueCheckFunc",
",",
"}",
"\n",
"}"
] | // NewLockingMap returns a new instance of LockingMap | [
"NewLockingMap",
"returns",
"a",
"new",
"instance",
"of",
"LockingMap"
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/lockstore/map.go#L71-L78 | train |
dropbox/godropbox | lockstore/map.go | Get | func (m *lockingMap) Get(key string) (interface{}, bool) {
m.keyLocker.RLock(key)
defer m.keyLocker.RUnlock(key)
m.lock.RLock()
defer m.lock.RUnlock()
val, ok := m.data[key]
if ok && (m.checkFunc == nil || m.checkFunc(key, val)) {
return val, true
} else {
// No value or it failed to check
return nil, false
}
} | go | func (m *lockingMap) Get(key string) (interface{}, bool) {
m.keyLocker.RLock(key)
defer m.keyLocker.RUnlock(key)
m.lock.RLock()
defer m.lock.RUnlock()
val, ok := m.data[key]
if ok && (m.checkFunc == nil || m.checkFunc(key, val)) {
return val, true
} else {
// No value or it failed to check
return nil, false
}
} | [
"func",
"(",
"m",
"*",
"lockingMap",
")",
"Get",
"(",
"key",
"string",
")",
"(",
"interface",
"{",
"}",
",",
"bool",
")",
"{",
"m",
".",
"keyLocker",
".",
"RLock",
"(",
"key",
")",
"\n",
"defer",
"m",
".",
"keyLocker",
".",
"RUnlock",
"(",
"key",
")",
"\n",
"m",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"m",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n",
"val",
",",
"ok",
":=",
"m",
".",
"data",
"[",
"key",
"]",
"\n",
"if",
"ok",
"&&",
"(",
"m",
".",
"checkFunc",
"==",
"nil",
"||",
"m",
".",
"checkFunc",
"(",
"key",
",",
"val",
")",
")",
"{",
"return",
"val",
",",
"true",
"\n",
"}",
"else",
"{",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n",
"}"
] | // Get returns the value, ok for a given key from within the map. If a ValueCheckFunc
// was defined for the map, the value is only returned if that function returns true. | [
"Get",
"returns",
"the",
"value",
"ok",
"for",
"a",
"given",
"key",
"from",
"within",
"the",
"map",
".",
"If",
"a",
"ValueCheckFunc",
"was",
"defined",
"for",
"the",
"map",
"the",
"value",
"is",
"only",
"returned",
"if",
"that",
"function",
"returns",
"true",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/lockstore/map.go#L82-L96 | train |
dropbox/godropbox | lockstore/map.go | Delete | func (m *lockingMap) Delete(key string) {
m.keyLocker.Lock(key)
defer m.keyLocker.Unlock(key)
m.lock.Lock()
defer m.lock.Unlock()
delete(m.data, key)
} | go | func (m *lockingMap) Delete(key string) {
m.keyLocker.Lock(key)
defer m.keyLocker.Unlock(key)
m.lock.Lock()
defer m.lock.Unlock()
delete(m.data, key)
} | [
"func",
"(",
"m",
"*",
"lockingMap",
")",
"Delete",
"(",
"key",
"string",
")",
"{",
"m",
".",
"keyLocker",
".",
"Lock",
"(",
"key",
")",
"\n",
"defer",
"m",
".",
"keyLocker",
".",
"Unlock",
"(",
"key",
")",
"\n",
"m",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"delete",
"(",
"m",
".",
"data",
",",
"key",
")",
"\n",
"}"
] | // Delete removes a key from the map if it exists. Returns nothing. | [
"Delete",
"removes",
"a",
"key",
"from",
"the",
"map",
"if",
"it",
"exists",
".",
"Returns",
"nothing",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/lockstore/map.go#L99-L107 | train |
dropbox/godropbox | net2/managed_connection.go | NewManagedConn | func NewManagedConn(
network string,
address string,
handle resource_pool.ManagedHandle,
pool ConnectionPool,
options ConnectionOptions) ManagedConn {
addr := NetworkAddress{
Network: network,
Address: address,
}
return &managedConnImpl{
addr: addr,
handle: handle,
pool: pool,
options: options,
}
} | go | func NewManagedConn(
network string,
address string,
handle resource_pool.ManagedHandle,
pool ConnectionPool,
options ConnectionOptions) ManagedConn {
addr := NetworkAddress{
Network: network,
Address: address,
}
return &managedConnImpl{
addr: addr,
handle: handle,
pool: pool,
options: options,
}
} | [
"func",
"NewManagedConn",
"(",
"network",
"string",
",",
"address",
"string",
",",
"handle",
"resource_pool",
".",
"ManagedHandle",
",",
"pool",
"ConnectionPool",
",",
"options",
"ConnectionOptions",
")",
"ManagedConn",
"{",
"addr",
":=",
"NetworkAddress",
"{",
"Network",
":",
"network",
",",
"Address",
":",
"address",
",",
"}",
"\n",
"return",
"&",
"managedConnImpl",
"{",
"addr",
":",
"addr",
",",
"handle",
":",
"handle",
",",
"pool",
":",
"pool",
",",
"options",
":",
"options",
",",
"}",
"\n",
"}"
] | // This creates a managed connection wrapper. | [
"This",
"creates",
"a",
"managed",
"connection",
"wrapper",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/net2/managed_connection.go#L51-L69 | train |
dropbox/godropbox | net2/managed_connection.go | RawConn | func (c *managedConnImpl) RawConn() net.Conn {
h, _ := c.handle.Handle()
return h.(net.Conn)
} | go | func (c *managedConnImpl) RawConn() net.Conn {
h, _ := c.handle.Handle()
return h.(net.Conn)
} | [
"func",
"(",
"c",
"*",
"managedConnImpl",
")",
"RawConn",
"(",
")",
"net",
".",
"Conn",
"{",
"h",
",",
"_",
":=",
"c",
".",
"handle",
".",
"Handle",
"(",
")",
"\n",
"return",
"h",
".",
"(",
"net",
".",
"Conn",
")",
"\n",
"}"
] | // See ManagedConn for documentation. | [
"See",
"ManagedConn",
"for",
"documentation",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/net2/managed_connection.go#L77-L80 | train |
dropbox/godropbox | net2/port.go | GetPort | func GetPort(addr net.Addr) (int, error) {
_, lport, err := net.SplitHostPort(addr.String())
if err != nil {
return -1, err
}
lportInt, err := strconv.Atoi(lport)
if err != nil {
return -1, err
}
return lportInt, nil
} | go | func GetPort(addr net.Addr) (int, error) {
_, lport, err := net.SplitHostPort(addr.String())
if err != nil {
return -1, err
}
lportInt, err := strconv.Atoi(lport)
if err != nil {
return -1, err
}
return lportInt, nil
} | [
"func",
"GetPort",
"(",
"addr",
"net",
".",
"Addr",
")",
"(",
"int",
",",
"error",
")",
"{",
"_",
",",
"lport",
",",
"err",
":=",
"net",
".",
"SplitHostPort",
"(",
"addr",
".",
"String",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"err",
"\n",
"}",
"\n",
"lportInt",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"lport",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"err",
"\n",
"}",
"\n",
"return",
"lportInt",
",",
"nil",
"\n",
"}"
] | // Returns the port information. | [
"Returns",
"the",
"port",
"information",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/net2/port.go#L9-L19 | train |
dropbox/godropbox | math2/rand2/rand.go | NewSource | func NewSource(seed int64) rand.Source {
return &lockedSource{
src: rand.NewSource(seed),
}
} | go | func NewSource(seed int64) rand.Source {
return &lockedSource{
src: rand.NewSource(seed),
}
} | [
"func",
"NewSource",
"(",
"seed",
"int64",
")",
"rand",
".",
"Source",
"{",
"return",
"&",
"lockedSource",
"{",
"src",
":",
"rand",
".",
"NewSource",
"(",
"seed",
")",
",",
"}",
"\n",
"}"
] | // This returns a thread-safe random source. | [
"This",
"returns",
"a",
"thread",
"-",
"safe",
"random",
"source",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/math2/rand2/rand.go#L37-L41 | train |
dropbox/godropbox | math2/rand2/rand.go | GetSeed | func GetSeed() int64 {
now := time.Now()
return now.Unix() + int64(now.Nanosecond()) + 12345*int64(os.Getpid())
} | go | func GetSeed() int64 {
now := time.Now()
return now.Unix() + int64(now.Nanosecond()) + 12345*int64(os.Getpid())
} | [
"func",
"GetSeed",
"(",
")",
"int64",
"{",
"now",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"return",
"now",
".",
"Unix",
"(",
")",
"+",
"int64",
"(",
"now",
".",
"Nanosecond",
"(",
")",
")",
"+",
"12345",
"*",
"int64",
"(",
"os",
".",
"Getpid",
"(",
")",
")",
"\n",
"}"
] | // Generates a seed based on the current time and the process ID. | [
"Generates",
"a",
"seed",
"based",
"on",
"the",
"current",
"time",
"and",
"the",
"process",
"ID",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/math2/rand2/rand.go#L44-L47 | train |
dropbox/godropbox | math2/rand2/rand.go | Dur | func Dur(max time.Duration) time.Duration {
return time.Duration(Int63n(int64(max)))
} | go | func Dur(max time.Duration) time.Duration {
return time.Duration(Int63n(int64(max)))
} | [
"func",
"Dur",
"(",
"max",
"time",
".",
"Duration",
")",
"time",
".",
"Duration",
"{",
"return",
"time",
".",
"Duration",
"(",
"Int63n",
"(",
"int64",
"(",
"max",
")",
")",
")",
"\n",
"}"
] | // Dur returns a pseudo-random Duration in [0, max) | [
"Dur",
"returns",
"a",
"pseudo",
"-",
"random",
"Duration",
"in",
"[",
"0",
"max",
")"
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/math2/rand2/rand.go#L101-L103 | train |
dropbox/godropbox | math2/rand2/rand.go | SampleInts | func SampleInts(n int, k int) (res []int, err error) {
if k < 0 {
err = errors.Newf("invalid sample size k")
return
}
if n < k {
err = errors.Newf("sample size k larger than n")
return
}
picked := set.NewSet()
for picked.Len() < k {
i := Intn(n)
picked.Add(i)
}
res = make([]int, k)
e := 0
for i := range picked.Iter() {
res[e] = i.(int)
e++
}
return
} | go | func SampleInts(n int, k int) (res []int, err error) {
if k < 0 {
err = errors.Newf("invalid sample size k")
return
}
if n < k {
err = errors.Newf("sample size k larger than n")
return
}
picked := set.NewSet()
for picked.Len() < k {
i := Intn(n)
picked.Add(i)
}
res = make([]int, k)
e := 0
for i := range picked.Iter() {
res[e] = i.(int)
e++
}
return
} | [
"func",
"SampleInts",
"(",
"n",
"int",
",",
"k",
"int",
")",
"(",
"res",
"[",
"]",
"int",
",",
"err",
"error",
")",
"{",
"if",
"k",
"<",
"0",
"{",
"err",
"=",
"errors",
".",
"Newf",
"(",
"\"invalid sample size k\"",
")",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"n",
"<",
"k",
"{",
"err",
"=",
"errors",
".",
"Newf",
"(",
"\"sample size k larger than n\"",
")",
"\n",
"return",
"\n",
"}",
"\n",
"picked",
":=",
"set",
".",
"NewSet",
"(",
")",
"\n",
"for",
"picked",
".",
"Len",
"(",
")",
"<",
"k",
"{",
"i",
":=",
"Intn",
"(",
"n",
")",
"\n",
"picked",
".",
"Add",
"(",
"i",
")",
"\n",
"}",
"\n",
"res",
"=",
"make",
"(",
"[",
"]",
"int",
",",
"k",
")",
"\n",
"e",
":=",
"0",
"\n",
"for",
"i",
":=",
"range",
"picked",
".",
"Iter",
"(",
")",
"{",
"res",
"[",
"e",
"]",
"=",
"i",
".",
"(",
"int",
")",
"\n",
"e",
"++",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // Samples 'k' unique ints from the range [0, n) | [
"Samples",
"k",
"unique",
"ints",
"from",
"the",
"range",
"[",
"0",
"n",
")"
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/math2/rand2/rand.go#L118-L143 | train |
dropbox/godropbox | math2/rand2/rand.go | Sample | func Sample(population []interface{}, k int) (res []interface{}, err error) {
n := len(population)
idxs, err := SampleInts(n, k)
if err != nil {
return
}
res = []interface{}{}
for _, idx := range idxs {
res = append(res, population[idx])
}
return
} | go | func Sample(population []interface{}, k int) (res []interface{}, err error) {
n := len(population)
idxs, err := SampleInts(n, k)
if err != nil {
return
}
res = []interface{}{}
for _, idx := range idxs {
res = append(res, population[idx])
}
return
} | [
"func",
"Sample",
"(",
"population",
"[",
"]",
"interface",
"{",
"}",
",",
"k",
"int",
")",
"(",
"res",
"[",
"]",
"interface",
"{",
"}",
",",
"err",
"error",
")",
"{",
"n",
":=",
"len",
"(",
"population",
")",
"\n",
"idxs",
",",
"err",
":=",
"SampleInts",
"(",
"n",
",",
"k",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"res",
"=",
"[",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"for",
"_",
",",
"idx",
":=",
"range",
"idxs",
"{",
"res",
"=",
"append",
"(",
"res",
",",
"population",
"[",
"idx",
"]",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // Samples 'k' elements from the given slice | [
"Samples",
"k",
"elements",
"from",
"the",
"given",
"slice"
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/math2/rand2/rand.go#L146-L159 | train |
dropbox/godropbox | math2/rand2/rand.go | PickN | func PickN(population []interface{}, n int) (
picked []interface{}, remaining []interface{}, err error) {
total := len(population)
idxs, err := SampleInts(total, n)
if err != nil {
return
}
sort.Ints(idxs)
picked, remaining = []interface{}{}, []interface{}{}
for x, elem := range population {
if len(idxs) > 0 && x == idxs[0] {
picked = append(picked, elem)
idxs = idxs[1:]
} else {
remaining = append(remaining, elem)
}
}
return
} | go | func PickN(population []interface{}, n int) (
picked []interface{}, remaining []interface{}, err error) {
total := len(population)
idxs, err := SampleInts(total, n)
if err != nil {
return
}
sort.Ints(idxs)
picked, remaining = []interface{}{}, []interface{}{}
for x, elem := range population {
if len(idxs) > 0 && x == idxs[0] {
picked = append(picked, elem)
idxs = idxs[1:]
} else {
remaining = append(remaining, elem)
}
}
return
} | [
"func",
"PickN",
"(",
"population",
"[",
"]",
"interface",
"{",
"}",
",",
"n",
"int",
")",
"(",
"picked",
"[",
"]",
"interface",
"{",
"}",
",",
"remaining",
"[",
"]",
"interface",
"{",
"}",
",",
"err",
"error",
")",
"{",
"total",
":=",
"len",
"(",
"population",
")",
"\n",
"idxs",
",",
"err",
":=",
"SampleInts",
"(",
"total",
",",
"n",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"sort",
".",
"Ints",
"(",
"idxs",
")",
"\n",
"picked",
",",
"remaining",
"=",
"[",
"]",
"interface",
"{",
"}",
"{",
"}",
",",
"[",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"for",
"x",
",",
"elem",
":=",
"range",
"population",
"{",
"if",
"len",
"(",
"idxs",
")",
">",
"0",
"&&",
"x",
"==",
"idxs",
"[",
"0",
"]",
"{",
"picked",
"=",
"append",
"(",
"picked",
",",
"elem",
")",
"\n",
"idxs",
"=",
"idxs",
"[",
"1",
":",
"]",
"\n",
"}",
"else",
"{",
"remaining",
"=",
"append",
"(",
"remaining",
",",
"elem",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // Same as 'Sample' except it returns both the 'picked' sample set and the
// 'remaining' elements. | [
"Same",
"as",
"Sample",
"except",
"it",
"returns",
"both",
"the",
"picked",
"sample",
"set",
"and",
"the",
"remaining",
"elements",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/math2/rand2/rand.go#L163-L184 | train |
dropbox/godropbox | math2/rand2/rand.go | Shuffle | func Shuffle(collection Swapper) {
// Fisher-Yates shuffle.
for i := collection.Len() - 1; i >= 0; i-- {
collection.Swap(i, Intn(i+1))
}
} | go | func Shuffle(collection Swapper) {
// Fisher-Yates shuffle.
for i := collection.Len() - 1; i >= 0; i-- {
collection.Swap(i, Intn(i+1))
}
} | [
"func",
"Shuffle",
"(",
"collection",
"Swapper",
")",
"{",
"for",
"i",
":=",
"collection",
".",
"Len",
"(",
")",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
"{",
"collection",
".",
"Swap",
"(",
"i",
",",
"Intn",
"(",
"i",
"+",
"1",
")",
")",
"\n",
"}",
"\n",
"}"
] | // Randomly shuffles the collection in place. | [
"Randomly",
"shuffles",
"the",
"collection",
"in",
"place",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/math2/rand2/rand.go#L195-L200 | train |
dropbox/godropbox | sync2/semaphore.go | TryAcquire | func (sem *boundedSemaphore) TryAcquire(timeout time.Duration) bool {
if timeout > 0 {
// Wait until we get a slot or timeout expires.
tm := time.NewTimer(timeout)
defer tm.Stop()
select {
case <-sem.slots:
return true
case <-tm.C:
// Timeout expired. In very rare cases this might happen even if
// there is a slot available, e.g. GC pause after we create the timer
// and select randomly picked this one out of the two available channels.
// We should do one final immediate check below.
}
}
// Return true if we have a slot available immediately and false otherwise.
select {
case <-sem.slots:
return true
default:
return false
}
} | go | func (sem *boundedSemaphore) TryAcquire(timeout time.Duration) bool {
if timeout > 0 {
// Wait until we get a slot or timeout expires.
tm := time.NewTimer(timeout)
defer tm.Stop()
select {
case <-sem.slots:
return true
case <-tm.C:
// Timeout expired. In very rare cases this might happen even if
// there is a slot available, e.g. GC pause after we create the timer
// and select randomly picked this one out of the two available channels.
// We should do one final immediate check below.
}
}
// Return true if we have a slot available immediately and false otherwise.
select {
case <-sem.slots:
return true
default:
return false
}
} | [
"func",
"(",
"sem",
"*",
"boundedSemaphore",
")",
"TryAcquire",
"(",
"timeout",
"time",
".",
"Duration",
")",
"bool",
"{",
"if",
"timeout",
">",
"0",
"{",
"tm",
":=",
"time",
".",
"NewTimer",
"(",
"timeout",
")",
"\n",
"defer",
"tm",
".",
"Stop",
"(",
")",
"\n",
"select",
"{",
"case",
"<-",
"sem",
".",
"slots",
":",
"return",
"true",
"\n",
"case",
"<-",
"tm",
".",
"C",
":",
"}",
"\n",
"}",
"\n",
"select",
"{",
"case",
"<-",
"sem",
".",
"slots",
":",
"return",
"true",
"\n",
"default",
":",
"return",
"false",
"\n",
"}",
"\n",
"}"
] | // TryAcquire returns true if it acquires a resource slot within the
// timeout, false otherwise. | [
"TryAcquire",
"returns",
"true",
"if",
"it",
"acquires",
"a",
"resource",
"slot",
"within",
"the",
"timeout",
"false",
"otherwise",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/sync2/semaphore.go#L47-L70 | train |
dropbox/godropbox | database/sqlbuilder/expression.go | Literal | func Literal(v interface{}) Expression {
value, err := sqltypes.BuildValue(v)
if err != nil {
panic(errors.Wrap(err, "Invalid literal value"))
}
return &literalExpression{value: value}
} | go | func Literal(v interface{}) Expression {
value, err := sqltypes.BuildValue(v)
if err != nil {
panic(errors.Wrap(err, "Invalid literal value"))
}
return &literalExpression{value: value}
} | [
"func",
"Literal",
"(",
"v",
"interface",
"{",
"}",
")",
"Expression",
"{",
"value",
",",
"err",
":=",
"sqltypes",
".",
"BuildValue",
"(",
"v",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"Invalid literal value\"",
")",
")",
"\n",
"}",
"\n",
"return",
"&",
"literalExpression",
"{",
"value",
":",
"value",
"}",
"\n",
"}"
] | // Returns an escaped literal string | [
"Returns",
"an",
"escaped",
"literal",
"string"
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/sqlbuilder/expression.go#L368-L374 | train |
dropbox/godropbox | database/sqlbuilder/expression.go | Eq | func Eq(lhs, rhs Expression) BoolExpression {
lit, ok := rhs.(*literalExpression)
if ok && sqltypes.Value(lit.value).IsNull() {
return newBoolExpression(lhs, rhs, []byte(" IS "))
}
return newBoolExpression(lhs, rhs, []byte("="))
} | go | func Eq(lhs, rhs Expression) BoolExpression {
lit, ok := rhs.(*literalExpression)
if ok && sqltypes.Value(lit.value).IsNull() {
return newBoolExpression(lhs, rhs, []byte(" IS "))
}
return newBoolExpression(lhs, rhs, []byte("="))
} | [
"func",
"Eq",
"(",
"lhs",
",",
"rhs",
"Expression",
")",
"BoolExpression",
"{",
"lit",
",",
"ok",
":=",
"rhs",
".",
"(",
"*",
"literalExpression",
")",
"\n",
"if",
"ok",
"&&",
"sqltypes",
".",
"Value",
"(",
"lit",
".",
"value",
")",
".",
"IsNull",
"(",
")",
"{",
"return",
"newBoolExpression",
"(",
"lhs",
",",
"rhs",
",",
"[",
"]",
"byte",
"(",
"\" IS \"",
")",
")",
"\n",
"}",
"\n",
"return",
"newBoolExpression",
"(",
"lhs",
",",
"rhs",
",",
"[",
"]",
"byte",
"(",
"\"=\"",
")",
")",
"\n",
"}"
] | // Returns a representation of "a=b" | [
"Returns",
"a",
"representation",
"of",
"a",
"=",
"b"
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/sqlbuilder/expression.go#L441-L447 | train |
dropbox/godropbox | database/sqlbuilder/expression.go | Lt | func Lt(lhs Expression, rhs Expression) BoolExpression {
return newBoolExpression(lhs, rhs, []byte("<"))
} | go | func Lt(lhs Expression, rhs Expression) BoolExpression {
return newBoolExpression(lhs, rhs, []byte("<"))
} | [
"func",
"Lt",
"(",
"lhs",
"Expression",
",",
"rhs",
"Expression",
")",
"BoolExpression",
"{",
"return",
"newBoolExpression",
"(",
"lhs",
",",
"rhs",
",",
"[",
"]",
"byte",
"(",
"\"<\"",
")",
")",
"\n",
"}"
] | // Returns a representation of "a<b" | [
"Returns",
"a",
"representation",
"of",
"a<b"
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/sqlbuilder/expression.go#L469-L471 | train |
dropbox/godropbox | memcache/raw_ascii_client.go | NewRawAsciiClient | func NewRawAsciiClient(shard int, channel io.ReadWriter) ClientShard {
return &RawAsciiClient{
shard: shard,
channel: channel,
validState: true,
writer: bufio.NewWriter(channel),
reader: bufio.NewReader(channel),
}
} | go | func NewRawAsciiClient(shard int, channel io.ReadWriter) ClientShard {
return &RawAsciiClient{
shard: shard,
channel: channel,
validState: true,
writer: bufio.NewWriter(channel),
reader: bufio.NewReader(channel),
}
} | [
"func",
"NewRawAsciiClient",
"(",
"shard",
"int",
",",
"channel",
"io",
".",
"ReadWriter",
")",
"ClientShard",
"{",
"return",
"&",
"RawAsciiClient",
"{",
"shard",
":",
"shard",
",",
"channel",
":",
"channel",
",",
"validState",
":",
"true",
",",
"writer",
":",
"bufio",
".",
"NewWriter",
"(",
"channel",
")",
",",
"reader",
":",
"bufio",
".",
"NewReader",
"(",
"channel",
")",
",",
"}",
"\n",
"}"
] | // This creates a new memcache RawAsciiClient. | [
"This",
"creates",
"a",
"new",
"memcache",
"RawAsciiClient",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/raw_ascii_client.go#L30-L38 | train |
dropbox/godropbox | sync2/boundedrwlock.go | NewBoundedRWLock | func NewBoundedRWLock(capacity int) *BoundedRWLock {
return &BoundedRWLock{
waiters: make(chan *rwwait, capacity),
control: &sync.Mutex{},
}
} | go | func NewBoundedRWLock(capacity int) *BoundedRWLock {
return &BoundedRWLock{
waiters: make(chan *rwwait, capacity),
control: &sync.Mutex{},
}
} | [
"func",
"NewBoundedRWLock",
"(",
"capacity",
"int",
")",
"*",
"BoundedRWLock",
"{",
"return",
"&",
"BoundedRWLock",
"{",
"waiters",
":",
"make",
"(",
"chan",
"*",
"rwwait",
",",
"capacity",
")",
",",
"control",
":",
"&",
"sync",
".",
"Mutex",
"{",
"}",
",",
"}",
"\n",
"}"
] | // Create a new BoundedRWLock with the given capacity.
//
// RLocks or WLocks beyond this capacity will fail fast with an error. | [
"Create",
"a",
"new",
"BoundedRWLock",
"with",
"the",
"given",
"capacity",
".",
"RLocks",
"or",
"WLocks",
"beyond",
"this",
"capacity",
"will",
"fail",
"fast",
"with",
"an",
"error",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/sync2/boundedrwlock.go#L32-L37 | train |
dropbox/godropbox | sync2/boundedrwlock.go | RLock | func (rw *BoundedRWLock) RLock(timeout time.Duration) (err error) {
deadline := time.After(timeout)
rw.control.Lock()
if rw.nextWriter != nil {
me := newWait(false)
select {
case rw.waiters <- me:
default:
err = errors.New("Waiter capacity reached in RLock")
}
rw.control.Unlock()
if err != nil {
return
}
woken := me.WaitAtomic(deadline)
if !woken {
return errors.New("Waiter timeout")
}
} else {
rw.readers++
rw.control.Unlock()
}
return
} | go | func (rw *BoundedRWLock) RLock(timeout time.Duration) (err error) {
deadline := time.After(timeout)
rw.control.Lock()
if rw.nextWriter != nil {
me := newWait(false)
select {
case rw.waiters <- me:
default:
err = errors.New("Waiter capacity reached in RLock")
}
rw.control.Unlock()
if err != nil {
return
}
woken := me.WaitAtomic(deadline)
if !woken {
return errors.New("Waiter timeout")
}
} else {
rw.readers++
rw.control.Unlock()
}
return
} | [
"func",
"(",
"rw",
"*",
"BoundedRWLock",
")",
"RLock",
"(",
"timeout",
"time",
".",
"Duration",
")",
"(",
"err",
"error",
")",
"{",
"deadline",
":=",
"time",
".",
"After",
"(",
"timeout",
")",
"\n",
"rw",
".",
"control",
".",
"Lock",
"(",
")",
"\n",
"if",
"rw",
".",
"nextWriter",
"!=",
"nil",
"{",
"me",
":=",
"newWait",
"(",
"false",
")",
"\n",
"select",
"{",
"case",
"rw",
".",
"waiters",
"<-",
"me",
":",
"default",
":",
"err",
"=",
"errors",
".",
"New",
"(",
"\"Waiter capacity reached in RLock\"",
")",
"\n",
"}",
"\n",
"rw",
".",
"control",
".",
"Unlock",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"woken",
":=",
"me",
".",
"WaitAtomic",
"(",
"deadline",
")",
"\n",
"if",
"!",
"woken",
"{",
"return",
"errors",
".",
"New",
"(",
"\"Waiter timeout\"",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"rw",
".",
"readers",
"++",
"\n",
"rw",
".",
"control",
".",
"Unlock",
"(",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // Wait for a read lock for up to 'timeout'.
//
// Error will be non-nil on timeout or when the wait list is at capacity. | [
"Wait",
"for",
"a",
"read",
"lock",
"for",
"up",
"to",
"timeout",
".",
"Error",
"will",
"be",
"non",
"-",
"nil",
"on",
"timeout",
"or",
"when",
"the",
"wait",
"list",
"is",
"at",
"capacity",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/sync2/boundedrwlock.go#L42-L66 | train |
dropbox/godropbox | sync2/boundedrwlock.go | WLock | func (rw *BoundedRWLock) WLock(timeout time.Duration) (err error) {
deadline := time.After(timeout)
rw.control.Lock()
if rw.readers != 0 || rw.nextWriter != nil {
me := newWait(true)
if rw.nextWriter == nil {
rw.nextWriter = me
} else {
select {
case rw.waiters <- me:
default:
err = errors.New("Waiter capacity reached in WLock")
}
}
rw.control.Unlock()
if err != nil {
return
}
woken := me.WaitAtomic(deadline)
if !woken {
return errors.New("Waiter timeout")
}
rw.control.Lock()
if rw.readers != 0 {
panic("readers??")
}
if rw.nextWriter != me {
panic("not me??")
}
} else {
rw.nextWriter = newWait(true)
}
rw.control.Unlock()
return
} | go | func (rw *BoundedRWLock) WLock(timeout time.Duration) (err error) {
deadline := time.After(timeout)
rw.control.Lock()
if rw.readers != 0 || rw.nextWriter != nil {
me := newWait(true)
if rw.nextWriter == nil {
rw.nextWriter = me
} else {
select {
case rw.waiters <- me:
default:
err = errors.New("Waiter capacity reached in WLock")
}
}
rw.control.Unlock()
if err != nil {
return
}
woken := me.WaitAtomic(deadline)
if !woken {
return errors.New("Waiter timeout")
}
rw.control.Lock()
if rw.readers != 0 {
panic("readers??")
}
if rw.nextWriter != me {
panic("not me??")
}
} else {
rw.nextWriter = newWait(true)
}
rw.control.Unlock()
return
} | [
"func",
"(",
"rw",
"*",
"BoundedRWLock",
")",
"WLock",
"(",
"timeout",
"time",
".",
"Duration",
")",
"(",
"err",
"error",
")",
"{",
"deadline",
":=",
"time",
".",
"After",
"(",
"timeout",
")",
"\n",
"rw",
".",
"control",
".",
"Lock",
"(",
")",
"\n",
"if",
"rw",
".",
"readers",
"!=",
"0",
"||",
"rw",
".",
"nextWriter",
"!=",
"nil",
"{",
"me",
":=",
"newWait",
"(",
"true",
")",
"\n",
"if",
"rw",
".",
"nextWriter",
"==",
"nil",
"{",
"rw",
".",
"nextWriter",
"=",
"me",
"\n",
"}",
"else",
"{",
"select",
"{",
"case",
"rw",
".",
"waiters",
"<-",
"me",
":",
"default",
":",
"err",
"=",
"errors",
".",
"New",
"(",
"\"Waiter capacity reached in WLock\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"rw",
".",
"control",
".",
"Unlock",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"woken",
":=",
"me",
".",
"WaitAtomic",
"(",
"deadline",
")",
"\n",
"if",
"!",
"woken",
"{",
"return",
"errors",
".",
"New",
"(",
"\"Waiter timeout\"",
")",
"\n",
"}",
"\n",
"rw",
".",
"control",
".",
"Lock",
"(",
")",
"\n",
"if",
"rw",
".",
"readers",
"!=",
"0",
"{",
"panic",
"(",
"\"readers??\"",
")",
"\n",
"}",
"\n",
"if",
"rw",
".",
"nextWriter",
"!=",
"me",
"{",
"panic",
"(",
"\"not me??\"",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"rw",
".",
"nextWriter",
"=",
"newWait",
"(",
"true",
")",
"\n",
"}",
"\n",
"rw",
".",
"control",
".",
"Unlock",
"(",
")",
"\n",
"return",
"\n",
"}"
] | // Lock for writing, waiting up to 'timeout' for successful exclusive
// acquisition of the lock. | [
"Lock",
"for",
"writing",
"waiting",
"up",
"to",
"timeout",
"for",
"successful",
"exclusive",
"acquisition",
"of",
"the",
"lock",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/sync2/boundedrwlock.go#L83-L118 | train |
dropbox/godropbox | sync2/boundedrwlock.go | WaitAtomic | func (wait *rwwait) WaitAtomic(after <-chan time.Time) bool {
select {
case <-wait.wake:
return true
case <-after:
}
swapped := atomic.CompareAndSwapInt32(&wait.alive, 1, 0)
// They're gonna put it.
if !swapped {
<-wait.wake
return true
}
return false
} | go | func (wait *rwwait) WaitAtomic(after <-chan time.Time) bool {
select {
case <-wait.wake:
return true
case <-after:
}
swapped := atomic.CompareAndSwapInt32(&wait.alive, 1, 0)
// They're gonna put it.
if !swapped {
<-wait.wake
return true
}
return false
} | [
"func",
"(",
"wait",
"*",
"rwwait",
")",
"WaitAtomic",
"(",
"after",
"<-",
"chan",
"time",
".",
"Time",
")",
"bool",
"{",
"select",
"{",
"case",
"<-",
"wait",
".",
"wake",
":",
"return",
"true",
"\n",
"case",
"<-",
"after",
":",
"}",
"\n",
"swapped",
":=",
"atomic",
".",
"CompareAndSwapInt32",
"(",
"&",
"wait",
".",
"alive",
",",
"1",
",",
"0",
")",
"\n",
"if",
"!",
"swapped",
"{",
"<-",
"wait",
".",
"wake",
"\n",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // Wait for a signal on the waiter, with the guarantee that both goroutines
// will agree on whether or not the signal was delivered.
//
// Returns true if the wake occurred, false on timeout. | [
"Wait",
"for",
"a",
"signal",
"on",
"the",
"waiter",
"with",
"the",
"guarantee",
"that",
"both",
"goroutines",
"will",
"agree",
"on",
"whether",
"or",
"not",
"the",
"signal",
"was",
"delivered",
".",
"Returns",
"true",
"if",
"the",
"wake",
"occurred",
"false",
"on",
"timeout",
"."
] | 5749d3b71cbefd8eacc316df3f0a6fcb9991bb51 | https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/sync2/boundedrwlock.go#L191-L204 | train |
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",
"{",
"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",
"_",
",",
"err",
":=",
"readLittleEndian",
"(",
"raw",
".",
"VariableLengthData",
"(",
")",
",",
"&",
"xe",
".",
"xid",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"raw",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"Failed to read xid\"",
")",
"\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",
"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",
"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",
"if",
"c",
".",
"forceFailEverything",
"{",
"return",
"NewMutateResponse",
"(",
"key",
",",
"StatusInternalError",
",",
"0",
")",
"\n",
"}",
"\n",
"_",
",",
"ok",
":=",
"c",
".",
"data",
"[",
"key",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"NewMutateResponse",
"(",
"key",
",",
"StatusKeyNotFound",
",",
"0",
")",
"\n",
"}",
"\n",
"delete",
"(",
"c",
".",
"data",
",",
"key",
")",
"\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",
"(",
"\"Append not implemented\"",
")",
")",
"\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",
"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",
"(",
"\"Stat not implemented\"",
")",
",",
"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",
"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",
"(",
"\"Invalid database name specified\"",
")",
"\n",
"}",
"\n",
"buf",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n",
"_",
",",
"_",
"=",
"buf",
".",
"WriteString",
"(",
"\"SELECT \"",
")",
"\n",
"if",
"err",
"=",
"writeComment",
"(",
"q",
".",
"comment",
",",
"buf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"q",
".",
"distinct",
"{",
"_",
",",
"_",
"=",
"buf",
".",
"WriteString",
"(",
"\"DISTINCT \"",
")",
"\n",
"}",
"\n",
"if",
"q",
".",
"projections",
"==",
"nil",
"||",
"len",
"(",
"q",
".",
"projections",
")",
"==",
"0",
"{",
"return",
"\"\"",
",",
"errors",
".",
"Newf",
"(",
"\"No column selected. Generated sql: %s\"",
",",
"buf",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"for",
"i",
",",
"col",
":=",
"range",
"q",
".",
"projections",
"{",
"if",
"i",
">",
"0",
"{",
"_",
"=",
"buf",
".",
"WriteByte",
"(",
"','",
")",
"\n",
"}",
"\n",
"if",
"col",
"==",
"nil",
"{",
"return",
"\"\"",
",",
"errors",
".",
"Newf",
"(",
"\"nil column selected. Generated sql: %s\"",
",",
"buf",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"if",
"err",
"=",
"col",
".",
"SerializeSqlForColumnList",
"(",
"buf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"_",
",",
"_",
"=",
"buf",
".",
"WriteString",
"(",
"\" FROM \"",
")",
"\n",
"if",
"q",
".",
"table",
"==",
"nil",
"{",
"return",
"\"\"",
",",
"errors",
".",
"Newf",
"(",
"\"nil table. Generated sql: %s\"",
",",
"buf",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"if",
"err",
"=",
"q",
".",
"table",
".",
"SerializeSql",
"(",
"database",
",",
"buf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"q",
".",
"where",
"!=",
"nil",
"{",
"_",
",",
"_",
"=",
"buf",
".",
"WriteString",
"(",
"\" WHERE \"",
")",
"\n",
"if",
"err",
"=",
"q",
".",
"where",
".",
"SerializeSql",
"(",
"buf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"q",
".",
"group",
"!=",
"nil",
"{",
"_",
",",
"_",
"=",
"buf",
".",
"WriteString",
"(",
"\" GROUP BY \"",
")",
"\n",
"if",
"err",
"=",
"q",
".",
"group",
".",
"SerializeSql",
"(",
"buf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"q",
".",
"order",
"!=",
"nil",
"{",
"_",
",",
"_",
"=",
"buf",
".",
"WriteString",
"(",
"\" ORDER BY \"",
")",
"\n",
"if",
"err",
"=",
"q",
".",
"order",
".",
"SerializeSql",
"(",
"buf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"q",
".",
"limit",
">=",
"0",
"{",
"if",
"q",
".",
"offset",
">=",
"0",
"{",
"_",
",",
"_",
"=",
"buf",
".",
"WriteString",
"(",
"fmt",
".",
"Sprintf",
"(",
"\" LIMIT %d, %d\"",
",",
"q",
".",
"offset",
",",
"q",
".",
"limit",
")",
")",
"\n",
"}",
"else",
"{",
"_",
",",
"_",
"=",
"buf",
".",
"WriteString",
"(",
"fmt",
".",
"Sprintf",
"(",
"\" LIMIT %d\"",
",",
"q",
".",
"limit",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"q",
".",
"forUpdate",
"{",
"_",
",",
"_",
"=",
"buf",
".",
"WriteString",
"(",
"\" FOR UPDATE\"",
")",
"\n",
"}",
"else",
"if",
"q",
".",
"withSharedLock",
"{",
"_",
",",
"_",
"=",
"buf",
".",
"WriteString",
"(",
"\" LOCK IN SHARE MODE\"",
")",
"\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",
"if",
"len",
"(",
"raw",
".",
"VariableLengthData",
"(",
")",
")",
">",
"0",
"{",
"return",
"raw",
",",
"errors",
".",
"New",
"(",
"\"GTID binlog event larger than expected size\"",
")",
"\n",
"}",
"\n",
"data",
":=",
"raw",
".",
"FixedLengthData",
"(",
")",
"\n",
"var",
"commitData",
"uint8",
"\n",
"data",
",",
"err",
":=",
"readLittleEndian",
"(",
"data",
",",
"&",
"commitData",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"raw",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"Failed to read commit flag\"",
")",
"\n",
"}",
"\n",
"if",
"commitData",
"==",
"0",
"{",
"gle",
".",
"commit",
"=",
"false",
"\n",
"}",
"else",
"if",
"commitData",
"==",
"1",
"{",
"gle",
".",
"commit",
"=",
"true",
"\n",
"}",
"else",
"{",
"return",
"raw",
",",
"errors",
".",
"Newf",
"(",
"\"Commit data is not 0 or 1: %d\"",
",",
"commitData",
")",
"\n",
"}",
"\n",
"data",
",",
"err",
"=",
"readLittleEndian",
"(",
"data",
",",
"&",
"gle",
".",
"sid",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"raw",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"Failed to read sid\"",
")",
"\n",
"}",
"\n",
"data",
",",
"err",
"=",
"readLittleEndian",
"(",
"data",
",",
"&",
"gle",
".",
"gno",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"raw",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"Failed to read GNO\"",
")",
"\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",
"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",
"b",
",",
"err",
":=",
"reader",
".",
"ReadByte",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"typ",
":=",
"ValueType",
"(",
"b",
")",
"\n",
"if",
"typ",
"==",
"NullType",
"{",
"*",
"v",
"=",
"Value",
"{",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"length",
",",
"err",
":=",
"binary",
".",
"ReadUvarint",
"(",
"reader",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"raw",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"length",
")",
"\n",
"n",
",",
"err",
":=",
"reader",
".",
"Read",
"(",
"raw",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"uint64",
"(",
"n",
")",
"!=",
"length",
"{",
"return",
"errors",
".",
"Newf",
"(",
"\"Not enough bytes to read Value\"",
")",
"\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",
"(",
"\"Unknown type %d\"",
",",
"int",
"(",
"typ",
")",
")",
"\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",
"(",
"\"# of row entries %d does not match # of destinations %d\"",
",",
"len",
"(",
"row",
")",
",",
"len",
"(",
"dest",
")",
")",
"\n",
"}",
"\n",
"if",
"row",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"row",
")",
";",
"i",
"++",
"{",
"if",
"row",
"[",
"i",
"]",
".",
"IsNull",
"(",
")",
"{",
"continue",
"\n",
"}",
"\n",
"err",
":=",
"ConvertAssign",
"(",
"row",
"[",
"i",
"]",
",",
"dest",
"[",
"i",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\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",
"(",
")",
"{",
"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",
"(",
"\"Attempted to access element outside buffer\"",
")",
"\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",
"if",
"vector",
".",
"bytesLength",
"(",
")",
">",
"len",
"(",
"vector",
".",
"data",
")",
"{",
"vector",
".",
"data",
"=",
"append",
"(",
"vector",
".",
"data",
",",
"0",
")",
"\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",
"{",
"mask",
":=",
"byte",
"(",
"^",
"(",
"1",
"<<",
"byteOffset",
")",
")",
"\n",
"newByte",
"=",
"oldByte",
"&",
"mask",
"\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",
"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",
"oldByte",
":=",
"vector",
".",
"data",
"[",
"byteIndex",
"]",
"\n",
"var",
"newByte",
"byte",
"\n",
"if",
"bit",
"==",
"1",
"{",
"newByte",
"=",
"oldByte",
"|",
"1",
"<<",
"byteOffset",
"\n",
"}",
"else",
"{",
"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",
"if",
"vector",
".",
"bytesLength",
"(",
")",
">",
"len",
"(",
"vector",
".",
"data",
")",
"{",
"vector",
".",
"data",
"=",
"append",
"(",
"vector",
".",
"data",
",",
"0",
")",
"\n",
"}",
"\n",
"byteIndex",
":=",
"uint32",
"(",
"index",
">>",
"3",
")",
"\n",
"byteOffset",
":=",
"uint32",
"(",
"index",
"%",
"8",
")",
"\n",
"var",
"bitToInsert",
"byte",
"\n",
"if",
"bit",
"==",
"1",
"{",
"bitToInsert",
"=",
"1",
"<<",
"byteOffset",
"\n",
"}",
"\n",
"oldByte",
":=",
"vector",
".",
"data",
"[",
"byteIndex",
"]",
"\n",
"leftoverBit",
":=",
"(",
"oldByte",
"&",
"0x80",
")",
">>",
"7",
"\n",
"bottomMask",
":=",
"byte",
"(",
"(",
"1",
"<<",
"byteOffset",
")",
"-",
"1",
")",
"\n",
"topMask",
":=",
"^",
"bottomMask",
"\n",
"top",
":=",
"(",
"oldByte",
"&",
"topMask",
")",
"<<",
"1",
"\n",
"newByte",
":=",
"bitToInsert",
"|",
"(",
"oldByte",
"&",
"bottomMask",
")",
"|",
"top",
"\n",
"vector",
".",
"data",
"[",
"byteIndex",
"]",
"=",
"newByte",
"\n",
"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",
"oldByte",
":=",
"vector",
".",
"data",
"[",
"byteIndex",
"]",
"\n",
"bit",
":=",
"shiftLower",
"(",
"0",
",",
"vector",
".",
"data",
"[",
"byteIndex",
"+",
"1",
":",
"]",
")",
"\n",
"bottomMask",
":=",
"byte",
"(",
"(",
"1",
"<<",
"byteOffset",
")",
"-",
"1",
")",
"\n",
"topMask",
":=",
"byte",
"(",
"^",
"(",
"(",
"1",
"<<",
"(",
"byteOffset",
"+",
"1",
")",
")",
"-",
"1",
")",
")",
"\n",
"newTop",
":=",
"(",
"oldByte",
"&",
"topMask",
")",
">>",
"1",
"|",
"(",
"bit",
"<<",
"7",
")",
"\n",
"newByte",
":=",
"(",
"bottomMask",
"&",
"oldByte",
")",
"|",
"newTop",
"\n",
"vector",
".",
"data",
"[",
"byteIndex",
"]",
"=",
"newByte",
"\n",
"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",
"m",
".",
"rwMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"rwMutex",
".",
"Unlock",
"(",
")",
"\n",
"oldAddrs",
":=",
"set",
".",
"NewSet",
"(",
")",
"\n",
"for",
"_",
",",
"state",
":=",
"range",
"m",
".",
"shardStates",
"{",
"oldAddrs",
".",
"Add",
"(",
"state",
".",
"Address",
")",
"\n",
"}",
"\n",
"for",
"address",
":=",
"range",
"set",
".",
"Subtract",
"(",
"newAddrs",
",",
"oldAddrs",
")",
".",
"Iter",
"(",
")",
"{",
"if",
"err",
":=",
"m",
".",
"pool",
".",
"Register",
"(",
"\"tcp\"",
",",
"address",
".",
"(",
"string",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"m",
".",
"logError",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"address",
":=",
"range",
"set",
".",
"Subtract",
"(",
"oldAddrs",
",",
"newAddrs",
")",
".",
"Iter",
"(",
")",
"{",
"if",
"err",
":=",
"m",
".",
"pool",
".",
"Unregister",
"(",
"\"tcp\"",
",",
"address",
".",
"(",
"string",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"m",
".",
"logError",
"(",
"err",
")",
"\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",
"for",
"_",
",",
"key",
":=",
"range",
"keys",
"{",
"shardId",
":=",
"m",
".",
"getShardId",
"(",
"key",
",",
"numShards",
")",
"\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",
"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",
"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",
"(",
"\"Error encountered in readBuffer:\"",
",",
"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",
"(",
"\"Error encountered in writeBuffer:\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"else",
"if",
"size",
"!=",
"len",
"(",
"buf",
")",
"{",
"panic",
"(",
"errors",
".",
"New",
"(",
"\"Short Write: io.Writer not compliant\"",
")",
")",
"\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",
"(",
"\"nosync: mutex is already locked\"",
")",
"\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",
"(",
"\"sync: negative WaitGroup counter\"",
")",
"\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",
"(",
"\"Date\"",
")",
".",
"New",
"(",
")",
".",
"Call",
"(",
"\"getTime\"",
")",
".",
"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",
"(",
"\"$makeFunc\"",
",",
"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",
"(",
"\"Object\"",
")",
".",
"Call",
"(",
"\"keys\"",
",",
"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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.