id
int32
0
151
idx
stringlengths
8
10
nl_tokens
sequence
pl_tokens
sequence
0
maxmin-1
[ "SetMaxStructPoolSize", "sets", "the", "struct", "pools", "max", "size", ".", "this", "may", "be", "usefull", "for", "fine", "grained", "performance", "tuning", "towards", "your", "application", "however", "the", "default", "should", "be", "fine", "for", "nearly", "all", "cases", ".", "only", "increase", "if", "you", "have", "a", "deeply", "nested", "struct", "structure", ".", "NOTE", ":", "this", "method", "is", "not", "thread", "-", "safe", "NOTE", ":", "this", "is", "only", "here", "to", "keep", "compatibility", "with", "v5", "in", "v6", "the", "method", "will", "be", "removed" ]
[ "func", "(", "v", "*", "Validate", ")", "SetMaxStructPoolSize", "(", "<mask>", "int", ")", "{", "structPool", "=", "&", "sync", ".", "Pool", "{", "New", ":", "newStructErrors", "}", "\n", "}" ]
1
maxmin-2
[ "NewSimpleBackoff", "creates", "a", "Backoff", "which", "ranges", "from", "min", "to", "max", "increasing", "by", "multiple", "each", "time", ".", "(", "t", "=", "start", "*", "multiple", "*", "n", "for", "the", "nth", "iteration", ")", "It", "also", "adds", "(", "and", "yes", "the", "jitter", "is", "always", "added", "never", "subtracted", ")", "a", "random", "amount", "of", "jitter", "up", "to", "jitterMultiple", "percent", "(", "that", "is", "jitterMultiple", "=", "0", ".", "0", "is", "no", "jitter", "0", ".", "15", "is", "15%", "added", "jitter", ")", ".", "The", "total", "time", "may", "exceed", "max", "when", "accounting", "for", "jitter", "such", "that", "the", "absolute", "max", "is", "max", "+", "max", "*", "jiterMultiple" ]
[ "func", "NewExponentialBackoff", "(", "<mask>", ",", "max", "time", ".", "Duration", ",", "jitterMultiple", ",", "multiple", "float64", ")", "*", "ExponentialBackoff", "{", "return", "&", "ExponentialBackoff", "{", "start", ":", "min", ",", "current", ":", "min", ",", "max", ":", "max", ",", "jitterMultiple", ":", "jitterMultiple", ",", "multiple", ":", "multiple", ",", "}", "\n", "}" ]
2
maxmin-3
[ "ScaleNewWithRange", "is", "a", "wrapper", "around", "gtk_scale_new_with_range", "()", "." ]
[ "func", "ScaleNewWithRange", "(", "orientation", "Orientation", ",", "<mask>", ",", "max", ",", "step", "float64", ")", "(", "*", "Scale", ",", "error", ")", "{", "c", ":=", "C", ".", "gtk_scale_new_with_range", "(", "C", ".", "GtkOrientation", "(", "orientation", ")", ",", "C", ".", "gdouble", "(", "min", ")", ",", "C", ".", "gdouble", "(", "max", ")", ",", "C", ".", "gdouble", "(", "step", ")", ")", "\n\n", "if", "c", "==", "nil", "{", "return", "nil", ",", "nilPtrErr", "\n", "}", "\n", "return", "wrapScale", "(", "glib", ".", "Take", "(", "unsafe", ".", "Pointer", "(", "c", ")", ")", ")", ",", "nil", "\n", "}" ]
3
maxmin-4
[ "Read", "wraps", "csv", ".", "Reader", ".", "Read", "creating", "a", "map", "of", "column", "name", "to", "field", "value", ".", "If", "the", "line", "has", "fewer", "columns", "than", "Reader", ".", "Columns", "the", "map", "will", "not", "contain", "keys", "for", "these", "columns", ";", "thus", "we", "can", "distinguish", "between", "missing", "columns", "and", "columns", "with", "empty", "values", ".", "If", "the", "line", "has", "more", "columns", "than", "Reader", ".", "Columns", "Reader", ".", "Read", "()", "ignores", "them", "." ]
[ "func", "(", "r", "*", "Reader", ")", "Read", "(", ")", "(", "record", "map", "[", "string", "]", "string", ",", "err", "error", ")", "{", "var", "rawRecord", "[", "]", "string", "\n", "rawRecord", ",", "err", "=", "r", ".", "Reader", ".", "Read", "(", ")", "\n", "length", ":=", "<mask>", "(", "len", "(", "rawRecord", ")", ",", "len", "(", "r", ".", "Columns", ")", ")", "\n", "record", "=", "make", "(", "map", "[", "string", "]", "string", ")", "\n", "for", "index", ":=", "0", ";", "index", "<", "length", ";", "index", "++", "{", "column", ":=", "r", ".", "Columns", "[", "index", "]", "\n", "if", "_", ",", "exists", ":=", "record", "[", "column", "]", ";", "exists", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "column", ")", "\n", "}", "\n", "record", "[", "column", "]", "=", "rawRecord", "[", "index", "]", "\n", "}", "\n", "return", "\n", "}" ]
4
maxmin-5
[ "Step", "increases", "ProgressBar", "value", "by", "1", "if", "the", "value", "is", "less", "than", "ProgressBar", "high", "limit" ]
[ "func", "(", "b", "*", "ProgressBar", ")", "Step", "(", ")", "int", "{", "b", ".", "mtx", ".", "Lock", "(", ")", "\n", "defer", "b", ".", "mtx", ".", "Unlock", "(", ")", "\n", "b", ".", "value", "++", "\n\n", "if", "b", ".", "value", ">", "b", ".", "<mask>", "{", "b", ".", "value", "=", "b", ".", "max", "\n", "}", "\n\n", "return", "b", ".", "value", "\n", "}" ]
5
maxmin-6
[ "Read", "presents", "one", "or", "more", "IDAT", "chunks", "as", "one", "continuous", "stream", "(", "minus", "the", "intermediate", "chunk", "headers", "and", "footers", ")", ".", "If", "the", "PNG", "data", "looked", "like", ":", "...", "len0", "IDAT", "xxx", "crc0", "len1", "IDAT", "yy", "crc1", "len2", "IEND", "crc2", "then", "this", "reader", "presents", "xxxyy", ".", "For", "well", "-", "formed", "PNG", "data", "the", "decoder", "state", "immediately", "before", "the", "first", "Read", "call", "is", "that", "d", ".", "r", "is", "positioned", "between", "the", "first", "IDAT", "and", "xxx", "and", "the", "decoder", "state", "immediately", "after", "the", "last", "Read", "call", "is", "that", "d", ".", "r", "is", "positioned", "between", "yy", "and", "crc1", "." ]
[ "func", "(", "d", "*", "decoder", ")", "Read", "(", "p", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "if", "len", "(", "p", ")", "==", "0", "{", "return", "0", ",", "nil", "\n", "}", "\n", "for", "d", ".", "idatLength", "==", "0", "{", "// We have exhausted an IDAT chunk. Verify the checksum of that chunk.", "if", "err", ":=", "d", ".", "verifyChecksum", "(", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "// Read the length and chunk type of the next chunk, and check that", "// it is an IDAT chunk.", "if", "_", ",", "err", ":=", "io", ".", "ReadFull", "(", "d", ".", "r", ",", "d", ".", "tmp", "[", ":", "8", "]", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "d", ".", "idatLength", "=", "binary", ".", "BigEndian", ".", "Uint32", "(", "d", ".", "tmp", "[", ":", "4", "]", ")", "\n", "if", "string", "(", "d", ".", "tmp", "[", "4", ":", "8", "]", ")", "!=", "\"", "\"", "{", "return", "0", ",", "FormatError", "(", "\"", "\"", ")", "\n", "}", "\n", "d", ".", "crc", ".", "Reset", "(", ")", "\n", "d", ".", "crc", ".", "Write", "(", "d", ".", "tmp", "[", "4", ":", "8", "]", ")", "\n", "}", "\n", "if", "int", "(", "d", ".", "idatLength", ")", "<", "0", "{", "return", "0", ",", "UnsupportedError", "(", "\"", "\"", ")", "\n", "}", "\n", "n", ",", "err", ":=", "d", ".", "r", ".", "Read", "(", "p", "[", ":", "<mask>", "(", "len", "(", "p", ")", ",", "int", "(", "d", ".", "idatLength", ")", ")", "]", ")", "\n", "d", ".", "crc", ".", "Write", "(", "p", "[", ":", "n", "]", ")", "\n", "d", ".", "idatLength", "-=", "uint32", "(", "n", ")", "\n", "return", "n", ",", "err", "\n", "}" ]
6
maxmin-7
[ "The", "assumption", "that", "bucket", "counts", "increase", "monotonically", "with", "increasing", "upperBound", "may", "be", "violated", "during", ":", "*", "Recording", "rule", "evaluation", "of", "histogram_quantile", "especially", "when", "rate", "()", "has", "been", "applied", "to", "the", "underlying", "bucket", "timeseries", ".", "*", "Evaluation", "of", "histogram_quantile", "computed", "over", "federated", "bucket", "timeseries", "especially", "when", "rate", "()", "has", "been", "applied", ".", "This", "is", "because", "scraped", "data", "is", "not", "made", "available", "to", "rule", "evaluation", "or", "federation", "atomically", "so", "some", "buckets", "are", "computed", "with", "data", "from", "the", "most", "recent", "scrapes", "but", "the", "other", "buckets", "are", "missing", "data", "from", "the", "most", "recent", "scrape", ".", "Monotonicity", "is", "usually", "guaranteed", "because", "if", "a", "bucket", "with", "upper", "bound", "u1", "has", "count", "c1", "then", "any", "bucket", "with", "a", "higher", "upper", "bound", "u", ">", "u1", "must", "have", "counted", "all", "c1", "observations", "and", "perhaps", "more", "so", "that", "c", ">", "=", "c1", ".", "Randomly", "interspersed", "partial", "sampling", "breaks", "that", "guarantee", "and", "rate", "()", "exacerbates", "it", ".", "Specifically", "suppose", "bucket", "le", "=", "1000", "has", "a", "count", "of", "10", "from", "4", "samples", "but", "the", "bucket", "with", "le", "=", "2000", "has", "a", "count", "of", "7", "from", "3", "samples", ".", "The", "monotonicity", "is", "broken", ".", "It", "is", "exacerbated", "by", "rate", "()", "because", "under", "normal", "operation", "cumulative", "counting", "of", "buckets", "will", "cause", "the", "bucket", "counts", "to", "diverge", "such", "that", "small", "differences", "from", "missing", "samples", "are", "not", "a", "problem", ".", "rate", "()", "removes", "this", "divergence", ".", ")", "bucketQuantile", "depends", "on", "that", "monotonicity", "to", "do", "a", "binary", "search", "for", "the", "bucket", "with", "the", "φ", "-", "quantile", "count", "so", "breaking", "the", "monotonicity", "guarantee", "causes", "bucketQuantile", "()", "to", "return", "undefined", "(", "nonsense", ")", "results", ".", "As", "a", "somewhat", "hacky", "solution", "until", "ingestion", "is", "atomic", "per", "scrape", "we", "calculate", "the", "envelope", "of", "the", "histogram", "buckets", "essentially", "removing", "any", "decreases", "in", "the", "count", "between", "successive", "buckets", "." ]
[ "func", "ensureMonotonic", "(", "buckets", "buckets", ")", "{", "<mask>", ":=", "buckets", "[", "0", "]", ".", "count", "\n", "for", "i", ":=", "range", "buckets", "[", "1", ":", "]", "{", "switch", "{", "case", "buckets", "[", "i", "]", ".", "count", ">", "max", ":", "max", "=", "buckets", "[", "i", "]", ".", "count", "\n", "case", "buckets", "[", "i", "]", ".", "count", "<", "max", ":", "buckets", "[", "i", "]", ".", "count", "=", "max", "\n", "}", "\n", "}", "\n", "}" ]
7
maxmin-8
[ "CanPageDown", "returns", "whether", "a", "list", "can", "still", "PageDown", "()", "." ]
[ "func", "(", "l", "*", "List", ")", "CanPageDown", "(", ")", "bool", "{", "<mask>", ":=", "len", "(", "l", ".", "scope", ")", "\n", "return", "l", ".", "start", "+", "l", ".", "size", "<", "max", "\n", "}" ]
8
maxmin-9
[ "KNearest", "returns", "the", "k", "nearest", "points", "near", "point", "within", "maxDistance", "that", "match", "the", "accept", "criteria", "." ]
[ "func", "(", "points", "*", "PointsIndex", ")", "KNearest", "(", "point", "Point", ",", "k", "int", ",", "maxDistance", "Meters", ",", "accept", "func", "(", "p", "Point", ")", "bool", ")", "[", "]", "Point", "{", "nearbyPoints", ":=", "make", "(", "[", "]", "Point", ",", "0", ")", "\n", "pointEntry", ":=", "points", ".", "index", ".", "GetEntryAt", "(", "point", ")", ".", "(", "set", ")", "\n", "nearbyPoints", "=", "append", "(", "nearbyPoints", ",", "getPoints", "(", "[", "]", "interface", "{", "}", "{", "pointEntry", "}", ",", "accept", ")", "...", ")", "\n\n", "totalCount", ":=", "0", "\n", "idx", ":=", "cellOf", "(", "point", ",", "points", ".", "index", ".", "resolution", ")", "\n", "// Explicitely assign a greater max distance so that we definitely return enough points", "// and make sure it searches at least one square away.", "coarseMaxDistance", ":=", "math", ".", "Max", "(", "float64", "(", "maxDistance", ")", "*", "2.0", ",", "float64", "(", "points", ".", "index", ".", "resolution", ")", "*", "2.0", "+", "0.01", ")", "\n\n", "for", "d", ":=", "1", ";", "float64", "(", "d", ")", "*", "float64", "(", "points", ".", "index", ".", "resolution", ")", "<=", "coarseMaxDistance", ";", "d", "++", "{", "oldCount", ":=", "len", "(", "nearbyPoints", ")", "\n\n", "nearbyPoints", "=", "getPointsAppend", "(", "nearbyPoints", ",", "points", ".", "index", ".", "get", "(", "idx", ".", "x", "-", "d", ",", "idx", ".", "x", "+", "d", ",", "idx", ".", "y", "+", "d", ",", "idx", ".", "y", "+", "d", ")", ",", "accept", ")", "\n", "nearbyPoints", "=", "getPointsAppend", "(", "nearbyPoints", ",", "points", ".", "index", ".", "get", "(", "idx", ".", "x", "-", "d", ",", "idx", ".", "x", "+", "d", ",", "idx", ".", "y", "-", "d", ",", "idx", ".", "y", "-", "d", ")", ",", "accept", ")", "\n", "nearbyPoints", "=", "getPointsAppend", "(", "nearbyPoints", ",", "points", ".", "index", ".", "get", "(", "idx", ".", "x", "-", "d", ",", "idx", ".", "x", "-", "d", ",", "idx", ".", "y", "-", "d", "+", "1", ",", "idx", ".", "y", "+", "d", "-", "1", ")", ",", "accept", ")", "\n", "nearbyPoints", "=", "getPointsAppend", "(", "nearbyPoints", ",", "points", ".", "index", ".", "get", "(", "idx", ".", "x", "+", "d", ",", "idx", ".", "x", "+", "d", ",", "idx", ".", "y", "-", "d", "+", "1", ",", "idx", ".", "y", "+", "d", "-", "1", ")", ",", "accept", ")", "\n\n", "totalCount", "+=", "len", "(", "nearbyPoints", ")", "-", "oldCount", "\n\n", "if", "totalCount", ">", "k", "{", "break", "\n", "}", "\n", "}", "\n\n", "sortedPoints", ":=", "&", "sortedPoints", "{", "nearbyPoints", ",", "point", "}", "\n", "sort", ".", "Sort", "(", "sortedPoints", ")", "\n\n", "k", "=", "<mask>", "(", "k", ",", "len", "(", "sortedPoints", ".", "points", ")", ")", "\n\n", "// filter points which longer than maxDistance away from point.", "for", "i", ",", "nearbyPoint", ":=", "range", "sortedPoints", ".", "points", "{", "if", "Distance", "(", "point", ",", "nearbyPoint", ")", ">", "maxDistance", "||", "i", "==", "k", "{", "k", "=", "i", "\n", "break", "\n", "}", "\n", "}", "\n\n", "return", "sortedPoints", ".", "points", "[", "0", ":", "k", "]", "\n", "}" ]
9
maxmin-10
[ "GetClientOfferingsFilterParams", "returns", "offerings", "filter", "parameters", "for", "client", "." ]
[ "func", "(", "h", "*", "Handler", ")", "GetClientOfferingsFilterParams", "(", "tkn", "string", ")", "(", "*", "GetClientOfferingsFilterParamsResult", ",", "error", ")", "{", "logger", ":=", "h", ".", "logger", ".", "Add", "(", "\"", "\"", ",", "\"", "\"", ")", "\n\n", "if", "!", "h", ".", "token", ".", "Check", "(", "tkn", ")", "{", "logger", ".", "Warn", "(", "\"", "\"", ")", "\n", "return", "nil", ",", "ErrAccessDenied", "\n", "}", "\n\n", "countries", ",", "err", ":=", "h", ".", "offeringCountries", "(", "logger", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "<mask>", ",", "max", ",", "err", ":=", "h", ".", "offeringsMinMaxPrice", "(", "logger", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "GetClientOfferingsFilterParamsResult", "{", "countries", ",", "min", ",", "max", "}", ",", "nil", "\n", "}" ]
10
maxmin-11
[ "Any", "returns", "the", "position", "of", "the", "end", "of", "the", "current", "element", "that", "begins", "at", "pos", ";", "handles", "any", "valid", "json", "element" ]
[ "func", "Any", "(", "in", "[", "]", "byte", ",", "pos", "int", ")", "(", "int", ",", "error", ")", "{", "pos", ",", "err", ":=", "skipSpace", "(", "in", ",", "pos", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n\n", "switch", "in", "[", "pos", "]", "{", "case", "'\"'", ":", "return", "String", "(", "in", ",", "pos", ")", "\n", "case", "'{'", ":", "return", "Object", "(", "in", ",", "pos", ")", "\n", "case", "'.'", ",", "'-'", ",", "'1'", ",", "'2'", ",", "'3'", ",", "'4'", ",", "'5'", ",", "'6'", ",", "'7'", ",", "'8'", ",", "'9'", ",", "'0'", ":", "return", "Number", "(", "in", ",", "pos", ")", "\n", "case", "'['", ":", "return", "Array", "(", "in", ",", "pos", ")", "\n", "case", "'t'", ",", "'f'", ":", "return", "Boolean", "(", "in", ",", "pos", ")", "\n", "case", "'n'", ":", "return", "Null", "(", "in", ",", "pos", ")", "\n", "default", ":", "<mask>", ":=", "len", "(", "in", ")", "-", "pos", "\n", "if", "max", ">", "20", "{", "max", "=", "20", "\n", "}", "\n\n", "return", "0", ",", "opErr", "{", "pos", ":", "pos", ",", "msg", ":", "\"", "\"", ",", "content", ":", "string", "(", "in", "[", "pos", ":", "pos", "+", "max", "]", ")", ",", "}", "\n", "}", "\n", "}" ]
11
maxmin-12
[ "lexEscape", "scans", "a", "string", "escape", "sequence", ".", "The", "initial", "escaping", "character", "(", "\\", ")", "has", "already", "been", "seen", ".", "NOTE", ":", "This", "function", "as", "well", "as", "the", "helper", "function", "digitVal", "()", "and", "associated", "tests", "have", "been", "adapted", "from", "the", "corresponding", "functions", "in", "the", "go", "/", "scanner", "package", "of", "the", "Go", "standard", "library", "to", "work", "for", "Prometheus", "-", "style", "strings", ".", "None", "of", "the", "actual", "escaping", "/", "quoting", "logic", "was", "changed", "in", "this", "function", "-", "it", "was", "only", "modified", "to", "integrate", "with", "our", "lexer", "." ]
[ "func", "lexEscape", "(", "l", "*", "lexer", ")", "{", "var", "n", "int", "\n", "var", "base", ",", "<mask>", "uint32", "\n\n", "ch", ":=", "l", ".", "next", "(", ")", "\n", "switch", "ch", "{", "case", "'a'", ",", "'b'", ",", "'f'", ",", "'n'", ",", "'r'", ",", "'t'", ",", "'v'", ",", "'\\\\'", ",", "l", ".", "stringOpen", ":", "return", "\n", "case", "'0'", ",", "'1'", ",", "'2'", ",", "'3'", ",", "'4'", ",", "'5'", ",", "'6'", ",", "'7'", ":", "n", ",", "base", ",", "max", "=", "3", ",", "8", ",", "255", "\n", "case", "'x'", ":", "ch", "=", "l", ".", "next", "(", ")", "\n", "n", ",", "base", ",", "max", "=", "2", ",", "16", ",", "255", "\n", "case", "'u'", ":", "ch", "=", "l", ".", "next", "(", ")", "\n", "n", ",", "base", ",", "max", "=", "4", ",", "16", ",", "unicode", ".", "MaxRune", "\n", "case", "'U'", ":", "ch", "=", "l", ".", "next", "(", ")", "\n", "n", ",", "base", ",", "max", "=", "8", ",", "16", ",", "unicode", ".", "MaxRune", "\n", "case", "eof", ":", "l", ".", "errorf", "(", "\"", "\"", ")", "\n", "default", ":", "l", ".", "errorf", "(", "\"", "\"", ",", "ch", ")", "\n", "}", "\n\n", "var", "x", "uint32", "\n", "for", "n", ">", "0", "{", "d", ":=", "uint32", "(", "digitVal", "(", "ch", ")", ")", "\n", "if", "d", ">=", "base", "{", "if", "ch", "==", "eof", "{", "l", ".", "errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "l", ".", "errorf", "(", "\"", "\"", ",", "ch", ")", "\n", "}", "\n", "x", "=", "x", "*", "base", "+", "d", "\n", "ch", "=", "l", ".", "next", "(", ")", "\n", "n", "--", "\n", "}", "\n\n", "if", "x", ">", "max", "||", "0xD800", "<=", "x", "&&", "x", "<", "0xE000", "{", "l", ".", "errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "}" ]
12
maxmin-13
[ "Read", "is", "io", ".", "Reader", "s", "Read", ".", "Read", "fills", "the", "data", "with", "sine", "wave", "samples", "." ]
[ "func", "(", "s", "*", "stream", ")", "Read", "(", "buf", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "if", "len", "(", "s", ".", "remaining", ")", ">", "0", "{", "n", ":=", "copy", "(", "buf", ",", "s", ".", "remaining", ")", "\n", "s", ".", "remaining", "=", "s", ".", "remaining", "[", "n", ":", "]", "\n", "return", "n", ",", "nil", "\n", "}", "\n\n", "var", "origBuf", "[", "]", "byte", "\n", "if", "len", "(", "buf", ")", "%", "4", ">", "0", "{", "origBuf", "=", "buf", "\n", "buf", "=", "make", "(", "[", "]", "byte", ",", "len", "(", "origBuf", ")", "+", "4", "-", "len", "(", "origBuf", ")", "%", "4", ")", "\n", "}", "\n\n", "const", "length", "=", "int64", "(", "sampleRate", "/", "frequency", ")", "\n", "p", ":=", "s", ".", "position", "/", "4", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "buf", ")", "/", "4", ";", "i", "++", "{", "const", "<mask>", "=", "32767", "\n", "b", ":=", "int16", "(", "math", ".", "Sin", "(", "2", "*", "math", ".", "Pi", "*", "float64", "(", "p", ")", "/", "float64", "(", "length", ")", ")", "*", "max", ")", "\n", "buf", "[", "4", "*", "i", "]", "=", "byte", "(", "b", ")", "\n", "buf", "[", "4", "*", "i", "+", "1", "]", "=", "byte", "(", "b", ">>", "8", ")", "\n", "buf", "[", "4", "*", "i", "+", "2", "]", "=", "byte", "(", "b", ")", "\n", "buf", "[", "4", "*", "i", "+", "3", "]", "=", "byte", "(", "b", ">>", "8", ")", "\n", "p", "++", "\n", "}", "\n\n", "s", ".", "position", "+=", "int64", "(", "len", "(", "buf", ")", ")", "\n", "s", ".", "position", "%=", "length", "*", "4", "\n\n", "if", "origBuf", "!=", "nil", "{", "n", ":=", "copy", "(", "origBuf", ",", "buf", ")", "\n", "s", ".", "remaining", "=", "buf", "[", "n", ":", "]", "\n", "return", "n", ",", "nil", "\n", "}", "\n", "return", "len", "(", "buf", ")", ",", "nil", "\n", "}" ]
13
maxmin-14
[ "getCWStatsSet", "gets", "the", "stats", "set", "for", "either", "CPU", "or", "Memory", "based", "on", "the", "function", "pointer", "." ]
[ "func", "(", "queue", "*", "Queue", ")", "getCWStatsSet", "(", "f", "getUsageFunc", ")", "(", "*", "ecstcs", ".", "CWStatsSet", ",", "error", ")", "{", "queue", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "queue", ".", "lock", ".", "Unlock", "(", ")", "\n\n", "queueLength", ":=", "len", "(", "queue", ".", "buffer", ")", "\n", "if", "queueLength", "<", "2", "{", "// Need at least 2 data points to calculate this.", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "var", "<mask>", ",", "max", ",", "sum", "float64", "\n", "var", "sampleCount", "int64", "\n", "min", "=", "math", ".", "MaxFloat64", "\n", "max", "=", "-", "math", ".", "MaxFloat64", "\n", "sum", "=", "0", "\n", "sampleCount", "=", "0", "\n\n", "for", "_", ",", "stat", ":=", "range", "queue", ".", "buffer", "{", "perc", ":=", "f", "(", "&", "stat", ")", "\n", "if", "math", ".", "IsNaN", "(", "perc", ")", "{", "continue", "\n", "}", "\n\n", "min", "=", "math", ".", "Min", "(", "min", ",", "perc", ")", "\n", "max", "=", "math", ".", "Max", "(", "max", ",", "perc", ")", "\n", "sampleCount", "++", "\n", "sum", "+=", "perc", "\n", "}", "\n\n", "return", "&", "ecstcs", ".", "CWStatsSet", "{", "Max", ":", "&", "max", ",", "Min", ":", "&", "min", ",", "SampleCount", ":", "&", "sampleCount", ",", "Sum", ":", "&", "sum", ",", "}", ",", "nil", "\n", "}" ]
14
maxmin-15
[ "RateLimit", "is", "a", "Gin", "middleware", "for", "rate", "limitting", "incoming", "requests", "based", "on", "the", "client", "s", "IP", "address", ".", "The", "resulting", "middleware", "will", "use", "the", "client", "to", "talk", "to", "the", "Redis", "server", ".", "The", "hasher", "is", "used", "to", "keep", "track", "of", "counters", "and", "to", "provide", "an", "estimate", "of", "when", "the", "client", "should", "be", "able", "to", "do", "requests", "again", ".", "The", "limit", "per", "period", "is", "defined", "by", "the", "max", ".", "Response", "format", "Once", "a", "client", "reaches", "the", "imposed", "limit", "they", "will", "receive", "a", "JSON", "response", "similar", "to", "the", "following", ":", "{", "messages", ":", "[", "Rate", "limit", "exceeded", ".", "Try", "again", "in", "1", "minute", "from", "now", "]", "status", ":", "error", "}" ]
[ "func", "RateLimit", "(", "client", "*", "redis", ".", "Client", ",", "hasher", "speedbump", ".", "RateHasher", ",", "<mask>", "int64", ")", "gin", ".", "HandlerFunc", "{", "limiter", ":=", "speedbump", ".", "NewLimiter", "(", "client", ",", "hasher", ",", "max", ")", "\n\n", "return", "func", "(", "c", "*", "gin", ".", "Context", ")", "{", "// Attempt to perform the request", "ip", ",", "_", ",", "_", ":=", "net", ".", "SplitHostPort", "(", "c", ".", "Request", ".", "RemoteAddr", ")", "\n", "ok", ",", "err", ":=", "limiter", ".", "Attempt", "(", "ip", ")", "\n\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n\n", "if", "!", "ok", "{", "nextTime", ":=", "time", ".", "Now", "(", ")", ".", "Add", "(", "hasher", ".", "Duration", "(", ")", ")", "\n\n", "c", ".", "JSON", "(", "429", ",", "gin", ".", "H", "{", "\"", "\"", ":", "\"", "\"", ",", "\"", "\"", ":", "[", "]", "string", "{", "\"", "\"", "+", "humanize", ".", "Time", "(", "nextTime", ")", "}", ",", "}", ")", "\n", "c", ".", "Abort", "(", ")", "\n", "}", "\n\n", "c", ".", "Next", "(", ")", "\n\n", "// After the request", "// log.Print(ip + \" was limited because it exceeded the max rate\")", "}", "\n", "}" ]
15
maxmin-16
[ "returns", "true", "if", "the", "next", "n", "values", "in", "in", "can", "be", "packed", "using", "bits", "bits", "per", "value", "." ]
[ "func", "canPack", "(", "src", "[", "]", "uint32", ",", "bits", ",", "n", "int", ")", "bool", "{", "if", "len", "(", "src", ")", "<", "n", "{", "return", "false", "\n", "}", "\n\n", "end", ":=", "len", "(", "src", ")", "\n", "if", "n", "<", "end", "{", "end", "=", "n", "\n", "}", "\n\n", "<mask>", ":=", "uint32", "(", "(", "2", "<<", "uint32", "(", "bits", "-", "1", ")", ")", "-", "1", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "end", ";", "i", "++", "{", "if", "src", "[", "i", "]", ">", "max", "{", "return", "false", "\n", "}", "\n", "}", "\n\n", "return", "true", "\n", "}" ]
16
maxmin-17
[ "tick", "updates", "the", "minimum", "quiescence", "timer", "." ]
[ "func", "(", "q", "*", "quiescence", ")", "tick", "(", ")", "{", "now", ":=", "time", ".", "Now", "(", ")", "\n\n", "// If this is the first tick, set up the timer and calculate the max", "// deadline.", "if", "q", ".", "timer", "==", "nil", "{", "q", ".", "timer", "=", "time", ".", "NewTimer", "(", "q", ".", "<mask>", ")", "\n", "go", "func", "(", ")", "{", "select", "{", "case", "<-", "q", ".", "timer", ".", "C", ":", "q", ".", "ch", "<-", "q", ".", "template", "\n", "}", "\n", "}", "(", ")", "\n\n", "q", ".", "deadline", "=", "now", ".", "Add", "(", "q", ".", "max", ")", "\n", "return", "\n", "}", "\n\n", "// Snooze the timer for the min time, or snooze less if we are coming", "// up against the max time. If the timer has already fired and the reset", "// doesn't work that's ok because we guarantee that the channel gets our", "// template which means that we are obsolete and a fresh quiescence will", "// be set up.", "if", "now", ".", "Add", "(", "q", ".", "min", ")", ".", "Before", "(", "q", ".", "deadline", ")", "{", "q", ".", "timer", ".", "Reset", "(", "q", ".", "min", ")", "\n", "}", "else", "if", "dur", ":=", "q", ".", "deadline", ".", "Sub", "(", "now", ")", ";", "dur", ">", "0", "{", "q", ".", "timer", ".", "Reset", "(", "dur", ")", "\n", "}", "\n", "}" ]
17
maxmin-18
[ "integer", "types" ]
[ "func", "convertNvInteger", "(", "v", "interface", "{", "}", ",", "<mask>", ",", "max", "int64", ")", "(", "driver", ".", "Value", ",", "error", ")", "{", "if", "v", "==", "nil", "{", "return", "v", ",", "nil", "\n", "}", "\n\n", "rv", ":=", "reflect", ".", "ValueOf", "(", "v", ")", "\n", "switch", "rv", ".", "Kind", "(", ")", "{", "// bool is represented in HDB as tinyint", "case", "reflect", ".", "Bool", ":", "return", "rv", ".", "Bool", "(", ")", ",", "nil", "\n", "case", "reflect", ".", "Int", ",", "reflect", ".", "Int8", ",", "reflect", ".", "Int16", ",", "reflect", ".", "Int32", ",", "reflect", ".", "Int64", ":", "i64", ":=", "rv", ".", "Int", "(", ")", "\n", "if", "i64", ">", "max", "||", "i64", "<", "min", "{", "return", "nil", ",", "ErrIntegerOutOfRange", "\n", "}", "\n", "return", "i64", ",", "nil", "\n", "case", "reflect", ".", "Uint", ",", "reflect", ".", "Uint8", ",", "reflect", ".", "Uint16", ",", "reflect", ".", "Uint32", ",", "reflect", ".", "Uint64", ":", "u64", ":=", "rv", ".", "Uint", "(", ")", "\n", "if", "u64", ">", "uint64", "(", "max", ")", "{", "return", "nil", ",", "ErrIntegerOutOfRange", "\n", "}", "\n", "return", "int64", "(", "u64", ")", ",", "nil", "\n", "case", "reflect", ".", "Ptr", ":", "// indirect pointers", "if", "rv", ".", "IsNil", "(", ")", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "return", "convertNvInteger", "(", "rv", ".", "Elem", "(", ")", ".", "Interface", "(", ")", ",", "min", ",", "max", ")", "\n", "}", "\n\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "v", ")", "\n", "}" ]
18
maxmin-19
[ "OptFieldTypeInt", "adds", "an", "integer", "field", "." ]
[ "func", "OptFieldTypeInt", "(", "<mask>", "int64", ",", "max", "int64", ")", "FieldOption", "{", "return", "func", "(", "options", "*", "FieldOptions", ")", "{", "options", ".", "fieldType", "=", "FieldTypeInt", "\n", "options", ".", "min", "=", "min", "\n", "options", ".", "max", "=", "max", "\n", "}", "\n", "}" ]
19
maxmin-20
[ "rayCasting", "returns", "a", "slice", "of", "line", "originating", "from", "point", "cx", "cy", "and", "intersecting", "with", "objects" ]
[ "func", "rayCasting", "(", "cx", ",", "cy", "float64", ",", "objects", "[", "]", "object", ")", "[", "]", "line", "{", "const", "rayLength", "=", "1000", "// something large enough to reach all objects", "\n\n", "var", "rays", "[", "]", "line", "\n", "for", "_", ",", "obj", ":=", "range", "objects", "{", "// Cast two rays per point", "for", "_", ",", "p", ":=", "range", "obj", ".", "points", "(", ")", "{", "l", ":=", "line", "{", "cx", ",", "cy", ",", "p", "[", "0", "]", ",", "p", "[", "1", "]", "}", "\n", "angle", ":=", "l", ".", "angle", "(", ")", "\n\n", "for", "_", ",", "offset", ":=", "range", "[", "]", "float64", "{", "-", "0.005", ",", "0.005", "}", "{", "points", ":=", "[", "]", "[", "2", "]", "float64", "{", "}", "\n", "ray", ":=", "newRay", "(", "cx", ",", "cy", ",", "rayLength", ",", "angle", "+", "offset", ")", "\n\n", "// Unpack all objects", "for", "_", ",", "o", ":=", "range", "objects", "{", "for", "_", ",", "wall", ":=", "range", "o", ".", "walls", "{", "if", "px", ",", "py", ",", "ok", ":=", "intersection", "(", "ray", ",", "wall", ")", ";", "ok", "{", "points", "=", "append", "(", "points", ",", "[", "2", "]", "float64", "{", "px", ",", "py", "}", ")", "\n", "}", "\n", "}", "\n", "}", "\n\n", "// Find the point closest to start of ray", "<mask>", ":=", "math", ".", "Inf", "(", "1", ")", "\n", "minI", ":=", "-", "1", "\n", "for", "i", ",", "p", ":=", "range", "points", "{", "d2", ":=", "(", "cx", "-", "p", "[", "0", "]", ")", "*", "(", "cx", "-", "p", "[", "0", "]", ")", "+", "(", "cy", "-", "p", "[", "1", "]", ")", "*", "(", "cy", "-", "p", "[", "1", "]", ")", "\n", "if", "d2", "<", "min", "{", "min", "=", "d2", "\n", "minI", "=", "i", "\n", "}", "\n", "}", "\n", "rays", "=", "append", "(", "rays", ",", "line", "{", "cx", ",", "cy", ",", "points", "[", "minI", "]", "[", "0", "]", ",", "points", "[", "minI", "]", "[", "1", "]", "}", ")", "\n", "}", "\n", "}", "\n", "}", "\n\n", "// Sort rays based on angle, otherwise light triangles will not come out right", "sort", ".", "Slice", "(", "rays", ",", "func", "(", "i", "int", ",", "j", "int", ")", "bool", "{", "return", "rays", "[", "i", "]", ".", "angle", "(", ")", "<", "rays", "[", "j", "]", ".", "angle", "(", ")", "\n", "}", ")", "\n", "return", "rays", "\n", "}" ]
20
maxmin-21
[ "float", "types" ]
[ "func", "convertNvFloat", "(", "v", "interface", "{", "}", ",", "<mask>", "float64", ")", "(", "driver", ".", "Value", ",", "error", ")", "{", "if", "v", "==", "nil", "{", "return", "v", ",", "nil", "\n", "}", "\n\n", "rv", ":=", "reflect", ".", "ValueOf", "(", "v", ")", "\n", "switch", "rv", ".", "Kind", "(", ")", "{", "case", "reflect", ".", "Float32", ",", "reflect", ".", "Float64", ":", "f64", ":=", "rv", ".", "Float", "(", ")", "\n", "if", "math", ".", "Abs", "(", "f64", ")", ">", "max", "{", "return", "nil", ",", "ErrFloatOutOfRange", "\n", "}", "\n", "return", "f64", ",", "nil", "\n", "case", "reflect", ".", "Ptr", ":", "// indirect pointers", "if", "rv", ".", "IsNil", "(", ")", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "return", "convertNvFloat", "(", "rv", ".", "Elem", "(", ")", ".", "Interface", "(", ")", ",", "max", ")", "\n", "}", "\n\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "v", ")", "\n", "}" ]
21
maxmin-22
[ "clamp", "clamps", "v", "to", "the", "range", "[", "min", "max", "]", "." ]
[ "func", "clamp", "(", "v", ",", "<mask>", ",", "max", "int", ")", "int", "{", "if", "min", ">", "max", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "v", "<", "min", "{", "return", "min", "\n", "}", "\n", "if", "max", "<", "v", "{", "return", "max", "\n", "}", "\n", "return", "v", "\n", "}" ]
22
maxmin-23
[ "/", "*", "NewProgressBar", "creates", "a", "new", "ProgressBar", ".", "parent", "-", "is", "container", "that", "keeps", "the", "control", ".", "width", "and", "heigth", "-", "are", "minimal", "size", "of", "the", "control", ".", "scale", "-", "the", "way", "of", "scaling", "the", "control", "when", "the", "parent", "is", "resized", ".", "Use", "DoNotScale", "constant", "if", "the", "control", "should", "keep", "its", "original", "size", "." ]
[ "func", "CreateProgressBar", "(", "parent", "Control", ",", "width", ",", "height", "int", ",", "scale", "int", ")", "*", "ProgressBar", "{", "b", ":=", "new", "(", "ProgressBar", ")", "\n", "b", ".", "BaseControl", "=", "NewBaseControl", "(", ")", "\n\n", "if", "height", "==", "AutoSize", "{", "height", "=", "1", "\n", "}", "\n", "if", "width", "==", "AutoSize", "{", "width", "=", "10", "\n", "}", "\n\n", "b", ".", "SetSize", "(", "width", ",", "height", ")", "\n", "b", ".", "SetConstraints", "(", "width", ",", "height", ")", "\n", "b", ".", "SetTabStop", "(", "false", ")", "\n", "b", ".", "SetScale", "(", "scale", ")", "\n", "b", ".", "<mask>", "=", "0", "\n", "b", ".", "max", "=", "10", "\n", "b", ".", "direction", "=", "Horizontal", "\n", "b", ".", "parent", "=", "parent", "\n", "b", ".", "align", "=", "AlignCenter", "\n\n", "if", "parent", "!=", "nil", "{", "parent", ".", "AddChild", "(", "b", ")", "\n", "}", "\n\n", "return", "b", "\n", "}" ]
23
maxmin-24
[ "PageDown", "moves", "the", "visible", "list", "forward", "by", "x", "items", ".", "Where", "x", "is", "the", "size", "of", "the", "visible", "items", "on", "the", "list", ".", "The", "selected", "item", "becomes", "the", "first", "visible", "item", "." ]
[ "func", "(", "l", "*", "List", ")", "PageDown", "(", ")", "{", "start", ":=", "l", ".", "start", "+", "l", ".", "size", "\n", "<mask>", ":=", "len", "(", "l", ".", "scope", ")", "-", "l", ".", "size", "\n\n", "switch", "{", "case", "len", "(", "l", ".", "scope", ")", "<", "l", ".", "size", ":", "l", ".", "start", "=", "0", "\n", "case", "start", ">", "max", ":", "l", ".", "start", "=", "max", "\n", "default", ":", "l", ".", "start", "=", "start", "\n", "}", "\n\n", "cursor", ":=", "l", ".", "start", "\n\n", "if", "cursor", "==", "l", ".", "cursor", "{", "l", ".", "cursor", "=", "len", "(", "l", ".", "scope", ")", "-", "1", "\n", "}", "else", "if", "cursor", ">", "l", ".", "cursor", "{", "l", ".", "cursor", "=", "cursor", "\n", "}", "\n", "}" ]
24
maxmin-25
[ "merge", "merges", "two", "similar", "Signature", "zapping", "out", "differences", "." ]
[ "func", "(", "s", "*", "Signature", ")", "merge", "(", "r", "*", "Signature", ")", "*", "Signature", "{", "<mask>", ":=", "s", ".", "SleepMin", "\n", "if", "r", ".", "SleepMin", "<", "min", "{", "min", "=", "r", ".", "SleepMin", "\n", "}", "\n", "max", ":=", "s", ".", "SleepMax", "\n", "if", "r", ".", "SleepMax", ">", "max", "{", "max", "=", "r", ".", "SleepMax", "\n", "}", "\n", "return", "&", "Signature", "{", "State", ":", "s", ".", "State", ",", "// Drop right side.", "CreatedBy", ":", "s", ".", "CreatedBy", ",", "// Drop right side.", "SleepMin", ":", "min", ",", "SleepMax", ":", "max", ",", "Stack", ":", "*", "s", ".", "Stack", ".", "merge", "(", "&", "r", ".", "Stack", ")", ",", "Locked", ":", "s", ".", "Locked", "||", "r", ".", "Locked", ",", "// TODO(maruel): This is weirdo.", "}", "\n", "}" ]
25
maxmin-26
[ "parseShadow", "parses", "the", "row", "of", "a", "shadowed", "password", "." ]
[ "func", "parseShadow", "(", "row", "string", ")", "(", "*", "Shadow", ",", "error", ")", "{", "fields", ":=", "strings", ".", "Split", "(", "row", ",", "\"", "\"", ")", "\n", "if", "len", "(", "fields", ")", "!=", "9", "{", "return", "nil", ",", "rowError", "{", "_SHADOW_FILE", ",", "row", "}", "\n", "}", "\n\n", "var", "inactive", ",", "expire", ",", "flag", "int", "\n\n", "changed", ",", "err", ":=", "parseChange", "(", "fields", "[", "2", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "atoiError", "{", "_SHADOW_FILE", ",", "row", ",", "\"", "\"", "}", "\n", "}", "\n", "<mask>", ",", "err", ":=", "strconv", ".", "Atoi", "(", "fields", "[", "3", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "atoiError", "{", "_SHADOW_FILE", ",", "row", ",", "\"", "\"", "}", "\n", "}", "\n", "max", ",", "err", ":=", "strconv", ".", "Atoi", "(", "fields", "[", "4", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "atoiError", "{", "_SHADOW_FILE", ",", "row", ",", "\"", "\"", "}", "\n", "}", "\n", "warn", ",", "err", ":=", "strconv", ".", "Atoi", "(", "fields", "[", "5", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "atoiError", "{", "_SHADOW_FILE", ",", "row", ",", "\"", "\"", "}", "\n", "}", "\n\n", "// Optional fields", "if", "fields", "[", "6", "]", "!=", "\"", "\"", "{", "if", "inactive", ",", "err", "=", "strconv", ".", "Atoi", "(", "fields", "[", "6", "]", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "atoiError", "{", "_SHADOW_FILE", ",", "row", ",", "\"", "\"", "}", "\n", "}", "\n", "}", "\n", "if", "fields", "[", "7", "]", "!=", "\"", "\"", "{", "if", "expire", ",", "err", "=", "strconv", ".", "Atoi", "(", "fields", "[", "7", "]", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "atoiError", "{", "_SHADOW_FILE", ",", "row", ",", "\"", "\"", "}", "\n", "}", "\n", "}", "\n", "if", "fields", "[", "8", "]", "!=", "\"", "\"", "{", "if", "flag", ",", "err", "=", "strconv", ".", "Atoi", "(", "fields", "[", "8", "]", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "atoiError", "{", "_SHADOW_FILE", ",", "row", ",", "\"", "\"", "}", "\n", "}", "\n", "}", "\n\n", "return", "&", "Shadow", "{", "fields", "[", "0", "]", ",", "fields", "[", "1", "]", ",", "changed", ",", "min", ",", "max", ",", "warn", ",", "inactive", ",", "expire", ",", "flag", ",", "}", ",", "nil", "\n", "}" ]
26
maxmin-27
[ "String", "returns", "the", "position", "of", "the", "string", "that", "begins", "at", "the", "specified", "pos" ]
[ "func", "String", "(", "in", "[", "]", "byte", ",", "pos", "int", ")", "(", "int", ",", "error", ")", "{", "pos", ",", "err", ":=", "skipSpace", "(", "in", ",", "pos", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n\n", "<mask>", ":=", "len", "(", "in", ")", "\n\n", "if", "v", ":=", "in", "[", "pos", "]", ";", "v", "!=", "'\"'", "{", "return", "0", ",", "newError", "(", "pos", ",", "v", ")", "\n", "}", "\n", "pos", "++", "\n\n", "for", "{", "switch", "in", "[", "pos", "]", "{", "case", "'\\\\'", ":", "if", "in", "[", "pos", "+", "1", "]", "==", "'\"'", "{", "pos", "++", "\n", "}", "\n", "case", "'\"'", ":", "return", "pos", "+", "1", ",", "nil", "\n", "}", "\n", "pos", "++", "\n\n", "if", "pos", ">=", "max", "{", "break", "\n", "}", "\n", "}", "\n\n", "return", "0", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}" ]
27
maxmin-28
[ "Left", "returns", "the", "number", "of", "remaining", "requests", "for", "id", "during", "a", "current", "period", "." ]
[ "func", "(", "r", "*", "RateLimiter", ")", "Left", "(", "id", "string", ")", "(", "int64", ",", "error", ")", "{", "// Retrieve attempted count.", "attempted", ",", "err", ":=", "r", ".", "Attempted", "(", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n\n", "// Left is max minus attempted.", "left", ":=", "r", ".", "<mask>", "-", "attempted", "\n", "if", "left", "<", "0", "{", "return", "0", ",", "nil", "\n", "}", "\n\n", "return", "left", ",", "nil", "\n", "}" ]
28
maxmin-29
[ "Next", "moves", "the", "visible", "list", "forward", "one", "item", ".", "If", "the", "selected", "item", "is", "out", "of", "view", "the", "new", "select", "item", "becomes", "the", "first", "visible", "item", ".", "If", "the", "list", "is", "already", "at", "the", "bottom", "nothing", "happens", "." ]
[ "func", "(", "l", "*", "List", ")", "Next", "(", ")", "{", "<mask>", ":=", "len", "(", "l", ".", "scope", ")", "-", "1", "\n\n", "if", "l", ".", "cursor", "<", "max", "{", "l", ".", "cursor", "++", "\n", "}", "\n\n", "if", "l", ".", "start", "+", "l", ".", "size", "<=", "l", ".", "cursor", "{", "l", ".", "start", "=", "l", ".", "cursor", "-", "l", ".", "size", "+", "1", "\n", "}", "\n", "}" ]
29
maxmin-30
[ "stacks", "is", "a", "wrapper", "for", "runtime", ".", "Stack", "that", "attempts", "to", "recover", "the", "data", "for", "all", "goroutines", "." ]
[ "func", "stacks", "(", "all", "bool", ",", "<mask>", "int", ")", "[", "]", "byte", "{", "// We don't know how big the traces are, so grow a few times if they don't fit. Start large, though.", "n", ":=", "initialMaxStackBufSize", "\n", "var", "trace", "[", "]", "byte", "\n", "for", "n", "<=", "max", "{", "trace", "=", "make", "(", "[", "]", "byte", ",", "n", ")", "\n", "nbytes", ":=", "runtime", ".", "Stack", "(", "trace", ",", "all", ")", "\n", "if", "nbytes", "<", "len", "(", "trace", ")", "{", "return", "trace", "[", ":", "nbytes", "]", "\n", "}", "\n", "n", "*=", "2", "\n", "}", "\n", "return", "trace", "\n", "}" ]
30
maxmin-31
[ "ScaleButtonNew", "()", "is", "a", "wrapper", "around", "gtk_scale_button_new", "()", "." ]
[ "func", "ScaleButtonNew", "(", "size", "IconSize", ",", "<mask>", ",", "max", ",", "step", "float64", ",", "icons", "[", "]", "string", ")", "(", "*", "ScaleButton", ",", "error", ")", "{", "cicons", ":=", "make", "(", "[", "]", "*", "C", ".", "gchar", ",", "len", "(", "icons", ")", ")", "\n", "for", "i", ",", "icon", ":=", "range", "icons", "{", "cicons", "[", "i", "]", "=", "(", "*", "C", ".", "gchar", ")", "(", "C", ".", "CString", "(", "icon", ")", ")", "\n", "defer", "C", ".", "free", "(", "unsafe", ".", "Pointer", "(", "cicons", "[", "i", "]", ")", ")", "\n", "}", "\n", "cicons", "=", "append", "(", "cicons", ",", "nil", ")", "\n\n", "c", ":=", "C", ".", "gtk_scale_button_new", "(", "C", ".", "GtkIconSize", "(", "size", ")", ",", "C", ".", "gdouble", "(", "min", ")", ",", "C", ".", "gdouble", "(", "max", ")", ",", "C", ".", "gdouble", "(", "step", ")", ",", "&", "cicons", "[", "0", "]", ")", "\n", "if", "c", "==", "nil", "{", "return", "nil", ",", "nilPtrErr", "\n", "}", "\n", "return", "wrapScaleButton", "(", "glib", ".", "Take", "(", "unsafe", ".", "Pointer", "(", "c", ")", ")", ")", ",", "nil", "\n", "}" ]
31
maxmin-32
[ "ParseWaitConfig", "parses", "a", "string", "of", "the", "format", "minimum", "(", ":", "maximum", ")", "into", "a", "WaitConfig", "." ]
[ "func", "ParseWaitConfig", "(", "s", "string", ")", "(", "*", "WaitConfig", ",", "error", ")", "{", "s", "=", "strings", ".", "TrimSpace", "(", "s", ")", "\n", "if", "len", "(", "s", ")", "<", "1", "{", "return", "nil", ",", "ErrWaitStringEmpty", "\n", "}", "\n\n", "parts", ":=", "strings", ".", "Split", "(", "s", ",", "\"", "\"", ")", "\n\n", "var", "<mask>", ",", "max", "time", ".", "Duration", "\n", "var", "err", "error", "\n\n", "switch", "len", "(", "parts", ")", "{", "case", "1", ":", "min", ",", "err", "=", "time", ".", "ParseDuration", "(", "strings", ".", "TrimSpace", "(", "parts", "[", "0", "]", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "max", "=", "4", "*", "min", "\n", "case", "2", ":", "min", ",", "err", "=", "time", ".", "ParseDuration", "(", "strings", ".", "TrimSpace", "(", "parts", "[", "0", "]", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "max", ",", "err", "=", "time", ".", "ParseDuration", "(", "strings", ".", "TrimSpace", "(", "parts", "[", "1", "]", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "default", ":", "return", "nil", ",", "ErrWaitInvalidFormat", "\n", "}", "\n\n", "if", "min", "<", "0", "||", "max", "<", "0", "{", "return", "nil", ",", "ErrWaitNegative", "\n", "}", "\n\n", "if", "max", "<", "min", "{", "return", "nil", ",", "ErrWaitMinLTMax", "\n", "}", "\n\n", "var", "c", "WaitConfig", "\n", "c", ".", "Min", "=", "TimeDuration", "(", "min", ")", "\n", "c", ".", "Max", "=", "TimeDuration", "(", "max", ")", "\n\n", "return", "&", "c", ",", "nil", "\n", "}" ]
32
maxmin-33
[ "arrayLen", "returns", "the", "length", "of", "the", "array", "whose", "composite", "literal", "elements", "are", "elts", "." ]
[ "func", "(", "b", "*", "builder", ")", "arrayLen", "(", "fn", "*", "Function", ",", "elts", "[", "]", "ast", ".", "Expr", ")", "int64", "{", "var", "<mask>", "int64", "=", "-", "1", "\n", "var", "i", "int64", "=", "-", "1", "\n", "for", "_", ",", "e", ":=", "range", "elts", "{", "if", "kv", ",", "ok", ":=", "e", ".", "(", "*", "ast", ".", "KeyValueExpr", ")", ";", "ok", "{", "i", "=", "b", ".", "expr", "(", "fn", ",", "kv", ".", "Key", ")", ".", "(", "*", "Const", ")", ".", "Int64", "(", ")", "\n", "}", "else", "{", "i", "++", "\n", "}", "\n", "if", "i", ">", "max", "{", "max", "=", "i", "\n", "}", "\n", "}", "\n", "return", "max", "+", "1", "\n", "}" ]
33
maxmin-34
[ "Number", "returns", "the", "end", "position", "of", "the", "number", "that", "begins", "at", "the", "specified", "pos" ]
[ "func", "Number", "(", "in", "[", "]", "byte", ",", "pos", "int", ")", "(", "int", ",", "error", ")", "{", "pos", ",", "err", ":=", "skipSpace", "(", "in", ",", "pos", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n\n", "<mask>", ":=", "len", "(", "in", ")", "\n", "for", "{", "v", ":=", "in", "[", "pos", "]", "\n", "switch", "v", "{", "case", "'-'", ",", "'+'", ",", "'.'", ",", "'e'", ",", "'E'", ",", "'1'", ",", "'2'", ",", "'3'", ",", "'4'", ",", "'5'", ",", "'6'", ",", "'7'", ",", "'8'", ",", "'9'", ",", "'0'", ":", "pos", "++", "\n", "default", ":", "return", "pos", ",", "nil", "\n", "}", "\n\n", "if", "pos", ">=", "max", "{", "return", "pos", ",", "nil", "\n", "}", "\n", "}", "\n\n", "return", "pos", ",", "nil", "\n", "}" ]
34
maxmin-35
[ "-----------------", "own", "methods", "-------------------------", "SetValue", "sets", "new", "progress", "value", ".", "If", "value", "exceeds", "ProgressBar", "limits", "then", "the", "limit", "value", "is", "used" ]
[ "func", "(", "b", "*", "ProgressBar", ")", "SetValue", "(", "pos", "int", ")", "{", "b", ".", "mtx", ".", "Lock", "(", ")", "\n", "defer", "b", ".", "mtx", ".", "Unlock", "(", ")", "\n", "if", "pos", "<", "b", ".", "<mask>", "{", "b", ".", "value", "=", "b", ".", "min", "\n", "}", "else", "if", "pos", ">", "b", ".", "max", "{", "b", ".", "value", "=", "b", ".", "max", "\n", "}", "else", "{", "b", ".", "value", "=", "pos", "\n", "}", "\n", "}" ]
35
maxmin-36
[ "Items", "returns", "a", "slice", "equal", "to", "the", "size", "of", "the", "list", "with", "the", "current", "visible", "items", "and", "the", "index", "of", "the", "active", "item", "in", "this", "list", "." ]
[ "func", "(", "l", "*", "List", ")", "Items", "(", ")", "(", "[", "]", "interface", "{", "}", ",", "int", ")", "{", "var", "result", "[", "]", "interface", "{", "}", "\n", "<mask>", ":=", "len", "(", "l", ".", "scope", ")", "\n", "end", ":=", "l", ".", "start", "+", "l", ".", "size", "\n\n", "if", "end", ">", "max", "{", "end", "=", "max", "\n", "}", "\n\n", "active", ":=", "NotFound", "\n\n", "for", "i", ",", "j", ":=", "l", ".", "start", ",", "0", ";", "i", "<", "end", ";", "i", ",", "j", "=", "i", "+", "1", ",", "j", "+", "1", "{", "if", "l", ".", "cursor", "==", "i", "{", "active", "=", "j", "\n", "}", "\n\n", "result", "=", "append", "(", "result", ",", "*", "l", ".", "scope", "[", "i", "]", ")", "\n", "}", "\n\n", "return", "result", ",", "active", "\n", "}" ]
36
maxmin-37
[ "Find", "the", "price", "in", "the", "given", "package", "with", "the", "specified", "size", "and", "iops" ]
[ "func", "FindPerformanceIOPSPrice", "(", "productPackage", "datatypes", ".", "Product_Package", ",", "size", "int", ",", "iops", "int", ")", "(", "datatypes", ".", "Product_Item_Price", ",", "error", ")", "{", "for", "_", ",", "item", ":=", "range", "productPackage", ".", "Items", "{", "if", "int", "(", "*", "item", ".", "Capacity", ")", "!=", "int", "(", "iops", ")", "{", "continue", "\n", "}", "\n", "for", "_", ",", "price", ":=", "range", "item", ".", "Prices", "{", "// Only collect prices from valid location groups.", "if", "price", ".", "LocationGroupId", "!=", "nil", "{", "continue", "\n", "}", "\n", "if", "!", "hasCategory", "(", "price", ".", "Categories", ",", "\"", "\"", ")", "{", "continue", "\n", "}", "\n", "<mask>", ",", "err", ":=", "strconv", ".", "Atoi", "(", "*", "price", ".", "CapacityRestrictionMinimum", ")", "\n", "if", "err", "!=", "nil", "{", "return", "datatypes", ".", "Product_Item_Price", "{", "}", ",", "bosherr", ".", "Errorf", "(", "\"", "\"", ",", "iops", ")", "\n", "}", "\n", "if", "size", "<", "int", "(", "min", ")", "{", "continue", "\n", "}", "\n", "max", ",", "err", ":=", "strconv", ".", "Atoi", "(", "*", "price", ".", "CapacityRestrictionMaximum", ")", "\n", "if", "err", "!=", "nil", "{", "return", "datatypes", ".", "Product_Item_Price", "{", "}", ",", "bosherr", ".", "Errorf", "(", "\"", "\"", ",", "iops", ")", "\n", "}", "\n", "if", "size", ">", "int", "(", "max", ")", "{", "continue", "\n", "}", "\n", "return", "price", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "datatypes", ".", "Product_Item_Price", "{", "}", ",", "bosherr", ".", "Errorf", "(", "\"", "\"", ",", "iops", ")", "\n", "}" ]
37
maxmin-38
[ "Attempt", "attempts", "to", "perform", "a", "request", "for", "an", "id", "and", "returns", "whether", "it", "was", "successful", "or", "not", "." ]
[ "func", "(", "r", "*", "RateLimiter", ")", "Attempt", "(", "id", "string", ")", "(", "bool", ",", "error", ")", "{", "// Create hash from id", "hash", ":=", "r", ".", "hasher", ".", "Hash", "(", "id", ")", "\n\n", "// Get value for hash in Redis. If redis.Nil is returned, key does not", "// exist.", "exists", ":=", "true", "\n\n", "val", ",", "err", ":=", "r", ".", "redisClient", ".", "Get", "(", "hash", ")", ".", "Result", "(", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "==", "redis", ".", "Nil", "{", "// Key does not exist. See: http://redis.io/commands/GET", "exists", "=", "false", "\n", "}", "else", "{", "return", "false", ",", "err", "\n", "}", "\n", "}", "\n\n", "// If key exists and is >= max requests, return false.", "if", "exists", "{", "intVal", ",", "err", ":=", "strconv", ".", "ParseInt", "(", "val", ",", "10", ",", "64", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n\n", "if", "intVal", ">=", "r", ".", "<mask>", "{", "return", "false", ",", "nil", "\n", "}", "\n", "}", "\n\n", "// Otherwise, increment and expire key for hasher.Duration(). Note, we call", "// Expire even when key already exists to avoid race condition where key", "// expires between prior existence check and this Incr call.", "//", "// See: http://redis.io/commands/INCR", "// See: http://redis.io/commands/INCR#pattern-rate-limiter-1", "err", "=", "r", ".", "redisClient", ".", "Watch", "(", "func", "(", "rx", "*", "redis", ".", "Tx", ")", "error", "{", "_", ",", "err", ":=", "rx", ".", "Pipelined", "(", "func", "(", "pipe", "*", "redis", ".", "Pipeline", ")", "error", "{", "if", "err", ":=", "pipe", ".", "Incr", "(", "hash", ")", ".", "Err", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "pipe", ".", "Expire", "(", "hash", ",", "r", ".", "hasher", ".", "Duration", "(", ")", ")", ".", "Err", "(", ")", "\n", "}", ")", "\n\n", "return", "err", "\n", "}", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n\n", "return", "true", ",", "nil", "\n", "}" ]
38
maxmin-39
[ "===", "floor", "(", "Vector", "ValueTypeVector", ")", "Vector", "===", "===", "max_over_time", "(", "Matrix", "ValueTypeMatrix", ")", "Vector", "===" ]
[ "func", "funcMaxOverTime", "(", "vals", "[", "]", "Value", ",", "args", "Expressions", ",", "enh", "*", "EvalNodeHelper", ")", "Vector", "{", "return", "aggrOverTime", "(", "vals", ",", "enh", ",", "func", "(", "values", "[", "]", "Point", ")", "float64", "{", "<mask>", ":=", "values", "[", "0", "]", ".", "V", "\n", "for", "_", ",", "v", ":=", "range", "values", "{", "if", "v", ".", "V", ">", "max", "||", "math", ".", "IsNaN", "(", "max", ")", "{", "max", "=", "v", ".", "V", "\n", "}", "\n", "}", "\n", "return", "max", "\n", "}", ")", "\n", "}" ]
39
maxmin-40
[ "expandVmwareDistributedVirtualSwitchTrunkVlanSpec", "reads", "certain", "ResourceData", "keys", "and", "returns", "a", "VmwareDistributedVirtualSwitchTrunkVlanSpec", "." ]
[ "func", "expandVmwareDistributedVirtualSwitchTrunkVlanSpec", "(", "d", "*", "schema", ".", "ResourceData", ")", "*", "types", ".", "VmwareDistributedVirtualSwitchTrunkVlanSpec", "{", "var", "ranges", "[", "]", "types", ".", "NumericRange", "\n", "data", ":=", "d", ".", "Get", "(", "\"", "\"", ")", ".", "(", "*", "schema", ".", "Set", ")", ".", "List", "(", ")", "\n", "for", "_", ",", "v", ":=", "range", "data", "{", "log", ".", "Printf", "(", "\"", "\"", ",", "v", ")", "\n", "r", ":=", "v", ".", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "<mask>", ":=", "r", "[", "\"", "\"", "]", ".", "(", "int", ")", "\n", "max", ":=", "r", "[", "\"", "\"", "]", ".", "(", "int", ")", "\n", "rng", ":=", "types", ".", "NumericRange", "{", "Start", ":", "int32", "(", "min", ")", ",", "End", ":", "int32", "(", "max", ")", ",", "}", "\n", "ranges", "=", "append", "(", "ranges", ",", "rng", ")", "\n", "}", "\n\n", "if", "len", "(", "ranges", ")", "<", "1", "{", "return", "nil", "\n", "}", "\n\n", "obj", ":=", "&", "types", ".", "VmwareDistributedVirtualSwitchTrunkVlanSpec", "{", "VlanId", ":", "ranges", ",", "}", "\n", "return", "obj", "\n", "}" ]
40
maxmin-41
[ "SetCursor", "sets", "the", "position", "of", "the", "cursor", "in", "the", "list", ".", "Values", "out", "of", "bounds", "will", "be", "clamped", "." ]
[ "func", "(", "l", "*", "List", ")", "SetCursor", "(", "i", "int", ")", "{", "<mask>", ":=", "len", "(", "l", ".", "scope", ")", "-", "1", "\n", "if", "i", ">=", "max", "{", "i", "=", "max", "\n", "}", "\n", "if", "i", "<", "0", "{", "i", "=", "0", "\n", "}", "\n", "l", ".", "cursor", "=", "i", "\n\n", "if", "l", ".", "start", ">", "l", ".", "cursor", "{", "l", ".", "start", "=", "l", ".", "cursor", "\n", "}", "else", "if", "l", ".", "start", "+", "l", ".", "size", "<=", "l", ".", "cursor", "{", "l", ".", "start", "=", "l", ".", "cursor", "-", "l", ".", "size", "+", "1", "\n", "}", "\n", "}" ]
41
maxmin-42
[ "newQuiescence", "creates", "a", "new", "quiescence", "timer", "for", "the", "given", "template", "." ]
[ "func", "newQuiescence", "(", "ch", "chan", "*", "template", ".", "Template", ",", "<mask>", ",", "max", "time", ".", "Duration", ",", "t", "*", "template", ".", "Template", ")", "*", "quiescence", "{", "return", "&", "quiescence", "{", "template", ":", "t", ",", "min", ":", "min", ",", "max", ":", "max", ",", "ch", ":", "ch", ",", "}", "\n", "}" ]
42
maxmin-43
[ "SetLimits", "set", "new", "ProgressBar", "limits", ".", "The", "current", "value", "is", "adjusted", "if", "it", "exceeds", "new", "limits" ]
[ "func", "(", "b", "*", "ProgressBar", ")", "SetLimits", "(", "<mask>", ",", "max", "int", ")", "{", "b", ".", "min", "=", "min", "\n", "b", ".", "max", "=", "max", "\n\n", "if", "b", ".", "value", "<", "b", ".", "min", "{", "b", ".", "value", "=", "min", "\n", "}", "\n", "if", "b", ".", "value", ">", "b", ".", "max", "{", "b", ".", "value", "=", "max", "\n", "}", "\n", "}" ]
43
maxmin-44
[ "AddInRange", "increments", "a", "value", "by", "the", "passed", "quantity", "while", "ensuring", "the", "values", "always", "remain", "within", "the", "supplied", "min", "/", "max", "range", "." ]
[ "func", "addInRange", "(", "n", "int16", ",", "increment", "int16", ",", "<mask>", "int16", ",", "max", "int16", ")", "int16", "{", "return", "ensureInRange", "(", "n", "+", "increment", ",", "min", ",", "max", ")", "\n", "}" ]
44
maxmin-45
[ "Check", "the", "virtual", "server", "instance", "is", "ready", "for", "use" ]
[ "func", "(", "c", "*", "ClientManager", ")", "WaitInstanceUntilReady", "(", "id", "int", ",", "until", "time", ".", "Time", ")", "error", "{", "for", "{", "virtualGuest", ",", "found", ",", "err", ":=", "c", ".", "GetInstance", "(", "id", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "!", "found", "{", "return", "bosherr", ".", "WrapErrorf", "(", "err", ",", "\"", "\"", ",", "id", ")", "\n", "}", "\n\n", "lastReload", ":=", "virtualGuest", ".", "LastOperatingSystemReload", "\n", "activeTxn", ":=", "virtualGuest", ".", "ActiveTransaction", "\n", "provisionDate", ":=", "virtualGuest", ".", "ProvisionDate", "\n\n", "// if lastReload != nil && lastReload.ModifyDate != nil {", "// \tfmt.Println(\"lastReload: \", (*lastReload.ModifyDate).Format(time.RFC3339))", "// }", "// if activeTxn != nil && activeTxn.TransactionStatus != nil && activeTxn.TransactionStatus.Name != nil {", "// \tfmt.Println(\"activeTxn: \", *activeTxn.TransactionStatus.Name)", "// }", "// if provisionDate != nil {", "// \tfmt.Println(\"provisionDate: \", (*provisionDate).Format(time.RFC3339))", "// }", "reloading", ":=", "activeTxn", "!=", "nil", "&&", "lastReload", "!=", "nil", "&&", "*", "activeTxn", ".", "Id", "==", "*", "lastReload", ".", "Id", "\n", "if", "provisionDate", "!=", "nil", "&&", "!", "reloading", "{", "// fmt.Println(\"power state:\", *virtualGuest.PowerState.KeyName)", "if", "*", "virtualGuest", ".", "PowerState", ".", "KeyName", "==", "\"", "\"", "{", "return", "nil", "\n", "}", "\n", "}", "\n\n", "now", ":=", "time", ".", "Now", "(", ")", "\n", "if", "now", ".", "After", "(", "until", ")", "{", "return", "bosherr", ".", "Errorf", "(", "\"", "\"", ",", "*", "virtualGuest", ".", "Id", ")", "\n", "}", "\n\n", "<mask>", ":=", "math", ".", "Min", "(", "float64", "(", "10.0", ")", ",", "float64", "(", "until", ".", "Sub", "(", "now", ")", ")", ")", "\n", "time", ".", "Sleep", "(", "time", ".", "Duration", "(", "min", ")", "*", "time", ".", "Second", ")", "\n", "}", "\n", "}" ]
45
maxmin-46
[ "Repaint", "draws", "the", "control", "on", "its", "View", "surface", ".", "Horizontal", "ProgressBar", "supports", "custom", "title", "over", "the", "bar", ".", "One", "can", "set", "title", "using", "method", "SetTitle", ".", "There", "are", "a", "few", "predefined", "variables", "that", "can", "be", "used", "inside", "title", "to", "show", "value", "or", "total", "progress", ".", "Variable", "must", "be", "enclosed", "with", "double", "curly", "brackets", ".", "Available", "variables", ":", "percent", "-", "the", "current", "percentage", "rounded", "to", "closest", "integer", "value", "-", "raw", "ProgressBar", "value", "min", "-", "lower", "ProgressBar", "limit", "max", "-", "upper", "ProgressBar", "limit", "Examples", ":", "pb", ".", "SetTitle", "(", "{{", "value", "}}", "of", "{{", "max", "}}", ")", "pb", ".", "SetTitle", "(", "{{", "percent", "}}", "%", ")" ]
[ "func", "(", "b", "*", "ProgressBar", ")", "Draw", "(", ")", "{", "if", "b", ".", "hidden", "{", "return", "\n", "}", "\n\n", "b", ".", "mtx", ".", "RLock", "(", ")", "\n", "defer", "b", ".", "mtx", ".", "RUnlock", "(", ")", "\n", "if", "b", ".", "<mask>", "<=", "b", ".", "min", "{", "return", "\n", "}", "\n\n", "PushAttributes", "(", ")", "\n", "defer", "PopAttributes", "(", ")", "\n\n", "fgOff", ",", "fgOn", ":=", "RealColor", "(", "b", ".", "fg", ",", "b", ".", "Style", "(", ")", ",", "ColorProgressText", ")", ",", "RealColor", "(", "b", ".", "fgActive", ",", "b", ".", "Style", "(", ")", ",", "ColorProgressActiveText", ")", "\n", "bgOff", ",", "bgOn", ":=", "RealColor", "(", "b", ".", "bg", ",", "b", ".", "Style", "(", ")", ",", "ColorProgressBack", ")", ",", "RealColor", "(", "b", ".", "bgActive", ",", "b", ".", "Style", "(", ")", ",", "ColorProgressActiveBack", ")", "\n\n", "parts", ":=", "[", "]", "rune", "(", "SysObject", "(", "ObjProgressBar", ")", ")", "\n", "cFilled", ",", "cEmpty", ":=", "parts", "[", "0", "]", ",", "parts", "[", "1", "]", "\n\n", "prc", ":=", "0", "\n", "if", "b", ".", "value", ">=", "b", ".", "max", "{", "prc", "=", "100", "\n", "}", "else", "if", "b", ".", "value", "<", "b", ".", "max", "&&", "b", ".", "value", ">", "b", ".", "min", "{", "prc", "=", "(", "100", "*", "(", "b", ".", "value", "-", "b", ".", "min", ")", ")", "/", "(", "b", ".", "max", "-", "b", ".", "min", ")", "\n", "}", "\n\n", "var", "title", "string", "\n", "if", "b", ".", "direction", "==", "Horizontal", "&&", "b", ".", "Title", "(", ")", "!=", "\"", "\"", "{", "title", "=", "b", ".", "Title", "(", ")", "\n", "title", "=", "strings", ".", "Replace", "(", "title", ",", "\"", "\"", ",", "strconv", ".", "Itoa", "(", "prc", ")", ",", "-", "1", ")", "\n", "title", "=", "strings", ".", "Replace", "(", "title", ",", "\"", "\"", ",", "strconv", ".", "Itoa", "(", "b", ".", "value", ")", ",", "-", "1", ")", "\n", "title", "=", "strings", ".", "Replace", "(", "title", ",", "\"", "\"", ",", "strconv", ".", "Itoa", "(", "b", ".", "min", ")", ",", "-", "1", ")", "\n", "title", "=", "strings", ".", "Replace", "(", "title", ",", "\"", "\"", ",", "strconv", ".", "Itoa", "(", "b", ".", "max", ")", ",", "-", "1", ")", "\n", "}", "\n\n", "x", ",", "y", ":=", "b", ".", "Pos", "(", ")", "\n", "w", ",", "h", ":=", "b", ".", "Size", "(", ")", "\n\n", "if", "b", ".", "direction", "==", "Horizontal", "{", "filled", ":=", "prc", "*", "w", "/", "100", "\n", "sFilled", ":=", "strings", ".", "Repeat", "(", "string", "(", "cFilled", ")", ",", "filled", ")", "\n", "sEmpty", ":=", "strings", ".", "Repeat", "(", "string", "(", "cEmpty", ")", ",", "w", "-", "filled", ")", "\n\n", "for", "yy", ":=", "y", ";", "yy", "<", "y", "+", "h", ";", "yy", "++", "{", "SetTextColor", "(", "fgOn", ")", "\n", "SetBackColor", "(", "bgOn", ")", "\n", "DrawRawText", "(", "x", ",", "yy", ",", "sFilled", ")", "\n", "SetTextColor", "(", "fgOff", ")", "\n", "SetBackColor", "(", "bgOff", ")", "\n", "DrawRawText", "(", "x", "+", "filled", ",", "yy", ",", "sEmpty", ")", "\n", "}", "\n\n", "if", "title", "!=", "\"", "\"", "{", "shift", ",", "str", ":=", "AlignText", "(", "title", ",", "w", ",", "b", ".", "align", ")", "\n", "titleClr", ":=", "RealColor", "(", "b", ".", "titleFg", ",", "b", ".", "Style", "(", ")", ",", "ColorProgressTitleText", ")", "\n", "var", "sOn", ",", "sOff", "string", "\n", "if", "filled", "==", "0", "||", "shift", ">=", "filled", "{", "sOff", "=", "str", "\n", "}", "else", "if", "w", "==", "filled", "||", "shift", "+", "xs", ".", "Len", "(", "str", ")", "<", "filled", "{", "sOn", "=", "str", "\n", "}", "else", "{", "r", ":=", "filled", "-", "shift", "\n", "sOn", "=", "xs", ".", "Slice", "(", "str", ",", "0", ",", "r", ")", "\n", "sOff", "=", "xs", ".", "Slice", "(", "str", ",", "r", ",", "-", "1", ")", "\n", "}", "\n", "SetTextColor", "(", "titleClr", ")", "\n", "if", "sOn", "!=", "\"", "\"", "{", "SetBackColor", "(", "bgOn", ")", "\n", "DrawRawText", "(", "x", "+", "shift", ",", "y", ",", "sOn", ")", "\n", "}", "\n", "if", "sOff", "!=", "\"", "\"", "{", "SetBackColor", "(", "bgOff", ")", "\n", "DrawRawText", "(", "x", "+", "shift", "+", "xs", ".", "Len", "(", "sOn", ")", ",", "y", ",", "sOff", ")", "\n", "}", "\n", "}", "\n", "}", "else", "{", "filled", ":=", "prc", "*", "h", "/", "100", "\n", "sFilled", ":=", "strings", ".", "Repeat", "(", "string", "(", "cFilled", ")", ",", "w", ")", "\n", "sEmpty", ":=", "strings", ".", "Repeat", "(", "string", "(", "cEmpty", ")", ",", "w", ")", "\n", "for", "yy", ":=", "y", ";", "yy", "<", "y", "+", "h", "-", "filled", ";", "yy", "++", "{", "SetTextColor", "(", "fgOff", ")", "\n", "SetBackColor", "(", "bgOff", ")", "\n", "DrawRawText", "(", "x", ",", "yy", ",", "sEmpty", ")", "\n", "}", "\n", "for", "yy", ":=", "y", "+", "h", "-", "filled", ";", "yy", "<", "y", "+", "h", ";", "yy", "++", "{", "SetTextColor", "(", "fgOff", ")", "\n", "SetBackColor", "(", "bgOff", ")", "\n", "DrawRawText", "(", "x", ",", "yy", ",", "sFilled", ")", "\n", "}", "\n", "}", "\n", "}" ]
46
maxmin-47
[ "computedCropArea", "retrieve", "the", "theorical", "crop", "area", ".", "It", "is", "defined", "by", "Height", "Width", "Mode", "and" ]
[ "func", "(", "c", "Config", ")", "computedCropArea", "(", "bounds", "image", ".", "Rectangle", ",", "size", "image", ".", "Point", ")", "(", "r", "image", ".", "Rectangle", ")", "{", "<mask>", ":=", "bounds", ".", "Min", "\n", "switch", "c", ".", "Mode", "{", "case", "Centered", ":", "rMin", ":=", "c", ".", "centeredMin", "(", "bounds", ")", "\n", "r", "=", "image", ".", "Rect", "(", "rMin", ".", "X", "-", "size", ".", "X", "/", "2", ",", "rMin", ".", "Y", "-", "size", ".", "Y", "/", "2", ",", "rMin", ".", "X", "-", "size", ".", "X", "/", "2", "+", "size", ".", "X", ",", "rMin", ".", "Y", "-", "size", ".", "Y", "/", "2", "+", "size", ".", "Y", ")", "\n", "default", ":", "// TopLeft", "rMin", ":=", "image", ".", "Point", "{", "min", ".", "X", "+", "c", ".", "Anchor", ".", "X", ",", "min", ".", "Y", "+", "c", ".", "Anchor", ".", "Y", "}", "\n", "r", "=", "image", ".", "Rect", "(", "rMin", ".", "X", ",", "rMin", ".", "Y", ",", "rMin", ".", "X", "+", "size", ".", "X", ",", "rMin", ".", "Y", "+", "size", ".", "Y", ")", "\n", "}", "\n", "return", "\n", "}" ]
47
maxmin-48
[ "SetRange", "()", "is", "a", "wrapper", "around", "gtk_range_set_range", "()", "." ]
[ "func", "(", "v", "*", "Range", ")", "SetRange", "(", "<mask>", ",", "max", "float64", ")", "{", "C", ".", "gtk_range_set_range", "(", "v", ".", "native", "(", ")", ",", "C", ".", "gdouble", "(", "min", ")", ",", "C", ".", "gdouble", "(", "max", ")", ")", "\n", "}" ]
48
maxmin-49
[ "ResolveCreate", "is", "invoked", "when", "dns", "name", "is", "not", "owned", "by", "any", "resource", "ResolveCreate", "takes", "minimal", "(", "string", "comparison", "of", "Target", ")", "endpoint", "to", "acquire", "the", "DNS", "record" ]
[ "func", "(", "s", "PerResource", ")", "ResolveCreate", "(", "candidates", "[", "]", "*", "endpoint", ".", "Endpoint", ")", "*", "endpoint", ".", "Endpoint", "{", "var", "<mask>", "*", "endpoint", ".", "Endpoint", "\n", "for", "_", ",", "ep", ":=", "range", "candidates", "{", "if", "min", "==", "nil", "||", "s", ".", "less", "(", "ep", ",", "min", ")", "{", "min", "=", "ep", "\n", "}", "\n", "}", "\n", "return", "min", "\n", "}" ]
49
maxmin-50
[ "readAtLeast", "is", "an", "optimized", "version", "of", "io", ".", "ReadAtLeast", "which", "omits", "some", "checks", "that", "don", "t", "need", "to", "be", "performed", "when", "called", "from", "Read", "()", "in", "this", "package", "." ]
[ "func", "readAtLeast", "(", "r", "io", ".", "Reader", ",", "buf", "[", "]", "byte", ",", "<mask>", "int", ")", "error", "{", "var", "n", "int", "\n", "var", "err", "error", "\n", "// Most common case, we get all the bytes in one read", "if", "n", ",", "err", "=", "r", ".", "Read", "(", "buf", ")", ";", "n", "==", "min", "{", "return", "nil", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "// Fall back to looping", "var", "nn", "int", "\n", "for", "n", "<", "min", "{", "nn", ",", "err", "=", "r", ".", "Read", "(", "buf", "[", "n", ":", "]", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "==", "io", ".", "EOF", "&&", "n", ">", "0", "{", "err", "=", "io", ".", "ErrUnexpectedEOF", "\n", "}", "\n", "return", "err", "\n", "}", "\n", "n", "+=", "nn", "\n", "}", "\n", "return", "nil", "\n", "}" ]
50
maxmin-51
[ "SpinButtonNewWithRange", "()", "is", "a", "wrapper", "around", "gtk_spin_button_new_with_range", "()", "." ]
[ "func", "SpinButtonNewWithRange", "(", "<mask>", ",", "max", ",", "step", "float64", ")", "(", "*", "SpinButton", ",", "error", ")", "{", "c", ":=", "C", ".", "gtk_spin_button_new_with_range", "(", "C", ".", "gdouble", "(", "min", ")", ",", "C", ".", "gdouble", "(", "max", ")", ",", "C", ".", "gdouble", "(", "step", ")", ")", "\n", "if", "c", "==", "nil", "{", "return", "nil", ",", "nilPtrErr", "\n", "}", "\n", "return", "wrapSpinButton", "(", "glib", ".", "Take", "(", "unsafe", ".", "Pointer", "(", "c", ")", ")", ")", ",", "nil", "\n", "}" ]
51
maxmin-52
[ "===", "min_over_time", "(", "Matrix", "ValueTypeMatrix", ")", "Vector", "===" ]
[ "func", "funcMinOverTime", "(", "vals", "[", "]", "Value", ",", "args", "Expressions", ",", "enh", "*", "EvalNodeHelper", ")", "Vector", "{", "return", "aggrOverTime", "(", "vals", ",", "enh", ",", "func", "(", "values", "[", "]", "Point", ")", "float64", "{", "<mask>", ":=", "values", "[", "0", "]", ".", "V", "\n", "for", "_", ",", "v", ":=", "range", "values", "{", "if", "v", ".", "V", "<", "min", "||", "math", ".", "IsNaN", "(", "min", ")", "{", "min", "=", "v", ".", "V", "\n", "}", "\n", "}", "\n", "return", "min", "\n", "}", ")", "\n", "}" ]
52
maxmin-53
[ "extractTimeRange", "returns", "minimum", "and", "maximum", "timestamp", "in", "milliseconds", "as", "provided", "by", "the", "time", "range", ".", "It", "defaults", "either", "boundary", "to", "the", "minimum", "and", "maximum", "possible", "value", "." ]
[ "func", "extractTimeRange", "(", "<mask>", ",", "max", "*", "time", ".", "Time", ")", "(", "mint", ",", "maxt", "time", ".", "Time", ",", "err", "error", ")", "{", "if", "min", "==", "nil", "{", "mint", "=", "minTime", "\n", "}", "else", "{", "mint", "=", "*", "min", "\n", "}", "\n", "if", "max", "==", "nil", "{", "maxt", "=", "maxTime", "\n", "}", "else", "{", "maxt", "=", "*", "max", "\n", "}", "\n", "if", "mint", ".", "After", "(", "maxt", ")", "{", "return", "mint", ",", "maxt", ",", "errors", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "mint", ",", "maxt", ",", "nil", "\n", "}" ]
53
maxmin-54
[ "NewLimiter", "creates", "a", "new", "instance", "of", "a", "rate", "limiter", "." ]
[ "func", "NewLimiter", "(", "client", "*", "redis", ".", "Client", ",", "hasher", "RateHasher", ",", "<mask>", "int64", ",", ")", "*", "RateLimiter", "{", "return", "&", "RateLimiter", "{", "redisClient", ":", "client", ",", "hasher", ":", "hasher", ",", "max", ":", "max", ",", "}", "\n", "}" ]
54
maxmin-55
[ "===", "clamp_max", "(", "Vector", "ValueTypeVector", "max", "Scalar", ")", "Vector", "===" ]
[ "func", "funcClampMax", "(", "vals", "[", "]", "Value", ",", "args", "Expressions", ",", "enh", "*", "EvalNodeHelper", ")", "Vector", "{", "vec", ":=", "vals", "[", "0", "]", ".", "(", "Vector", ")", "\n", "<mask>", ":=", "vals", "[", "1", "]", ".", "(", "Vector", ")", "[", "0", "]", ".", "Point", ".", "V", "\n", "for", "_", ",", "el", ":=", "range", "vec", "{", "enh", ".", "out", "=", "append", "(", "enh", ".", "out", ",", "Sample", "{", "Metric", ":", "enh", ".", "dropMetricName", "(", "el", ".", "Metric", ")", ",", "Point", ":", "Point", "{", "V", ":", "math", ".", "Min", "(", "max", ",", "el", ".", "V", ")", "}", ",", "}", ")", "\n", "}", "\n", "return", "enh", ".", "out", "\n", "}" ]
55
maxmin-56
[ "ValidateLevelFilter", "verifies", "that", "the", "log", "levels", "within", "the", "filter", "are", "valid", "." ]
[ "func", "ValidateLevelFilter", "(", "<mask>", "logutils", ".", "LogLevel", ",", "filter", "*", "logutils", ".", "LevelFilter", ")", "bool", "{", "for", "_", ",", "level", ":=", "range", "filter", ".", "Levels", "{", "if", "level", "==", "min", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
56
maxmin-57
[ "generates", "round", "robin", "indexes", "for", "a", "slice", "of", "length", "max", "starting", "from", "index", "start" ]
[ "func", "roundIndex", "(", "start", ",", "<mask>", "int", ")", "[", "]", "int", "{", "if", "start", "<", "0", "{", "start", "=", "0", "\n", "}", "\n", "result", ":=", "make", "(", "[", "]", "int", ",", "max", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "max", ";", "i", "++", "{", "if", "start", "+", "i", "<", "max", "{", "result", "[", "i", "]", "=", "start", "+", "i", "\n", "}", "else", "{", "result", "[", "i", "]", "=", "int", "(", "math", ".", "Abs", "(", "float64", "(", "max", "-", "(", "start", "+", "i", ")", ")", ")", ")", "\n", "}", "\n", "}", "\n", "return", "result", "\n", "}" ]
57
maxmin-58
[ "===", "clamp_min", "(", "Vector", "ValueTypeVector", "min", "Scalar", ")", "Vector", "===" ]
[ "func", "funcClampMin", "(", "vals", "[", "]", "Value", ",", "args", "Expressions", ",", "enh", "*", "EvalNodeHelper", ")", "Vector", "{", "vec", ":=", "vals", "[", "0", "]", ".", "(", "Vector", ")", "\n", "<mask>", ":=", "vals", "[", "1", "]", ".", "(", "Vector", ")", "[", "0", "]", ".", "Point", ".", "V", "\n", "for", "_", ",", "el", ":=", "range", "vec", "{", "enh", ".", "out", "=", "append", "(", "enh", ".", "out", ",", "Sample", "{", "Metric", ":", "enh", ".", "dropMetricName", "(", "el", ".", "Metric", ")", ",", "Point", ":", "Point", "{", "V", ":", "math", ".", "Max", "(", "min", ",", "el", ".", "V", ")", "}", ",", "}", ")", "\n", "}", "\n", "return", "enh", ".", "out", "\n", "}" ]
58
maxmin-59
[ "SetRange", "is", "a", "wrapper", "around", "gtk_spin_button_set_range", "()", "." ]
[ "func", "(", "v", "*", "SpinButton", ")", "SetRange", "(", "<mask>", ",", "max", "float64", ")", "{", "C", ".", "gtk_spin_button_set_range", "(", "v", ".", "native", "(", ")", ",", "C", ".", "gdouble", "(", "min", ")", ",", "C", ".", "gdouble", "(", "max", ")", ")", "\n", "}" ]
59
maxmin-60
[ "ensureInRange", "adjusts", "the", "passed", "value", "if", "necessary", "to", "ensure", "it", "is", "within", "the", "passed", "min", "/", "max", "range", "." ]
[ "func", "ensureInRange", "(", "n", "int16", ",", "<mask>", "int16", ",", "max", "int16", ")", "int16", "{", "if", "n", "<", "min", "{", "return", "min", "\n", "}", "else", "if", "n", ">", "max", "{", "return", "max", "\n", "}", "else", "{", "return", "n", "\n", "}", "\n", "}" ]
60
maxmin-61
[ "NewLargeObject", "provides", "a", "io", ".", "writer", "to", "upload", "data", "as", "a", "segmented", "upload", "It", "will", "upload", "all", "the", "segments", "into", "a", "second", "container", "named", "<container", ">", ".", "These", "segments", "will", "have", "names", "like", "large_file", "/", "1290206778", ".", "25", "/", "00000000", "large_file", "/", "1290206778", ".", "25", "/", "00000001", "etc", ".", "The", "main", "benefit", "for", "using", "a", "separate", "container", "is", "that", "the", "main", "container", "listings", "will", "not", "be", "polluted", "with", "all", "the", "segment", "names", ".", "The", "reason", "for", "using", "the", "segment", "name", "format", "of", "<name", ">", "/", "<timestamp", ">", "/", "<segment", ">", "is", "so", "that", "an", "upload", "of", "a", "new", "file", "with", "the", "same", "name", "won’t", "overwrite", "the", "contents", "of", "the", "first", "until", "the", "last", "moment", "when", "the", "manifest", "file", "is", "updated", ".", "swift", "will", "manage", "these", "segment", "files", "for", "you", "deleting", "old", "segments", "on", "deletes", "and", "overwrites", "etc", ".", "You", "can", "override", "this", "behavior", "with", "the", "--", "leave", "-", "segments", "option", "if", "desired", ";", "this", "is", "useful", "if", "you", "want", "to", "have", "multiple", "versions", "of", "the", "same", "large", "object", "available", "." ]
[ "func", "NewLargeObject", "(", "c", "*", "swift", ".", "Connection", ",", "path", "string", ",", "concurrency", "int", ",", "partSize", "int64", ",", "expireAfter", "int64", ",", "logger", "cpiLogger", ".", "Logger", ")", "(", "*", "largeObject", ",", "error", ")", "{", "pathParts", ":=", "strings", ".", "SplitN", "(", "path", ",", "\"", "\"", ",", "2", ")", "\n", "objectName", ":=", "\"", "\"", "\n", "if", "len", "(", "pathParts", ")", ">", "1", "{", "objectName", "=", "pathParts", "[", "1", "]", "\n", "}", "\n", "// #nosec G401", "lo", ":=", "largeObject", "{", "c", ":", "c", ",", "container", ":", "pathParts", "[", "0", "]", ",", "objectName", ":", "objectName", ",", "timestamp", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "time", ".", "Now", "(", ")", ".", "UnixNano", "(", ")", ")", ",", "expire", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "expireAfter", ")", ",", "bufsz", ":", "max64", "(", "minPartSize", ",", "partSize", ")", ",", "ch", ":", "make", "(", "chan", "*", "part", ")", ",", "md5OfParts", ":", "md5", ".", "New", "(", ")", ",", "md5", ":", "md5", ".", "New", "(", ")", ",", "bp", ":", "newBufferPool", "(", "minPartSize", ")", ",", "logger", ":", "logger", ",", "}", "\n\n", "for", "i", ":=", "0", ";", "i", "<", "<mask>", "(", "concurrency", ",", "1", ")", ";", "i", "++", "{", "go", "lo", ".", "worker", "(", ")", "\n", "}", "\n\n", "// Create segment container if it doesn't already exist", "err", ":=", "c", ".", "ContainerCreate", "(", "lo", ".", "container", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "lo", ",", "nil", "\n", "}" ]
61
maxmin-62
[ "/", "*", "Set", "the", "maximum", "number", "of", "trace", "segments", "allowed", "in", "a", "transaction", "trace", ".", "By", "default", "the", "maximum", "is", "set", "to", "2000", "which", "means", "the", "first", "2000", "segments", "in", "a", "transaction", "will", "create", "trace", "segments", "if", "the", "transaction", "exceeds", "the", "trace", "threshold", "(", "4", "x", "apdex_t", ")", "." ]
[ "func", "TransactionSetMaxTraceSegments", "(", "id", "int64", ",", "<mask>", "int", ")", "(", "int", ",", "error", ")", "{", "return", "errNo", "(", "C", ".", "newrelic_transaction_set_max_trace_segments", "(", "C", ".", "long", "(", "id", ")", ",", "C", ".", "int", "(", "max", ")", ")", ")", "\n", "}" ]
62
maxmin-63
[ "Encode", "writes", "v", "to", "the", "stream", "encoding", "it", "based", "on", "the", "emitter", "configured", "on", "e", "." ]
[ "func", "(", "e", "*", "StreamEncoder", ")", "Encode", "(", "v", "interface", "{", "}", ")", "error", "{", "if", "err", ":=", "e", ".", "Open", "(", "-", "1", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "e", ".", "<mask>", ">=", "0", "&&", "e", ".", "cnt", ">=", "e", ".", "max", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "e", ".", "max", ")", "\n", "}", "\n\n", "if", "!", "e", ".", "oneshot", "&&", "e", ".", "cnt", "!=", "0", "{", "e", ".", "err", "=", "e", ".", "Emitter", ".", "EmitArrayNext", "(", ")", "\n", "}", "\n\n", "if", "e", ".", "err", "==", "nil", "{", "e", ".", "err", "=", "(", "Encoder", "{", "Emitter", ":", "e", ".", "Emitter", ",", "SortMapKeys", ":", "e", ".", "SortMapKeys", ",", "}", ")", ".", "Encode", "(", "v", ")", "\n\n", "if", "e", ".", "cnt", "++", ";", "e", ".", "max", ">=", "0", "&&", "e", ".", "cnt", ">=", "e", ".", "max", "{", "e", ".", "Close", "(", ")", "\n", "}", "\n", "}", "\n\n", "return", "e", ".", "err", "\n", "}" ]
63
maxmin-64
[ "DistanceForStrings", "returns", "the", "edit", "distance", "between", "source", "and", "target", ".", "It", "has", "a", "runtime", "proportional", "to", "len", "(", "source", ")", "*", "len", "(", "target", ")", "and", "memory", "use", "proportional", "to", "len", "(", "target", ")", "." ]
[ "func", "DistanceForStrings", "(", "source", "[", "]", "rune", ",", "target", "[", "]", "rune", ",", "op", "Options", ")", "int", "{", "// Note: This algorithm is a specialization of MatrixForStrings.", "// MatrixForStrings returns the full edit matrix. However, we only need a", "// single value (see DistanceForMatrix) and the main loop of the algorithm", "// only uses the current and previous row. As such we create a 2D matrix,", "// but with height 2 (enough to store current and previous row).", "height", ":=", "len", "(", "source", ")", "+", "1", "\n", "width", ":=", "len", "(", "target", ")", "+", "1", "\n", "matrix", ":=", "make", "(", "[", "]", "[", "]", "int", ",", "2", ")", "\n\n", "// Initialize trivial distances (from/to empty string). That is, fill", "// the left column and the top row with row/column indices.", "for", "i", ":=", "0", ";", "i", "<", "2", ";", "i", "++", "{", "matrix", "[", "i", "]", "=", "make", "(", "[", "]", "int", ",", "width", ")", "\n", "matrix", "[", "i", "]", "[", "0", "]", "=", "i", "\n", "}", "\n", "for", "j", ":=", "1", ";", "j", "<", "width", ";", "j", "++", "{", "matrix", "[", "0", "]", "[", "j", "]", "=", "j", "\n", "}", "\n\n", "// Fill in the remaining cells: for each prefix pair, choose the", "// (edit history, operation) pair with the lowest cost.", "for", "i", ":=", "1", ";", "i", "<", "height", ";", "i", "++", "{", "cur", ":=", "matrix", "[", "i", "%", "2", "]", "\n", "prev", ":=", "matrix", "[", "(", "i", "-", "1", ")", "%", "2", "]", "\n", "cur", "[", "0", "]", "=", "i", "\n", "for", "j", ":=", "1", ";", "j", "<", "width", ";", "j", "++", "{", "delCost", ":=", "prev", "[", "j", "]", "+", "op", ".", "DelCost", "\n", "matchSubCost", ":=", "prev", "[", "j", "-", "1", "]", "\n", "if", "!", "op", ".", "Matches", "(", "source", "[", "i", "-", "1", "]", ",", "target", "[", "j", "-", "1", "]", ")", "{", "matchSubCost", "+=", "op", ".", "SubCost", "\n", "}", "\n", "insCost", ":=", "cur", "[", "j", "-", "1", "]", "+", "op", ".", "InsCost", "\n", "cur", "[", "j", "]", "=", "<mask>", "(", "delCost", ",", "min", "(", "matchSubCost", ",", "insCost", ")", ")", "\n", "}", "\n", "}", "\n", "return", "matrix", "[", "(", "height", "-", "1", ")", "%", "2", "]", "[", "width", "-", "1", "]", "\n", "}" ]
64
maxmin-65
[ "Spawn", "the", "rsync", "process" ]
[ "func", "rsyncSendSetup", "(", "path", "string", ",", "rsyncArgs", "string", ")", "(", "*", "exec", ".", "Cmd", ",", "net", ".", "Conn", ",", "io", ".", "ReadCloser", ",", "error", ")", "{", "auds", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "uuid", ".", "NewRandom", "(", ")", ".", "String", "(", ")", ")", "\n", "if", "len", "(", "auds", ")", ">", "shared", ".", "ABSTRACT_UNIX_SOCK_LEN", "-", "1", "{", "auds", "=", "auds", "[", ":", "shared", ".", "ABSTRACT_UNIX_SOCK_LEN", "-", "1", "]", "\n", "}", "\n\n", "l", ",", "err", ":=", "net", ".", "Listen", "(", "\"", "\"", ",", "auds", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "nil", ",", "err", "\n", "}", "\n\n", "execPath", ",", "err", ":=", "os", ".", "Readlink", "(", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "nil", ",", "err", "\n", "}", "\n\n", "if", "!", "shared", ".", "PathExists", "(", "execPath", ")", "{", "execPath", "=", "os", ".", "Args", "[", "0", "]", "\n", "}", "\n\n", "rsyncCmd", ":=", "fmt", ".", "Sprintf", "(", "\"", "\\\"", "\\\"", "\"", ",", "execPath", ",", "auds", ")", "\n\n", "args", ":=", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "}", "\n\n", "// Ignore deletions (requires 3.1 or higher)", "rsyncCheckVersion", ":=", "func", "(", "<mask>", "string", ")", "bool", "{", "out", ",", "err", ":=", "shared", ".", "RunCommand", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", "\n", "}", "\n\n", "fields", ":=", "strings", ".", "Split", "(", "out", ",", "\"", "\"", ")", "\n", "curVer", ",", "err", ":=", "version", ".", "Parse", "(", "fields", "[", "3", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", "\n", "}", "\n\n", "minVer", ",", "err", ":=", "version", ".", "Parse", "(", "min", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", "\n", "}", "\n\n", "return", "curVer", ".", "Compare", "(", "minVer", ")", ">=", "0", "\n", "}", "\n\n", "if", "rsyncCheckVersion", "(", "\"", "\"", ")", "{", "args", "=", "append", "(", "args", ",", "\"", "\"", ")", "\n", "}", "\n\n", "if", "rsyncArgs", "!=", "\"", "\"", "{", "args", "=", "append", "(", "args", ",", "strings", ".", "Split", "(", "rsyncArgs", ",", "\"", "\"", ")", "...", ")", "\n", "}", "\n\n", "args", "=", "append", "(", "args", ",", "[", "]", "string", "{", "path", ",", "\"", "\"", "}", "...", ")", "\n", "args", "=", "append", "(", "args", ",", "[", "]", "string", "{", "\"", "\"", ",", "rsyncCmd", "}", "...", ")", "\n\n", "cmd", ":=", "exec", ".", "Command", "(", "\"", "\"", ",", "args", "...", ")", "\n", "cmd", ".", "Stdout", "=", "os", ".", "Stderr", "\n\n", "stderr", ",", "err", ":=", "cmd", ".", "StderrPipe", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "nil", ",", "err", "\n", "}", "\n\n", "if", "err", ":=", "cmd", ".", "Start", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "nil", ",", "err", "\n", "}", "\n\n", "conn", ",", "err", ":=", "l", ".", "Accept", "(", ")", "\n", "if", "err", "!=", "nil", "{", "cmd", ".", "Process", ".", "Kill", "(", ")", "\n", "cmd", ".", "Wait", "(", ")", "\n", "return", "nil", ",", "nil", ",", "nil", ",", "err", "\n", "}", "\n", "l", ".", "Close", "(", ")", "\n\n", "return", "cmd", ",", "conn", ",", "stderr", ",", "nil", "\n", "}" ]
65
maxmin-66
[ "match", "recursively", "traverses", "the", "provided", "type", "and", "outputs", "a", "matcher", "string", "for", "it", "that", "is", "compatible", "with", "the", "Pact", "dsl", "." ]
[ "func", "match", "(", "srcType", "reflect", ".", "Type", ",", "params", "params", ")", "Matcher", "{", "switch", "kind", ":=", "srcType", ".", "Kind", "(", ")", ";", "kind", "{", "case", "reflect", ".", "Ptr", ":", "return", "match", "(", "srcType", ".", "Elem", "(", ")", ",", "params", ")", "\n", "case", "reflect", ".", "Slice", ",", "reflect", ".", "Array", ":", "return", "EachLike", "(", "match", "(", "srcType", ".", "Elem", "(", ")", ",", "getDefaults", "(", ")", ")", ",", "params", ".", "slice", ".", "<mask>", ")", "\n", "case", "reflect", ".", "Struct", ":", "result", ":=", "StructMatcher", "{", "}", "\n\n", "for", "i", ":=", "0", ";", "i", "<", "srcType", ".", "NumField", "(", ")", ";", "i", "++", "{", "field", ":=", "srcType", ".", "Field", "(", "i", ")", "\n", "result", "[", "field", ".", "Tag", ".", "Get", "(", "\"", "\"", ")", "]", "=", "match", "(", "field", ".", "Type", ",", "pluckParams", "(", "field", ".", "Type", ",", "field", ".", "Tag", ".", "Get", "(", "\"", "\"", ")", ")", ")", "\n", "}", "\n", "return", "result", "\n", "case", "reflect", ".", "String", ":", "if", "params", ".", "str", ".", "regEx", "!=", "\"", "\"", "{", "return", "Term", "(", "params", ".", "str", ".", "example", ",", "params", ".", "str", ".", "regEx", ")", "\n", "}", "\n", "if", "params", ".", "str", ".", "example", "!=", "\"", "\"", "{", "return", "Like", "(", "params", ".", "str", ".", "example", ")", "\n", "}", "\n\n", "return", "Like", "(", "\"", "\"", ")", "\n", "case", "reflect", ".", "Bool", ":", "return", "Like", "(", "true", ")", "\n", "case", "reflect", ".", "Int", ",", "reflect", ".", "Int8", ",", "reflect", ".", "Int16", ",", "reflect", ".", "Int32", ",", "reflect", ".", "Int64", ",", "reflect", ".", "Uint", ",", "reflect", ".", "Uint8", ",", "reflect", ".", "Uint16", ",", "reflect", ".", "Uint32", ",", "reflect", ".", "Uint64", ":", "return", "Like", "(", "1", ")", "\n", "case", "reflect", ".", "Float32", ",", "reflect", ".", "Float64", ":", "return", "Like", "(", "1.1", ")", "\n", "default", ":", "panic", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "srcType", ")", ")", "\n", "}", "\n", "}" ]
66
maxmin-67
[ "NormalizeMax", "sets", "the", "max", "value", "to", "1", "and", "normalize", "the", "rest", "of", "the", "data", "." ]
[ "func", "NormalizeMax", "(", "buf", "*", "audio", ".", "FloatBuffer", ")", "{", "if", "buf", "==", "nil", "{", "return", "\n", "}", "\n", "<mask>", ":=", "0.0", "\n\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "buf", ".", "Data", ")", ";", "i", "++", "{", "if", "math", ".", "Abs", "(", "buf", ".", "Data", "[", "i", "]", ")", ">", "max", "{", "max", "=", "math", ".", "Abs", "(", "buf", ".", "Data", "[", "i", "]", ")", "\n", "}", "\n", "}", "\n\n", "if", "max", "!=", "0.0", "{", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "buf", ".", "Data", ")", ";", "i", "++", "{", "buf", ".", "Data", "[", "i", "]", "/=", "max", "\n", "}", "\n", "}", "\n", "}" ]
67
maxmin-68
[ "ParseRange", "returns", "a", "new", "range", "object", "and", "nil", "if", "the", "given", "range", "definition", "was", "valid", "or", "nil", "and", "an", "error", "if", "it", "was", "invalid", "." ]
[ "func", "ParseRange", "(", "rangeStr", "string", ")", "(", "*", "Range", ",", "error", ")", "{", "// Set defaults", "t", ":=", "&", "Range", "{", "Start", ":", "0", ",", "End", ":", "math", ".", "Inf", "(", "1", ")", ",", "AlertOnInside", ":", "false", ",", "}", "\n", "// Remove leading and trailing whitespace", "rangeStr", "=", "strings", ".", "Trim", "(", "rangeStr", ",", "\"", "\\n", "\\r", "\"", ")", "\n\n", "// Check for inverted semantics", "if", "rangeStr", "[", "0", "]", "==", "'@'", "{", "t", ".", "AlertOnInside", "=", "true", "\n", "rangeStr", "=", "rangeStr", "[", "1", ":", "]", "\n", "}", "\n\n", "// Parse lower limit", "endPos", ":=", "strings", ".", "Index", "(", "rangeStr", ",", "\"", "\"", ")", "\n", "if", "endPos", ">", "-", "1", "{", "if", "rangeStr", "[", "0", "]", "==", "'~'", "{", "t", ".", "Start", "=", "math", ".", "Inf", "(", "-", "1", ")", "\n", "}", "else", "{", "<mask>", ",", "err", ":=", "strconv", ".", "ParseFloat", "(", "rangeStr", "[", "0", ":", "endPos", "]", ",", "64", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "t", ".", "Start", "=", "min", "\n", "}", "\n", "rangeStr", "=", "rangeStr", "[", "endPos", "+", "1", ":", "]", "\n", "}", "\n\n", "// Parse upper limit", "if", "len", "(", "rangeStr", ")", ">", "0", "{", "max", ",", "err", ":=", "strconv", ".", "ParseFloat", "(", "rangeStr", ",", "64", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "t", ".", "End", "=", "max", "\n", "}", "\n\n", "if", "t", ".", "End", "<", "t", ".", "Start", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// OK", "return", "t", ",", "nil", "\n", "}" ]
68
maxmin-69
[ "hasNextEnts", "returns", "if", "there", "is", "any", "available", "entries", "for", "execution", ".", "This", "is", "a", "fast", "check", "without", "heavy", "raftLog", ".", "slice", "()", "in", "raftLog", ".", "nextEnts", "()", "." ]
[ "func", "(", "l", "*", "raftLog", ")", "hasNextEnts", "(", ")", "bool", "{", "off", ":=", "<mask>", "(", "l", ".", "applied", "+", "1", ",", "l", ".", "firstIndex", "(", ")", ")", "\n", "return", "l", ".", "committed", "+", "1", ">", "off", "\n", "}" ]
69
maxmin-70
[ "Core", "takes", "the", "name", "of", "a", "core", "file", "and", "returns", "a", "Process", "that", "represents", "the", "state", "of", "the", "inferior", "that", "generated", "the", "core", "file", "." ]
[ "func", "Core", "(", "coreFile", ",", "base", ",", "exePath", "string", ")", "(", "*", "Process", ",", "error", ")", "{", "core", ",", "err", ":=", "os", ".", "Open", "(", "coreFile", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "p", ":=", "&", "Process", "{", "base", ":", "base", ",", "files", ":", "make", "(", "map", "[", "string", "]", "*", "file", ")", "}", "\n", "if", "exePath", "!=", "\"", "\"", "{", "bin", ",", "err", ":=", "os", ".", "Open", "(", "exePath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "p", ".", "exe", "=", "bin", "\n", "}", "\n\n", "if", "err", ":=", "p", ".", "readExec", "(", "p", ".", "exe", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "err", ":=", "p", ".", "readCore", "(", "core", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "err", ":=", "p", ".", "readDebugInfo", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// Sort then merge mappings, just to clean up a bit.", "mappings", ":=", "p", ".", "memory", ".", "mappings", "\n", "sort", ".", "Slice", "(", "mappings", ",", "func", "(", "i", ",", "j", "int", ")", "bool", "{", "return", "mappings", "[", "i", "]", ".", "<mask>", "<", "mappings", "[", "j", "]", ".", "min", "\n", "}", ")", "\n", "ms", ":=", "mappings", "[", "1", ":", "]", "\n", "mappings", "=", "mappings", "[", ":", "1", "]", "\n", "for", "_", ",", "m", ":=", "range", "ms", "{", "k", ":=", "mappings", "[", "len", "(", "mappings", ")", "-", "1", "]", "\n", "if", "m", ".", "min", "==", "k", ".", "max", "&&", "m", ".", "perm", "==", "k", ".", "perm", "&&", "m", ".", "f", "==", "k", ".", "f", "&&", "m", ".", "off", "==", "k", ".", "off", "+", "k", ".", "Size", "(", ")", "{", "k", ".", "max", "=", "m", ".", "max", "\n", "// TODO: also check origF?", "}", "else", "{", "mappings", "=", "append", "(", "mappings", ",", "m", ")", "\n", "}", "\n", "}", "\n", "p", ".", "memory", ".", "mappings", "=", "mappings", "\n\n", "// Memory map all the mappings.", "hostPageSize", ":=", "int64", "(", "syscall", ".", "Getpagesize", "(", ")", ")", "\n", "for", "_", ",", "m", ":=", "range", "p", ".", "memory", ".", "mappings", "{", "size", ":=", "m", ".", "max", ".", "Sub", "(", "m", ".", "min", ")", "\n", "if", "m", ".", "f", "==", "nil", "{", "// We don't have any source for this data.", "// Could be a mapped file that we couldn't find.", "// Could be a mapping madvised as MADV_DONTDUMP.", "// Pretend this is read-as-zero.", "// The other option is to just throw away", "// the mapping (and thus make Read*s of this", "// mapping fail).", "p", ".", "warnings", "=", "append", "(", "p", ".", "warnings", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "m", ".", "min", ",", "m", ".", "max", ")", ")", "\n", "// TODO: this allocation could be large.", "// Use mmap to avoid real backing store for all those zeros, or", "// perhaps split the mapping up into chunks and share the zero contents among them.", "m", ".", "contents", "=", "make", "(", "[", "]", "byte", ",", "size", ")", "\n", "continue", "\n", "}", "\n", "if", "m", ".", "perm", "&", "Write", "!=", "0", "&&", "m", ".", "f", "!=", "core", "{", "p", ".", "warnings", "=", "append", "(", "p", ".", "warnings", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "m", ".", "min", ",", "m", ".", "max", ",", "m", ".", "f", ".", "Name", "(", ")", ")", ")", "\n", "}", "\n", "// Data in core file might not be aligned enough for the host.", "// Expand memory range so we can map full pages.", "minOff", ":=", "m", ".", "off", "\n", "maxOff", ":=", "m", ".", "off", "+", "size", "\n", "minOff", "-=", "minOff", "%", "hostPageSize", "\n", "if", "maxOff", "%", "hostPageSize", "!=", "0", "{", "maxOff", "+=", "hostPageSize", "-", "maxOff", "%", "hostPageSize", "\n", "}", "\n\n", "// Read data from file.", "data", ",", "err", ":=", "mapFile", "(", "int", "(", "m", ".", "f", ".", "Fd", "(", ")", ")", ",", "minOff", ",", "int", "(", "maxOff", "-", "minOff", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\\n", "\"", ",", "m", ".", "f", ".", "Name", "(", ")", ",", "minOff", ",", "err", ")", "\n", "}", "\n\n", "// Trim any data we mapped but don't need.", "data", "=", "data", "[", "m", ".", "off", "-", "minOff", ":", "]", "\n", "data", "=", "data", "[", ":", "size", "]", "\n\n", "m", ".", "contents", "=", "data", "\n", "}", "\n\n", "// Build page table for mapping lookup.", "for", "_", ",", "m", ":=", "range", "p", ".", "memory", ".", "mappings", "{", "err", ":=", "p", ".", "addMapping", "(", "m", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n\n", "return", "p", ",", "nil", "\n", "}" ]
70
maxmin-71
[ "Generate", "random", "number", "in", "[", "0", "n", ")" ]
[ "func", "GenerateRandomInt64", "(", "<mask>", ",", "max", "int64", ")", "int64", "{", "upper", ":=", "max", "-", "min", "\n\n", "nBig", ",", "err", ":=", "rand", ".", "Int", "(", "rand", ".", "Reader", ",", "big", ".", "NewInt", "(", "upper", ")", ")", "\n\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n\n", "return", "nBig", ".", "Int64", "(", ")", "+", "min", "\n", "}" ]
71
maxmin-72
[ "compactLogs", "takes", "the", "last", "inclusive", "index", "of", "a", "snapshot", "and", "trims", "the", "logs", "that", "are", "no", "longer", "needed", "." ]
[ "func", "(", "r", "*", "Raft", ")", "compactLogs", "(", "snapIdx", "uint64", ")", "error", "{", "defer", "metrics", ".", "MeasureSince", "(", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", "}", ",", "time", ".", "Now", "(", ")", ")", "\n", "// Determine log ranges to compact", "minLog", ",", "err", ":=", "r", ".", "logs", ".", "FirstIndex", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// Check if we have enough logs to truncate", "lastLogIdx", ",", "_", ":=", "r", ".", "getLastLog", "(", ")", "\n", "if", "lastLogIdx", "<=", "r", ".", "conf", ".", "TrailingLogs", "{", "return", "nil", "\n", "}", "\n\n", "// Truncate up to the end of the snapshot, or `TrailingLogs`", "// back from the head, which ever is further back. This ensures", "// at least `TrailingLogs` entries, but does not allow logs", "// after the snapshot to be removed.", "maxLog", ":=", "<mask>", "(", "snapIdx", ",", "lastLogIdx", "-", "r", ".", "conf", ".", "TrailingLogs", ")", "\n\n", "// Log this", "r", ".", "logger", ".", "Info", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "minLog", ",", "maxLog", ")", ")", "\n\n", "// Compact the logs", "if", "err", ":=", "r", ".", "logs", ".", "DeleteRange", "(", "minLog", ",", "maxLog", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
72
maxmin-73
[ "Generate", "random", "number", "in", "[", "0", "n", ")" ]
[ "func", "GenerateRandomInt", "(", "<mask>", ",", "max", "int", ")", "int", "{", "return", "int", "(", "GenerateRandomInt64", "(", "int64", "(", "min", ")", ",", "int64", "(", "max", ")", ")", ")", "\n", "}" ]
73
maxmin-74
[ "CreateRandom", "returns", "a", "random", "byte", "string", "of", "given", "length", "from", "given", "byte", "string" ]
[ "func", "CreateRandom", "(", "bs", "[", "]", "byte", ",", "length", "int", ")", "[", "]", "byte", "{", "filled", ":=", "make", "(", "[", "]", "byte", ",", "length", ")", "\n", "<mask>", ":=", "len", "(", "bs", ")", "\n\n", "for", "i", ":=", "0", ";", "i", "<", "length", ";", "i", "++", "{", "Shuffle", "(", "bs", ")", "\n", "filled", "[", "i", "]", "=", "bs", "[", "random", "(", "0", ",", "max", ")", "]", "\n", "}", "\n\n", "return", "filled", "\n", "}" ]
74
maxmin-75
[ "Decodes", "the", "next", "value", "from", "the", "stream", "into", "v", "." ]
[ "func", "(", "d", "*", "StreamDecoder", ")", "Decode", "(", "v", "interface", "{", "}", ")", "error", "{", "if", "d", ".", "err", "!=", "nil", "{", "return", "d", ".", "err", "\n", "}", "\n\n", "err", ":=", "error", "(", "nil", ")", "\n", "cnt", ":=", "d", ".", "cnt", "\n", "<mask>", ":=", "d", ".", "max", "\n", "dec", ":=", "Decoder", "{", "Parser", ":", "d", ".", "Parser", ",", "MapType", ":", "d", ".", "MapType", ",", "}", "\n\n", "switch", "d", ".", "typ", "{", "case", "Unknown", ":", "err", "=", "d", ".", "init", "(", ")", "\n", "max", "=", "d", ".", "max", "\n", "case", "Array", ":", "if", "cnt", "==", "max", "{", "err", "=", "dec", ".", "Parser", ".", "ParseArrayEnd", "(", "cnt", ")", "\n", "}", "else", "if", "cnt", "!=", "0", "{", "err", "=", "dec", ".", "Parser", ".", "ParseArrayNext", "(", "cnt", ")", "\n", "}", "\n", "}", "\n\n", "if", "err", "==", "nil", "{", "if", "cnt", "==", "max", "{", "err", "=", "End", "\n", "}", "else", "{", "switch", "err", "=", "dec", ".", "Decode", "(", "v", ")", ";", "err", "{", "case", "nil", ":", "cnt", "++", "\n", "case", "End", ":", "cnt", "++", "\n", "max", "=", "cnt", "\n", "default", ":", "if", "max", "<", "0", "&&", "dec", ".", "Parser", ".", "ParseArrayEnd", "(", "cnt", ")", "==", "nil", "{", "err", "=", "End", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n\n", "d", ".", "err", "=", "err", "\n", "d", ".", "cnt", "=", "cnt", "\n", "d", ".", "max", "=", "max", "\n", "return", "err", "\n", "}" ]
75
maxmin-76
[ "Len", "returns", "the", "number", "of", "values", "remaining", "to", "be", "read", "from", "the", "stream", "which", "may", "be", "-", "1", "if", "the", "underlying", "format", "doesn", "t", "provide", "this", "information", ".", "If", "an", "error", "occurred", "while", "decoding", "the", "stream", "the", "method", "returns", "zero", "because", "no", "more", "values", "can", "be", "read", "." ]
[ "func", "(", "d", "*", "StreamDecoder", ")", "Len", "(", ")", "int", "{", "if", "d", ".", "err", "!=", "nil", "{", "return", "0", "\n", "}", "\n\n", "if", "d", ".", "typ", "==", "Unknown", "{", "if", "d", ".", "init", "(", ")", "!=", "nil", "{", "return", "0", "\n", "}", "\n", "}", "\n\n", "return", "d", ".", "<mask>", "-", "d", ".", "cnt", "\n", "}" ]
76
maxmin-77
[ "slice", "returns", "a", "slice", "of", "log", "entries", "from", "lo", "through", "hi", "-", "1", "inclusive", "." ]
[ "func", "(", "l", "*", "raftLog", ")", "slice", "(", "lo", ",", "hi", ",", "maxSize", "uint64", ")", "(", "[", "]", "pb", ".", "Entry", ",", "error", ")", "{", "err", ":=", "l", ".", "mustCheckOutOfBounds", "(", "lo", ",", "hi", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "lo", "==", "hi", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "var", "ents", "[", "]", "pb", ".", "Entry", "\n", "if", "lo", "<", "l", ".", "unstable", ".", "offset", "{", "storedEnts", ",", "err", ":=", "l", ".", "storage", ".", "Entries", "(", "lo", ",", "<mask>", "(", "hi", ",", "l", ".", "unstable", ".", "offset", ")", ",", "maxSize", ")", "\n", "if", "err", "==", "ErrCompacted", "{", "return", "nil", ",", "err", "\n", "}", "else", "if", "err", "==", "ErrUnavailable", "{", "l", ".", "logger", ".", "Panicf", "(", "\"", "\"", ",", "lo", ",", "min", "(", "hi", ",", "l", ".", "unstable", ".", "offset", ")", ")", "\n", "}", "else", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "// TODO(bdarnell)", "\n", "}", "\n\n", "// check if ents has reached the size limitation", "if", "uint64", "(", "len", "(", "storedEnts", ")", ")", "<", "min", "(", "hi", ",", "l", ".", "unstable", ".", "offset", ")", "-", "lo", "{", "return", "storedEnts", ",", "nil", "\n", "}", "\n\n", "ents", "=", "storedEnts", "\n", "}", "\n", "if", "hi", ">", "l", ".", "unstable", ".", "offset", "{", "unstable", ":=", "l", ".", "unstable", ".", "slice", "(", "max", "(", "lo", ",", "l", ".", "unstable", ".", "offset", ")", ",", "hi", ")", "\n", "if", "len", "(", "ents", ")", ">", "0", "{", "combined", ":=", "make", "(", "[", "]", "pb", ".", "Entry", ",", "len", "(", "ents", ")", "+", "len", "(", "unstable", ")", ")", "\n", "n", ":=", "copy", "(", "combined", ",", "ents", ")", "\n", "copy", "(", "combined", "[", "n", ":", "]", ",", "unstable", ")", "\n", "ents", "=", "combined", "\n", "}", "else", "{", "ents", "=", "unstable", "\n", "}", "\n", "}", "\n", "return", "limitSize", "(", "ents", ",", "maxSize", ")", ",", "nil", "\n", "}" ]
77
maxmin-78
[ "Generate", "-", "used", "to", "generate", "a", "struct", "for", "a", "given", "job" ]
[ "func", "Generate", "(", "packagename", "string", ",", "fileBytes", "[", "]", "byte", ",", "outputDir", "string", ")", "{", "b", ":=", "preprocessJobManifest", "(", "fileBytes", ")", "\n", "objects", ":=", "make", "(", "map", "[", "string", "]", "map", "[", "string", "]", "ObjectField", ")", "\n", "var", "properties", "[", "]", "string", "\n", "for", "_", ",", "v", ":=", "range", "b", ".", "recs", "{", "properties", "=", "append", "(", "properties", ",", "v", ".", "Orig", ")", "\n", "}", "\n", "for", "i", ":=", "0", ";", "i", "<", "b", ".", "<mask>", ";", "i", "++", "{", "for", "_", ",", "v", ":=", "range", "b", ".", "recs", "{", "if", "v", ".", "Length", "-", "1", ">=", "i", "{", "var", "structname", "=", "v", ".", "StructName", "(", "i", ",", "packagename", ",", "properties", ")", "\n", "var", "typeName", "=", "v", ".", "TypeName", "(", "i", ",", "properties", ")", "\n", "elementName", ":=", "v", ".", "Slice", "[", "i", "]", "\n", "attributeName", ":=", "FormatName", "(", "elementName", ")", "\n\n", "if", "_", ",", "ok", ":=", "objects", "[", "structname", "]", ";", "!", "ok", "{", "objects", "[", "structname", "]", "=", "make", "(", "map", "[", "string", "]", "ObjectField", ")", "\n", "}", "\n\n", "if", "previousElement", ",", "ok", ":=", "objects", "[", "structname", "]", "[", "attributeName", "]", ";", "!", "ok", "{", "lo", ".", "G", ".", "Debug", "(", "\"", "\"", ",", "attributeName", ",", "\"", "\"", ",", "structname", ",", "\"", "\"", ",", "typeName", ")", "\n", "objects", "[", "structname", "]", "[", "attributeName", "]", "=", "ObjectField", "{", "ElementName", ":", "attributeName", ",", "ElementType", ":", "typeName", ",", "ElementAnnotation", ":", "createElementAnnotation", "(", "elementName", ")", ",", "Meta", ":", "v", ".", "Yaml", ",", "}", "\n", "}", "else", "{", "if", "previousElement", ".", "ElementAnnotation", "!=", "createElementAnnotation", "(", "elementName", ")", "{", "lo", ".", "G", ".", "Warning", "(", "\"", "\"", ",", "structname", ",", "\"", "\"", ",", "attributeName", ",", "\"", "\"", ")", "\n", "previousElement", ".", "ElementAnnotation", "=", "\"", "\\\"", "\\\"", "\"", "\n", "objects", "[", "structname", "]", "[", "attributeName", "]", "=", "previousElement", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "structs", ":=", "generateStructs", "(", "objects", ",", "packagename", ")", "\n", "writeStructsToDisk", "(", "structs", ",", "outputDir", ")", "\n", "}" ]
78
maxmin-79
[ "printHistogram", "prints", "the", "histogram", "data", "in", "a", "human", "-", "readable", "format", "." ]
[ "func", "(", "histogram", "histogramData", ")", "printHistogram", "(", ")", "{", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "histogram", ".", "totalCount", ")", "\n", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "histogram", ".", "<mask>", ")", "\n", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "histogram", ".", "max", ")", "\n", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "float64", "(", "histogram", ".", "sum", ")", "/", "float64", "(", "histogram", ".", "totalCount", ")", ")", "\n", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", "\n\n", "numBins", ":=", "len", "(", "histogram", ".", "bins", ")", "\n", "for", "index", ",", "count", ":=", "range", "histogram", ".", "countPerBin", "{", "if", "count", "==", "0", "{", "continue", "\n", "}", "\n\n", "// The last bin represents the bin that contains the range from", "// the last bin up to infinity so it's processed differently than the", "// other bins.", "if", "index", "==", "len", "(", "histogram", ".", "countPerBin", ")", "-", "1", "{", "lowerBound", ":=", "int", "(", "histogram", ".", "bins", "[", "numBins", "-", "1", "]", ")", "\n", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "lowerBound", ",", "\"", "\"", ",", "count", ")", "\n", "continue", "\n", "}", "\n\n", "upperBound", ":=", "int", "(", "histogram", ".", "bins", "[", "index", "]", ")", "\n", "lowerBound", ":=", "0", "\n", "if", "index", ">", "0", "{", "lowerBound", "=", "int", "(", "histogram", ".", "bins", "[", "index", "-", "1", "]", ")", "\n", "}", "\n\n", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "lowerBound", ",", "upperBound", ",", "count", ")", "\n", "}", "\n", "fmt", ".", "Println", "(", ")", "\n", "}" ]
79
maxmin-80
[ "parseDosTime", "converts", "a", "32bit", "DOS", "time", "value", "to", "time", ".", "Time" ]
[ "func", "parseDosTime", "(", "t", "uint32", ")", "time", ".", "Time", "{", "n", ":=", "int", "(", "t", ")", "\n", "sec", ":=", "n", "&", "0x1f", "<<", "1", "\n", "<mask>", ":=", "n", ">>", "5", "&", "0x3f", "\n", "hr", ":=", "n", ">>", "11", "&", "0x1f", "\n", "day", ":=", "n", ">>", "16", "&", "0x1f", "\n", "mon", ":=", "time", ".", "Month", "(", "n", ">>", "21", "&", "0x0f", ")", "\n", "yr", ":=", "n", ">>", "25", "&", "0x7f", "+", "1980", "\n", "return", "time", ".", "Date", "(", "yr", ",", "mon", ",", "day", ",", "hr", ",", "min", ",", "sec", ",", "0", ",", "time", ".", "Local", ")", "\n", "}" ]
80
maxmin-81
[ "String", "returns", "the", "string", "representation", "of", "a", "PerfDatum", "suitable", "for", "check", "output", "." ]
[ "func", "(", "p", "PerfDatum", ")", "String", "(", ")", "string", "{", "val", ":=", "fmtPerfFloat", "(", "p", ".", "value", ")", "\n", "value", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "p", ".", "label", ",", "val", ",", "p", ".", "unit", ")", "\n", "value", "+=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "fmtThreshold", "(", "p", ".", "warn", ")", ",", "fmtThreshold", "(", "p", ".", "crit", ")", ")", "\n", "value", "+=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "fmtThreshold", "(", "p", ".", "<mask>", ")", ",", "fmtThreshold", "(", "p", ".", "max", ")", ")", "\n", "return", "value", "\n", "}" ]
81
maxmin-82
[ "AskInt", "asks", "the", "user", "to", "enter", "an", "integer", "between", "a", "min", "and", "max", "value" ]
[ "func", "AskInt", "(", "question", "string", ",", "<mask>", "int64", ",", "max", "int64", ",", "defaultAnswer", "string", ")", "int64", "{", "for", "{", "answer", ":=", "askQuestion", "(", "question", ",", "defaultAnswer", ")", "\n\n", "result", ",", "err", ":=", "strconv", ".", "ParseInt", "(", "answer", ",", "10", ",", "64", ")", "\n\n", "if", "err", "==", "nil", "&&", "(", "min", "==", "-", "1", "||", "result", ">=", "min", ")", "&&", "(", "max", "==", "-", "1", "||", "result", "<=", "max", ")", "{", "return", "result", "\n", "}", "\n\n", "invalidInput", "(", ")", "\n", "}", "\n", "}" ]
82
maxmin-83
[ "fetchLoop", "is", "run", "in", "a", "goroutine" ]
[ "func", "(", "mp", "*", "master", ")", "fetchLoop", "(", ")", "{", "<mask>", ":=", "mp", ".", "Config", ".", "MinFetchInterval", "\n", "time", ".", "Sleep", "(", "min", ")", "\n", "for", "{", "t0", ":=", "time", ".", "Now", "(", ")", "\n", "mp", ".", "fetch", "(", ")", "\n", "//duration fetch of fetch", "diff", ":=", "time", ".", "Now", "(", ")", ".", "Sub", "(", "t0", ")", "\n", "if", "diff", "<", "min", "{", "delay", ":=", "min", "-", "diff", "\n", "//ensures at least MinFetchInterval delay.", "//should be throttled by the fetcher!", "time", ".", "Sleep", "(", "delay", ")", "\n", "}", "\n", "}", "\n", "}" ]
83
maxmin-84
[ "TODO", "needs", "test", "since", "it", "is", "not", "quiet", "right" ]
[ "func", "getPrec", "(", "num", "float64", ",", "better", "bool", ")", "int", "{", "<mask>", ":=", "3", "\n", "eps", ":=", "0.0005", "\n", "if", "better", "{", "max", "=", "6", "\n", "eps", "=", "0.0000005", "\n", "}", "\n", "prec", ":=", "0", "\n", "for", "math", ".", "Mod", "(", "num", ",", "1", ")", ">", "eps", "{", "num", "*=", "10", "\n", "eps", "*=", "10", "\n", "prec", "++", "\n", "}", "\n\n", "if", "max", "<", "prec", "{", "return", "max", "\n", "}", "\n", "return", "prec", "\n", "}" ]
84
maxmin-85
[ "Quantize", "quantizes", "the", "audio", "signal", "to", "match", "the", "target", "bitDepth" ]
[ "func", "Quantize", "(", "buf", "*", "audio", ".", "FloatBuffer", ",", "bitDepth", "int", ")", "{", "if", "buf", "==", "nil", "{", "return", "\n", "}", "\n", "<mask>", ":=", "math", ".", "Pow", "(", "2", ",", "float64", "(", "bitDepth", ")", ")", "-", "1", "\n\n", "bufLen", ":=", "len", "(", "buf", ".", "Data", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "bufLen", ";", "i", "++", "{", "buf", ".", "Data", "[", "i", "]", "=", "round", "(", "(", "buf", ".", "Data", "[", "i", "]", "+", "1", ")", "*", "max", ")", "/", "max", "-", "1.0", "\n", "}", "\n", "}" ]
85
maxmin-86
[ "CleanUrl", "check", "the", "characteres", "in", "url", "and", "parser", "it", "with", "url", ".", "Parse", ".", "If", "url", "is", "ok", "return", "one", "string", "with", "it", "or", "if", "the", "scheme", "is", "missing", "return", "the", "url", "and", "an", "error", "." ]
[ "func", "CleanUrl", "(", "rawurl", "string", ",", "<mask>", ",", "max", "int", ")", "(", "string", ",", "error", ")", "{", "err", ":=", "CheckUrl", "(", "rawurl", ",", "min", ",", "max", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "e", ".", "Forward", "(", "err", ")", "\n", "}", "\n", "u", ",", "err", ":=", "url", ".", "Parse", "(", "rawurl", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "e", ".", "Push", "(", "e", ".", "New", "(", "ErrInvUrl", ")", ",", "err", ")", "\n", "}", "\n", "if", "u", ".", "Scheme", "==", "\"", "\"", "{", "return", "u", ".", "String", "(", ")", ",", "e", ".", "New", "(", "ErrNoScheme", ")", "\n", "}", "\n", "return", "u", ".", "String", "(", ")", ",", "nil", "\n", "}" ]
86
maxmin-87
[ "unaryClientInterceptor", "returns", "a", "new", "retrying", "unary", "client", "interceptor", ".", "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", ")", "." ]
[ "func", "(", "c", "*", "Client", ")", "unaryClientInterceptor", "(", "logger", "*", "zap", ".", "Logger", ",", "optFuncs", "...", "retryOption", ")", "grpc", ".", "UnaryClientInterceptor", "{", "intOpts", ":=", "reuseOrNewWithCallOptions", "(", "defaultOptions", ",", "optFuncs", ")", "\n", "return", "func", "(", "ctx", "context", ".", "Context", ",", "method", "string", ",", "req", ",", "reply", "interface", "{", "}", ",", "cc", "*", "grpc", ".", "ClientConn", ",", "invoker", "grpc", ".", "UnaryInvoker", ",", "opts", "...", "grpc", ".", "CallOption", ")", "error", "{", "grpcOpts", ",", "retryOpts", ":=", "filterCallOptions", "(", "opts", ")", "\n", "callOpts", ":=", "reuseOrNewWithCallOptions", "(", "intOpts", ",", "retryOpts", ")", "\n", "// short circuit for simplicity, and avoiding allocations.", "if", "callOpts", ".", "<mask>", "==", "0", "{", "return", "invoker", "(", "ctx", ",", "method", ",", "req", ",", "reply", ",", "cc", ",", "grpcOpts", "...", ")", "\n", "}", "\n", "var", "lastErr", "error", "\n", "for", "attempt", ":=", "uint", "(", "0", ")", ";", "attempt", "<", "callOpts", ".", "max", ";", "attempt", "++", "{", "if", "err", ":=", "waitRetryBackoff", "(", "ctx", ",", "attempt", ",", "callOpts", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "logger", ".", "Debug", "(", "\"", "\"", ",", "zap", ".", "String", "(", "\"", "\"", ",", "cc", ".", "Target", "(", ")", ")", ",", "zap", ".", "Uint", "(", "\"", "\"", ",", "attempt", ")", ",", ")", "\n", "lastErr", "=", "invoker", "(", "ctx", ",", "method", ",", "req", ",", "reply", ",", "cc", ",", "grpcOpts", "...", ")", "\n", "if", "lastErr", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "logger", ".", "Warn", "(", "\"", "\"", ",", "zap", ".", "String", "(", "\"", "\"", ",", "cc", ".", "Target", "(", ")", ")", ",", "zap", ".", "Uint", "(", "\"", "\"", ",", "attempt", ")", ",", "zap", ".", "Error", "(", "lastErr", ")", ",", ")", "\n", "if", "isContextError", "(", "lastErr", ")", "{", "if", "ctx", ".", "Err", "(", ")", "!=", "nil", "{", "// its the context deadline or cancellation.", "return", "lastErr", "\n", "}", "\n", "// its the callCtx deadline or cancellation, in which case try again.", "continue", "\n", "}", "\n", "if", "callOpts", ".", "retryAuth", "&&", "rpctypes", ".", "Error", "(", "lastErr", ")", "==", "rpctypes", ".", "ErrInvalidAuthToken", "{", "gterr", ":=", "c", ".", "getToken", "(", "ctx", ")", "\n", "if", "gterr", "!=", "nil", "{", "logger", ".", "Warn", "(", "\"", "\"", ",", "zap", ".", "String", "(", "\"", "\"", ",", "cc", ".", "Target", "(", ")", ")", ",", "zap", ".", "Error", "(", "gterr", ")", ",", ")", "\n", "return", "lastErr", "// return the original error for simplicity", "\n", "}", "\n", "continue", "\n", "}", "\n", "if", "!", "isSafeRetry", "(", "c", ".", "lg", ",", "lastErr", ",", "callOpts", ")", "{", "return", "lastErr", "\n", "}", "\n", "}", "\n", "return", "lastErr", "\n", "}", "\n", "}" ]
87
maxmin-88
[ "RunBoundedArgs", "wraps", "a", "function", "in", "a", "function", "that", "checks", "its", "argument", "count", "is", "within", "a", "range", "." ]
[ "func", "RunBoundedArgs", "(", "<mask>", "int", ",", "max", "int", ",", "run", "func", "(", "[", "]", "string", ")", "error", ")", "func", "(", "*", "cobra", ".", "Command", ",", "[", "]", "string", ")", "{", "return", "func", "(", "cmd", "*", "cobra", ".", "Command", ",", "args", "[", "]", "string", ")", "{", "if", "len", "(", "args", ")", "<", "min", "||", "len", "(", "args", ")", ">", "max", "{", "fmt", ".", "Printf", "(", "\"", "\\n", "\\n", "\"", ",", "min", ",", "max", ",", "len", "(", "args", ")", ")", "\n", "cmd", ".", "Usage", "(", ")", "\n", "}", "else", "{", "if", "err", ":=", "run", "(", "args", ")", ";", "err", "!=", "nil", "{", "ErrorAndExit", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}" ]
88
maxmin-89
[ "canExecuteConcurrently", "checks", "whether", "the", "provided", "ProwJob", "can", "be", "executed", "concurrently", "." ]
[ "func", "(", "c", "*", "Controller", ")", "canExecuteConcurrently", "(", "pj", "*", "prowapi", ".", "ProwJob", ")", "bool", "{", "c", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "lock", ".", "Unlock", "(", ")", "\n\n", "if", "<mask>", ":=", "c", ".", "config", "(", ")", ".", "MaxConcurrency", ";", "max", ">", "0", "{", "var", "running", "int", "\n", "for", "_", ",", "num", ":=", "range", "c", ".", "pendingJobs", "{", "running", "+=", "num", "\n", "}", "\n", "if", "running", ">=", "max", "{", "c", ".", "log", ".", "WithFields", "(", "pjutil", ".", "ProwJobFields", "(", "pj", ")", ")", ".", "Debugf", "(", "\"", "\"", ",", "running", ")", "\n", "return", "false", "\n", "}", "\n", "}", "\n\n", "if", "pj", ".", "Spec", ".", "MaxConcurrency", "==", "0", "{", "c", ".", "pendingJobs", "[", "pj", ".", "Spec", ".", "Job", "]", "++", "\n", "return", "true", "\n", "}", "\n\n", "numPending", ":=", "c", ".", "pendingJobs", "[", "pj", ".", "Spec", ".", "Job", "]", "\n", "if", "numPending", ">=", "pj", ".", "Spec", ".", "MaxConcurrency", "{", "c", ".", "log", ".", "WithFields", "(", "pjutil", ".", "ProwJobFields", "(", "pj", ")", ")", ".", "Debugf", "(", "\"", "\"", ",", "pj", ".", "Spec", ".", "Job", ",", "numPending", ")", "\n", "return", "false", "\n", "}", "\n", "c", ".", "pendingJobs", "[", "pj", ".", "Spec", ".", "Job", "]", "++", "\n", "return", "true", "\n", "}" ]
89
maxmin-90
[ "CheckInt64Bounds", "verifies", "that", "v", "is", "within", "min", "and", "max", "t", "represents", "the", "original", "type", "of", "v", "." ]
[ "func", "CheckInt64Bounds", "(", "v", "int64", ",", "<mask>", "int64", ",", "max", "uint64", ",", "t", "reflect", ".", "Type", ")", "(", "err", "error", ")", "{", "if", "v", "<", "min", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "v", ",", "min", ",", "t", ")", "\n", "}", "\n", "if", "v", ">", "0", "&&", "uint64", "(", "v", ")", ">", "max", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "v", ",", "max", ",", "t", ")", "\n", "}", "\n", "return", "\n", "}" ]
90
maxmin-91
[ "projects", "returns", "the", "list", "of", "accessible", "gcp", "projects" ]
[ "func", "projects", "(", "<mask>", "int", ")", "(", "[", "]", "string", ",", "error", ")", "{", "out", ",", "err", ":=", "output", "(", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "max", ")", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "strings", ".", "Split", "(", "out", ",", "\"", "\\n", "\"", ")", ",", "nil", "\n", "}" ]
91
maxmin-92
[ "backoff", "computes", "a", "random", "exponential", "backoff", "value", "for", "a", "given", "number", "of", "attempts", "and", "boundaries", "of", "min", "and", "max", "backoff", "durations", "." ]
[ "func", "backoff", "(", "rand", "*", "rand", ".", "Rand", ",", "attempt", "int", ",", "<mask>", ",", "max", "time", ".", "Duration", ")", "time", ".", "Duration", "{", "if", "attempt", "<=", "0", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "min", ">", "max", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// Hardcoded backoff coefficient, maybe we'll make it configuration in the", "// future?", "const", "coeff", "=", "2.0", "\n", "return", "jitteredBackoff", "(", "rand", ",", "attempt", ",", "min", ",", "max", ",", "coeff", ")", "\n", "}" ]
92
maxmin-93
[ "assumes", "a", "to", "be", "sorted", "in", "descending", "order", "returns", "a", "subslice", "of", "a", "along", "with", "its", "indices", "(", "inclusive", ")" ]
[ "func", "cropResults", "(", "a", "[", "]", "int64", ",", "<mask>", "int64", ")", "(", "[", "]", "int64", ",", "int", ",", "int", ")", "{", "res", ":=", "[", "]", "int64", "{", "}", "\n", "firstIndex", ":=", "-", "1", "\n", "lastIndex", ":=", "0", "\n", "for", "i", ",", "v", ":=", "range", "a", "{", "if", "v", "<=", "max", "{", "res", "=", "append", "(", "res", ",", "v", ")", "\n", "if", "firstIndex", "==", "-", "1", "{", "firstIndex", "=", "i", "\n", "}", "\n", "lastIndex", "=", "i", "\n", "if", "len", "(", "res", ")", ">=", "resultsPerPage", "{", "break", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "res", ",", "firstIndex", ",", "lastIndex", "\n", "}" ]
93
maxmin-94
[ "sendHeartbeat", "sends", "a", "heartbeat", "RPC", "to", "the", "given", "peer", "." ]
[ "func", "(", "r", "*", "raft", ")", "sendHeartbeat", "(", "to", "uint64", ",", "ctx", "[", "]", "byte", ")", "{", "// Attach the commit as min(to.matched, r.committed).", "// When the leader sends out heartbeat message,", "// the receiver(follower) might not be matched with the leader", "// or it might not have all the committed entries.", "// The leader MUST NOT forward the follower's commit to", "// an unmatched index.", "commit", ":=", "<mask>", "(", "r", ".", "getProgress", "(", "to", ")", ".", "Match", ",", "r", ".", "raftLog", ".", "committed", ")", "\n", "m", ":=", "pb", ".", "Message", "{", "To", ":", "to", ",", "Type", ":", "pb", ".", "MsgHeartbeat", ",", "Commit", ":", "commit", ",", "Context", ":", "ctx", ",", "}", "\n\n", "r", ".", "send", "(", "m", ")", "\n", "}" ]
94
maxmin-95
[ "purgeFile", "is", "the", "internal", "implementation", "for", "PurgeFile", "which", "can", "post", "purged", "files", "to", "purgec", "if", "non", "-", "nil", "." ]
[ "func", "purgeFile", "(", "lg", "*", "zap", ".", "Logger", ",", "dirname", "string", ",", "suffix", "string", ",", "<mask>", "uint", ",", "interval", "time", ".", "Duration", ",", "stop", "<-", "chan", "struct", "{", "}", ",", "purgec", "chan", "<-", "string", ")", "<-", "chan", "error", "{", "errC", ":=", "make", "(", "chan", "error", ",", "1", ")", "\n", "go", "func", "(", ")", "{", "for", "{", "fnames", ",", "err", ":=", "ReadDir", "(", "dirname", ")", "\n", "if", "err", "!=", "nil", "{", "errC", "<-", "err", "\n", "return", "\n", "}", "\n", "newfnames", ":=", "make", "(", "[", "]", "string", ",", "0", ")", "\n", "for", "_", ",", "fname", ":=", "range", "fnames", "{", "if", "strings", ".", "HasSuffix", "(", "fname", ",", "suffix", ")", "{", "newfnames", "=", "append", "(", "newfnames", ",", "fname", ")", "\n", "}", "\n", "}", "\n", "sort", ".", "Strings", "(", "newfnames", ")", "\n", "fnames", "=", "newfnames", "\n", "for", "len", "(", "newfnames", ")", ">", "int", "(", "max", ")", "{", "f", ":=", "filepath", ".", "Join", "(", "dirname", ",", "newfnames", "[", "0", "]", ")", "\n", "l", ",", "err", ":=", "TryLockFile", "(", "f", ",", "os", ".", "O_WRONLY", ",", "PrivateFileMode", ")", "\n", "if", "err", "!=", "nil", "{", "break", "\n", "}", "\n", "if", "err", "=", "os", ".", "Remove", "(", "f", ")", ";", "err", "!=", "nil", "{", "errC", "<-", "err", "\n", "return", "\n", "}", "\n", "if", "err", "=", "l", ".", "Close", "(", ")", ";", "err", "!=", "nil", "{", "if", "lg", "!=", "nil", "{", "lg", ".", "Warn", "(", "\"", "\"", ",", "zap", ".", "String", "(", "\"", "\"", ",", "l", ".", "Name", "(", ")", ")", ",", "zap", ".", "Error", "(", "err", ")", ")", "\n", "}", "else", "{", "plog", ".", "Errorf", "(", "\"", "\"", ",", "l", ".", "Name", "(", ")", ",", "err", ")", "\n", "}", "\n", "errC", "<-", "err", "\n", "return", "\n", "}", "\n", "if", "lg", "!=", "nil", "{", "lg", ".", "Info", "(", "\"", "\"", ",", "zap", ".", "String", "(", "\"", "\"", ",", "f", ")", ")", "\n", "}", "else", "{", "plog", ".", "Infof", "(", "\"", "\"", ",", "f", ")", "\n", "}", "\n", "newfnames", "=", "newfnames", "[", "1", ":", "]", "\n", "}", "\n", "if", "purgec", "!=", "nil", "{", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "fnames", ")", "-", "len", "(", "newfnames", ")", ";", "i", "++", "{", "purgec", "<-", "fnames", "[", "i", "]", "\n", "}", "\n", "}", "\n", "select", "{", "case", "<-", "time", ".", "After", "(", "interval", ")", ":", "case", "<-", "stop", ":", "return", "\n", "}", "\n", "}", "\n", "}", "(", ")", "\n", "return", "errC", "\n", "}" ]
95
maxmin-96
[ "backoff", "is", "used", "to", "compute", "an", "exponential", "backoff", "duration", ".", "Base", "time", "is", "scaled", "by", "the", "current", "round", "up", "to", "some", "maximum", "scale", "factor", "." ]
[ "func", "backoff", "(", "base", "time", ".", "Duration", ",", "round", ",", "limit", "uint64", ")", "time", ".", "Duration", "{", "power", ":=", "<mask>", "(", "round", ",", "limit", ")", "\n", "for", "power", ">", "2", "{", "base", "*=", "2", "\n", "power", "--", "\n", "}", "\n", "return", "base", "\n", "}" ]
96
maxmin-97
[ "splitMappingsAt", "ensures", "that", "a", "is", "not", "in", "the", "middle", "of", "any", "mapping", ".", "Splits", "mappings", "as", "necessary", "." ]
[ "func", "(", "p", "*", "Process", ")", "splitMappingsAt", "(", "a", "Address", ")", "{", "for", "_", ",", "m", ":=", "range", "p", ".", "memory", ".", "mappings", "{", "if", "a", "<", "m", ".", "<mask>", "||", "a", ">", "m", ".", "max", "{", "continue", "\n", "}", "\n", "if", "a", "==", "m", ".", "min", "||", "a", "==", "m", ".", "max", "{", "return", "\n", "}", "\n", "// Split this mapping at a.", "m2", ":=", "new", "(", "Mapping", ")", "\n", "*", "m2", "=", "*", "m", "\n", "m", ".", "max", "=", "a", "\n", "m2", ".", "min", "=", "a", "\n", "if", "m2", ".", "f", "!=", "nil", "{", "m2", ".", "off", "+=", "m", ".", "Size", "(", ")", "\n", "}", "\n", "if", "m2", ".", "origF", "!=", "nil", "{", "m2", ".", "origOff", "+=", "m", ".", "Size", "(", ")", "\n", "}", "\n", "p", ".", "memory", ".", "mappings", "=", "append", "(", "p", ".", "memory", ".", "mappings", ",", "m2", ")", "\n", "return", "\n", "}", "\n", "}" ]
97
maxmin-98
[ "markObjects", "finds", "all", "the", "live", "objects", "in", "the", "heap", "and", "marks", "them", "in", "the", "p", ".", "heapInfo", "mark", "fields", "." ]
[ "func", "(", "p", "*", "Process", ")", "markObjects", "(", ")", "{", "ptrSize", ":=", "p", ".", "proc", ".", "PtrSize", "(", ")", "\n\n", "// number of live objects found so far", "n", ":=", "0", "\n", "// total size of live objects", "var", "live", "int64", "\n\n", "var", "q", "[", "]", "Object", "\n\n", "// Function to call when we find a new pointer.", "add", ":=", "func", "(", "x", "core", ".", "Address", ")", "{", "h", ":=", "p", ".", "findHeapInfo", "(", "x", ")", "\n", "if", "h", "==", "nil", "{", "// not in heap or not in a valid span", "// Invalid spans can happen with intra-stack pointers.", "return", "\n", "}", "\n", "// Round down to object start.", "x", "=", "h", ".", "base", ".", "Add", "(", "x", ".", "Sub", "(", "h", ".", "base", ")", "/", "h", ".", "size", "*", "h", ".", "size", ")", "\n", "// Object start may map to a different info. Reload heap info.", "h", "=", "p", ".", "findHeapInfo", "(", "x", ")", "\n", "// Find mark bit", "b", ":=", "uint64", "(", "x", ")", "%", "heapInfoSize", "/", "8", "\n", "if", "h", ".", "mark", "&", "(", "uint64", "(", "1", ")", "<<", "b", ")", "!=", "0", "{", "// already found", "return", "\n", "}", "\n", "h", ".", "mark", "|=", "uint64", "(", "1", ")", "<<", "b", "\n", "n", "++", "\n", "live", "+=", "h", ".", "size", "\n", "q", "=", "append", "(", "q", ",", "Object", "(", "x", ")", ")", "\n", "}", "\n\n", "// Start with scanning all the roots.", "// Note that we don't just use the DWARF roots, just in case DWARF isn't complete.", "// Instead we use exactly what the runtime uses.", "// Goroutine roots", "for", "_", ",", "g", ":=", "range", "p", ".", "goroutines", "{", "for", "_", ",", "f", ":=", "range", "g", ".", "frames", "{", "for", "a", ":=", "range", "f", ".", "Live", "{", "add", "(", "p", ".", "proc", ".", "ReadPtr", "(", "a", ")", ")", "\n", "}", "\n", "}", "\n", "}", "\n\n", "// Global roots", "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", "gc", ":=", "m", ".", "r", ".", "Field", "(", "\"", "\"", "+", "s", "+", "\"", "\"", ")", ".", "Field", "(", "\"", "\"", ")", ".", "Address", "(", ")", "\n", "num", ":=", "max", ".", "Sub", "(", "min", ")", "/", "ptrSize", "\n", "for", "i", ":=", "int64", "(", "0", ")", ";", "i", "<", "num", ";", "i", "++", "{", "if", "p", ".", "proc", ".", "ReadUint8", "(", "gc", ".", "Add", "(", "i", "/", "8", ")", ")", ">>", "uint", "(", "i", "%", "8", ")", "&", "1", "!=", "0", "{", "add", "(", "p", ".", "proc", ".", "ReadPtr", "(", "min", ".", "Add", "(", "i", "*", "ptrSize", ")", ")", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n\n", "// Finalizers", "for", "_", ",", "r", ":=", "range", "p", ".", "globals", "{", "if", "!", "strings", ".", "HasPrefix", "(", "r", ".", "Name", ",", "\"", "\"", ")", "{", "continue", "\n", "}", "\n", "for", "_", ",", "f", ":=", "range", "r", ".", "Type", ".", "Fields", "{", "if", "f", ".", "Type", ".", "Kind", "==", "KindPtr", "{", "add", "(", "p", ".", "proc", ".", "ReadPtr", "(", "r", ".", "Addr", ".", "Add", "(", "f", ".", "Off", ")", ")", ")", "\n", "}", "\n", "}", "\n", "}", "\n\n", "// Expand root set to all reachable objects.", "for", "len", "(", "q", ")", ">", "0", "{", "x", ":=", "q", "[", "len", "(", "q", ")", "-", "1", "]", "\n", "q", "=", "q", "[", ":", "len", "(", "q", ")", "-", "1", "]", "\n\n", "// Scan object for pointers.", "size", ":=", "p", ".", "Size", "(", "x", ")", "\n", "for", "i", ":=", "int64", "(", "0", ")", ";", "i", "<", "size", ";", "i", "+=", "ptrSize", "{", "a", ":=", "core", ".", "Address", "(", "x", ")", ".", "Add", "(", "i", ")", "\n", "if", "p", ".", "isPtrFromHeap", "(", "a", ")", "{", "add", "(", "p", ".", "proc", ".", "ReadPtr", "(", "a", ")", ")", "\n", "}", "\n", "}", "\n", "}", "\n\n", "p", ".", "nObj", "=", "n", "\n\n", "// Initialize firstIdx fields in the heapInfo, for fast object index lookups.", "n", "=", "0", "\n", "p", ".", "ForEachObject", "(", "func", "(", "x", "Object", ")", "bool", "{", "h", ":=", "p", ".", "findHeapInfo", "(", "p", ".", "Addr", "(", "x", ")", ")", "\n", "if", "h", ".", "firstIdx", "==", "-", "1", "{", "h", ".", "firstIdx", "=", "n", "\n", "}", "\n", "n", "++", "\n", "return", "true", "\n", "}", ")", "\n", "if", "n", "!=", "p", ".", "nObj", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// Update stats to include the live/garbage distinction.", "alloc", ":=", "p", ".", "Stats", "(", ")", ".", "Child", "(", "\"", "\"", ")", ".", "Child", "(", "\"", "\"", ")", ".", "Child", "(", "\"", "\"", ")", "\n", "alloc", ".", "Children", "=", "[", "]", "*", "Stats", "{", "&", "Stats", "{", "\"", "\"", ",", "live", ",", "nil", "}", ",", "&", "Stats", "{", "\"", "\"", ",", "alloc", ".", "Size", "-", "live", ",", "nil", "}", ",", "}", "\n", "}" ]
98
maxmin-99
[ "serve", "runs", "the", "listener", "to", "accept", "and", "manage", "new", "incoming", "connections", "blocking", "until", "the", "channel", "is", "closed", "." ]
[ "func", "(", "ch", "*", "Channel", ")", "serve", "(", ")", "{", "acceptBackoff", ":=", "0", "*", "time", ".", "Millisecond", "\n\n", "for", "{", "netConn", ",", "err", ":=", "ch", ".", "mutable", ".", "l", ".", "Accept", "(", ")", "\n", "if", "err", "!=", "nil", "{", "// Backoff from new accepts if this is a temporary error", "if", "ne", ",", "ok", ":=", "err", ".", "(", "net", ".", "Error", ")", ";", "ok", "&&", "ne", ".", "Temporary", "(", ")", "{", "if", "acceptBackoff", "==", "0", "{", "acceptBackoff", "=", "5", "*", "time", ".", "Millisecond", "\n", "}", "else", "{", "acceptBackoff", "*=", "2", "\n", "}", "\n", "if", "<mask>", ":=", "1", "*", "time", ".", "Second", ";", "acceptBackoff", ">", "max", "{", "acceptBackoff", "=", "max", "\n", "}", "\n", "ch", ".", "log", ".", "WithFields", "(", "ErrField", "(", "err", ")", ",", "LogField", "{", "\"", "\"", ",", "acceptBackoff", "}", ",", ")", ".", "Warn", "(", "\"", "\"", ")", "\n", "time", ".", "Sleep", "(", "acceptBackoff", ")", "\n", "continue", "\n", "}", "else", "{", "// Only log an error if this didn't happen due to a Close.", "if", "ch", ".", "State", "(", ")", ">=", "ChannelStartClose", "{", "return", "\n", "}", "\n", "ch", ".", "log", ".", "WithFields", "(", "ErrField", "(", "err", ")", ")", ".", "Fatal", "(", "\"", "\"", ")", "\n", "return", "\n", "}", "\n", "}", "\n\n", "acceptBackoff", "=", "0", "\n\n", "// Perform the connection handshake in a background goroutine.", "go", "func", "(", ")", "{", "// Register the connection in the peer once the channel is set up.", "events", ":=", "connectionEvents", "{", "OnActive", ":", "ch", ".", "inboundConnectionActive", ",", "OnCloseStateChange", ":", "ch", ".", "connectionCloseStateChange", ",", "OnExchangeUpdated", ":", "ch", ".", "exchangeUpdated", ",", "}", "\n", "if", "_", ",", "err", ":=", "ch", ".", "inboundHandshake", "(", "context", ".", "Background", "(", ")", ",", "netConn", ",", "events", ")", ";", "err", "!=", "nil", "{", "netConn", ".", "Close", "(", ")", "\n", "}", "\n", "}", "(", ")", "\n", "}", "\n", "}" ]
99
maxmin-100
[ "ParseUintHex", "parses", "a", "hexadecimanl", "representation", "of", "a", "uint64", "from", "b", ".", "The", "function", "is", "equivalent", "to", "calling", "strconv", ".", "ParseUint", "(", "string", "(", "b", ")", "16", "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", ".", "ParseUint", ")", ".", "Because", "it", "only", "works", "with", "base", "16", "the", "function", "is", "also", "significantly", "faster", "than", "strconv", ".", "ParseUint", "." ]
[ "func", "ParseUintHex", "(", "b", "[", "]", "byte", ")", "(", "uint64", ",", "error", ")", "{", "const", "<mask>", "=", "Uint64Max", "\n", "const", "lim", "=", "max", "/", "0x10", "\n", "var", "val", "uint64", "\n\n", "if", "len", "(", "b", ")", "==", "0", "{", "return", "0", ",", "errorInvalidUint64", "(", "b", ")", "\n", "}", "\n\n", "for", "_", ",", "d", ":=", "range", "b", "{", "var", "x", "uint64", "\n\n", "switch", "{", "case", "d", ">=", "'0'", "&&", "d", "<=", "'9'", ":", "x", "=", "uint64", "(", "d", "-", "'0'", ")", "\n\n", "case", "d", ">=", "'A'", "&&", "d", "<=", "'F'", ":", "x", "=", "uint64", "(", "d", "-", "'A'", ")", "+", "0xA", "\n\n", "case", "d", ">=", "'a'", "&&", "d", "<=", "'f'", ":", "x", "=", "uint64", "(", "d", "-", "'a'", ")", "+", "0xA", "\n\n", "default", ":", "return", "0", ",", "errorInvalidUint64", "(", "b", ")", "\n", "}", "\n\n", "if", "val", ">", "lim", "{", "return", "0", ",", "errorOverflowUint64", "(", "b", ")", "\n", "}", "\n\n", "if", "val", "*=", "0x10", ";", "val", ">", "(", "max", "-", "x", ")", "{", "return", "0", ",", "errorOverflowUint64", "(", "b", ")", "\n", "}", "\n\n", "val", "+=", "x", "\n", "}", "\n\n", "return", "val", ",", "nil", "\n", "}" ]

Dataset Card for "code_x_glue_cc_cloze_testing_maxmin"

Dataset Summary

CodeXGLUE ClozeTesting-maxmin dataset, available at https://github.com/microsoft/CodeXGLUE/tree/main/Code-Code/ClozeTesting-maxmin

Cloze tests are widely adopted in Natural Languages Processing to evaluate the performance of the trained language models. The task is aimed to predict the answers for the blank with the context of the blank, which can be formulated as a multi-choice classification problem. Here we present the two cloze testing datasets in code domain with six different programming languages: ClozeTest-maxmin and ClozeTest-all. Each instance in the dataset contains a masked code function, its docstring and the target word. The only difference between ClozeTest-maxmin and ClozeTest-all is their selected words sets, where ClozeTest-maxmin only contains two words while ClozeTest-all contains 930 words.

Supported Tasks and Leaderboards

  • slot-filling: The dataset can be used to train a model for predicting the missing token from a piece of code, similar to the Cloze test.

Languages

  • Go programming language
  • Java programming language
  • Javascript programming language
  • PHP programming language
  • Python programming language
  • Ruby programming language

Dataset Structure

Data Instances

go

An example of 'train' looks as follows.

{
    "id": 0, 
    "idx": "maxmin-1", 
    "nl_tokens": ["SetMaxStructPoolSize", "sets", "the", "struct", "pools", "max", "size", ".", "this", "may", "be", "usefull", "for", "fine", "grained", "performance", "tuning", "towards", "your", "application", "however", "the", "default", "should", "be", "fine", "for", "nearly", "all", "cases", ".", "only", "increase", "if", "you", "have", "a", "deeply", "nested", "struct", "structure", ".", "NOTE", ":", "this", "method", "is", "not", "thread", "-", "safe", "NOTE", ":", "this", "is", "only", "here", "to", "keep", "compatibility", "with", "v5", "in", "v6", "the", "method", "will", "be", "removed"], 
    "pl_tokens": ["func", "(", "v", "*", "Validate", ")", "SetMaxStructPoolSize", "(", "<mask>", "int", ")", "{", "structPool", "=", "&", "sync", ".", "Pool", "{", "New", ":", "newStructErrors", "}", "\n", "}"]
}

java

An example of 'train' looks as follows.

{
    "id": 0, 
    "idx": "maxmin-1", 
    "nl_tokens": ["Test", "whether", "find", "can", "be", "found", "at", "position", "startPos", "in", "the", "string", "src", "."], 
    "pl_tokens": ["public", "static", "boolean", "startsWith", "(", "char", "[", "]", "src", ",", "char", "[", "]", "find", ",", "int", "startAt", ")", "{", "int", "startPos", "=", "startAt", ";", "boolean", "result", "=", "true", ";", "// Check ranges", "if", "(", "src", ".", "length", "<", "startPos", "+", "find", ".", "length", ")", "{", "result", "=", "false", ";", "}", "else", "{", "final", "int", "<mask>", "=", "find", ".", "length", ";", "for", "(", "int", "a", "=", "0", ";", "a", "<", "max", "&&", "result", ";", "a", "++", ")", "{", "if", "(", "src", "[", "startPos", "]", "!=", "find", "[", "a", "]", ")", "{", "result", "=", "false", ";", "}", "startPos", "++", ";", "}", "}", "return", "result", ";", "}"]
}

javascript

An example of 'train' looks as follows.

{
    "id": 0, 
    "idx": "maxmin-1", 
    "nl_tokens": ["string", ".", "max", "Maximum", "length", "of", "the", "string"], 
    "pl_tokens": ["function", "(", "string", ")", "{", "// string.check check sting type and size", "return", "(", "(", "typeof", "string", "===", "'string'", "||", "string", "instanceof", "String", ")", "&&", "string", ".", "length", ">=", "this", ".", "<mask>", "&&", "string", ".", "length", "<=", "this", ".", "max", "&&", "(", "!", "this", ".", "match", "||", "string", ".", "match", "(", "this", ".", "match", ")", ")", ")", ";", "}"]
}

php

An example of 'train' looks as follows.

{
    "id": 0, 
    "idx": "maxmin-1", 
    "nl_tokens": ["Read", "the", "next", "character", "from", "the", "supplied", "string", ".", "Return", "null", "when", "we", "have", "run", "out", "of", "characters", "."], 
    "pl_tokens": ["public", "function", "readOne", "(", ")", "{", "if", "(", "$", "this", "->", "pos", "<=", "$", "this", "->", "<mask>", ")", "{", "$", "value", "=", "$", "this", "->", "string", "[", "$", "this", "->", "pos", "]", ";", "$", "this", "->", "pos", "+=", "1", ";", "}", "else", "{", "$", "value", "=", "null", ";", "}", "return", "$", "value", ";", "}"]
}

python

An example of 'train' looks as follows.

{
    "id": 0, 
    "idx": "maxmin-1", 
    "nl_tokens": ["Returns", "intermediary", "colors", "for", "given", "list", "of", "colors", "."], 
    "pl_tokens": ["def", "_interpolate", "(", "self", ",", "colors", ",", "n", "=", "100", ")", ":", "gradient", "=", "[", "]", "for", "i", "in", "_range", "(", "n", ")", ":", "l", "=", "len", "(", "colors", ")", "-", "1", "x", "=", "int", "(", "1.0", "*", "i", "/", "n", "*", "l", ")", "x", "=", "<mask>", "(", "x", "+", "0", ",", "l", ")", "y", "=", "min", "(", "x", "+", "1", ",", "l", ")", "base", "=", "1.0", "*", "n", "/", "l", "*", "x", "d", "=", "(", "i", "-", "base", ")", "/", "(", "1.0", "*", "n", "/", "l", ")", "r", "=", "colors", "[", "x", "]", ".", "r", "*", "(", "1", "-", "d", ")", "+", "colors", "[", "y", "]", ".", "r", "*", "d", "g", "=", "colors", "[", "x", "]", ".", "g", "*", "(", "1", "-", "d", ")", "+", "colors", "[", "y", "]", ".", "g", "*", "d", "b", "=", "colors", "[", "x", "]", ".", "b", "*", "(", "1", "-", "d", ")", "+", "colors", "[", "y", "]", ".", "b", "*", "d", "a", "=", "colors", "[", "x", "]", ".", "a", "*", "(", "1", "-", "d", ")", "+", "colors", "[", "y", "]", ".", "a", "*", "d", "gradient", ".", "append", "(", "color", "(", "r", ",", "g", ",", "b", ",", "a", ",", "mode", "=", "\"rgb\"", ")", ")", "gradient", ".", "append", "(", "colors", "[", "-", "1", "]", ")", "return", "gradient"]
}

ruby

An example of 'train' looks as follows.

{
    "id": 0, 
    "idx": "maxmin-1", 
    "nl_tokens": ["Delete", "all", "copies", "that", "are", "older", "than", "the", "max", "age", "provided", "in", "seconds", "."], 
    "pl_tokens": ["def", "clean", "(", "<mask>", ":", "24", "*", "60", "*", "60", ")", "Futex", ".", "new", "(", "file", ",", "log", ":", "@log", ")", ".", "open", "do", "list", "=", "load", "list", ".", "reject!", "do", "|", "s", "|", "if", "s", "[", ":time", "]", ">=", "Time", ".", "now", "-", "max", "false", "else", "@log", ".", "debug", "(", "\"Copy ##{s[:name]}/#{s[:host]}:#{s[:port]} is too old, over #{Age.new(s[:time])}\"", ")", "true", "end", "end", "save", "(", "list", ")", "deleted", "=", "0", "files", ".", "each", "do", "|", "f", "|", "next", "unless", "list", ".", "find", "{", "|", "s", "|", "s", "[", ":name", "]", "==", "File", ".", "basename", "(", "f", ",", "Copies", "::", "EXT", ")", "}", ".", "nil?", "file", "=", "File", ".", "join", "(", "@dir", ",", "f", ")", "size", "=", "File", ".", "size", "(", "file", ")", "File", ".", "delete", "(", "file", ")", "@log", ".", "debug", "(", "\"Copy at #{f} deleted: #{Size.new(size)}\"", ")", "deleted", "+=", "1", "end", "list", ".", "select!", "do", "|", "s", "|", "cp", "=", "File", ".", "join", "(", "@dir", ",", "\"#{s[:name]}#{Copies::EXT}\"", ")", "wallet", "=", "Wallet", ".", "new", "(", "cp", ")", "begin", "wallet", ".", "refurbish", "raise", "\"Invalid protocol #{wallet.protocol} in #{cp}\"", "unless", "wallet", ".", "protocol", "==", "Zold", "::", "PROTOCOL", "true", "rescue", "StandardError", "=>", "e", "FileUtils", ".", "rm_rf", "(", "cp", ")", "@log", ".", "debug", "(", "\"Copy at #{cp} deleted: #{Backtrace.new(e)}\"", ")", "deleted", "+=", "1", "false", "end", "end", "save", "(", "list", ")", "deleted", "end", "end"]
}

Data Fields

In the following each data field in go is explained for each config. The data fields are the same among all splits.

go, java, javascript, php, python, ruby

field name type description
id int32 Index of the sample
idx string Original index in the dataset
nl_tokens Sequence[string] Natural language tokens
pl_tokens Sequence[string] Programming language tokens

Data Splits

name train
go 152
java 482
javascript 272
php 407
python 1264
ruby 38

Dataset Creation

Curation Rationale

[More Information Needed]

Source Data

Initial Data Collection and Normalization

Data from CodeSearchNet Challenge dataset. [More Information Needed]

Who are the source language producers?

Software Engineering developers.

Annotations

Annotation process

[More Information Needed]

Who are the annotators?

[More Information Needed]

Personal and Sensitive Information

[More Information Needed]

Considerations for Using the Data

Social Impact of Dataset

[More Information Needed]

Discussion of Biases

[More Information Needed]

Other Known Limitations

[More Information Needed]

Additional Information

Dataset Curators

https://github.com/microsoft, https://github.com/madlag

Licensing Information

Computational Use of Data Agreement (C-UDA) License.

Citation Information

@article{CodeXGLUE,
  title={CodeXGLUE: An Open Challenge for Code Intelligence},
  journal={arXiv},
  year={2020},
}
@article{feng2020codebert,
  title={CodeBERT: A Pre-Trained Model for Programming and Natural Languages},
  author={Feng, Zhangyin and Guo, Daya and Tang, Duyu and Duan, Nan and Feng, Xiaocheng and Gong, Ming and Shou, Linjun and Qin, Bing and Liu, Ting and Jiang, Daxin and others},
  journal={arXiv preprint arXiv:2002.08155},
  year={2020}
}
@article{husain2019codesearchnet,
  title={CodeSearchNet Challenge: Evaluating the State of Semantic Code Search},
  author={Husain, Hamel and Wu, Ho-Hsiang and Gazit, Tiferet and Allamanis, Miltiadis and Brockschmidt, Marc},
  journal={arXiv preprint arXiv:1909.09436},
  year={2019}
}

Contributions

Thanks to @madlag (and partly also @ncoop57) for adding this dataset.

Downloads last month
436
Edit dataset card