id
int32
0
151
idx
stringlengths
8
10
nl_tokens
sequence
pl_tokens
sequence
100
maxmin-101
[ "/", "*", "retrieve", "or", "set", "trackbar", "position" ]
[ "func", "(", "win", "*", "Window", ")", "GetTrackbarPos", "(", "name", "string", ")", "(", "value", ",", "<mask>", "int", ")", "{", "rv", ":=", "C", ".", "cvGetTrackbarPos", "(", "win", ".", "trackbarName", "[", "name", "]", ",", "win", ".", "name_c", ")", "\n", "return", "int", "(", "rv", ")", ",", "win", ".", "trackbarMax", "[", "name", "]", "\n", "}" ]
101
maxmin-102
[ "Update", "the", "min", "and", "max", "fields", "if", "value", "is", "less", "than", "or", "greater", "than", "the", "current", "min", "/", "max", "value", "." ]
[ "func", "(", "histogram", "*", "histogramData", ")", "Update", "(", "value", "int64", ")", "{", "if", "value", ">", "histogram", ".", "<mask>", "{", "histogram", ".", "max", "=", "value", "\n", "}", "\n", "if", "value", "<", "histogram", ".", "min", "{", "histogram", ".", "min", "=", "value", "\n", "}", "\n\n", "histogram", ".", "sum", "+=", "value", "\n", "histogram", ".", "totalCount", "++", "\n\n", "for", "index", ":=", "0", ";", "index", "<=", "len", "(", "histogram", ".", "bins", ")", ";", "index", "++", "{", "// Allocate value in the last buckets if we reached the end of the Bounds array.", "if", "index", "==", "len", "(", "histogram", ".", "bins", ")", "{", "histogram", ".", "countPerBin", "[", "index", "]", "++", "\n", "break", "\n", "}", "\n\n", "// Check if the value should be added to the \"index\" bin", "if", "value", "<", "int64", "(", "histogram", ".", "bins", "[", "index", "]", ")", "{", "histogram", ".", "countPerBin", "[", "index", "]", "++", "\n", "break", "\n", "}", "\n", "}", "\n", "}" ]
102
maxmin-103
[ "ReadUint32", "returns", "a", "uint32", "read", "from", "address", "a", "of", "the", "inferior", "." ]
[ "func", "(", "p", "*", "Process", ")", "ReadUint32", "(", "a", "Address", ")", "uint32", "{", "m", ":=", "p", ".", "findMapping", "(", "a", ")", "\n", "if", "m", "==", "nil", "{", "panic", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "a", ")", ")", "\n", "}", "\n", "b", ":=", "m", ".", "contents", "[", "a", ".", "Sub", "(", "m", ".", "<mask>", ")", ":", "]", "\n", "if", "len", "(", "b", ")", "<", "4", "{", "var", "buf", "[", "4", "]", "byte", "\n", "b", "=", "buf", "[", ":", "]", "\n", "p", ".", "ReadAt", "(", "b", ",", "a", ")", "\n", "}", "\n", "if", "p", ".", "littleEndian", "{", "return", "binary", ".", "LittleEndian", ".", "Uint32", "(", "b", ")", "\n", "}", "\n", "return", "binary", ".", "BigEndian", ".", "Uint32", "(", "b", ")", "\n", "}" ]
103
maxmin-104
[ "NewThrottle", "creates", "a", "new", "throttle", "with", "a", "max", "number", "of", "workers", "." ]
[ "func", "NewThrottle", "(", "<mask>", "int", ")", "*", "Throttle", "{", "return", "&", "Throttle", "{", "ch", ":", "make", "(", "chan", "struct", "{", "}", ",", "max", ")", ",", "errCh", ":", "make", "(", "chan", "error", ",", "max", ")", ",", "}", "\n", "}" ]
104
maxmin-105
[ "ReadUint64", "returns", "a", "uint64", "read", "from", "address", "a", "of", "the", "inferior", "." ]
[ "func", "(", "p", "*", "Process", ")", "ReadUint64", "(", "a", "Address", ")", "uint64", "{", "m", ":=", "p", ".", "findMapping", "(", "a", ")", "\n", "if", "m", "==", "nil", "{", "panic", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "a", ")", ")", "\n", "}", "\n", "b", ":=", "m", ".", "contents", "[", "a", ".", "Sub", "(", "m", ".", "<mask>", ")", ":", "]", "\n", "if", "len", "(", "b", ")", "<", "8", "{", "var", "buf", "[", "8", "]", "byte", "\n", "b", "=", "buf", "[", ":", "]", "\n", "p", ".", "ReadAt", "(", "b", ",", "a", ")", "\n", "}", "\n", "if", "p", ".", "littleEndian", "{", "return", "binary", ".", "LittleEndian", ".", "Uint64", "(", "b", ")", "\n", "}", "\n", "return", "binary", ".", "BigEndian", ".", "Uint64", "(", "b", ")", "\n", "}" ]
105
maxmin-106
[ "add", "records", "that", "PCs", "in", "the", "range", "[", "min", "max", ")", "map", "to", "function", "f", "." ]
[ "func", "(", "t", "*", "funcTab", ")", "add", "(", "<mask>", ",", "max", "core", ".", "Address", ",", "f", "*", "Func", ")", "{", "t", ".", "entries", "=", "append", "(", "t", ".", "entries", ",", "funcTabEntry", "{", "min", ":", "min", ",", "max", ":", "max", ",", "f", ":", "f", "}", ")", "\n", "}" ]
106
maxmin-107
[ "insertStr", "inserts", "s", "into", "ss", "preserving", "sorting", "(", "it", "assumes", "that", "ss", "is", "sorted", ")", ".", "If", "a", "copy", "is", "necessary", "(", "because", "cap", "(", "ss", ")", "is", "too", "small", ")", "only", "does", "one", "copy", "(", "unlike", "append", "(", "append", "(", "ss", "[", ":", "idx", "]", "newS", ")", "ss", "[", "idx", ":", "]", "...", ")", ")", ".", "This", "is", "because", "directory", "nodes", "may", "include", "a", "large", "number", "of", "children", ".", "This", "is", "used", "to", "preserve", "the", "order", "in", "DirectoryNode", ".", "Children", "which", "must", "be", "maintained", "so", "that", "equivalent", "directories", "have", "the", "same", "hash", ".", "Returns", "true", "if", "newS", "was", "added", "to", "ss", "and", "false", "otherwise", "(", "if", "newS", "is", "already", "in", "ss", ")", "." ]
[ "func", "insertStr", "(", "ss", "*", "[", "]", "string", ",", "newS", "string", ")", "bool", "{", "sz", ":=", "cap", "(", "*", "ss", ")", "\n", "idx", ":=", "sort", ".", "SearchStrings", "(", "*", "ss", ",", "newS", ")", "\n", "if", "idx", ">=", "len", "(", "*", "ss", ")", "||", "(", "*", "ss", ")", "[", "idx", "]", "!=", "newS", "{", "// Need to insert new element", "if", "sz", ">=", "(", "len", "(", "*", "ss", ")", "+", "1", ")", "{", "*", "ss", "=", "(", "*", "ss", ")", "[", ":", "len", "(", "*", "ss", ")", "+", "1", "]", "\n", "copy", "(", "(", "*", "ss", ")", "[", "idx", "+", "1", ":", "]", ",", "(", "*", "ss", ")", "[", "idx", ":", "]", ")", "\n", "(", "*", "ss", ")", "[", "idx", "]", "=", "newS", "\n", "}", "else", "{", "// Need to grow ss (i.e. make a copy)", "// - Using a factor (instead of always adding a constant number of", "// elements) ensures amortized constant time for insertions, and keeping", "// it reasonably low avoids wasting too much space. Current value of", "// 1.33 is arbitrary.", "// - If sz is small, grow sz by at least a constant amount (must be >=1,", "// currently 10)", "cap1", ",", "cap2", ":=", "int", "(", "float64", "(", "sz", ")", "*", "1.33", ")", ",", "sz", "+", "10", "\n", "newSs", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "*", "ss", ")", "+", "1", ",", "<mask>", "(", "cap1", ",", "cap2", ")", ")", "\n", "copy", "(", "newSs", ",", "(", "*", "ss", ")", "[", ":", "idx", "]", ")", "\n", "copy", "(", "newSs", "[", "idx", "+", "1", ":", "]", ",", "(", "*", "ss", ")", "[", "idx", ":", "]", ")", "\n", "newSs", "[", "idx", "]", "=", "newS", "\n", "*", "ss", "=", "newSs", "\n", "}", "\n", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}" ]
107
maxmin-108
[ "Return", "the", "min", "/", "max", "frames", "from", "an", "unsorted", "list" ]
[ "func", "minMaxFrame", "(", "frames", "[", "]", "int", ")", "(", "int", ",", "int", ")", "{", "srcframes", ":=", "make", "(", "[", "]", "int", ",", "len", "(", "frames", ")", ",", "len", "(", "frames", ")", ")", "\n", "copy", "(", "srcframes", ",", "frames", ")", "\n", "sort", ".", "Ints", "(", "srcframes", ")", "\n", "<mask>", ",", "max", ":=", "srcframes", "[", "0", "]", ",", "srcframes", "[", "len", "(", "srcframes", ")", "-", "1", "]", "\n", "return", "min", ",", "max", "\n", "}" ]
108
maxmin-109
[ "selectProject", "returns", "the", "user", "-", "selected", "project", "defaulting", "to", "the", "current", "gcloud", "one", "." ]
[ "func", "selectProject", "(", "choice", "string", ")", "(", "string", ",", "error", ")", "{", "fmt", ".", "Print", "(", "\"", "\"", ")", "\n", "who", ",", "err", ":=", "currentAccount", "(", ")", "\n", "if", "err", "!=", "nil", "{", "logrus", ".", "Warn", "(", "\"", "\"", ")", "\n", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "fmt", ".", "Println", "(", "who", ")", "\n\n", "var", "projs", "[", "]", "string", "\n\n", "if", "choice", "==", "\"", "\"", "{", "fmt", ".", "Printf", "(", "\"", "\"", ",", "who", ")", "\n", "fmt", ".", "Println", "(", ")", "\n", "const", "<mask>", "=", "20", "\n", "projs", ",", "err", "=", "projects", "(", "max", ")", "\n", "for", "_", ",", "proj", ":=", "range", "projs", "{", "fmt", ".", "Println", "(", "\"", "\"", ",", "proj", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "if", "len", "(", "projs", ")", "==", "0", "{", "fmt", ".", "Println", "(", "\"", "\"", ")", "\n", "return", "\"", "\"", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "len", "(", "projs", ")", "==", "max", "{", "fmt", ".", "Println", "(", "\"", "\"", ")", "\n", "fmt", ".", "Println", "(", "\"", "\"", ")", "\n", "}", "\n\n", "def", ",", "err", ":=", "currentProject", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "fmt", ".", "Printf", "(", "\"", "\"", ",", "def", ")", "\n", "fmt", ".", "Scanln", "(", "&", "choice", ")", "\n\n", "// use default project", "if", "choice", "==", "\"", "\"", "{", "return", "def", ",", "nil", "\n", "}", "\n", "}", "\n\n", "// is this a project from the list?", "for", "_", ",", "p", ":=", "range", "projs", "{", "if", "p", "==", "choice", "{", "return", "choice", ",", "nil", "\n", "}", "\n", "}", "\n\n", "fmt", ".", "Printf", "(", "\"", "\"", ",", "who", ",", "choice", ")", "\n", "fmt", ".", "Println", "(", ")", "\n\n", "// no, make sure user has access to it", "if", "err", "=", "exec", ".", "Command", "(", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "choice", ")", ".", "Run", "(", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "who", ",", "err", ")", "\n", "}", "\n\n", "return", "choice", ",", "nil", "\n", "}" ]
109
maxmin-110
[ "process", "is", "used", "to", "process", "the", "Mark", "channel", ".", "This", "is", "not", "thread", "-", "safe", "so", "only", "run", "one", "goroutine", "for", "process", ".", "One", "is", "sufficient", "because", "all", "goroutine", "ops", "use", "purely", "memory", "and", "cpu", ".", "Each", "index", "has", "to", "emit", "atleast", "one", "begin", "watermark", "in", "serial", "order", "otherwise", "waiters", "can", "get", "blocked", "idefinitely", ".", "Example", ":", "We", "had", "an", "watermark", "at", "100", "and", "a", "waiter", "at", "101", "if", "no", "watermark", "is", "emitted", "at", "index", "101", "then", "waiter", "would", "get", "stuck", "indefinitely", "as", "it", "can", "t", "decide", "whether", "the", "task", "at", "101", "has", "decided", "not", "to", "emit", "watermark", "or", "it", "didn", "t", "get", "scheduled", "yet", "." ]
[ "func", "(", "w", "*", "WaterMark", ")", "process", "(", "closer", "*", "Closer", ")", "{", "defer", "closer", ".", "Done", "(", ")", "\n\n", "var", "indices", "uint64Heap", "\n", "// pending maps raft proposal index to the number of pending mutations for this proposal.", "pending", ":=", "make", "(", "map", "[", "uint64", "]", "int", ")", "\n", "waiters", ":=", "make", "(", "map", "[", "uint64", "]", "[", "]", "chan", "struct", "{", "}", ")", "\n\n", "heap", ".", "Init", "(", "&", "indices", ")", "\n", "var", "loop", "uint64", "\n\n", "processOne", ":=", "func", "(", "index", "uint64", ",", "done", "bool", ")", "{", "// If not already done, then set. Otherwise, don't undo a done entry.", "prev", ",", "present", ":=", "pending", "[", "index", "]", "\n", "if", "!", "present", "{", "heap", ".", "Push", "(", "&", "indices", ",", "index", ")", "\n", "}", "\n\n", "delta", ":=", "1", "\n", "if", "done", "{", "delta", "=", "-", "1", "\n", "}", "\n", "pending", "[", "index", "]", "=", "prev", "+", "delta", "\n\n", "loop", "++", "\n", "if", "len", "(", "indices", ")", ">", "0", "&&", "loop", "%", "10000", "==", "0", "{", "<mask>", ":=", "indices", "[", "0", "]", "\n", "w", ".", "elog", ".", "Printf", "(", "\"", "\\n", "\"", ",", "w", ".", "Name", ",", "index", ",", "len", "(", "indices", ")", ",", "w", ".", "DoneUntil", "(", ")", ",", "min", ",", "pending", "[", "min", "]", ")", "\n", "}", "\n\n", "// Update mark by going through all indices in order; and checking if they have", "// been done. Stop at the first index, which isn't done.", "doneUntil", ":=", "w", ".", "DoneUntil", "(", ")", "\n", "if", "doneUntil", ">", "index", "{", "AssertTruef", "(", "false", ",", "\"", "\"", ",", "w", ".", "Name", ",", "doneUntil", ",", "index", ")", "\n", "}", "\n\n", "until", ":=", "doneUntil", "\n", "loops", ":=", "0", "\n\n", "for", "len", "(", "indices", ")", ">", "0", "{", "min", ":=", "indices", "[", "0", "]", "\n", "if", "done", ":=", "pending", "[", "min", "]", ";", "done", ">", "0", "{", "break", "// len(indices) will be > 0.", "\n", "}", "\n", "// Even if done is called multiple times causing it to become", "// negative, we should still pop the index.", "heap", ".", "Pop", "(", "&", "indices", ")", "\n", "delete", "(", "pending", ",", "min", ")", "\n", "until", "=", "min", "\n", "loops", "++", "\n", "}", "\n", "for", "i", ":=", "doneUntil", "+", "1", ";", "i", "<=", "until", ";", "i", "++", "{", "toNotify", ":=", "waiters", "[", "i", "]", "\n", "for", "_", ",", "ch", ":=", "range", "toNotify", "{", "close", "(", "ch", ")", "\n", "}", "\n", "delete", "(", "waiters", ",", "i", ")", "// Release the memory back.", "\n", "}", "\n", "if", "until", "!=", "doneUntil", "{", "AssertTrue", "(", "atomic", ".", "CompareAndSwapUint64", "(", "&", "w", ".", "doneUntil", ",", "doneUntil", ",", "until", ")", ")", "\n", "w", ".", "elog", ".", "Printf", "(", "\"", "\\n", "\"", ",", "w", ".", "Name", ",", "until", ",", "loops", ")", "\n", "}", "\n", "}", "\n\n", "for", "{", "select", "{", "case", "<-", "closer", ".", "HasBeenClosed", "(", ")", ":", "return", "\n", "case", "mark", ":=", "<-", "w", ".", "markCh", ":", "if", "mark", ".", "waiter", "!=", "nil", "{", "doneUntil", ":=", "atomic", ".", "LoadUint64", "(", "&", "w", ".", "doneUntil", ")", "\n", "if", "doneUntil", ">=", "mark", ".", "index", "{", "close", "(", "mark", ".", "waiter", ")", "\n", "}", "else", "{", "ws", ",", "ok", ":=", "waiters", "[", "mark", ".", "index", "]", "\n", "if", "!", "ok", "{", "waiters", "[", "mark", ".", "index", "]", "=", "[", "]", "chan", "struct", "{", "}", "{", "mark", ".", "waiter", "}", "\n", "}", "else", "{", "waiters", "[", "mark", ".", "index", "]", "=", "append", "(", "ws", ",", "mark", ".", "waiter", ")", "\n", "}", "\n", "}", "\n", "}", "else", "{", "if", "mark", ".", "index", ">", "0", "{", "processOne", "(", "mark", ".", "index", ",", "mark", ".", "done", ")", "\n", "}", "\n", "for", "_", ",", "index", ":=", "range", "mark", ".", "indices", "{", "processOne", "(", "index", ",", "mark", ".", "done", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "}" ]
110
maxmin-111
[ "RuntimeLiblxcVersionAtLeast", "checks", "if", "the", "system", "s", "liblxc", "matches", "the", "provided", "version", "requirement" ]
[ "func", "RuntimeLiblxcVersionAtLeast", "(", "major", "int", ",", "minor", "int", ",", "micro", "int", ")", "bool", "{", "version", ":=", "golxc", ".", "Version", "(", ")", "\n", "version", "=", "strings", ".", "Replace", "(", "version", ",", "\"", "\"", ",", "\"", "\"", ",", "1", ")", "\n", "parts", ":=", "strings", ".", "Split", "(", "version", ",", "\"", "\"", ")", "\n", "partsLen", ":=", "len", "(", "parts", ")", "\n", "if", "partsLen", "==", "0", "{", "return", "false", "\n", "}", "\n\n", "develParts", ":=", "strings", ".", "Split", "(", "parts", "[", "partsLen", "-", "1", "]", ",", "\"", "\"", ")", "\n", "if", "len", "(", "develParts", ")", "==", "2", "&&", "develParts", "[", "1", "]", "==", "\"", "\"", "{", "return", "true", "\n", "}", "\n\n", "maj", ":=", "-", "1", "\n", "<mask>", ":=", "-", "1", "\n", "mic", ":=", "-", "1", "\n\n", "for", "i", ",", "v", ":=", "range", "parts", "{", "if", "i", ">", "2", "{", "break", "\n", "}", "\n\n", "num", ",", "err", ":=", "strconv", ".", "Atoi", "(", "v", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", "\n", "}", "\n\n", "switch", "i", "{", "case", "0", ":", "maj", "=", "num", "\n", "case", "1", ":", "min", "=", "num", "\n", "case", "2", ":", "mic", "=", "num", "\n", "}", "\n", "}", "\n\n", "/* Major version is greater. */", "if", "maj", ">", "major", "{", "return", "true", "\n", "}", "\n\n", "if", "maj", "<", "major", "{", "return", "false", "\n", "}", "\n\n", "/* Minor number is greater.*/", "if", "min", ">", "minor", "{", "return", "true", "\n", "}", "\n\n", "if", "min", "<", "minor", "{", "return", "false", "\n", "}", "\n\n", "/* Patch number is greater. */", "if", "mic", ">", "micro", "{", "return", "true", "\n", "}", "\n\n", "if", "mic", "<", "micro", "{", "return", "false", "\n", "}", "\n\n", "return", "true", "\n", "}" ]
111
maxmin-112
[ "replicateTo", "is", "a", "helper", "to", "replicate", "()", "used", "to", "replicate", "the", "logs", "up", "to", "a", "given", "last", "index", ".", "If", "the", "follower", "log", "is", "behind", "we", "take", "care", "to", "bring", "them", "up", "to", "date", "." ]
[ "func", "(", "r", "*", "Raft", ")", "replicateTo", "(", "s", "*", "followerReplication", ",", "lastIndex", "uint64", ")", "(", "shouldStop", "bool", ")", "{", "// Create the base request", "var", "req", "AppendEntriesRequest", "\n", "var", "resp", "AppendEntriesResponse", "\n", "var", "start", "time", ".", "Time", "\n", "START", ":", "// Prevent an excessive retry rate on errors", "if", "s", ".", "failures", ">", "0", "{", "select", "{", "case", "<-", "time", ".", "After", "(", "backoff", "(", "failureWait", ",", "s", ".", "failures", ",", "maxFailureScale", ")", ")", ":", "case", "<-", "r", ".", "shutdownCh", ":", "}", "\n", "}", "\n\n", "// Setup the request", "if", "err", ":=", "r", ".", "setupAppendEntries", "(", "s", ",", "&", "req", ",", "s", ".", "nextIndex", ",", "lastIndex", ")", ";", "err", "==", "ErrLogNotFound", "{", "goto", "SEND_SNAP", "\n", "}", "else", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n\n", "// Make the RPC call", "start", "=", "time", ".", "Now", "(", ")", "\n", "if", "err", ":=", "r", ".", "trans", ".", "AppendEntries", "(", "s", ".", "peer", ".", "ID", ",", "s", ".", "peer", ".", "Address", ",", "&", "req", ",", "&", "resp", ")", ";", "err", "!=", "nil", "{", "r", ".", "logger", ".", "Error", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "s", ".", "peer", ",", "err", ")", ")", "\n", "s", ".", "failures", "++", "\n", "return", "\n", "}", "\n", "appendStats", "(", "string", "(", "s", ".", "peer", ".", "ID", ")", ",", "start", ",", "float32", "(", "len", "(", "req", ".", "Entries", ")", ")", ")", "\n\n", "// Check for a newer term, stop running", "if", "resp", ".", "Term", ">", "req", ".", "Term", "{", "r", ".", "handleStaleTerm", "(", "s", ")", "\n", "return", "true", "\n", "}", "\n\n", "// Update the last contact", "s", ".", "setLastContact", "(", ")", "\n\n", "// Update s based on success", "if", "resp", ".", "Success", "{", "// Update our replication state", "updateLastAppended", "(", "s", ",", "&", "req", ")", "\n\n", "// Clear any failures, allow pipelining", "s", ".", "failures", "=", "0", "\n", "s", ".", "allowPipeline", "=", "true", "\n", "}", "else", "{", "s", ".", "nextIndex", "=", "<mask>", "(", "min", "(", "s", ".", "nextIndex", "-", "1", ",", "resp", ".", "LastLog", "+", "1", ")", ",", "1", ")", "\n", "if", "resp", ".", "NoRetryBackoff", "{", "s", ".", "failures", "=", "0", "\n", "}", "else", "{", "s", ".", "failures", "++", "\n", "}", "\n", "r", ".", "logger", ".", "Warn", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "s", ".", "peer", ",", "s", ".", "nextIndex", ")", ")", "\n", "}", "\n\n", "CHECK_MORE", ":", "// Poll the stop channel here in case we are looping and have been asked", "// to stop, or have stepped down as leader. Even for the best effort case", "// where we are asked to replicate to a given index and then shutdown,", "// it's better to not loop in here to send lots of entries to a straggler", "// that's leaving the cluster anyways.", "select", "{", "case", "<-", "s", ".", "stopCh", ":", "return", "true", "\n", "default", ":", "}", "\n\n", "// Check if there are more logs to replicate", "if", "s", ".", "nextIndex", "<=", "lastIndex", "{", "goto", "START", "\n", "}", "\n", "return", "\n\n", "// SEND_SNAP is used when we fail to get a log, usually because the follower", "// is too far behind, and we must ship a snapshot down instead", "SEND_SNAP", ":", "if", "stop", ",", "err", ":=", "r", ".", "sendLatestSnapshot", "(", "s", ")", ";", "stop", "{", "return", "true", "\n", "}", "else", "if", "err", "!=", "nil", "{", "r", ".", "logger", ".", "Error", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "s", ".", "peer", ",", "err", ")", ")", "\n", "return", "\n", "}", "\n\n", "// Check if there is more to replicate", "goto", "CHECK_MORE", "\n", "}" ]
112
maxmin-113
[ "NewPerfDatum", "returns", "a", "PerfDatum", "object", "suitable", "to", "use", "in", "a", "check", "result", ".", "unit", "must", "a", "valid", "Nagios", "unit", "i", ".", "e", ".", "one", "of", "us", "ms", "s", "%", "b", "kb", "mb", "gb", "tb", "c", "or", "the", "empty", "string", ".", "Zero", "to", "four", "thresholds", "may", "be", "supplied", ":", "min", "max", "warn", "and", "crit", ".", "Thresholds", "may", "be", "positive", "infinity", "negative", "infinity", "or", "NaN", "in", "which", "case", "they", "will", "be", "omitted", "in", "check", "output", "." ]
[ "func", "NewPerfDatum", "(", "label", "string", ",", "unit", "string", ",", "value", "float64", ",", "thresholds", "...", "float64", ")", "(", "*", "PerfDatum", ",", "error", ")", "{", "datum", ":=", "new", "(", "PerfDatum", ")", "\n", "datum", ".", "label", "=", "label", "\n", "datum", ".", "value", "=", "value", "\n", "datum", ".", "unit", "=", "unit", "\n", "if", "!", "validUnit", "(", "unit", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "unit", ")", "\n", "}", "\n", "if", "math", ".", "IsInf", "(", "value", ",", "0", ")", "||", "math", ".", "IsNaN", "(", "value", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "value", ")", "\n", "}", "\n", "if", "len", "(", "thresholds", ")", ">=", "1", "{", "datum", ".", "<mask>", "=", "&", "thresholds", "[", "0", "]", "\n", "}", "\n", "if", "len", "(", "thresholds", ")", ">=", "2", "{", "datum", ".", "max", "=", "&", "thresholds", "[", "1", "]", "\n", "}", "\n", "if", "len", "(", "thresholds", ")", ">=", "3", "{", "datum", ".", "warn", "=", "&", "thresholds", "[", "2", "]", "\n", "}", "\n", "if", "len", "(", "thresholds", ")", ">=", "4", "{", "datum", ".", "crit", "=", "&", "thresholds", "[", "3", "]", "\n", "}", "\n", "return", "datum", ",", "nil", "\n", "}" ]
113
maxmin-114
[ "maybeAppend", "returns", "(", "0", "false", ")", "if", "the", "entries", "cannot", "be", "appended", ".", "Otherwise", "it", "returns", "(", "last", "index", "of", "new", "entries", "true", ")", "." ]
[ "func", "(", "l", "*", "raftLog", ")", "maybeAppend", "(", "index", ",", "logTerm", ",", "committed", "uint64", ",", "ents", "...", "pb", ".", "Entry", ")", "(", "lastnewi", "uint64", ",", "ok", "bool", ")", "{", "if", "l", ".", "matchTerm", "(", "index", ",", "logTerm", ")", "{", "lastnewi", "=", "index", "+", "uint64", "(", "len", "(", "ents", ")", ")", "\n", "ci", ":=", "l", ".", "findConflict", "(", "ents", ")", "\n", "switch", "{", "case", "ci", "==", "0", ":", "case", "ci", "<=", "l", ".", "committed", ":", "l", ".", "logger", ".", "Panicf", "(", "\"", "\"", ",", "ci", ",", "l", ".", "committed", ")", "\n", "default", ":", "offset", ":=", "index", "+", "1", "\n", "l", ".", "append", "(", "ents", "[", "ci", "-", "offset", ":", "]", "...", ")", "\n", "}", "\n", "l", ".", "commitTo", "(", "<mask>", "(", "committed", ",", "lastnewi", ")", ")", "\n", "return", "lastnewi", ",", "true", "\n", "}", "\n", "return", "0", ",", "false", "\n", "}" ]
114
maxmin-115
[ "Return", "a", "slice", "of", "w", ".", "RS", "allowing", "the", "start", "and", "stop", "to", "be", "out", "of", "bounds", "." ]
[ "func", "(", "w", "*", "SnowballWord", ")", "slice", "(", "start", ",", "stop", "int", ")", "[", "]", "rune", "{", "startMin", ":=", "0", "\n", "if", "start", "<", "startMin", "{", "start", "=", "startMin", "\n", "}", "\n", "<mask>", ":=", "len", "(", "w", ".", "RS", ")", "-", "1", "\n", "if", "start", ">", "max", "{", "start", "=", "max", "\n", "}", "\n", "if", "stop", ">", "max", "{", "stop", "=", "max", "\n", "}", "\n", "return", "w", ".", "RS", "[", "start", ":", "stop", "]", "\n", "}" ]
115
maxmin-116
[ "All", "the", "Read", "*", "functions", "below", "will", "panic", "if", "something", "goes", "wrong", ".", "ReadAt", "reads", "len", "(", "b", ")", "bytes", "at", "address", "a", "in", "the", "inferior", "and", "stores", "them", "in", "b", "." ]
[ "func", "(", "p", "*", "Process", ")", "ReadAt", "(", "b", "[", "]", "byte", ",", "a", "Address", ")", "{", "for", "{", "m", ":=", "p", ".", "findMapping", "(", "a", ")", "\n", "if", "m", "==", "nil", "{", "panic", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "a", ")", ")", "\n", "}", "\n", "n", ":=", "copy", "(", "b", ",", "m", ".", "contents", "[", "a", ".", "Sub", "(", "m", ".", "<mask>", ")", ":", "]", ")", "\n", "if", "n", "==", "len", "(", "b", ")", "{", "return", "\n", "}", "\n", "// Modify request to get data from the next mapping.", "b", "=", "b", "[", "n", ":", "]", "\n", "a", "=", "a", ".", "Add", "(", "int64", "(", "n", ")", ")", "\n", "}", "\n", "}" ]
116
maxmin-117
[ "sort", "must", "be", "called", "after", "all", "the", "adds", "but", "before", "any", "find", "." ]
[ "func", "(", "t", "*", "funcTab", ")", "sort", "(", ")", "{", "sort", ".", "Slice", "(", "t", ".", "entries", ",", "func", "(", "i", ",", "j", "int", ")", "bool", "{", "return", "t", ".", "entries", "[", "i", "]", ".", "<mask>", "<", "t", ".", "entries", "[", "j", "]", ".", "min", "\n", "}", ")", "\n", "}" ]
117
maxmin-118
[ "ValidateLength", "checks", "whether", "the", "given", "data", "match", "the", "given", "rules", ".", "It", "checks", "if", "the", "value", "has", "more", "or", "equal", "min", "chars", "and", "less", "or", "equal", "max", "chars", ".", "If", "you", "don", "t", "want", "to", "check", "both", "just", "pass", "a", "zero", "value", ":", "ValidateLength", "(", "value", "0", "100", ")", "//", "Checks", "if", "value", "has", "at", "most", "100", "characters", "ValidateLength", "(", "value", "100", "0", ")", "//", "Checks", "if", "value", "has", "at", "least", "100", "characters", "ValidateLength", "(", "value", "20", "100", ")", "//", "Checks", "if", "value", "has", "at", "least", "20", "characters", "and", "at", "most", "100", "characters" ]
[ "func", "ValidateLength", "(", "value", "string", ",", "<mask>", ",", "max", "int", ")", "bool", "{", "l", ":=", "len", "(", "value", ")", "\n", "if", "min", ">", "0", "&&", "l", "<", "min", "{", "return", "false", "\n", "}", "\n", "if", "max", ">", "0", "&&", "l", ">", "max", "{", "return", "false", "\n", "}", "\n", "return", "true", "\n", "}" ]
118
maxmin-119
[ "NewDottedVersion", "returns", "a", "new", "Version", "." ]
[ "func", "NewDottedVersion", "(", "versionString", "string", ")", "(", "*", "DottedVersion", ",", "error", ")", "{", "formatError", ":=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "versionString", ")", "\n", "split", ":=", "strings", ".", "Split", "(", "versionString", ",", "\"", "\"", ")", "\n", "if", "len", "(", "split", ")", "<", "2", "{", "return", "nil", ",", "formatError", "\n", "}", "\n\n", "maj", ",", "err", ":=", "strconv", ".", "Atoi", "(", "split", "[", "0", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "formatError", "\n", "}", "\n\n", "<mask>", ",", "err", ":=", "strconv", ".", "Atoi", "(", "split", "[", "1", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "formatError", "\n", "}", "\n\n", "patch", ":=", "-", "1", "\n", "if", "len", "(", "split", ")", "==", "3", "{", "patch", ",", "err", "=", "strconv", ".", "Atoi", "(", "split", "[", "2", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "formatError", "\n", "}", "\n", "}", "\n\n", "return", "&", "DottedVersion", "{", "Major", ":", "maj", ",", "Minor", ":", "min", ",", "Patch", ":", "patch", ",", "}", ",", "nil", "\n", "}" ]
119
maxmin-120
[ "ParseInt", "parses", "a", "decimanl", "representation", "of", "an", "int64", "from", "b", ".", "The", "function", "is", "equivalent", "to", "calling", "strconv", ".", "ParseInt", "(", "string", "(", "b", ")", "10", "64", ")", "but", "it", "prevents", "Go", "from", "making", "a", "memory", "allocation", "for", "converting", "a", "byte", "slice", "to", "a", "string", "(", "escape", "analysis", "fails", "due", "to", "the", "error", "returned", "by", "strconv", ".", "ParseInt", ")", ".", "Because", "it", "only", "works", "with", "base", "10", "the", "function", "is", "also", "significantly", "faster", "than", "strconv", ".", "ParseInt", "." ]
[ "func", "ParseInt", "(", "b", "[", "]", "byte", ")", "(", "int64", ",", "error", ")", "{", "var", "val", "int64", "\n\n", "if", "len", "(", "b", ")", "==", "0", "{", "return", "0", ",", "errorInvalidUint64", "(", "b", ")", "\n", "}", "\n\n", "if", "b", "[", "0", "]", "==", "'-'", "{", "const", "<mask>", "=", "Int64Min", "\n", "const", "lim", "=", "max", "/", "10", "\n\n", "if", "b", "=", "b", "[", "1", ":", "]", ";", "len", "(", "b", ")", "==", "0", "{", "return", "0", ",", "errorInvalidUint64", "(", "b", ")", "\n", "}", "\n\n", "for", "_", ",", "d", ":=", "range", "b", "{", "if", "!", "(", "d", ">=", "'0'", "&&", "d", "<=", "'9'", ")", "{", "return", "0", ",", "errorInvalidInt64", "(", "b", ")", "\n", "}", "\n\n", "if", "val", "<", "lim", "{", "return", "0", ",", "errorOverflowInt64", "(", "b", ")", "\n", "}", "\n\n", "val", "*=", "10", "\n", "x", ":=", "int64", "(", "d", "-", "'0'", ")", "\n\n", "if", "val", "<", "(", "max", "+", "x", ")", "{", "return", "0", ",", "errorOverflowInt64", "(", "b", ")", "\n", "}", "\n\n", "val", "-=", "x", "\n", "}", "\n", "}", "else", "{", "const", "max", "=", "Int64Max", "\n", "const", "lim", "=", "max", "/", "10", "\n\n", "for", "_", ",", "d", ":=", "range", "b", "{", "if", "!", "(", "d", ">=", "'0'", "&&", "d", "<=", "'9'", ")", "{", "return", "0", ",", "errorInvalidInt64", "(", "b", ")", "\n", "}", "\n", "x", ":=", "int64", "(", "d", "-", "'0'", ")", "\n\n", "if", "val", ">", "lim", "{", "return", "0", ",", "errorOverflowInt64", "(", "b", ")", "\n", "}", "\n\n", "if", "val", "*=", "10", ";", "val", ">", "(", "max", "-", "x", ")", "{", "return", "0", ",", "errorOverflowInt64", "(", "b", ")", "\n", "}", "\n\n", "val", "+=", "x", "\n", "}", "\n", "}", "\n\n", "return", "val", ",", "nil", "\n", "}" ]
120
maxmin-121
[ "Grow", "automatically", "grows", "the", "underlying", "buffer", "so", "that", "it", "can", "hold", "at", "least", "min", "elements" ]
[ "func", "(", "s", "*", "Stack", ")", "Grow", "(", "<mask>", "int", ")", "{", "// Automatically grow the stack to some long-enough length", "if", "min", "<=", "s", ".", "BufferSize", "(", ")", "{", "// we have enough", "return", "\n", "}", "\n\n", "s", ".", "Resize", "(", "calcNewSize", "(", "min", ")", ")", "\n", "}" ]
121
maxmin-122
[ "updateMax", "updates", "the", "maximum", "values", "for", "a", "node", "and", "its", "ancestors" ]
[ "func", "(", "x", "*", "intervalNode", ")", "updateMax", "(", ")", "{", "for", "x", "!=", "nil", "{", "oldmax", ":=", "x", ".", "<mask>", "\n", "max", ":=", "x", ".", "iv", ".", "Ivl", ".", "End", "\n", "if", "x", ".", "left", "!=", "nil", "&&", "x", ".", "left", ".", "max", ".", "Compare", "(", "max", ")", ">", "0", "{", "max", "=", "x", ".", "left", ".", "max", "\n", "}", "\n", "if", "x", ".", "right", "!=", "nil", "&&", "x", ".", "right", ".", "max", ".", "Compare", "(", "max", ")", ">", "0", "{", "max", "=", "x", ".", "right", ".", "max", "\n", "}", "\n", "if", "oldmax", ".", "Compare", "(", "max", ")", "==", "0", "{", "break", "\n", "}", "\n", "x", ".", "max", "=", "max", "\n", "x", "=", "x", ".", "parent", "\n", "}", "\n", "}" ]
122
maxmin-123
[ "Wrap", "builds", "a", "byte", "slice", "from", "strs", "wrapping", "on", "word", "boundaries", "before", "max", "chars" ]
[ "func", "Wrap", "(", "<mask>", "int", ",", "strs", "...", "string", ")", "[", "]", "byte", "{", "input", ":=", "make", "(", "[", "]", "byte", ",", "0", ")", "\n", "output", ":=", "make", "(", "[", "]", "byte", ",", "0", ")", "\n", "for", "_", ",", "s", ":=", "range", "strs", "{", "input", "=", "append", "(", "input", ",", "[", "]", "byte", "(", "s", ")", "...", ")", "\n", "}", "\n", "if", "len", "(", "input", ")", "<", "max", "{", "// Doesn't need to be wrapped", "return", "input", "\n", "}", "\n", "ls", ":=", "-", "1", "// Last seen space index", "\n", "lw", ":=", "-", "1", "// Last written byte index", "\n", "ll", ":=", "0", "// Length of current line", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "input", ")", ";", "i", "++", "{", "ll", "++", "\n", "switch", "input", "[", "i", "]", "{", "case", "' '", ",", "'\\t'", ":", "ls", "=", "i", "\n", "}", "\n", "if", "ll", ">=", "max", "{", "if", "ls", ">=", "0", "{", "output", "=", "append", "(", "output", ",", "input", "[", "lw", "+", "1", ":", "ls", "]", "...", ")", "\n", "output", "=", "append", "(", "output", ",", "'\\r'", ",", "'\\n'", ",", "' '", ")", "\n", "lw", "=", "ls", "// Jump over the space we broke on", "\n", "ll", "=", "1", "// Count leading space above", "\n", "// Rewind", "i", "=", "lw", "+", "1", "\n", "ls", "=", "-", "1", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "append", "(", "output", ",", "input", "[", "lw", "+", "1", ":", "]", "...", ")", "\n", "}" ]
123
maxmin-124
[ "streamClientInterceptor", "returns", "a", "new", "retrying", "stream", "client", "interceptor", "for", "server", "side", "streaming", "calls", ".", "The", "default", "configuration", "of", "the", "interceptor", "is", "to", "not", "retry", "*", "at", "all", "*", ".", "This", "behaviour", "can", "be", "changed", "through", "options", "(", "e", ".", "g", ".", "WithMax", ")", "on", "creation", "of", "the", "interceptor", "or", "on", "call", "(", "through", "grpc", ".", "CallOptions", ")", ".", "Retry", "logic", "is", "available", "*", "only", "for", "ServerStreams", "*", "i", ".", "e", ".", "1", ":", "n", "streams", "as", "the", "internal", "logic", "needs", "to", "buffer", "the", "messages", "sent", "by", "the", "client", ".", "If", "retry", "is", "enabled", "on", "any", "other", "streams", "(", "ClientStreams", "BidiStreams", ")", "the", "retry", "interceptor", "will", "fail", "the", "call", "." ]
[ "func", "(", "c", "*", "Client", ")", "streamClientInterceptor", "(", "logger", "*", "zap", ".", "Logger", ",", "optFuncs", "...", "retryOption", ")", "grpc", ".", "StreamClientInterceptor", "{", "intOpts", ":=", "reuseOrNewWithCallOptions", "(", "defaultOptions", ",", "optFuncs", ")", "\n", "return", "func", "(", "ctx", "context", ".", "Context", ",", "desc", "*", "grpc", ".", "StreamDesc", ",", "cc", "*", "grpc", ".", "ClientConn", ",", "method", "string", ",", "streamer", "grpc", ".", "Streamer", ",", "opts", "...", "grpc", ".", "CallOption", ")", "(", "grpc", ".", "ClientStream", ",", "error", ")", "{", "grpcOpts", ",", "retryOpts", ":=", "filterCallOptions", "(", "opts", ")", "\n", "callOpts", ":=", "reuseOrNewWithCallOptions", "(", "intOpts", ",", "retryOpts", ")", "\n", "// short circuit for simplicity, and avoiding allocations.", "if", "callOpts", ".", "<mask>", "==", "0", "{", "return", "streamer", "(", "ctx", ",", "desc", ",", "cc", ",", "method", ",", "grpcOpts", "...", ")", "\n", "}", "\n", "if", "desc", ".", "ClientStreams", "{", "return", "nil", ",", "grpc", ".", "Errorf", "(", "codes", ".", "Unimplemented", ",", "\"", "\"", ")", "\n", "}", "\n", "newStreamer", ",", "err", ":=", "streamer", "(", "ctx", ",", "desc", ",", "cc", ",", "method", ",", "grpcOpts", "...", ")", "\n", "logger", ".", "Warn", "(", "\"", "\"", ",", "zap", ".", "Error", "(", "err", ")", ")", "\n", "if", "err", "!=", "nil", "{", "// TODO(mwitkow): Maybe dial and transport errors should be retriable?", "return", "nil", ",", "err", "\n", "}", "\n", "retryingStreamer", ":=", "&", "serverStreamingRetryingStream", "{", "client", ":", "c", ",", "ClientStream", ":", "newStreamer", ",", "callOpts", ":", "callOpts", ",", "ctx", ":", "ctx", ",", "streamerCall", ":", "func", "(", "ctx", "context", ".", "Context", ")", "(", "grpc", ".", "ClientStream", ",", "error", ")", "{", "return", "streamer", "(", "ctx", ",", "desc", ",", "cc", ",", "method", ",", "grpcOpts", "...", ")", "\n", "}", ",", "}", "\n", "return", "retryingStreamer", ",", "nil", "\n", "}", "\n", "}" ]
124
maxmin-125
[ "ReadableN", "reports", "whether", "the", "n", "bytes", "starting", "at", "address", "a", "are", "readable", "." ]
[ "func", "(", "p", "*", "Process", ")", "ReadableN", "(", "a", "Address", ",", "n", "int64", ")", "bool", "{", "for", "{", "m", ":=", "p", ".", "findMapping", "(", "a", ")", "\n", "if", "m", "==", "nil", "||", "m", ".", "perm", "&", "Read", "==", "0", "{", "return", "false", "\n", "}", "\n", "c", ":=", "m", ".", "<mask>", ".", "Sub", "(", "a", ")", "\n", "if", "n", "<=", "c", "{", "return", "true", "\n", "}", "\n", "n", "-=", "c", "\n", "a", "=", "a", ".", "Add", "(", "c", ")", "\n", "}", "\n", "}" ]
125
maxmin-126
[ "DeleteRange", "implements", "the", "LogStore", "interface", "." ]
[ "func", "(", "i", "*", "InmemStore", ")", "DeleteRange", "(", "<mask>", ",", "max", "uint64", ")", "error", "{", "i", ".", "l", ".", "Lock", "(", ")", "\n", "defer", "i", ".", "l", ".", "Unlock", "(", ")", "\n", "for", "j", ":=", "min", ";", "j", "<=", "max", ";", "j", "++", "{", "delete", "(", "i", ".", "logs", ",", "j", ")", "\n", "}", "\n", "if", "min", "<=", "i", ".", "lowIndex", "{", "i", ".", "lowIndex", "=", "max", "+", "1", "\n", "}", "\n", "if", "max", ">=", "i", ".", "highIndex", "{", "i", ".", "highIndex", "=", "min", "-", "1", "\n", "}", "\n", "if", "i", ".", "lowIndex", ">", "i", ".", "highIndex", "{", "i", ".", "lowIndex", "=", "0", "\n", "i", ".", "highIndex", "=", "0", "\n", "}", "\n", "return", "nil", "\n", "}" ]
126
maxmin-127
[ "ReadUint8", "returns", "a", "uint8", "read", "from", "address", "a", "of", "the", "inferior", "." ]
[ "func", "(", "p", "*", "Process", ")", "ReadUint8", "(", "a", "Address", ")", "uint8", "{", "m", ":=", "p", ".", "findMapping", "(", "a", ")", "\n", "if", "m", "==", "nil", "{", "panic", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "a", ")", ")", "\n", "}", "\n", "return", "m", ".", "contents", "[", "a", ".", "Sub", "(", "m", ".", "<mask>", ")", "]", "\n", "}" ]
127
maxmin-128
[ "CheckUint64Bounds", "verifies", "that", "v", "is", "smaller", "than", "max", "t", "represents", "the", "original", "type", "of", "v", "." ]
[ "func", "CheckUint64Bounds", "(", "v", "uint64", ",", "<mask>", "uint64", ",", "t", "reflect", ".", "Type", ")", "(", "err", "error", ")", "{", "if", "v", ">", "max", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "v", ",", "max", ",", "t", ")", "\n", "}", "\n", "return", "\n", "}" ]
128
maxmin-129
[ "ReadUint16", "returns", "a", "uint16", "read", "from", "address", "a", "of", "the", "inferior", "." ]
[ "func", "(", "p", "*", "Process", ")", "ReadUint16", "(", "a", "Address", ")", "uint16", "{", "m", ":=", "p", ".", "findMapping", "(", "a", ")", "\n", "if", "m", "==", "nil", "{", "panic", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "a", ")", ")", "\n", "}", "\n", "b", ":=", "m", ".", "contents", "[", "a", ".", "Sub", "(", "m", ".", "<mask>", ")", ":", "]", "\n", "if", "len", "(", "b", ")", "<", "2", "{", "var", "buf", "[", "2", "]", "byte", "\n", "b", "=", "buf", "[", ":", "]", "\n", "p", ".", "ReadAt", "(", "b", ",", "a", ")", "\n", "}", "\n", "if", "p", ".", "littleEndian", "{", "return", "binary", ".", "LittleEndian", ".", "Uint16", "(", "b", ")", "\n", "}", "\n", "return", "binary", ".", "BigEndian", ".", "Uint16", "(", "b", ")", "\n", "}" ]
129
maxmin-130
[ "IsPtr", "reports", "whether", "the", "inferior", "at", "address", "a", "contains", "a", "pointer", "." ]
[ "func", "(", "p", "*", "Process", ")", "IsPtr", "(", "a", "core", ".", "Address", ")", "bool", "{", "h", ":=", "p", ".", "findHeapInfo", "(", "a", ")", "\n", "if", "h", "!=", "nil", "{", "return", "h", ".", "IsPtr", "(", "a", ",", "p", ".", "proc", ".", "PtrSize", "(", ")", ")", "\n", "}", "\n", "for", "_", ",", "m", ":=", "range", "p", ".", "modules", "{", "for", "_", ",", "s", ":=", "range", "[", "2", "]", "string", "{", "\"", "\"", ",", "\"", "\"", "}", "{", "<mask>", ":=", "core", ".", "Address", "(", "m", ".", "r", ".", "Field", "(", "s", ")", ".", "Uintptr", "(", ")", ")", "\n", "max", ":=", "core", ".", "Address", "(", "m", ".", "r", ".", "Field", "(", "\"", "\"", "+", "s", ")", ".", "Uintptr", "(", ")", ")", "\n", "if", "a", "<", "min", "||", "a", ">=", "max", "{", "continue", "\n", "}", "\n", "gc", ":=", "m", ".", "r", ".", "Field", "(", "\"", "\"", "+", "s", "+", "\"", "\"", ")", ".", "Field", "(", "\"", "\"", ")", ".", "Address", "(", ")", "\n", "i", ":=", "a", ".", "Sub", "(", "min", ")", "\n", "return", "p", ".", "proc", ".", "ReadUint8", "(", "gc", ".", "Add", "(", "i", "/", "8", ")", ")", ">>", "uint", "(", "i", "%", "8", ")", "!=", "0", "\n", "}", "\n", "}", "\n", "// Everywhere else can't be a pointer. At least, not a pointer into the Go heap.", "// TODO: stacks?", "// TODO: finalizers?", "return", "false", "\n", "}" ]
130
maxmin-131
[ "Open", "explicitly", "tells", "the", "encoder", "to", "start", "the", "stream", "setting", "the", "number", "of", "values", "to", "n", ".", "Depending", "on", "the", "actual", "format", "that", "the", "stream", "is", "encoding", "to", "n", "may", "or", "may", "not", "have", "to", "be", "accurate", "some", "formats", "also", "support", "passing", "a", "negative", "value", "to", "indicate", "that", "the", "number", "of", "elements", "is", "unknown", "." ]
[ "func", "(", "e", "*", "StreamEncoder", ")", "Open", "(", "n", "int", ")", "error", "{", "if", "err", ":=", "e", ".", "err", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "e", ".", "closed", "{", "return", "io", ".", "ErrClosedPipe", "\n", "}", "\n\n", "if", "!", "e", ".", "opened", "{", "e", ".", "<mask>", "=", "n", "\n", "e", ".", "opened", "=", "true", "\n\n", "if", "!", "e", ".", "oneshot", "{", "e", ".", "err", "=", "e", ".", "Emitter", ".", "EmitArrayBegin", "(", "n", ")", "\n", "}", "\n", "}", "\n\n", "return", "e", ".", "err", "\n", "}" ]
131
maxmin-132
[ "Intersects", "returns", "true", "if", "there", "is", "some", "tree", "node", "intersecting", "the", "given", "interval", "." ]
[ "func", "(", "ivt", "*", "IntervalTree", ")", "Intersects", "(", "iv", "Interval", ")", "bool", "{", "x", ":=", "ivt", ".", "root", "\n", "for", "x", "!=", "nil", "&&", "iv", ".", "Compare", "(", "&", "x", ".", "iv", ".", "Ivl", ")", "!=", "0", "{", "if", "x", ".", "left", "!=", "nil", "&&", "x", ".", "left", ".", "<mask>", ".", "Compare", "(", "iv", ".", "Begin", ")", ">", "0", "{", "x", "=", "x", ".", "left", "\n", "}", "else", "{", "x", "=", "x", ".", "right", "\n", "}", "\n", "}", "\n", "return", "x", "!=", "nil", "\n", "}" ]
132
maxmin-133
[ "jitteredBackoff", "implements", "the", "FullJitter", "algorithm", "presented", "in", "https", ":", "//", "aws", ".", "amazon", ".", "com", "/", "blogs", "/", "architecture", "/", "exponential", "-", "backoff", "-", "and", "-", "jitter", "/" ]
[ "func", "jitteredBackoff", "(", "rand", "*", "rand", ".", "Rand", ",", "attempt", "int", ",", "<mask>", ",", "max", "time", ".", "Duration", ",", "coeff", "float64", ")", "time", ".", "Duration", "{", "d", ":=", "time", ".", "Duration", "(", "float64", "(", "min", ")", "*", "math", ".", "Pow", "(", "coeff", ",", "float64", "(", "attempt", ")", ")", ")", "\n", "if", "d", ">", "max", "||", "d", "<=", "0", "/* overflow */", "{", "d", "=", "max", "\n", "}", "\n", "return", "min", "+", "time", ".", "Duration", "(", "rand", ".", "Int63n", "(", "int64", "(", "d", "-", "min", ")", ")", ")", "\n", "}" ]
133
maxmin-134
[ "visit", "will", "call", "a", "node", "visitor", "on", "each", "node", "that", "overlaps", "the", "given", "interval" ]
[ "func", "(", "x", "*", "intervalNode", ")", "visit", "(", "iv", "*", "Interval", ",", "nv", "nodeVisitor", ")", "bool", "{", "if", "x", "==", "nil", "{", "return", "true", "\n", "}", "\n", "v", ":=", "iv", ".", "Compare", "(", "&", "x", ".", "iv", ".", "Ivl", ")", "\n", "switch", "{", "case", "v", "<", "0", ":", "if", "!", "x", ".", "left", ".", "visit", "(", "iv", ",", "nv", ")", "{", "return", "false", "\n", "}", "\n", "case", "v", ">", "0", ":", "maxiv", ":=", "Interval", "{", "x", ".", "iv", ".", "Ivl", ".", "Begin", ",", "x", ".", "<mask>", "}", "\n", "if", "maxiv", ".", "Compare", "(", "iv", ")", "==", "0", "{", "if", "!", "x", ".", "left", ".", "visit", "(", "iv", ",", "nv", ")", "||", "!", "x", ".", "right", ".", "visit", "(", "iv", ",", "nv", ")", "{", "return", "false", "\n", "}", "\n", "}", "\n", "default", ":", "if", "!", "x", ".", "left", ".", "visit", "(", "iv", ",", "nv", ")", "||", "!", "nv", "(", "x", ")", "||", "!", "x", ".", "right", ".", "visit", "(", "iv", ",", "nv", ")", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
134
maxmin-135
[ "pluckParams", "converts", "a", "pact", "tag", "into", "a", "pactParams", "struct", "Supported", "Tag", "Formats", "Minimum", "Slice", "Size", ":", "pact", ":", "min", "=", "2", "String", "RegEx", ":", "pact", ":", "example", "=", "2000", "-", "01", "-", "01", "regex", "=", "^", "\\\\", "d", "{", "4", "}", "-", "\\\\", "d", "{", "2", "}", "-", "\\\\", "d", "{", "2", "}", "$" ]
[ "func", "pluckParams", "(", "srcType", "reflect", ".", "Type", ",", "pactTag", "string", ")", "params", "{", "params", ":=", "getDefaults", "(", ")", "\n", "if", "pactTag", "==", "\"", "\"", "{", "return", "params", "\n", "}", "\n\n", "switch", "kind", ":=", "srcType", ".", "Kind", "(", ")", ";", "kind", "{", "case", "reflect", ".", "Slice", ":", "if", "_", ",", "err", ":=", "fmt", ".", "Sscanf", "(", "pactTag", ",", "\"", "\"", ",", "&", "params", ".", "slice", ".", "<mask>", ")", ";", "err", "!=", "nil", "{", "triggerInvalidPactTagPanic", "(", "pactTag", ",", "err", ")", "\n", "}", "\n", "case", "reflect", ".", "String", ":", "fullRegex", ",", "_", ":=", "regexp", ".", "Compile", "(", "`regex=(.*)$`", ")", "\n", "exampleRegex", ",", "_", ":=", "regexp", ".", "Compile", "(", "`^example=(.*)`", ")", "\n\n", "if", "fullRegex", ".", "Match", "(", "[", "]", "byte", "(", "pactTag", ")", ")", "{", "components", ":=", "strings", ".", "Split", "(", "pactTag", ",", "\"", "\"", ")", "\n\n", "if", "len", "(", "components", "[", "1", "]", ")", "==", "0", "{", "triggerInvalidPactTagPanic", "(", "pactTag", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", ")", "\n", "}", "\n\n", "if", "_", ",", "err", ":=", "fmt", ".", "Sscanf", "(", "components", "[", "0", "]", ",", "\"", "\"", ",", "&", "params", ".", "str", ".", "example", ")", ";", "err", "!=", "nil", "{", "triggerInvalidPactTagPanic", "(", "pactTag", ",", "err", ")", "\n", "}", "\n", "params", ".", "str", ".", "regEx", "=", "strings", ".", "Replace", "(", "components", "[", "1", "]", ",", "`\\`", ",", "`\\\\`", ",", "-", "1", ")", "\n\n", "}", "else", "if", "exampleRegex", ".", "Match", "(", "[", "]", "byte", "(", "pactTag", ")", ")", "{", "components", ":=", "strings", ".", "Split", "(", "pactTag", ",", "\"", "\"", ")", "\n\n", "if", "len", "(", "components", ")", "!=", "2", "||", "strings", ".", "TrimSpace", "(", "components", "[", "1", "]", ")", "==", "\"", "\"", "{", "triggerInvalidPactTagPanic", "(", "pactTag", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", ")", "\n", "}", "\n\n", "params", ".", "str", ".", "example", "=", "components", "[", "1", "]", "\n", "}", "\n", "}", "\n\n", "return", "params", "\n", "}" ]
135
maxmin-136
[ "Sends", "an", "S3", "multipart", "upload", "initiation", "request", ".", "See", "http", ":", "//", "docs", ".", "amazonwebservices", ".", "com", "/", "AmazonS3", "/", "latest", "/", "dev", "/", "mpuoverview", ".", "html", ".", "The", "initial", "request", "returns", "an", "UploadId", "that", "we", "use", "to", "identify", "subsequent", "PUT", "requests", "." ]
[ "func", "newPutter", "(", "url", "url", ".", "URL", ",", "h", "http", ".", "Header", ",", "c", "*", "Config", ",", "b", "*", "Bucket", ")", "(", "p", "*", "putter", ",", "err", "error", ")", "{", "p", "=", "new", "(", "putter", ")", "\n", "p", ".", "url", "=", "url", "\n", "p", ".", "c", ",", "p", ".", "b", "=", "new", "(", "Config", ")", ",", "new", "(", "Bucket", ")", "\n", "*", "p", ".", "c", ",", "*", "p", ".", "b", "=", "*", "c", ",", "*", "b", "\n", "p", ".", "c", ".", "Concurrency", "=", "<mask>", "(", "c", ".", "Concurrency", ",", "1", ")", "\n", "p", ".", "c", ".", "NTry", "=", "max", "(", "c", ".", "NTry", ",", "1", ")", "\n", "p", ".", "bufsz", "=", "max64", "(", "minPartSize", ",", "c", ".", "PartSize", ")", "\n", "resp", ",", "err", ":=", "p", ".", "retryRequest", "(", "\"", "\"", ",", "url", ".", "String", "(", ")", "+", "\"", "\"", ",", "nil", ",", "h", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "checkClose", "(", "resp", ".", "Body", ",", "err", ")", "\n", "if", "resp", ".", "StatusCode", "!=", "200", "{", "return", "nil", ",", "newRespError", "(", "resp", ")", "\n", "}", "\n", "err", "=", "xml", ".", "NewDecoder", "(", "resp", ".", "Body", ")", ".", "Decode", "(", "p", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "p", ".", "ch", "=", "make", "(", "chan", "*", "part", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "p", ".", "c", ".", "Concurrency", ";", "i", "++", "{", "go", "p", ".", "worker", "(", ")", "\n", "}", "\n", "p", ".", "md5OfParts", "=", "md5", ".", "New", "(", ")", "\n", "p", ".", "md5", "=", "md5", ".", "New", "(", ")", "\n\n", "p", ".", "sp", "=", "bufferPool", "(", "p", ".", "bufsz", ")", "\n\n", "return", "p", ",", "nil", "\n", "}" ]
136
maxmin-137
[ "newSizeHistogram", "returns", "a", "new", "instance", "of", "keyValueSizeHistogram", "with", "properly", "initialized", "fields", "." ]
[ "func", "newSizeHistogram", "(", ")", "*", "sizeHistogram", "{", "// TODO(ibrahim): find appropriate bin size.", "keyBins", ":=", "createHistogramBins", "(", "1", ",", "16", ")", "\n", "valueBins", ":=", "createHistogramBins", "(", "1", ",", "30", ")", "\n", "return", "&", "sizeHistogram", "{", "keySizeHistogram", ":", "histogramData", "{", "bins", ":", "keyBins", ",", "countPerBin", ":", "make", "(", "[", "]", "int64", ",", "len", "(", "keyBins", ")", "+", "1", ")", ",", "<mask>", ":", "math", ".", "MinInt64", ",", "min", ":", "math", ".", "MaxInt64", ",", "sum", ":", "0", ",", "}", ",", "valueSizeHistogram", ":", "histogramData", "{", "bins", ":", "valueBins", ",", "countPerBin", ":", "make", "(", "[", "]", "int64", ",", "len", "(", "valueBins", ")", "+", "1", ")", ",", "max", ":", "math", ".", "MinInt64", ",", "min", ":", "math", ".", "MaxInt64", ",", "sum", ":", "0", ",", "}", ",", "}", "\n", "}" ]
137
maxmin-138
[ "Finds", "a", "Func", "for", "the", "given", "address", ".", "Sort", "must", "have", "been", "called", "already", "." ]
[ "func", "(", "t", "*", "funcTab", ")", "find", "(", "pc", "core", ".", "Address", ")", "*", "Func", "{", "n", ":=", "sort", ".", "Search", "(", "len", "(", "t", ".", "entries", ")", ",", "func", "(", "i", "int", ")", "bool", "{", "return", "t", ".", "entries", "[", "i", "]", ".", "<mask>", ">", "pc", "\n", "}", ")", "\n", "if", "n", "==", "len", "(", "t", ".", "entries", ")", "||", "pc", "<", "t", ".", "entries", "[", "n", "]", ".", "min", "||", "pc", ">=", "t", ".", "entries", "[", "n", "]", ".", "max", "{", "return", "nil", "\n", "}", "\n", "return", "t", ".", "entries", "[", "n", "]", ".", "f", "\n", "}" ]
138
maxmin-139
[ "simple", "CLI", "interface", ".", "Sample", "usage", ":", "goner", "-", "n", "=", "8", "-", "min", "=", "8", "-", "max", "=", "10", "-", "digits", "=", "3", "-", "punctuation", "=", "3", "-", "uppercase", "=", "4", "Flags", ":", "-", "n", ":", "number", "of", "passwords", "to", "generate", "-", "min", ":", "minimum", "length", "-", "max", ":", "maximum", "length", "-", "digits", ":", "digits", "(", "0", "-", "9", ")", "characters", "-", "punctuation", ":", "punctuation", "characters", "-", "uppercase", ":", "uppercase", "characters" ]
[ "func", "main", "(", ")", "{", "n", ":=", "flag", ".", "Int", "(", "\"", "\"", ",", "8", ",", "\"", "\"", ")", "\n", "<mask>", ":=", "flag", ".", "Int", "(", "\"", "\"", ",", "12", ",", "\"", "\"", ")", "\n", "max", ":=", "flag", ".", "Int", "(", "\"", "\"", ",", "0", ",", "\"", "\"", ")", "\n", "digits", ":=", "flag", ".", "Int", "(", "\"", "\"", ",", "3", ",", "\"", "\"", ")", "\n", "punctuation", ":=", "flag", ".", "Int", "(", "\"", "\"", ",", "1", ",", "\"", "\"", ")", "\n", "uppercase", ":=", "flag", ".", "Int", "(", "\"", "\"", ",", "1", ",", "\"", "\"", ")", "\n", "flag", ".", "Parse", "(", ")", "\n", "reqs", ":=", "garbler", ".", "PasswordStrengthRequirements", "{", "MinimumTotalLength", ":", "*", "min", ",", "MaximumTotalLength", ":", "*", "max", ",", "Uppercase", ":", "*", "uppercase", ",", "Digits", ":", "*", "digits", ",", "Punctuation", ":", "*", "punctuation", ",", "}", "\n", "for", "i", ":=", "0", ";", "i", "<", "*", "n", ";", "i", "++", "{", "pass", ",", "err", ":=", "garbler", ".", "NewPassword", "(", "&", "reqs", ")", "\n", "if", "err", "!=", "nil", "{", "fmt", ".", "Println", "(", "err", ")", "\n", "return", "\n", "}", "\n", "fmt", ".", "Println", "(", "pass", ")", "\n", "}", "\n", "}" ]
139
maxmin-140
[ "getLastIndex", "returns", "the", "last", "index", "in", "stable", "storage", ".", "Either", "from", "the", "last", "log", "or", "from", "the", "last", "snapshot", "." ]
[ "func", "(", "r", "*", "raftState", ")", "getLastIndex", "(", ")", "uint64", "{", "r", ".", "lastLock", ".", "Lock", "(", ")", "\n", "defer", "r", ".", "lastLock", ".", "Unlock", "(", ")", "\n", "return", "<mask>", "(", "r", ".", "lastLogIndex", ",", "r", ".", "lastSnapshotIndex", ")", "\n", "}" ]
140
maxmin-141
[ "Appends", "a", "header", "in", "the", "default", "format", "YYYY", "-", "MM", "-", "DD", "hh", ":", "mm", ":", "ss", ".", "sss", "[", "LVL", "]", "TAG", ":", ".", "If", "either", "of", "the", "Lshortfile", "or", "Llongfile", "flags", "are", "specified", "the", "file", "named", "and", "line", "number", "are", "included", "after", "the", "tag", "and", "before", "the", "final", "colon", "." ]
[ "func", "formatHeader", "(", "buf", "*", "[", "]", "byte", ",", "t", "time", ".", "Time", ",", "lvl", ",", "tag", "string", ",", "file", "string", ",", "line", "int", ")", "{", "year", ",", "month", ",", "day", ":=", "t", ".", "Date", "(", ")", "\n", "hour", ",", "<mask>", ",", "sec", ":=", "t", ".", "Clock", "(", ")", "\n", "ms", ":=", "t", ".", "Nanosecond", "(", ")", "/", "1e6", "\n\n", "itoa", "(", "buf", ",", "year", ",", "4", ")", "\n", "*", "buf", "=", "append", "(", "*", "buf", ",", "'-'", ")", "\n", "itoa", "(", "buf", ",", "int", "(", "month", ")", ",", "2", ")", "\n", "*", "buf", "=", "append", "(", "*", "buf", ",", "'-'", ")", "\n", "itoa", "(", "buf", ",", "day", ",", "2", ")", "\n", "*", "buf", "=", "append", "(", "*", "buf", ",", "' '", ")", "\n", "itoa", "(", "buf", ",", "hour", ",", "2", ")", "\n", "*", "buf", "=", "append", "(", "*", "buf", ",", "':'", ")", "\n", "itoa", "(", "buf", ",", "min", ",", "2", ")", "\n", "*", "buf", "=", "append", "(", "*", "buf", ",", "':'", ")", "\n", "itoa", "(", "buf", ",", "sec", ",", "2", ")", "\n", "*", "buf", "=", "append", "(", "*", "buf", ",", "'.'", ")", "\n", "itoa", "(", "buf", ",", "ms", ",", "3", ")", "\n", "*", "buf", "=", "append", "(", "*", "buf", ",", "\"", "\"", "...", ")", "\n", "*", "buf", "=", "append", "(", "*", "buf", ",", "lvl", "...", ")", "\n", "*", "buf", "=", "append", "(", "*", "buf", ",", "\"", "\"", "...", ")", "\n", "*", "buf", "=", "append", "(", "*", "buf", ",", "tag", "...", ")", "\n", "if", "file", "!=", "\"", "\"", "{", "*", "buf", "=", "append", "(", "*", "buf", ",", "' '", ")", "\n", "*", "buf", "=", "append", "(", "*", "buf", ",", "file", "...", ")", "\n", "*", "buf", "=", "append", "(", "*", "buf", ",", "':'", ")", "\n", "itoa", "(", "buf", ",", "line", ",", "-", "1", ")", "\n", "}", "\n", "*", "buf", "=", "append", "(", "*", "buf", ",", "\"", "\"", "...", ")", "\n", "}" ]
141
maxmin-142
[ "convertSuiteMeta", "converts", "a", "junit", "result", "in", "gcs", "to", "a", "ResultStore", "Suite", "." ]
[ "func", "convertSuiteMeta", "(", "suiteMeta", "gcs", ".", "SuitesMeta", ")", "resultstore", ".", "Suite", "{", "out", ":=", "resultstore", ".", "Suite", "{", "Name", ":", "path", ".", "Base", "(", "suiteMeta", ".", "Path", ")", ",", "Files", ":", "[", "]", "resultstore", ".", "File", "{", "{", "ContentType", ":", "\"", "\"", ",", "ID", ":", "resultstore", ".", "UUID", "(", ")", ",", "URL", ":", "suiteMeta", ".", "Path", ",", "// ensure the junit.xml file appears in artifacts list", "}", ",", "}", ",", "}", "\n", "for", "_", ",", "suite", ":=", "range", "suiteMeta", ".", "Suites", ".", "Suites", "{", "child", ":=", "resultstore", ".", "Suite", "{", "Name", ":", "suite", ".", "Name", ",", "Duration", ":", "dur", "(", "suite", ".", "Time", ")", ",", "}", "\n", "switch", "{", "case", "suite", ".", "Failures", ">", "0", "&&", "suite", ".", "Tests", ">=", "suite", ".", "Failures", ":", "child", ".", "Failures", "=", "append", "(", "child", ".", "Failures", ",", "resultstore", ".", "Failure", "{", "Message", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "suite", ".", "Failures", ",", "suite", ".", "Tests", ",", "float64", "(", "suite", ".", "Tests", "-", "suite", ".", "Failures", ")", "*", "100.0", "/", "float64", "(", "suite", ".", "Tests", ")", ")", ",", "}", ")", "\n", "case", "suite", ".", "Failures", ">", "0", ":", "child", ".", "Failures", "=", "append", "(", "child", ".", "Failures", ",", "resultstore", ".", "Failure", "{", "Message", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "suite", ".", "Failures", ")", ",", "}", ")", "\n", "}", "\n", "for", "_", ",", "result", ":=", "range", "suite", ".", "Results", "{", "name", ",", "tags", ":=", "stripTags", "(", "result", ".", "Name", ")", "\n", "class", ":=", "result", ".", "ClassName", "\n", "if", "class", "==", "\"", "\"", "{", "class", "=", "strings", ".", "Join", "(", "tags", ",", "\"", "\"", ")", "\n", "}", "else", "{", "class", "+=", "\"", "\"", "+", "strings", ".", "Join", "(", "tags", ",", "\"", "\"", ")", "\n", "}", "\n", "c", ":=", "resultstore", ".", "Case", "{", "Name", ":", "name", ",", "Class", ":", "class", ",", "Duration", ":", "dur", "(", "result", ".", "Time", ")", ",", "Result", ":", "resultstore", ".", "Completed", ",", "}", "\n", "const", "<mask>", "=", "5000", "// truncate messages to this length", "\n", "msg", ":=", "result", ".", "Message", "(", "max", ")", "\n", "switch", "{", "case", "result", ".", "Failure", "!=", "nil", ":", "// failing tests have a completed result with an error", "if", "msg", "==", "\"", "\"", "{", "msg", "=", "\"", "\"", "\n", "}", "\n", "c", ".", "Failures", "=", "append", "(", "c", ".", "Failures", ",", "resultstore", ".", "Failure", "{", "Message", ":", "msg", ",", "}", ")", "\n", "case", "result", ".", "Skipped", "!=", "nil", ":", "c", ".", "Result", "=", "resultstore", ".", "Skipped", "\n", "if", "msg", "!=", "\"", "\"", "{", "// skipped results do not require an error, but may.", "c", ".", "Errors", "=", "append", "(", "c", ".", "Errors", ",", "resultstore", ".", "Error", "{", "Message", ":", "msg", ",", "}", ")", "\n", "}", "\n", "}", "\n", "child", ".", "Cases", "=", "append", "(", "child", ".", "Cases", ",", "c", ")", "\n", "if", "c", ".", "Duration", ">", "child", ".", "Duration", "{", "child", ".", "Duration", "=", "c", ".", "Duration", "\n", "}", "\n", "}", "\n", "if", "child", ".", "Duration", ">", "out", ".", "Duration", "{", "// Assume suites run in parallel, so choose max", "out", ".", "Duration", "=", "child", ".", "Duration", "\n", "}", "\n", "out", ".", "Suites", "=", "append", "(", "out", ".", "Suites", ",", "child", ")", "\n", "}", "\n", "return", "out", "\n", "}" ]
142
maxmin-143
[ "withMax", "sets", "the", "maximum", "number", "of", "retries", "on", "this", "call", "or", "this", "interceptor", "." ]
[ "func", "withMax", "(", "maxRetries", "uint", ")", "retryOption", "{", "return", "retryOption", "{", "applyFunc", ":", "func", "(", "o", "*", "options", ")", "{", "o", ".", "<mask>", "=", "maxRetries", "\n", "}", "}", "\n", "}" ]
143
maxmin-144
[ "Check", "the", "user", "password", ".", "Graphics", "character", "are", "allowed", ".", "See", "unicode", ".", "IsGraphic", "." ]
[ "func", "CheckPassword", "(", "pass", "string", ",", "<mask>", ",", "max", "int", ")", "error", "{", "if", "len", "(", "pass", ")", "<", "min", "||", "len", "(", "pass", ")", ">", "max", "{", "return", "e", ".", "New", "(", "ErrInvalidPassLength", ")", "\n", "}", "\n", "for", "_", ",", "r", ":=", "range", "pass", "{", "if", "!", "unicode", ".", "IsGraphic", "(", "r", ")", "{", "return", "e", ".", "New", "(", "ErrInvalidPassChar", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
144
maxmin-145
[ "ContainerNextSnapshot", "returns", "the", "index", "the", "next", "snapshot", "of", "the", "container", "with", "the", "given", "name", "and", "pattern", "should", "have", "." ]
[ "func", "(", "c", "*", "Cluster", ")", "ContainerNextSnapshot", "(", "project", "string", ",", "name", "string", ",", "pattern", "string", ")", "int", "{", "base", ":=", "name", "+", "shared", ".", "SnapshotDelimiter", "\n", "length", ":=", "len", "(", "base", ")", "\n", "q", ":=", "`\nSELECT containers.name\n FROM containers\n JOIN projects ON projects.id = containers.project_id\n WHERE projects.name=? AND containers.type=? AND SUBSTR(containers.name,1,?)=?`", "\n", "var", "numstr", "string", "\n", "inargs", ":=", "[", "]", "interface", "{", "}", "{", "project", ",", "CTypeSnapshot", ",", "length", ",", "base", "}", "\n", "outfmt", ":=", "[", "]", "interface", "{", "}", "{", "numstr", "}", "\n", "results", ",", "err", ":=", "queryScan", "(", "c", ".", "db", ",", "q", ",", "inargs", ",", "outfmt", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", "\n", "}", "\n", "<mask>", ":=", "0", "\n\n", "for", "_", ",", "r", ":=", "range", "results", "{", "snapOnlyName", ":=", "strings", ".", "SplitN", "(", "r", "[", "0", "]", ".", "(", "string", ")", ",", "shared", ".", "SnapshotDelimiter", ",", "2", ")", "[", "1", "]", "\n", "fields", ":=", "strings", ".", "SplitN", "(", "pattern", ",", "\"", "\"", ",", "2", ")", "\n\n", "var", "num", "int", "\n", "count", ",", "err", ":=", "fmt", ".", "Sscanf", "(", "snapOnlyName", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "fields", "[", "0", "]", ",", "fields", "[", "1", "]", ")", ",", "&", "num", ")", "\n", "if", "err", "!=", "nil", "||", "count", "!=", "1", "{", "continue", "\n", "}", "\n", "if", "num", ">=", "max", "{", "max", "=", "num", "+", "1", "\n", "}", "\n", "}", "\n\n", "return", "max", "\n", "}" ]
145
maxmin-146
[ "Insert", "adds", "a", "node", "with", "the", "given", "interval", "into", "the", "tree", "." ]
[ "func", "(", "ivt", "*", "IntervalTree", ")", "Insert", "(", "ivl", "Interval", ",", "val", "interface", "{", "}", ")", "{", "var", "y", "*", "intervalNode", "\n", "z", ":=", "&", "intervalNode", "{", "iv", ":", "IntervalValue", "{", "ivl", ",", "val", "}", ",", "<mask>", ":", "ivl", ".", "End", ",", "c", ":", "red", "}", "\n", "x", ":=", "ivt", ".", "root", "\n", "for", "x", "!=", "nil", "{", "y", "=", "x", "\n", "if", "z", ".", "iv", ".", "Ivl", ".", "Begin", ".", "Compare", "(", "x", ".", "iv", ".", "Ivl", ".", "Begin", ")", "<", "0", "{", "x", "=", "x", ".", "left", "\n", "}", "else", "{", "x", "=", "x", ".", "right", "\n", "}", "\n", "}", "\n\n", "z", ".", "parent", "=", "y", "\n", "if", "y", "==", "nil", "{", "ivt", ".", "root", "=", "z", "\n", "}", "else", "{", "if", "z", ".", "iv", ".", "Ivl", ".", "Begin", ".", "Compare", "(", "y", ".", "iv", ".", "Ivl", ".", "Begin", ")", "<", "0", "{", "y", ".", "left", "=", "z", "\n", "}", "else", "{", "y", ".", "right", "=", "z", "\n", "}", "\n", "y", ".", "updateMax", "(", ")", "\n", "}", "\n", "z", ".", "c", "=", "red", "\n", "ivt", ".", "insertFixup", "(", "z", ")", "\n", "ivt", ".", "count", "++", "\n", "}" ]
146
maxmin-147
[ "nextEnts", "returns", "all", "the", "available", "entries", "for", "execution", ".", "If", "applied", "is", "smaller", "than", "the", "index", "of", "snapshot", "it", "returns", "all", "committed", "entries", "after", "the", "index", "of", "snapshot", "." ]
[ "func", "(", "l", "*", "raftLog", ")", "nextEnts", "(", ")", "(", "ents", "[", "]", "pb", ".", "Entry", ")", "{", "off", ":=", "<mask>", "(", "l", ".", "applied", "+", "1", ",", "l", ".", "firstIndex", "(", ")", ")", "\n", "if", "l", ".", "committed", "+", "1", ">", "off", "{", "ents", ",", "err", ":=", "l", ".", "slice", "(", "off", ",", "l", ".", "committed", "+", "1", ",", "l", ".", "maxNextEntsSize", ")", "\n", "if", "err", "!=", "nil", "{", "l", ".", "logger", ".", "Panicf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "ents", "\n", "}", "\n", "return", "nil", "\n", "}" ]
147
maxmin-148
[ "best", "-", "effort", "attempt", "to", "get", "an", "int", "from", "crypto", "/", "rand", ".", "if", "an", "error", "is", "returned", "it", "will", "fall", "back", "to", "math", "/", "rand", "." ]
[ "func", "randInt", "(", "<mask>", "int", ")", "int", "{", "i", ",", "err", ":=", "crypto", ".", "Int", "(", "crypto", ".", "Reader", ",", "big", ".", "NewInt", "(", "int64", "(", "max", ")", ")", ")", "\n", "if", "err", "==", "nil", "{", "return", "int", "(", "i", ".", "Int64", "(", ")", ")", "\n", "}", "\n", "return", "rand", ".", "Intn", "(", "max", ")", "\n", "}" ]
148
maxmin-149
[ "maybeDecrTo", "returns", "false", "if", "the", "given", "to", "index", "comes", "from", "an", "out", "of", "order", "message", ".", "Otherwise", "it", "decreases", "the", "progress", "next", "index", "to", "min", "(", "rejected", "last", ")", "and", "returns", "true", "." ]
[ "func", "(", "pr", "*", "Progress", ")", "maybeDecrTo", "(", "rejected", ",", "last", "uint64", ")", "bool", "{", "if", "pr", ".", "State", "==", "ProgressStateReplicate", "{", "// the rejection must be stale if the progress has matched and \"rejected\"", "// is smaller than \"match\".", "if", "rejected", "<=", "pr", ".", "Match", "{", "return", "false", "\n", "}", "\n", "// directly decrease next to match + 1", "pr", ".", "Next", "=", "pr", ".", "Match", "+", "1", "\n", "return", "true", "\n", "}", "\n\n", "// the rejection must be stale if \"rejected\" does not match next - 1", "if", "pr", ".", "Next", "-", "1", "!=", "rejected", "{", "return", "false", "\n", "}", "\n\n", "if", "pr", ".", "Next", "=", "<mask>", "(", "rejected", ",", "last", "+", "1", ")", ";", "pr", ".", "Next", "<", "1", "{", "pr", ".", "Next", "=", "1", "\n", "}", "\n", "pr", ".", "resume", "(", ")", "\n", "return", "true", "\n", "}" ]
149
maxmin-150
[ "setNewLogs", "is", "used", "to", "setup", "the", "logs", "which", "should", "be", "appended", "for", "a", "request", "." ]
[ "func", "(", "r", "*", "Raft", ")", "setNewLogs", "(", "req", "*", "AppendEntriesRequest", ",", "nextIndex", ",", "lastIndex", "uint64", ")", "error", "{", "// Append up to MaxAppendEntries or up to the lastIndex", "req", ".", "Entries", "=", "make", "(", "[", "]", "*", "Log", ",", "0", ",", "r", ".", "conf", ".", "MaxAppendEntries", ")", "\n", "maxIndex", ":=", "<mask>", "(", "nextIndex", "+", "uint64", "(", "r", ".", "conf", ".", "MaxAppendEntries", ")", "-", "1", ",", "lastIndex", ")", "\n", "for", "i", ":=", "nextIndex", ";", "i", "<=", "maxIndex", ";", "i", "++", "{", "oldLog", ":=", "new", "(", "Log", ")", "\n", "if", "err", ":=", "r", ".", "logs", ".", "GetLog", "(", "i", ",", "oldLog", ")", ";", "err", "!=", "nil", "{", "r", ".", "logger", ".", "Error", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "i", ",", "err", ")", ")", "\n", "return", "err", "\n", "}", "\n", "req", ".", "Entries", "=", "append", "(", "req", ".", "Entries", ",", "oldLog", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
150
maxmin-151
[ "successor", "is", "the", "next", "in", "-", "order", "node", "in", "the", "tree" ]
[ "func", "(", "x", "*", "intervalNode", ")", "successor", "(", ")", "*", "intervalNode", "{", "if", "x", ".", "right", "!=", "nil", "{", "return", "x", ".", "right", ".", "<mask>", "(", ")", "\n", "}", "\n", "y", ":=", "x", ".", "parent", "\n", "for", "y", "!=", "nil", "&&", "x", "==", "y", ".", "right", "{", "x", "=", "y", "\n", "y", "=", "y", ".", "parent", "\n", "}", "\n", "return", "y", "\n", "}" ]
151
maxmin-152
[ "StorageVolumeNextSnapshot", "returns", "the", "index", "the", "next", "snapshot", "of", "the", "storage", "volume", "with", "the", "given", "name", "should", "have", ".", "Note", "the", "code", "below", "doesn", "t", "deal", "with", "snapshots", "of", "snapshots", ".", "To", "do", "that", "we", "ll", "need", "to", "weed", "out", "based", "on", "#", "slashes", "in", "names" ]
[ "func", "(", "c", "*", "Cluster", ")", "StorageVolumeNextSnapshot", "(", "name", "string", ",", "typ", "int", ")", "int", "{", "base", ":=", "name", "+", "shared", ".", "SnapshotDelimiter", "+", "\"", "\"", "\n", "length", ":=", "len", "(", "base", ")", "\n", "q", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ")", "\n", "var", "numstr", "string", "\n", "inargs", ":=", "[", "]", "interface", "{", "}", "{", "typ", ",", "true", ",", "length", ",", "base", "}", "\n", "outfmt", ":=", "[", "]", "interface", "{", "}", "{", "numstr", "}", "\n", "results", ",", "err", ":=", "queryScan", "(", "c", ".", "db", ",", "q", ",", "inargs", ",", "outfmt", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", "\n", "}", "\n", "<mask>", ":=", "0", "\n\n", "for", "_", ",", "r", ":=", "range", "results", "{", "numstr", "=", "r", "[", "0", "]", ".", "(", "string", ")", "\n", "if", "len", "(", "numstr", ")", "<=", "length", "{", "continue", "\n", "}", "\n", "substr", ":=", "numstr", "[", "length", ":", "]", "\n", "var", "num", "int", "\n", "count", ",", "err", ":=", "fmt", ".", "Sscanf", "(", "substr", ",", "\"", "\"", ",", "&", "num", ")", "\n", "if", "err", "!=", "nil", "||", "count", "!=", "1", "{", "continue", "\n", "}", "\n", "if", "num", ">=", "max", "{", "max", "=", "num", "+", "1", "\n", "}", "\n", "}", "\n\n", "return", "max", "\n", "}" ]