id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
11,100 | influxdata/influxql | parser.go | parseShowDiagnosticsStatement | func (p *Parser) parseShowDiagnosticsStatement() (*ShowDiagnosticsStatement, error) {
stmt := &ShowDiagnosticsStatement{}
var err error
if tok, _, _ := p.ScanIgnoreWhitespace(); tok == FOR {
stmt.Module, err = p.parseString()
} else {
p.Unscan()
}
return stmt, err
} | go | func (p *Parser) parseShowDiagnosticsStatement() (*ShowDiagnosticsStatement, error) {
stmt := &ShowDiagnosticsStatement{}
var err error
if tok, _, _ := p.ScanIgnoreWhitespace(); tok == FOR {
stmt.Module, err = p.parseString()
} else {
p.Unscan()
}
return stmt, err
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"parseShowDiagnosticsStatement",
"(",
")",
"(",
"*",
"ShowDiagnosticsStatement",
",",
"error",
")",
"{",
"stmt",
":=",
"&",
"ShowDiagnosticsStatement",
"{",
"}",
"\n",
"var",
"err",
"error",
"\n\n",
"if",
"tok",
",",
"_",
",",
"_",
":=",
"p",
".",
"ScanIgnoreWhitespace",
"(",
")",
";",
"tok",
"==",
"FOR",
"{",
"stmt",
".",
"Module",
",",
"err",
"=",
"p",
".",
"parseString",
"(",
")",
"\n",
"}",
"else",
"{",
"p",
".",
"Unscan",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"stmt",
",",
"err",
"\n",
"}"
] | // parseShowDiagnostics parses a string and returns a ShowDiagnosticsStatement. | [
"parseShowDiagnostics",
"parses",
"a",
"string",
"and",
"returns",
"a",
"ShowDiagnosticsStatement",
"."
] | 1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513 | https://github.com/influxdata/influxql/blob/1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513/parser.go#L1974-L1985 |
11,101 | influxdata/influxql | parser.go | parseDropContinuousQueryStatement | func (p *Parser) parseDropContinuousQueryStatement() (*DropContinuousQueryStatement, error) {
stmt := &DropContinuousQueryStatement{}
// Read the id of the query to drop.
ident, err := p.ParseIdent()
if err != nil {
return nil, err
}
stmt.Name = ident
// Expect an "ON" keyword.
if tok, pos, lit := p.ScanIgnoreWhitespace(); tok != ON {
return nil, newParseError(tokstr(tok, lit), []string{"ON"}, pos)
}
// Read the name of the database to remove the query from.
if ident, err = p.ParseIdent(); err != nil {
return nil, err
}
stmt.Database = ident
return stmt, nil
} | go | func (p *Parser) parseDropContinuousQueryStatement() (*DropContinuousQueryStatement, error) {
stmt := &DropContinuousQueryStatement{}
// Read the id of the query to drop.
ident, err := p.ParseIdent()
if err != nil {
return nil, err
}
stmt.Name = ident
// Expect an "ON" keyword.
if tok, pos, lit := p.ScanIgnoreWhitespace(); tok != ON {
return nil, newParseError(tokstr(tok, lit), []string{"ON"}, pos)
}
// Read the name of the database to remove the query from.
if ident, err = p.ParseIdent(); err != nil {
return nil, err
}
stmt.Database = ident
return stmt, nil
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"parseDropContinuousQueryStatement",
"(",
")",
"(",
"*",
"DropContinuousQueryStatement",
",",
"error",
")",
"{",
"stmt",
":=",
"&",
"DropContinuousQueryStatement",
"{",
"}",
"\n\n",
"// Read the id of the query to drop.",
"ident",
",",
"err",
":=",
"p",
".",
"ParseIdent",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"stmt",
".",
"Name",
"=",
"ident",
"\n\n",
"// Expect an \"ON\" keyword.",
"if",
"tok",
",",
"pos",
",",
"lit",
":=",
"p",
".",
"ScanIgnoreWhitespace",
"(",
")",
";",
"tok",
"!=",
"ON",
"{",
"return",
"nil",
",",
"newParseError",
"(",
"tokstr",
"(",
"tok",
",",
"lit",
")",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"pos",
")",
"\n",
"}",
"\n\n",
"// Read the name of the database to remove the query from.",
"if",
"ident",
",",
"err",
"=",
"p",
".",
"ParseIdent",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"stmt",
".",
"Database",
"=",
"ident",
"\n\n",
"return",
"stmt",
",",
"nil",
"\n",
"}"
] | // parseDropContinuousQueriesStatement parses a string and returns a DropContinuousQueryStatement.
// This function assumes the "DROP CONTINUOUS" tokens have already been consumed. | [
"parseDropContinuousQueriesStatement",
"parses",
"a",
"string",
"and",
"returns",
"a",
"DropContinuousQueryStatement",
".",
"This",
"function",
"assumes",
"the",
"DROP",
"CONTINUOUS",
"tokens",
"have",
"already",
"been",
"consumed",
"."
] | 1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513 | https://github.com/influxdata/influxql/blob/1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513/parser.go#L1989-L2011 |
11,102 | influxdata/influxql | parser.go | parseFields | func (p *Parser) parseFields() (Fields, error) {
var fields Fields
for {
// Parse the field.
f, err := p.parseField()
if err != nil {
return nil, err
}
// Add new field.
fields = append(fields, f)
// If there's not a comma next then stop parsing fields.
if tok, _, _ := p.Scan(); tok != COMMA {
p.Unscan()
break
}
}
return fields, nil
} | go | func (p *Parser) parseFields() (Fields, error) {
var fields Fields
for {
// Parse the field.
f, err := p.parseField()
if err != nil {
return nil, err
}
// Add new field.
fields = append(fields, f)
// If there's not a comma next then stop parsing fields.
if tok, _, _ := p.Scan(); tok != COMMA {
p.Unscan()
break
}
}
return fields, nil
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"parseFields",
"(",
")",
"(",
"Fields",
",",
"error",
")",
"{",
"var",
"fields",
"Fields",
"\n\n",
"for",
"{",
"// Parse the field.",
"f",
",",
"err",
":=",
"p",
".",
"parseField",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Add new field.",
"fields",
"=",
"append",
"(",
"fields",
",",
"f",
")",
"\n\n",
"// If there's not a comma next then stop parsing fields.",
"if",
"tok",
",",
"_",
",",
"_",
":=",
"p",
".",
"Scan",
"(",
")",
";",
"tok",
"!=",
"COMMA",
"{",
"p",
".",
"Unscan",
"(",
")",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"fields",
",",
"nil",
"\n",
"}"
] | // parseFields parses a list of one or more fields. | [
"parseFields",
"parses",
"a",
"list",
"of",
"one",
"or",
"more",
"fields",
"."
] | 1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513 | https://github.com/influxdata/influxql/blob/1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513/parser.go#L2014-L2034 |
11,103 | influxdata/influxql | parser.go | parseField | func (p *Parser) parseField() (*Field, error) {
f := &Field{}
// Attempt to parse a regex.
re, err := p.parseRegex()
if err != nil {
return nil, err
} else if re != nil {
f.Expr = re
} else {
_, pos, _ := p.ScanIgnoreWhitespace()
p.Unscan()
// Parse the expression first.
expr, err := p.ParseExpr()
if err != nil {
return nil, err
}
var c validateField
Walk(&c, expr)
if c.foundInvalid {
return nil, fmt.Errorf("invalid operator %s in SELECT clause at line %d, char %d; operator is intended for WHERE clause", c.badToken, pos.Line+1, pos.Char+1)
}
f.Expr = expr
}
// Parse the alias if the current and next tokens are "WS AS".
alias, err := p.parseAlias()
if err != nil {
return nil, err
}
f.Alias = alias
// Consume all trailing whitespace.
p.consumeWhitespace()
return f, nil
} | go | func (p *Parser) parseField() (*Field, error) {
f := &Field{}
// Attempt to parse a regex.
re, err := p.parseRegex()
if err != nil {
return nil, err
} else if re != nil {
f.Expr = re
} else {
_, pos, _ := p.ScanIgnoreWhitespace()
p.Unscan()
// Parse the expression first.
expr, err := p.ParseExpr()
if err != nil {
return nil, err
}
var c validateField
Walk(&c, expr)
if c.foundInvalid {
return nil, fmt.Errorf("invalid operator %s in SELECT clause at line %d, char %d; operator is intended for WHERE clause", c.badToken, pos.Line+1, pos.Char+1)
}
f.Expr = expr
}
// Parse the alias if the current and next tokens are "WS AS".
alias, err := p.parseAlias()
if err != nil {
return nil, err
}
f.Alias = alias
// Consume all trailing whitespace.
p.consumeWhitespace()
return f, nil
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"parseField",
"(",
")",
"(",
"*",
"Field",
",",
"error",
")",
"{",
"f",
":=",
"&",
"Field",
"{",
"}",
"\n\n",
"// Attempt to parse a regex.",
"re",
",",
"err",
":=",
"p",
".",
"parseRegex",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"else",
"if",
"re",
"!=",
"nil",
"{",
"f",
".",
"Expr",
"=",
"re",
"\n",
"}",
"else",
"{",
"_",
",",
"pos",
",",
"_",
":=",
"p",
".",
"ScanIgnoreWhitespace",
"(",
")",
"\n",
"p",
".",
"Unscan",
"(",
")",
"\n",
"// Parse the expression first.",
"expr",
",",
"err",
":=",
"p",
".",
"ParseExpr",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"c",
"validateField",
"\n",
"Walk",
"(",
"&",
"c",
",",
"expr",
")",
"\n",
"if",
"c",
".",
"foundInvalid",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"c",
".",
"badToken",
",",
"pos",
".",
"Line",
"+",
"1",
",",
"pos",
".",
"Char",
"+",
"1",
")",
"\n",
"}",
"\n",
"f",
".",
"Expr",
"=",
"expr",
"\n",
"}",
"\n\n",
"// Parse the alias if the current and next tokens are \"WS AS\".",
"alias",
",",
"err",
":=",
"p",
".",
"parseAlias",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"f",
".",
"Alias",
"=",
"alias",
"\n\n",
"// Consume all trailing whitespace.",
"p",
".",
"consumeWhitespace",
"(",
")",
"\n\n",
"return",
"f",
",",
"nil",
"\n",
"}"
] | // parseField parses a single field. | [
"parseField",
"parses",
"a",
"single",
"field",
"."
] | 1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513 | https://github.com/influxdata/influxql/blob/1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513/parser.go#L2037-L2073 |
11,104 | influxdata/influxql | parser.go | parseAlias | func (p *Parser) parseAlias() (string, error) {
// Check if the next token is "AS". If not, then Unscan and exit.
if tok, _, _ := p.ScanIgnoreWhitespace(); tok != AS {
p.Unscan()
return "", nil
}
// Then we should have the alias identifier.
lit, err := p.ParseIdent()
if err != nil {
return "", err
}
return lit, nil
} | go | func (p *Parser) parseAlias() (string, error) {
// Check if the next token is "AS". If not, then Unscan and exit.
if tok, _, _ := p.ScanIgnoreWhitespace(); tok != AS {
p.Unscan()
return "", nil
}
// Then we should have the alias identifier.
lit, err := p.ParseIdent()
if err != nil {
return "", err
}
return lit, nil
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"parseAlias",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"// Check if the next token is \"AS\". If not, then Unscan and exit.",
"if",
"tok",
",",
"_",
",",
"_",
":=",
"p",
".",
"ScanIgnoreWhitespace",
"(",
")",
";",
"tok",
"!=",
"AS",
"{",
"p",
".",
"Unscan",
"(",
")",
"\n",
"return",
"\"",
"\"",
",",
"nil",
"\n",
"}",
"\n\n",
"// Then we should have the alias identifier.",
"lit",
",",
"err",
":=",
"p",
".",
"ParseIdent",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"lit",
",",
"nil",
"\n",
"}"
] | // parseAlias parses the "AS IDENT" alias for fields and dimensions. | [
"parseAlias",
"parses",
"the",
"AS",
"IDENT",
"alias",
"for",
"fields",
"and",
"dimensions",
"."
] | 1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513 | https://github.com/influxdata/influxql/blob/1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513/parser.go#L2100-L2113 |
11,105 | influxdata/influxql | parser.go | parseSources | func (p *Parser) parseSources(subqueries bool) (Sources, error) {
var sources Sources
for {
s, err := p.parseSource(subqueries)
if err != nil {
return nil, err
}
sources = append(sources, s)
if tok, _, _ := p.ScanIgnoreWhitespace(); tok != COMMA {
p.Unscan()
break
}
}
return sources, nil
} | go | func (p *Parser) parseSources(subqueries bool) (Sources, error) {
var sources Sources
for {
s, err := p.parseSource(subqueries)
if err != nil {
return nil, err
}
sources = append(sources, s)
if tok, _, _ := p.ScanIgnoreWhitespace(); tok != COMMA {
p.Unscan()
break
}
}
return sources, nil
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"parseSources",
"(",
"subqueries",
"bool",
")",
"(",
"Sources",
",",
"error",
")",
"{",
"var",
"sources",
"Sources",
"\n\n",
"for",
"{",
"s",
",",
"err",
":=",
"p",
".",
"parseSource",
"(",
"subqueries",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"sources",
"=",
"append",
"(",
"sources",
",",
"s",
")",
"\n\n",
"if",
"tok",
",",
"_",
",",
"_",
":=",
"p",
".",
"ScanIgnoreWhitespace",
"(",
")",
";",
"tok",
"!=",
"COMMA",
"{",
"p",
".",
"Unscan",
"(",
")",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"sources",
",",
"nil",
"\n",
"}"
] | // parseSources parses a comma delimited list of sources. | [
"parseSources",
"parses",
"a",
"comma",
"delimited",
"list",
"of",
"sources",
"."
] | 1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513 | https://github.com/influxdata/influxql/blob/1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513/parser.go#L2116-L2133 |
11,106 | influxdata/influxql | parser.go | peekRune | func (p *Parser) peekRune() rune {
r, _, _ := p.s.s.r.ReadRune()
if r != eof {
_ = p.s.s.r.UnreadRune()
}
return r
} | go | func (p *Parser) peekRune() rune {
r, _, _ := p.s.s.r.ReadRune()
if r != eof {
_ = p.s.s.r.UnreadRune()
}
return r
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"peekRune",
"(",
")",
"rune",
"{",
"r",
",",
"_",
",",
"_",
":=",
"p",
".",
"s",
".",
"s",
".",
"r",
".",
"ReadRune",
"(",
")",
"\n",
"if",
"r",
"!=",
"eof",
"{",
"_",
"=",
"p",
".",
"s",
".",
"s",
".",
"r",
".",
"UnreadRune",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"r",
"\n",
"}"
] | // peekRune returns the next rune that would be read by the scanner. | [
"peekRune",
"returns",
"the",
"next",
"rune",
"that",
"would",
"be",
"read",
"by",
"the",
"scanner",
"."
] | 1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513 | https://github.com/influxdata/influxql/blob/1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513/parser.go#L2136-L2143 |
11,107 | influxdata/influxql | parser.go | parseCondition | func (p *Parser) parseCondition() (Expr, error) {
// Check if the WHERE token exists.
if tok, _, _ := p.ScanIgnoreWhitespace(); tok != WHERE {
p.Unscan()
return nil, nil
}
// Scan the identifier for the source.
expr, err := p.ParseExpr()
if err != nil {
return nil, err
}
return expr, nil
} | go | func (p *Parser) parseCondition() (Expr, error) {
// Check if the WHERE token exists.
if tok, _, _ := p.ScanIgnoreWhitespace(); tok != WHERE {
p.Unscan()
return nil, nil
}
// Scan the identifier for the source.
expr, err := p.ParseExpr()
if err != nil {
return nil, err
}
return expr, nil
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"parseCondition",
"(",
")",
"(",
"Expr",
",",
"error",
")",
"{",
"// Check if the WHERE token exists.",
"if",
"tok",
",",
"_",
",",
"_",
":=",
"p",
".",
"ScanIgnoreWhitespace",
"(",
")",
";",
"tok",
"!=",
"WHERE",
"{",
"p",
".",
"Unscan",
"(",
")",
"\n",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"// Scan the identifier for the source.",
"expr",
",",
"err",
":=",
"p",
".",
"ParseExpr",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"expr",
",",
"nil",
"\n",
"}"
] | // parseCondition parses the "WHERE" clause of the query, if it exists. | [
"parseCondition",
"parses",
"the",
"WHERE",
"clause",
"of",
"the",
"query",
"if",
"it",
"exists",
"."
] | 1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513 | https://github.com/influxdata/influxql/blob/1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513/parser.go#L2219-L2233 |
11,108 | influxdata/influxql | parser.go | parseDimensions | func (p *Parser) parseDimensions() (Dimensions, error) {
// If the next token is not GROUP then exit.
if tok, _, _ := p.ScanIgnoreWhitespace(); tok != GROUP {
p.Unscan()
return nil, nil
}
// Now the next token should be "BY".
if tok, pos, lit := p.ScanIgnoreWhitespace(); tok != BY {
return nil, newParseError(tokstr(tok, lit), []string{"BY"}, pos)
}
var dimensions Dimensions
for {
// Parse the dimension.
d, err := p.parseDimension()
if err != nil {
return nil, err
}
// Add new dimension.
dimensions = append(dimensions, d)
// If there's not a comma next then stop parsing dimensions.
if tok, _, _ := p.Scan(); tok != COMMA {
p.Unscan()
break
}
}
return dimensions, nil
} | go | func (p *Parser) parseDimensions() (Dimensions, error) {
// If the next token is not GROUP then exit.
if tok, _, _ := p.ScanIgnoreWhitespace(); tok != GROUP {
p.Unscan()
return nil, nil
}
// Now the next token should be "BY".
if tok, pos, lit := p.ScanIgnoreWhitespace(); tok != BY {
return nil, newParseError(tokstr(tok, lit), []string{"BY"}, pos)
}
var dimensions Dimensions
for {
// Parse the dimension.
d, err := p.parseDimension()
if err != nil {
return nil, err
}
// Add new dimension.
dimensions = append(dimensions, d)
// If there's not a comma next then stop parsing dimensions.
if tok, _, _ := p.Scan(); tok != COMMA {
p.Unscan()
break
}
}
return dimensions, nil
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"parseDimensions",
"(",
")",
"(",
"Dimensions",
",",
"error",
")",
"{",
"// If the next token is not GROUP then exit.",
"if",
"tok",
",",
"_",
",",
"_",
":=",
"p",
".",
"ScanIgnoreWhitespace",
"(",
")",
";",
"tok",
"!=",
"GROUP",
"{",
"p",
".",
"Unscan",
"(",
")",
"\n",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"// Now the next token should be \"BY\".",
"if",
"tok",
",",
"pos",
",",
"lit",
":=",
"p",
".",
"ScanIgnoreWhitespace",
"(",
")",
";",
"tok",
"!=",
"BY",
"{",
"return",
"nil",
",",
"newParseError",
"(",
"tokstr",
"(",
"tok",
",",
"lit",
")",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"pos",
")",
"\n",
"}",
"\n\n",
"var",
"dimensions",
"Dimensions",
"\n",
"for",
"{",
"// Parse the dimension.",
"d",
",",
"err",
":=",
"p",
".",
"parseDimension",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Add new dimension.",
"dimensions",
"=",
"append",
"(",
"dimensions",
",",
"d",
")",
"\n\n",
"// If there's not a comma next then stop parsing dimensions.",
"if",
"tok",
",",
"_",
",",
"_",
":=",
"p",
".",
"Scan",
"(",
")",
";",
"tok",
"!=",
"COMMA",
"{",
"p",
".",
"Unscan",
"(",
")",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"dimensions",
",",
"nil",
"\n",
"}"
] | // parseDimensions parses the "GROUP BY" clause of the query, if it exists. | [
"parseDimensions",
"parses",
"the",
"GROUP",
"BY",
"clause",
"of",
"the",
"query",
"if",
"it",
"exists",
"."
] | 1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513 | https://github.com/influxdata/influxql/blob/1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513/parser.go#L2236-L2266 |
11,109 | influxdata/influxql | parser.go | parseDimension | func (p *Parser) parseDimension() (*Dimension, error) {
re, err := p.parseRegex()
if err != nil {
return nil, err
} else if re != nil {
return &Dimension{Expr: re}, nil
}
// Parse the expression first.
expr, err := p.ParseExpr()
if err != nil {
return nil, err
}
// Consume all trailing whitespace.
p.consumeWhitespace()
return &Dimension{Expr: expr}, nil
} | go | func (p *Parser) parseDimension() (*Dimension, error) {
re, err := p.parseRegex()
if err != nil {
return nil, err
} else if re != nil {
return &Dimension{Expr: re}, nil
}
// Parse the expression first.
expr, err := p.ParseExpr()
if err != nil {
return nil, err
}
// Consume all trailing whitespace.
p.consumeWhitespace()
return &Dimension{Expr: expr}, nil
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"parseDimension",
"(",
")",
"(",
"*",
"Dimension",
",",
"error",
")",
"{",
"re",
",",
"err",
":=",
"p",
".",
"parseRegex",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"else",
"if",
"re",
"!=",
"nil",
"{",
"return",
"&",
"Dimension",
"{",
"Expr",
":",
"re",
"}",
",",
"nil",
"\n",
"}",
"\n\n",
"// Parse the expression first.",
"expr",
",",
"err",
":=",
"p",
".",
"ParseExpr",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Consume all trailing whitespace.",
"p",
".",
"consumeWhitespace",
"(",
")",
"\n\n",
"return",
"&",
"Dimension",
"{",
"Expr",
":",
"expr",
"}",
",",
"nil",
"\n",
"}"
] | // parseDimension parses a single dimension. | [
"parseDimension",
"parses",
"a",
"single",
"dimension",
"."
] | 1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513 | https://github.com/influxdata/influxql/blob/1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513/parser.go#L2269-L2287 |
11,110 | influxdata/influxql | parser.go | parseFill | func (p *Parser) parseFill() (FillOption, interface{}, error) {
// Parse the expression first.
tok, _, lit := p.ScanIgnoreWhitespace()
p.Unscan()
if tok != IDENT || strings.ToLower(lit) != "fill" {
return NullFill, nil, nil
}
expr, err := p.ParseExpr()
if err != nil {
return NullFill, nil, err
}
fill, ok := expr.(*Call)
if !ok {
return NullFill, nil, errors.New("fill must be a function call")
} else if len(fill.Args) != 1 {
return NullFill, nil, errors.New("fill requires an argument, e.g.: 0, null, none, previous, linear")
}
switch fill.Args[0].String() {
case "null":
return NullFill, nil, nil
case "none":
return NoFill, nil, nil
case "previous":
return PreviousFill, nil, nil
case "linear":
return LinearFill, nil, nil
default:
switch num := fill.Args[0].(type) {
case *IntegerLiteral:
return NumberFill, num.Val, nil
case *NumberLiteral:
return NumberFill, num.Val, nil
default:
return NullFill, nil, fmt.Errorf("expected number argument in fill()")
}
}
} | go | func (p *Parser) parseFill() (FillOption, interface{}, error) {
// Parse the expression first.
tok, _, lit := p.ScanIgnoreWhitespace()
p.Unscan()
if tok != IDENT || strings.ToLower(lit) != "fill" {
return NullFill, nil, nil
}
expr, err := p.ParseExpr()
if err != nil {
return NullFill, nil, err
}
fill, ok := expr.(*Call)
if !ok {
return NullFill, nil, errors.New("fill must be a function call")
} else if len(fill.Args) != 1 {
return NullFill, nil, errors.New("fill requires an argument, e.g.: 0, null, none, previous, linear")
}
switch fill.Args[0].String() {
case "null":
return NullFill, nil, nil
case "none":
return NoFill, nil, nil
case "previous":
return PreviousFill, nil, nil
case "linear":
return LinearFill, nil, nil
default:
switch num := fill.Args[0].(type) {
case *IntegerLiteral:
return NumberFill, num.Val, nil
case *NumberLiteral:
return NumberFill, num.Val, nil
default:
return NullFill, nil, fmt.Errorf("expected number argument in fill()")
}
}
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"parseFill",
"(",
")",
"(",
"FillOption",
",",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"// Parse the expression first.",
"tok",
",",
"_",
",",
"lit",
":=",
"p",
".",
"ScanIgnoreWhitespace",
"(",
")",
"\n",
"p",
".",
"Unscan",
"(",
")",
"\n",
"if",
"tok",
"!=",
"IDENT",
"||",
"strings",
".",
"ToLower",
"(",
"lit",
")",
"!=",
"\"",
"\"",
"{",
"return",
"NullFill",
",",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"expr",
",",
"err",
":=",
"p",
".",
"ParseExpr",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"NullFill",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"fill",
",",
"ok",
":=",
"expr",
".",
"(",
"*",
"Call",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"NullFill",
",",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"len",
"(",
"fill",
".",
"Args",
")",
"!=",
"1",
"{",
"return",
"NullFill",
",",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"switch",
"fill",
".",
"Args",
"[",
"0",
"]",
".",
"String",
"(",
")",
"{",
"case",
"\"",
"\"",
":",
"return",
"NullFill",
",",
"nil",
",",
"nil",
"\n",
"case",
"\"",
"\"",
":",
"return",
"NoFill",
",",
"nil",
",",
"nil",
"\n",
"case",
"\"",
"\"",
":",
"return",
"PreviousFill",
",",
"nil",
",",
"nil",
"\n",
"case",
"\"",
"\"",
":",
"return",
"LinearFill",
",",
"nil",
",",
"nil",
"\n",
"default",
":",
"switch",
"num",
":=",
"fill",
".",
"Args",
"[",
"0",
"]",
".",
"(",
"type",
")",
"{",
"case",
"*",
"IntegerLiteral",
":",
"return",
"NumberFill",
",",
"num",
".",
"Val",
",",
"nil",
"\n",
"case",
"*",
"NumberLiteral",
":",
"return",
"NumberFill",
",",
"num",
".",
"Val",
",",
"nil",
"\n",
"default",
":",
"return",
"NullFill",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // parseFill parses the fill call and its options. | [
"parseFill",
"parses",
"the",
"fill",
"call",
"and",
"its",
"options",
"."
] | 1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513 | https://github.com/influxdata/influxql/blob/1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513/parser.go#L2290-L2327 |
11,111 | influxdata/influxql | parser.go | parseLocation | func (p *Parser) parseLocation() (*time.Location, error) {
// Parse the expression first.
tok, _, lit := p.ScanIgnoreWhitespace()
p.Unscan()
if tok != IDENT || strings.ToLower(lit) != "tz" {
return nil, nil
}
expr, err := p.ParseExpr()
if err != nil {
return nil, err
}
tz, ok := expr.(*Call)
if !ok {
return nil, errors.New("tz must be a function call")
} else if len(tz.Args) != 1 {
return nil, errors.New("tz requires exactly one argument")
}
tzname, ok := tz.Args[0].(*StringLiteral)
if !ok {
return nil, errors.New("expected string argument in tz()")
}
loc, err := time.LoadLocation(tzname.Val)
if err != nil {
// Do not pass the same error message as the error may contain sensitive pathnames.
return nil, fmt.Errorf("unable to find time zone %s", tzname.Val)
}
return loc, nil
} | go | func (p *Parser) parseLocation() (*time.Location, error) {
// Parse the expression first.
tok, _, lit := p.ScanIgnoreWhitespace()
p.Unscan()
if tok != IDENT || strings.ToLower(lit) != "tz" {
return nil, nil
}
expr, err := p.ParseExpr()
if err != nil {
return nil, err
}
tz, ok := expr.(*Call)
if !ok {
return nil, errors.New("tz must be a function call")
} else if len(tz.Args) != 1 {
return nil, errors.New("tz requires exactly one argument")
}
tzname, ok := tz.Args[0].(*StringLiteral)
if !ok {
return nil, errors.New("expected string argument in tz()")
}
loc, err := time.LoadLocation(tzname.Val)
if err != nil {
// Do not pass the same error message as the error may contain sensitive pathnames.
return nil, fmt.Errorf("unable to find time zone %s", tzname.Val)
}
return loc, nil
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"parseLocation",
"(",
")",
"(",
"*",
"time",
".",
"Location",
",",
"error",
")",
"{",
"// Parse the expression first.",
"tok",
",",
"_",
",",
"lit",
":=",
"p",
".",
"ScanIgnoreWhitespace",
"(",
")",
"\n",
"p",
".",
"Unscan",
"(",
")",
"\n",
"if",
"tok",
"!=",
"IDENT",
"||",
"strings",
".",
"ToLower",
"(",
"lit",
")",
"!=",
"\"",
"\"",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"expr",
",",
"err",
":=",
"p",
".",
"ParseExpr",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"tz",
",",
"ok",
":=",
"expr",
".",
"(",
"*",
"Call",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"len",
"(",
"tz",
".",
"Args",
")",
"!=",
"1",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"tzname",
",",
"ok",
":=",
"tz",
".",
"Args",
"[",
"0",
"]",
".",
"(",
"*",
"StringLiteral",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"loc",
",",
"err",
":=",
"time",
".",
"LoadLocation",
"(",
"tzname",
".",
"Val",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// Do not pass the same error message as the error may contain sensitive pathnames.",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tzname",
".",
"Val",
")",
"\n",
"}",
"\n",
"return",
"loc",
",",
"nil",
"\n",
"}"
] | // parseLocation parses the timezone call and its arguments. | [
"parseLocation",
"parses",
"the",
"timezone",
"call",
"and",
"its",
"arguments",
"."
] | 1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513 | https://github.com/influxdata/influxql/blob/1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513/parser.go#L2330-L2360 |
11,112 | influxdata/influxql | parser.go | ParseOptionalTokenAndInt | func (p *Parser) ParseOptionalTokenAndInt(t Token) (int, error) {
// Check if the token exists.
if tok, _, _ := p.ScanIgnoreWhitespace(); tok != t {
p.Unscan()
return 0, nil
}
// Scan the number.
tok, pos, lit := p.ScanIgnoreWhitespace()
if tok != INTEGER {
return 0, newParseError(tokstr(tok, lit), []string{"integer"}, pos)
}
// Parse number.
n, _ := strconv.ParseInt(lit, 10, 64)
if n < 0 {
msg := fmt.Sprintf("%s must be >= 0", t.String())
return 0, &ParseError{Message: msg, Pos: pos}
}
return int(n), nil
} | go | func (p *Parser) ParseOptionalTokenAndInt(t Token) (int, error) {
// Check if the token exists.
if tok, _, _ := p.ScanIgnoreWhitespace(); tok != t {
p.Unscan()
return 0, nil
}
// Scan the number.
tok, pos, lit := p.ScanIgnoreWhitespace()
if tok != INTEGER {
return 0, newParseError(tokstr(tok, lit), []string{"integer"}, pos)
}
// Parse number.
n, _ := strconv.ParseInt(lit, 10, 64)
if n < 0 {
msg := fmt.Sprintf("%s must be >= 0", t.String())
return 0, &ParseError{Message: msg, Pos: pos}
}
return int(n), nil
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"ParseOptionalTokenAndInt",
"(",
"t",
"Token",
")",
"(",
"int",
",",
"error",
")",
"{",
"// Check if the token exists.",
"if",
"tok",
",",
"_",
",",
"_",
":=",
"p",
".",
"ScanIgnoreWhitespace",
"(",
")",
";",
"tok",
"!=",
"t",
"{",
"p",
".",
"Unscan",
"(",
")",
"\n",
"return",
"0",
",",
"nil",
"\n",
"}",
"\n\n",
"// Scan the number.",
"tok",
",",
"pos",
",",
"lit",
":=",
"p",
".",
"ScanIgnoreWhitespace",
"(",
")",
"\n",
"if",
"tok",
"!=",
"INTEGER",
"{",
"return",
"0",
",",
"newParseError",
"(",
"tokstr",
"(",
"tok",
",",
"lit",
")",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"pos",
")",
"\n",
"}",
"\n\n",
"// Parse number.",
"n",
",",
"_",
":=",
"strconv",
".",
"ParseInt",
"(",
"lit",
",",
"10",
",",
"64",
")",
"\n",
"if",
"n",
"<",
"0",
"{",
"msg",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
".",
"String",
"(",
")",
")",
"\n",
"return",
"0",
",",
"&",
"ParseError",
"{",
"Message",
":",
"msg",
",",
"Pos",
":",
"pos",
"}",
"\n",
"}",
"\n\n",
"return",
"int",
"(",
"n",
")",
",",
"nil",
"\n",
"}"
] | // ParseOptionalTokenAndInt parses the specified token followed
// by an int, if it exists. | [
"ParseOptionalTokenAndInt",
"parses",
"the",
"specified",
"token",
"followed",
"by",
"an",
"int",
"if",
"it",
"exists",
"."
] | 1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513 | https://github.com/influxdata/influxql/blob/1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513/parser.go#L2364-L2385 |
11,113 | influxdata/influxql | parser.go | parseOrderBy | func (p *Parser) parseOrderBy() (SortFields, error) {
// Return nil result and nil error if no ORDER token at this position.
if tok, _, _ := p.ScanIgnoreWhitespace(); tok != ORDER {
p.Unscan()
return nil, nil
}
// Parse the required BY token.
if tok, pos, lit := p.ScanIgnoreWhitespace(); tok != BY {
return nil, newParseError(tokstr(tok, lit), []string{"BY"}, pos)
}
// Parse the ORDER BY fields.
fields, err := p.parseSortFields()
if err != nil {
return nil, err
}
return fields, nil
} | go | func (p *Parser) parseOrderBy() (SortFields, error) {
// Return nil result and nil error if no ORDER token at this position.
if tok, _, _ := p.ScanIgnoreWhitespace(); tok != ORDER {
p.Unscan()
return nil, nil
}
// Parse the required BY token.
if tok, pos, lit := p.ScanIgnoreWhitespace(); tok != BY {
return nil, newParseError(tokstr(tok, lit), []string{"BY"}, pos)
}
// Parse the ORDER BY fields.
fields, err := p.parseSortFields()
if err != nil {
return nil, err
}
return fields, nil
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"parseOrderBy",
"(",
")",
"(",
"SortFields",
",",
"error",
")",
"{",
"// Return nil result and nil error if no ORDER token at this position.",
"if",
"tok",
",",
"_",
",",
"_",
":=",
"p",
".",
"ScanIgnoreWhitespace",
"(",
")",
";",
"tok",
"!=",
"ORDER",
"{",
"p",
".",
"Unscan",
"(",
")",
"\n",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"// Parse the required BY token.",
"if",
"tok",
",",
"pos",
",",
"lit",
":=",
"p",
".",
"ScanIgnoreWhitespace",
"(",
")",
";",
"tok",
"!=",
"BY",
"{",
"return",
"nil",
",",
"newParseError",
"(",
"tokstr",
"(",
"tok",
",",
"lit",
")",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"pos",
")",
"\n",
"}",
"\n\n",
"// Parse the ORDER BY fields.",
"fields",
",",
"err",
":=",
"p",
".",
"parseSortFields",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"fields",
",",
"nil",
"\n",
"}"
] | // parseOrderBy parses the "ORDER BY" clause of a query, if it exists. | [
"parseOrderBy",
"parses",
"the",
"ORDER",
"BY",
"clause",
"of",
"a",
"query",
"if",
"it",
"exists",
"."
] | 1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513 | https://github.com/influxdata/influxql/blob/1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513/parser.go#L2388-L2407 |
11,114 | influxdata/influxql | parser.go | parseSortFields | func (p *Parser) parseSortFields() (SortFields, error) {
var fields SortFields
tok, pos, lit := p.ScanIgnoreWhitespace()
switch tok {
// The first field after an order by may not have a field name (e.g. ORDER BY ASC)
case ASC, DESC:
fields = append(fields, &SortField{Ascending: (tok == ASC)})
// If it's a token, parse it as a sort field. At least one is required.
case IDENT:
p.Unscan()
field, err := p.parseSortField()
if err != nil {
return nil, err
}
if lit != "time" {
return nil, errors.New("only ORDER BY time supported at this time")
}
fields = append(fields, field)
// Parse error...
default:
return nil, newParseError(tokstr(tok, lit), []string{"identifier", "ASC", "DESC"}, pos)
}
// Parse additional fields.
for {
tok, _, _ := p.ScanIgnoreWhitespace()
if tok != COMMA {
p.Unscan()
break
}
field, err := p.parseSortField()
if err != nil {
return nil, err
}
fields = append(fields, field)
}
if len(fields) > 1 {
return nil, errors.New("only ORDER BY time supported at this time")
}
return fields, nil
} | go | func (p *Parser) parseSortFields() (SortFields, error) {
var fields SortFields
tok, pos, lit := p.ScanIgnoreWhitespace()
switch tok {
// The first field after an order by may not have a field name (e.g. ORDER BY ASC)
case ASC, DESC:
fields = append(fields, &SortField{Ascending: (tok == ASC)})
// If it's a token, parse it as a sort field. At least one is required.
case IDENT:
p.Unscan()
field, err := p.parseSortField()
if err != nil {
return nil, err
}
if lit != "time" {
return nil, errors.New("only ORDER BY time supported at this time")
}
fields = append(fields, field)
// Parse error...
default:
return nil, newParseError(tokstr(tok, lit), []string{"identifier", "ASC", "DESC"}, pos)
}
// Parse additional fields.
for {
tok, _, _ := p.ScanIgnoreWhitespace()
if tok != COMMA {
p.Unscan()
break
}
field, err := p.parseSortField()
if err != nil {
return nil, err
}
fields = append(fields, field)
}
if len(fields) > 1 {
return nil, errors.New("only ORDER BY time supported at this time")
}
return fields, nil
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"parseSortFields",
"(",
")",
"(",
"SortFields",
",",
"error",
")",
"{",
"var",
"fields",
"SortFields",
"\n\n",
"tok",
",",
"pos",
",",
"lit",
":=",
"p",
".",
"ScanIgnoreWhitespace",
"(",
")",
"\n\n",
"switch",
"tok",
"{",
"// The first field after an order by may not have a field name (e.g. ORDER BY ASC)",
"case",
"ASC",
",",
"DESC",
":",
"fields",
"=",
"append",
"(",
"fields",
",",
"&",
"SortField",
"{",
"Ascending",
":",
"(",
"tok",
"==",
"ASC",
")",
"}",
")",
"\n",
"// If it's a token, parse it as a sort field. At least one is required.",
"case",
"IDENT",
":",
"p",
".",
"Unscan",
"(",
")",
"\n",
"field",
",",
"err",
":=",
"p",
".",
"parseSortField",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"lit",
"!=",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"fields",
"=",
"append",
"(",
"fields",
",",
"field",
")",
"\n",
"// Parse error...",
"default",
":",
"return",
"nil",
",",
"newParseError",
"(",
"tokstr",
"(",
"tok",
",",
"lit",
")",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"pos",
")",
"\n",
"}",
"\n\n",
"// Parse additional fields.",
"for",
"{",
"tok",
",",
"_",
",",
"_",
":=",
"p",
".",
"ScanIgnoreWhitespace",
"(",
")",
"\n\n",
"if",
"tok",
"!=",
"COMMA",
"{",
"p",
".",
"Unscan",
"(",
")",
"\n",
"break",
"\n",
"}",
"\n\n",
"field",
",",
"err",
":=",
"p",
".",
"parseSortField",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"fields",
"=",
"append",
"(",
"fields",
",",
"field",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"fields",
")",
">",
"1",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"fields",
",",
"nil",
"\n",
"}"
] | // parseSortFields parses the sort fields for an ORDER BY clause. | [
"parseSortFields",
"parses",
"the",
"sort",
"fields",
"for",
"an",
"ORDER",
"BY",
"clause",
"."
] | 1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513 | https://github.com/influxdata/influxql/blob/1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513/parser.go#L2410-L2459 |
11,115 | influxdata/influxql | parser.go | parseSortField | func (p *Parser) parseSortField() (*SortField, error) {
field := &SortField{}
// Parse sort field name.
ident, err := p.ParseIdent()
if err != nil {
return nil, err
}
field.Name = ident
// Check for optional ASC or DESC clause. Default is ASC.
tok, _, _ := p.ScanIgnoreWhitespace()
if tok != ASC && tok != DESC {
p.Unscan()
tok = ASC
}
field.Ascending = (tok == ASC)
return field, nil
} | go | func (p *Parser) parseSortField() (*SortField, error) {
field := &SortField{}
// Parse sort field name.
ident, err := p.ParseIdent()
if err != nil {
return nil, err
}
field.Name = ident
// Check for optional ASC or DESC clause. Default is ASC.
tok, _, _ := p.ScanIgnoreWhitespace()
if tok != ASC && tok != DESC {
p.Unscan()
tok = ASC
}
field.Ascending = (tok == ASC)
return field, nil
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"parseSortField",
"(",
")",
"(",
"*",
"SortField",
",",
"error",
")",
"{",
"field",
":=",
"&",
"SortField",
"{",
"}",
"\n\n",
"// Parse sort field name.",
"ident",
",",
"err",
":=",
"p",
".",
"ParseIdent",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"field",
".",
"Name",
"=",
"ident",
"\n\n",
"// Check for optional ASC or DESC clause. Default is ASC.",
"tok",
",",
"_",
",",
"_",
":=",
"p",
".",
"ScanIgnoreWhitespace",
"(",
")",
"\n",
"if",
"tok",
"!=",
"ASC",
"&&",
"tok",
"!=",
"DESC",
"{",
"p",
".",
"Unscan",
"(",
")",
"\n",
"tok",
"=",
"ASC",
"\n",
"}",
"\n",
"field",
".",
"Ascending",
"=",
"(",
"tok",
"==",
"ASC",
")",
"\n\n",
"return",
"field",
",",
"nil",
"\n",
"}"
] | // parseSortField parses one field of an ORDER BY clause. | [
"parseSortField",
"parses",
"one",
"field",
"of",
"an",
"ORDER",
"BY",
"clause",
"."
] | 1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513 | https://github.com/influxdata/influxql/blob/1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513/parser.go#L2462-L2481 |
11,116 | influxdata/influxql | parser.go | ParseVarRef | func (p *Parser) ParseVarRef() (*VarRef, error) {
// Parse the segments of the variable ref.
segments, err := p.parseSegmentedIdents()
if err != nil {
return nil, err
}
var dtype DataType
if tok, _, _ := p.Scan(); tok == DOUBLECOLON {
tok, pos, lit := p.Scan()
switch tok {
case IDENT:
switch strings.ToLower(lit) {
case "float":
dtype = Float
case "integer":
dtype = Integer
case "unsigned":
dtype = Unsigned
case "string":
dtype = String
case "boolean":
dtype = Boolean
default:
return nil, newParseError(tokstr(tok, lit), []string{"float", "integer", "unsigned", "string", "boolean", "field", "tag"}, pos)
}
case FIELD:
dtype = AnyField
case TAG:
dtype = Tag
default:
return nil, newParseError(tokstr(tok, lit), []string{"float", "integer", "string", "boolean", "field", "tag"}, pos)
}
} else {
p.Unscan()
}
vr := &VarRef{Val: strings.Join(segments, "."), Type: dtype}
return vr, nil
} | go | func (p *Parser) ParseVarRef() (*VarRef, error) {
// Parse the segments of the variable ref.
segments, err := p.parseSegmentedIdents()
if err != nil {
return nil, err
}
var dtype DataType
if tok, _, _ := p.Scan(); tok == DOUBLECOLON {
tok, pos, lit := p.Scan()
switch tok {
case IDENT:
switch strings.ToLower(lit) {
case "float":
dtype = Float
case "integer":
dtype = Integer
case "unsigned":
dtype = Unsigned
case "string":
dtype = String
case "boolean":
dtype = Boolean
default:
return nil, newParseError(tokstr(tok, lit), []string{"float", "integer", "unsigned", "string", "boolean", "field", "tag"}, pos)
}
case FIELD:
dtype = AnyField
case TAG:
dtype = Tag
default:
return nil, newParseError(tokstr(tok, lit), []string{"float", "integer", "string", "boolean", "field", "tag"}, pos)
}
} else {
p.Unscan()
}
vr := &VarRef{Val: strings.Join(segments, "."), Type: dtype}
return vr, nil
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"ParseVarRef",
"(",
")",
"(",
"*",
"VarRef",
",",
"error",
")",
"{",
"// Parse the segments of the variable ref.",
"segments",
",",
"err",
":=",
"p",
".",
"parseSegmentedIdents",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"dtype",
"DataType",
"\n",
"if",
"tok",
",",
"_",
",",
"_",
":=",
"p",
".",
"Scan",
"(",
")",
";",
"tok",
"==",
"DOUBLECOLON",
"{",
"tok",
",",
"pos",
",",
"lit",
":=",
"p",
".",
"Scan",
"(",
")",
"\n",
"switch",
"tok",
"{",
"case",
"IDENT",
":",
"switch",
"strings",
".",
"ToLower",
"(",
"lit",
")",
"{",
"case",
"\"",
"\"",
":",
"dtype",
"=",
"Float",
"\n",
"case",
"\"",
"\"",
":",
"dtype",
"=",
"Integer",
"\n",
"case",
"\"",
"\"",
":",
"dtype",
"=",
"Unsigned",
"\n",
"case",
"\"",
"\"",
":",
"dtype",
"=",
"String",
"\n",
"case",
"\"",
"\"",
":",
"dtype",
"=",
"Boolean",
"\n",
"default",
":",
"return",
"nil",
",",
"newParseError",
"(",
"tokstr",
"(",
"tok",
",",
"lit",
")",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"pos",
")",
"\n",
"}",
"\n",
"case",
"FIELD",
":",
"dtype",
"=",
"AnyField",
"\n",
"case",
"TAG",
":",
"dtype",
"=",
"Tag",
"\n",
"default",
":",
"return",
"nil",
",",
"newParseError",
"(",
"tokstr",
"(",
"tok",
",",
"lit",
")",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"pos",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"p",
".",
"Unscan",
"(",
")",
"\n",
"}",
"\n\n",
"vr",
":=",
"&",
"VarRef",
"{",
"Val",
":",
"strings",
".",
"Join",
"(",
"segments",
",",
"\"",
"\"",
")",
",",
"Type",
":",
"dtype",
"}",
"\n\n",
"return",
"vr",
",",
"nil",
"\n",
"}"
] | // ParseVarRef parses a reference to a measurement or field. | [
"ParseVarRef",
"parses",
"a",
"reference",
"to",
"a",
"measurement",
"or",
"field",
"."
] | 1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513 | https://github.com/influxdata/influxql/blob/1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513/parser.go#L2484-L2524 |
11,117 | influxdata/influxql | parser.go | ParseExpr | func (p *Parser) ParseExpr() (Expr, error) {
var err error
// Dummy root node.
root := &BinaryExpr{}
// Parse a non-binary expression type to start.
// This variable will always be the root of the expression tree.
root.RHS, err = p.parseUnaryExpr()
if err != nil {
return nil, err
}
// Loop over operations and unary exprs and build a tree based on precendence.
for {
// If the next token is NOT an operator then return the expression.
op, _, _ := p.ScanIgnoreWhitespace()
if !op.isOperator() {
p.Unscan()
return root.RHS, nil
}
// Otherwise parse the next expression.
var rhs Expr
if IsRegexOp(op) {
// RHS of a regex operator must be a regular expression.
if rhs, err = p.parseRegex(); err != nil {
return nil, err
}
// parseRegex can return an empty type, but we need it to be present
if rhs.(*RegexLiteral) == nil {
tok, pos, lit := p.ScanIgnoreWhitespace()
return nil, newParseError(tokstr(tok, lit), []string{"regex"}, pos)
}
} else {
if rhs, err = p.parseUnaryExpr(); err != nil {
return nil, err
}
}
// Find the right spot in the tree to add the new expression by
// descending the RHS of the expression tree until we reach the last
// BinaryExpr or a BinaryExpr whose RHS has an operator with
// precedence >= the operator being added.
for node := root; ; {
r, ok := node.RHS.(*BinaryExpr)
if !ok || r.Op.Precedence() >= op.Precedence() {
// Add the new expression here and break.
node.RHS = &BinaryExpr{LHS: node.RHS, RHS: rhs, Op: op}
break
}
node = r
}
}
} | go | func (p *Parser) ParseExpr() (Expr, error) {
var err error
// Dummy root node.
root := &BinaryExpr{}
// Parse a non-binary expression type to start.
// This variable will always be the root of the expression tree.
root.RHS, err = p.parseUnaryExpr()
if err != nil {
return nil, err
}
// Loop over operations and unary exprs and build a tree based on precendence.
for {
// If the next token is NOT an operator then return the expression.
op, _, _ := p.ScanIgnoreWhitespace()
if !op.isOperator() {
p.Unscan()
return root.RHS, nil
}
// Otherwise parse the next expression.
var rhs Expr
if IsRegexOp(op) {
// RHS of a regex operator must be a regular expression.
if rhs, err = p.parseRegex(); err != nil {
return nil, err
}
// parseRegex can return an empty type, but we need it to be present
if rhs.(*RegexLiteral) == nil {
tok, pos, lit := p.ScanIgnoreWhitespace()
return nil, newParseError(tokstr(tok, lit), []string{"regex"}, pos)
}
} else {
if rhs, err = p.parseUnaryExpr(); err != nil {
return nil, err
}
}
// Find the right spot in the tree to add the new expression by
// descending the RHS of the expression tree until we reach the last
// BinaryExpr or a BinaryExpr whose RHS has an operator with
// precedence >= the operator being added.
for node := root; ; {
r, ok := node.RHS.(*BinaryExpr)
if !ok || r.Op.Precedence() >= op.Precedence() {
// Add the new expression here and break.
node.RHS = &BinaryExpr{LHS: node.RHS, RHS: rhs, Op: op}
break
}
node = r
}
}
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"ParseExpr",
"(",
")",
"(",
"Expr",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"// Dummy root node.",
"root",
":=",
"&",
"BinaryExpr",
"{",
"}",
"\n\n",
"// Parse a non-binary expression type to start.",
"// This variable will always be the root of the expression tree.",
"root",
".",
"RHS",
",",
"err",
"=",
"p",
".",
"parseUnaryExpr",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Loop over operations and unary exprs and build a tree based on precendence.",
"for",
"{",
"// If the next token is NOT an operator then return the expression.",
"op",
",",
"_",
",",
"_",
":=",
"p",
".",
"ScanIgnoreWhitespace",
"(",
")",
"\n",
"if",
"!",
"op",
".",
"isOperator",
"(",
")",
"{",
"p",
".",
"Unscan",
"(",
")",
"\n",
"return",
"root",
".",
"RHS",
",",
"nil",
"\n",
"}",
"\n\n",
"// Otherwise parse the next expression.",
"var",
"rhs",
"Expr",
"\n",
"if",
"IsRegexOp",
"(",
"op",
")",
"{",
"// RHS of a regex operator must be a regular expression.",
"if",
"rhs",
",",
"err",
"=",
"p",
".",
"parseRegex",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"// parseRegex can return an empty type, but we need it to be present",
"if",
"rhs",
".",
"(",
"*",
"RegexLiteral",
")",
"==",
"nil",
"{",
"tok",
",",
"pos",
",",
"lit",
":=",
"p",
".",
"ScanIgnoreWhitespace",
"(",
")",
"\n",
"return",
"nil",
",",
"newParseError",
"(",
"tokstr",
"(",
"tok",
",",
"lit",
")",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"pos",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"if",
"rhs",
",",
"err",
"=",
"p",
".",
"parseUnaryExpr",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Find the right spot in the tree to add the new expression by",
"// descending the RHS of the expression tree until we reach the last",
"// BinaryExpr or a BinaryExpr whose RHS has an operator with",
"// precedence >= the operator being added.",
"for",
"node",
":=",
"root",
";",
";",
"{",
"r",
",",
"ok",
":=",
"node",
".",
"RHS",
".",
"(",
"*",
"BinaryExpr",
")",
"\n",
"if",
"!",
"ok",
"||",
"r",
".",
"Op",
".",
"Precedence",
"(",
")",
">=",
"op",
".",
"Precedence",
"(",
")",
"{",
"// Add the new expression here and break.",
"node",
".",
"RHS",
"=",
"&",
"BinaryExpr",
"{",
"LHS",
":",
"node",
".",
"RHS",
",",
"RHS",
":",
"rhs",
",",
"Op",
":",
"op",
"}",
"\n",
"break",
"\n",
"}",
"\n",
"node",
"=",
"r",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // ParseExpr parses an expression. | [
"ParseExpr",
"parses",
"an",
"expression",
"."
] | 1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513 | https://github.com/influxdata/influxql/blob/1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513/parser.go#L2527-L2580 |
11,118 | influxdata/influxql | parser.go | parseRegex | func (p *Parser) parseRegex() (*RegexLiteral, error) {
nextRune := p.peekRune()
if isWhitespace(nextRune) {
p.consumeWhitespace()
}
// If the next character is not a '/', then return nils.
nextRune = p.peekRune()
if nextRune != '/' {
return nil, nil
}
tok, pos, lit := p.s.ScanRegex()
if tok == BADESCAPE {
msg := fmt.Sprintf("bad escape: %s", lit)
return nil, &ParseError{Message: msg, Pos: pos}
} else if tok == BADREGEX {
msg := fmt.Sprintf("bad regex: %s", lit)
return nil, &ParseError{Message: msg, Pos: pos}
} else if tok != REGEX {
return nil, newParseError(tokstr(tok, lit), []string{"regex"}, pos)
}
re, err := regexp.Compile(lit)
if err != nil {
return nil, &ParseError{Message: err.Error(), Pos: pos}
}
return &RegexLiteral{Val: re}, nil
} | go | func (p *Parser) parseRegex() (*RegexLiteral, error) {
nextRune := p.peekRune()
if isWhitespace(nextRune) {
p.consumeWhitespace()
}
// If the next character is not a '/', then return nils.
nextRune = p.peekRune()
if nextRune != '/' {
return nil, nil
}
tok, pos, lit := p.s.ScanRegex()
if tok == BADESCAPE {
msg := fmt.Sprintf("bad escape: %s", lit)
return nil, &ParseError{Message: msg, Pos: pos}
} else if tok == BADREGEX {
msg := fmt.Sprintf("bad regex: %s", lit)
return nil, &ParseError{Message: msg, Pos: pos}
} else if tok != REGEX {
return nil, newParseError(tokstr(tok, lit), []string{"regex"}, pos)
}
re, err := regexp.Compile(lit)
if err != nil {
return nil, &ParseError{Message: err.Error(), Pos: pos}
}
return &RegexLiteral{Val: re}, nil
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"parseRegex",
"(",
")",
"(",
"*",
"RegexLiteral",
",",
"error",
")",
"{",
"nextRune",
":=",
"p",
".",
"peekRune",
"(",
")",
"\n",
"if",
"isWhitespace",
"(",
"nextRune",
")",
"{",
"p",
".",
"consumeWhitespace",
"(",
")",
"\n",
"}",
"\n\n",
"// If the next character is not a '/', then return nils.",
"nextRune",
"=",
"p",
".",
"peekRune",
"(",
")",
"\n",
"if",
"nextRune",
"!=",
"'/'",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"tok",
",",
"pos",
",",
"lit",
":=",
"p",
".",
"s",
".",
"ScanRegex",
"(",
")",
"\n\n",
"if",
"tok",
"==",
"BADESCAPE",
"{",
"msg",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"lit",
")",
"\n",
"return",
"nil",
",",
"&",
"ParseError",
"{",
"Message",
":",
"msg",
",",
"Pos",
":",
"pos",
"}",
"\n",
"}",
"else",
"if",
"tok",
"==",
"BADREGEX",
"{",
"msg",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"lit",
")",
"\n",
"return",
"nil",
",",
"&",
"ParseError",
"{",
"Message",
":",
"msg",
",",
"Pos",
":",
"pos",
"}",
"\n",
"}",
"else",
"if",
"tok",
"!=",
"REGEX",
"{",
"return",
"nil",
",",
"newParseError",
"(",
"tokstr",
"(",
"tok",
",",
"lit",
")",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"pos",
")",
"\n",
"}",
"\n\n",
"re",
",",
"err",
":=",
"regexp",
".",
"Compile",
"(",
"lit",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"&",
"ParseError",
"{",
"Message",
":",
"err",
".",
"Error",
"(",
")",
",",
"Pos",
":",
"pos",
"}",
"\n",
"}",
"\n\n",
"return",
"&",
"RegexLiteral",
"{",
"Val",
":",
"re",
"}",
",",
"nil",
"\n",
"}"
] | // parseRegex parses a regular expression. | [
"parseRegex",
"parses",
"a",
"regular",
"expression",
"."
] | 1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513 | https://github.com/influxdata/influxql/blob/1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513/parser.go#L2754-L2784 |
11,119 | influxdata/influxql | parser.go | parseCall | func (p *Parser) parseCall(name string) (*Call, error) {
name = strings.ToLower(name)
// Parse first function argument if one exists.
var args []Expr
re, err := p.parseRegex()
if err != nil {
return nil, err
} else if re != nil {
args = append(args, re)
} else {
// If there's a right paren then just return immediately.
if tok, _, _ := p.Scan(); tok == RPAREN {
return &Call{Name: name}, nil
}
p.Unscan()
arg, err := p.ParseExpr()
if err != nil {
return nil, err
}
args = append(args, arg)
}
// Parse additional function arguments if there is a comma.
for {
// If there's not a comma, stop parsing arguments.
if tok, _, _ := p.ScanIgnoreWhitespace(); tok != COMMA {
p.Unscan()
break
}
re, err := p.parseRegex()
if err != nil {
return nil, err
} else if re != nil {
args = append(args, re)
continue
}
// Parse an expression argument.
arg, err := p.ParseExpr()
if err != nil {
return nil, err
}
args = append(args, arg)
}
// There should be a right parentheses at the end.
if tok, pos, lit := p.Scan(); tok != RPAREN {
return nil, newParseError(tokstr(tok, lit), []string{")"}, pos)
}
return &Call{Name: name, Args: args}, nil
} | go | func (p *Parser) parseCall(name string) (*Call, error) {
name = strings.ToLower(name)
// Parse first function argument if one exists.
var args []Expr
re, err := p.parseRegex()
if err != nil {
return nil, err
} else if re != nil {
args = append(args, re)
} else {
// If there's a right paren then just return immediately.
if tok, _, _ := p.Scan(); tok == RPAREN {
return &Call{Name: name}, nil
}
p.Unscan()
arg, err := p.ParseExpr()
if err != nil {
return nil, err
}
args = append(args, arg)
}
// Parse additional function arguments if there is a comma.
for {
// If there's not a comma, stop parsing arguments.
if tok, _, _ := p.ScanIgnoreWhitespace(); tok != COMMA {
p.Unscan()
break
}
re, err := p.parseRegex()
if err != nil {
return nil, err
} else if re != nil {
args = append(args, re)
continue
}
// Parse an expression argument.
arg, err := p.ParseExpr()
if err != nil {
return nil, err
}
args = append(args, arg)
}
// There should be a right parentheses at the end.
if tok, pos, lit := p.Scan(); tok != RPAREN {
return nil, newParseError(tokstr(tok, lit), []string{")"}, pos)
}
return &Call{Name: name, Args: args}, nil
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"parseCall",
"(",
"name",
"string",
")",
"(",
"*",
"Call",
",",
"error",
")",
"{",
"name",
"=",
"strings",
".",
"ToLower",
"(",
"name",
")",
"\n\n",
"// Parse first function argument if one exists.",
"var",
"args",
"[",
"]",
"Expr",
"\n",
"re",
",",
"err",
":=",
"p",
".",
"parseRegex",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"else",
"if",
"re",
"!=",
"nil",
"{",
"args",
"=",
"append",
"(",
"args",
",",
"re",
")",
"\n",
"}",
"else",
"{",
"// If there's a right paren then just return immediately.",
"if",
"tok",
",",
"_",
",",
"_",
":=",
"p",
".",
"Scan",
"(",
")",
";",
"tok",
"==",
"RPAREN",
"{",
"return",
"&",
"Call",
"{",
"Name",
":",
"name",
"}",
",",
"nil",
"\n",
"}",
"\n",
"p",
".",
"Unscan",
"(",
")",
"\n\n",
"arg",
",",
"err",
":=",
"p",
".",
"ParseExpr",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"args",
"=",
"append",
"(",
"args",
",",
"arg",
")",
"\n",
"}",
"\n\n",
"// Parse additional function arguments if there is a comma.",
"for",
"{",
"// If there's not a comma, stop parsing arguments.",
"if",
"tok",
",",
"_",
",",
"_",
":=",
"p",
".",
"ScanIgnoreWhitespace",
"(",
")",
";",
"tok",
"!=",
"COMMA",
"{",
"p",
".",
"Unscan",
"(",
")",
"\n",
"break",
"\n",
"}",
"\n\n",
"re",
",",
"err",
":=",
"p",
".",
"parseRegex",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"else",
"if",
"re",
"!=",
"nil",
"{",
"args",
"=",
"append",
"(",
"args",
",",
"re",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"// Parse an expression argument.",
"arg",
",",
"err",
":=",
"p",
".",
"ParseExpr",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"args",
"=",
"append",
"(",
"args",
",",
"arg",
")",
"\n",
"}",
"\n\n",
"// There should be a right parentheses at the end.",
"if",
"tok",
",",
"pos",
",",
"lit",
":=",
"p",
".",
"Scan",
"(",
")",
";",
"tok",
"!=",
"RPAREN",
"{",
"return",
"nil",
",",
"newParseError",
"(",
"tokstr",
"(",
"tok",
",",
"lit",
")",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"pos",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"Call",
"{",
"Name",
":",
"name",
",",
"Args",
":",
"args",
"}",
",",
"nil",
"\n",
"}"
] | // parseCall parses a function call.
// This function assumes the function name and LPAREN have been consumed. | [
"parseCall",
"parses",
"a",
"function",
"call",
".",
"This",
"function",
"assumes",
"the",
"function",
"name",
"and",
"LPAREN",
"have",
"been",
"consumed",
"."
] | 1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513 | https://github.com/influxdata/influxql/blob/1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513/parser.go#L2788-L2842 |
11,120 | influxdata/influxql | parser.go | ScanIgnoreWhitespace | func (p *Parser) ScanIgnoreWhitespace() (tok Token, pos Pos, lit string) {
for {
tok, pos, lit = p.Scan()
if tok == WS || tok == COMMENT {
continue
}
return
}
} | go | func (p *Parser) ScanIgnoreWhitespace() (tok Token, pos Pos, lit string) {
for {
tok, pos, lit = p.Scan()
if tok == WS || tok == COMMENT {
continue
}
return
}
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"ScanIgnoreWhitespace",
"(",
")",
"(",
"tok",
"Token",
",",
"pos",
"Pos",
",",
"lit",
"string",
")",
"{",
"for",
"{",
"tok",
",",
"pos",
",",
"lit",
"=",
"p",
".",
"Scan",
"(",
")",
"\n",
"if",
"tok",
"==",
"WS",
"||",
"tok",
"==",
"COMMENT",
"{",
"continue",
"\n",
"}",
"\n",
"return",
"\n",
"}",
"\n",
"}"
] | // ScanIgnoreWhitespace scans the next non-whitespace and non-comment token. | [
"ScanIgnoreWhitespace",
"scans",
"the",
"next",
"non",
"-",
"whitespace",
"and",
"non",
"-",
"comment",
"token",
"."
] | 1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513 | https://github.com/influxdata/influxql/blob/1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513/parser.go#L2893-L2901 |
11,121 | influxdata/influxql | parser.go | consumeWhitespace | func (p *Parser) consumeWhitespace() {
if tok, _, _ := p.Scan(); tok != WS {
p.Unscan()
}
} | go | func (p *Parser) consumeWhitespace() {
if tok, _, _ := p.Scan(); tok != WS {
p.Unscan()
}
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"consumeWhitespace",
"(",
")",
"{",
"if",
"tok",
",",
"_",
",",
"_",
":=",
"p",
".",
"Scan",
"(",
")",
";",
"tok",
"!=",
"WS",
"{",
"p",
".",
"Unscan",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // consumeWhitespace scans the next token if it's whitespace. | [
"consumeWhitespace",
"scans",
"the",
"next",
"token",
"if",
"it",
"s",
"whitespace",
"."
] | 1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513 | https://github.com/influxdata/influxql/blob/1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513/parser.go#L2904-L2908 |
11,122 | influxdata/influxql | parser.go | parseTokens | func (p *Parser) parseTokens(toks []Token) error {
for _, expected := range toks {
if tok, pos, lit := p.ScanIgnoreWhitespace(); tok != expected {
return newParseError(tokstr(tok, lit), []string{tokens[expected]}, pos)
}
}
return nil
} | go | func (p *Parser) parseTokens(toks []Token) error {
for _, expected := range toks {
if tok, pos, lit := p.ScanIgnoreWhitespace(); tok != expected {
return newParseError(tokstr(tok, lit), []string{tokens[expected]}, pos)
}
}
return nil
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"parseTokens",
"(",
"toks",
"[",
"]",
"Token",
")",
"error",
"{",
"for",
"_",
",",
"expected",
":=",
"range",
"toks",
"{",
"if",
"tok",
",",
"pos",
",",
"lit",
":=",
"p",
".",
"ScanIgnoreWhitespace",
"(",
")",
";",
"tok",
"!=",
"expected",
"{",
"return",
"newParseError",
"(",
"tokstr",
"(",
"tok",
",",
"lit",
")",
",",
"[",
"]",
"string",
"{",
"tokens",
"[",
"expected",
"]",
"}",
",",
"pos",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // parseTokens consumes an expected sequence of tokens. | [
"parseTokens",
"consumes",
"an",
"expected",
"sequence",
"of",
"tokens",
"."
] | 1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513 | https://github.com/influxdata/influxql/blob/1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513/parser.go#L3032-L3039 |
11,123 | influxdata/influxql | parser.go | QuoteIdent | func QuoteIdent(segments ...string) string {
var buf bytes.Buffer
for i, segment := range segments {
needQuote := IdentNeedsQuotes(segment) ||
((i < len(segments)-1) && segment != "") || // not last segment && not ""
((i == 0 || i == len(segments)-1) && segment == "") // the first or last segment and an empty string
if needQuote {
_ = buf.WriteByte('"')
}
_, _ = buf.WriteString(qiReplacer.Replace(segment))
if needQuote {
_ = buf.WriteByte('"')
}
if i < len(segments)-1 {
_ = buf.WriteByte('.')
}
}
return buf.String()
} | go | func QuoteIdent(segments ...string) string {
var buf bytes.Buffer
for i, segment := range segments {
needQuote := IdentNeedsQuotes(segment) ||
((i < len(segments)-1) && segment != "") || // not last segment && not ""
((i == 0 || i == len(segments)-1) && segment == "") // the first or last segment and an empty string
if needQuote {
_ = buf.WriteByte('"')
}
_, _ = buf.WriteString(qiReplacer.Replace(segment))
if needQuote {
_ = buf.WriteByte('"')
}
if i < len(segments)-1 {
_ = buf.WriteByte('.')
}
}
return buf.String()
} | [
"func",
"QuoteIdent",
"(",
"segments",
"...",
"string",
")",
"string",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"for",
"i",
",",
"segment",
":=",
"range",
"segments",
"{",
"needQuote",
":=",
"IdentNeedsQuotes",
"(",
"segment",
")",
"||",
"(",
"(",
"i",
"<",
"len",
"(",
"segments",
")",
"-",
"1",
")",
"&&",
"segment",
"!=",
"\"",
"\"",
")",
"||",
"// not last segment && not \"\"",
"(",
"(",
"i",
"==",
"0",
"||",
"i",
"==",
"len",
"(",
"segments",
")",
"-",
"1",
")",
"&&",
"segment",
"==",
"\"",
"\"",
")",
"// the first or last segment and an empty string",
"\n\n",
"if",
"needQuote",
"{",
"_",
"=",
"buf",
".",
"WriteByte",
"(",
"'\"'",
")",
"\n",
"}",
"\n\n",
"_",
",",
"_",
"=",
"buf",
".",
"WriteString",
"(",
"qiReplacer",
".",
"Replace",
"(",
"segment",
")",
")",
"\n\n",
"if",
"needQuote",
"{",
"_",
"=",
"buf",
".",
"WriteByte",
"(",
"'\"'",
")",
"\n",
"}",
"\n\n",
"if",
"i",
"<",
"len",
"(",
"segments",
")",
"-",
"1",
"{",
"_",
"=",
"buf",
".",
"WriteByte",
"(",
"'.'",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"buf",
".",
"String",
"(",
")",
"\n",
"}"
] | // QuoteIdent returns a quoted identifier from multiple bare identifiers. | [
"QuoteIdent",
"returns",
"a",
"quoted",
"identifier",
"from",
"multiple",
"bare",
"identifiers",
"."
] | 1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513 | https://github.com/influxdata/influxql/blob/1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513/parser.go#L3055-L3077 |
11,124 | influxdata/influxql | parser.go | IdentNeedsQuotes | func IdentNeedsQuotes(ident string) bool {
// check if this identifier is a keyword
tok := Lookup(ident)
if tok != IDENT {
return true
}
for i, r := range ident {
if i == 0 && !isIdentFirstChar(r) {
return true
} else if i > 0 && !isIdentChar(r) {
return true
}
}
return false
} | go | func IdentNeedsQuotes(ident string) bool {
// check if this identifier is a keyword
tok := Lookup(ident)
if tok != IDENT {
return true
}
for i, r := range ident {
if i == 0 && !isIdentFirstChar(r) {
return true
} else if i > 0 && !isIdentChar(r) {
return true
}
}
return false
} | [
"func",
"IdentNeedsQuotes",
"(",
"ident",
"string",
")",
"bool",
"{",
"// check if this identifier is a keyword",
"tok",
":=",
"Lookup",
"(",
"ident",
")",
"\n",
"if",
"tok",
"!=",
"IDENT",
"{",
"return",
"true",
"\n",
"}",
"\n",
"for",
"i",
",",
"r",
":=",
"range",
"ident",
"{",
"if",
"i",
"==",
"0",
"&&",
"!",
"isIdentFirstChar",
"(",
"r",
")",
"{",
"return",
"true",
"\n",
"}",
"else",
"if",
"i",
">",
"0",
"&&",
"!",
"isIdentChar",
"(",
"r",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // IdentNeedsQuotes returns true if the ident string given would require quotes. | [
"IdentNeedsQuotes",
"returns",
"true",
"if",
"the",
"ident",
"string",
"given",
"would",
"require",
"quotes",
"."
] | 1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513 | https://github.com/influxdata/influxql/blob/1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513/parser.go#L3080-L3094 |
11,125 | influxdata/influxql | parser.go | newParseError | func newParseError(found string, expected []string, pos Pos) *ParseError {
return &ParseError{Found: found, Expected: expected, Pos: pos}
} | go | func newParseError(found string, expected []string, pos Pos) *ParseError {
return &ParseError{Found: found, Expected: expected, Pos: pos}
} | [
"func",
"newParseError",
"(",
"found",
"string",
",",
"expected",
"[",
"]",
"string",
",",
"pos",
"Pos",
")",
"*",
"ParseError",
"{",
"return",
"&",
"ParseError",
"{",
"Found",
":",
"found",
",",
"Expected",
":",
"expected",
",",
"Pos",
":",
"pos",
"}",
"\n",
"}"
] | // newParseError returns a new instance of ParseError. | [
"newParseError",
"returns",
"a",
"new",
"instance",
"of",
"ParseError",
"."
] | 1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513 | https://github.com/influxdata/influxql/blob/1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513/parser.go#L3117-L3119 |
11,126 | influxdata/influxql | parser.go | Error | func (e *ParseError) Error() string {
if e.Message != "" {
return fmt.Sprintf("%s at line %d, char %d", e.Message, e.Pos.Line+1, e.Pos.Char+1)
}
return fmt.Sprintf("found %s, expected %s at line %d, char %d", e.Found, strings.Join(e.Expected, ", "), e.Pos.Line+1, e.Pos.Char+1)
} | go | func (e *ParseError) Error() string {
if e.Message != "" {
return fmt.Sprintf("%s at line %d, char %d", e.Message, e.Pos.Line+1, e.Pos.Char+1)
}
return fmt.Sprintf("found %s, expected %s at line %d, char %d", e.Found, strings.Join(e.Expected, ", "), e.Pos.Line+1, e.Pos.Char+1)
} | [
"func",
"(",
"e",
"*",
"ParseError",
")",
"Error",
"(",
")",
"string",
"{",
"if",
"e",
".",
"Message",
"!=",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"e",
".",
"Message",
",",
"e",
".",
"Pos",
".",
"Line",
"+",
"1",
",",
"e",
".",
"Pos",
".",
"Char",
"+",
"1",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"e",
".",
"Found",
",",
"strings",
".",
"Join",
"(",
"e",
".",
"Expected",
",",
"\"",
"\"",
")",
",",
"e",
".",
"Pos",
".",
"Line",
"+",
"1",
",",
"e",
".",
"Pos",
".",
"Char",
"+",
"1",
")",
"\n",
"}"
] | // Error returns the string representation of the error. | [
"Error",
"returns",
"the",
"string",
"representation",
"of",
"the",
"error",
"."
] | 1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513 | https://github.com/influxdata/influxql/blob/1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513/parser.go#L3122-L3127 |
11,127 | influxdata/influxql | token.go | tokstr | func tokstr(tok Token, lit string) string {
if lit != "" {
return lit
}
return tok.String()
} | go | func tokstr(tok Token, lit string) string {
if lit != "" {
return lit
}
return tok.String()
} | [
"func",
"tokstr",
"(",
"tok",
"Token",
",",
"lit",
"string",
")",
"string",
"{",
"if",
"lit",
"!=",
"\"",
"\"",
"{",
"return",
"lit",
"\n",
"}",
"\n",
"return",
"tok",
".",
"String",
"(",
")",
"\n",
"}"
] | // tokstr returns a literal if provided, otherwise returns the token string. | [
"tokstr",
"returns",
"a",
"literal",
"if",
"provided",
"otherwise",
"returns",
"the",
"token",
"string",
"."
] | 1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513 | https://github.com/influxdata/influxql/blob/1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513/token.go#L312-L317 |
11,128 | influxdata/influxql | token.go | Lookup | func Lookup(ident string) Token {
if tok, ok := keywords[strings.ToLower(ident)]; ok {
return tok
}
return IDENT
} | go | func Lookup(ident string) Token {
if tok, ok := keywords[strings.ToLower(ident)]; ok {
return tok
}
return IDENT
} | [
"func",
"Lookup",
"(",
"ident",
"string",
")",
"Token",
"{",
"if",
"tok",
",",
"ok",
":=",
"keywords",
"[",
"strings",
".",
"ToLower",
"(",
"ident",
")",
"]",
";",
"ok",
"{",
"return",
"tok",
"\n",
"}",
"\n",
"return",
"IDENT",
"\n",
"}"
] | // Lookup returns the token associated with a given string. | [
"Lookup",
"returns",
"the",
"token",
"associated",
"with",
"a",
"given",
"string",
"."
] | 1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513 | https://github.com/influxdata/influxql/blob/1cbfca8e56b6eaa120f5b5161e4f0d5edcc9e513/token.go#L320-L325 |
11,129 | GuiaBolso/darwin | driver.go | NewGenericDriver | func NewGenericDriver(db *sql.DB, dialect Dialect) *GenericDriver {
if db == nil {
panic("darwin: sql.DB is nil")
}
if dialect == nil {
panic("darwin: dialect is nil")
}
return &GenericDriver{DB: db, Dialect: dialect}
} | go | func NewGenericDriver(db *sql.DB, dialect Dialect) *GenericDriver {
if db == nil {
panic("darwin: sql.DB is nil")
}
if dialect == nil {
panic("darwin: dialect is nil")
}
return &GenericDriver{DB: db, Dialect: dialect}
} | [
"func",
"NewGenericDriver",
"(",
"db",
"*",
"sql",
".",
"DB",
",",
"dialect",
"Dialect",
")",
"*",
"GenericDriver",
"{",
"if",
"db",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"dialect",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"GenericDriver",
"{",
"DB",
":",
"db",
",",
"Dialect",
":",
"dialect",
"}",
"\n",
"}"
] | // NewGenericDriver creates a new GenericDriver configured with db and dialect.
// Panic if db or dialect is nil | [
"NewGenericDriver",
"creates",
"a",
"new",
"GenericDriver",
"configured",
"with",
"db",
"and",
"dialect",
".",
"Panic",
"if",
"db",
"or",
"dialect",
"is",
"nil"
] | 86919dfcf80873d58ea2e527c15b1e02a5636ead | https://github.com/GuiaBolso/darwin/blob/86919dfcf80873d58ea2e527c15b1e02a5636ead/driver.go#L34-L44 |
11,130 | GuiaBolso/darwin | driver.go | Create | func (m *GenericDriver) Create() error {
err := transaction(m.DB, func(tx *sql.Tx) error {
_, err := tx.Exec(m.Dialect.CreateTableSQL())
return err
})
return err
} | go | func (m *GenericDriver) Create() error {
err := transaction(m.DB, func(tx *sql.Tx) error {
_, err := tx.Exec(m.Dialect.CreateTableSQL())
return err
})
return err
} | [
"func",
"(",
"m",
"*",
"GenericDriver",
")",
"Create",
"(",
")",
"error",
"{",
"err",
":=",
"transaction",
"(",
"m",
".",
"DB",
",",
"func",
"(",
"tx",
"*",
"sql",
".",
"Tx",
")",
"error",
"{",
"_",
",",
"err",
":=",
"tx",
".",
"Exec",
"(",
"m",
".",
"Dialect",
".",
"CreateTableSQL",
"(",
")",
")",
"\n",
"return",
"err",
"\n",
"}",
")",
"\n\n",
"return",
"err",
"\n",
"}"
] | // Create create the table darwin_migrations if necessary | [
"Create",
"create",
"the",
"table",
"darwin_migrations",
"if",
"necessary"
] | 86919dfcf80873d58ea2e527c15b1e02a5636ead | https://github.com/GuiaBolso/darwin/blob/86919dfcf80873d58ea2e527c15b1e02a5636ead/driver.go#L47-L54 |
11,131 | GuiaBolso/darwin | driver.go | Insert | func (m *GenericDriver) Insert(e MigrationRecord) error {
err := transaction(m.DB, func(tx *sql.Tx) error {
_, err := tx.Exec(m.Dialect.InsertSQL(),
e.Version,
e.Description,
e.Checksum,
e.AppliedAt.Unix(),
e.ExecutionTime,
)
return err
})
return err
} | go | func (m *GenericDriver) Insert(e MigrationRecord) error {
err := transaction(m.DB, func(tx *sql.Tx) error {
_, err := tx.Exec(m.Dialect.InsertSQL(),
e.Version,
e.Description,
e.Checksum,
e.AppliedAt.Unix(),
e.ExecutionTime,
)
return err
})
return err
} | [
"func",
"(",
"m",
"*",
"GenericDriver",
")",
"Insert",
"(",
"e",
"MigrationRecord",
")",
"error",
"{",
"err",
":=",
"transaction",
"(",
"m",
".",
"DB",
",",
"func",
"(",
"tx",
"*",
"sql",
".",
"Tx",
")",
"error",
"{",
"_",
",",
"err",
":=",
"tx",
".",
"Exec",
"(",
"m",
".",
"Dialect",
".",
"InsertSQL",
"(",
")",
",",
"e",
".",
"Version",
",",
"e",
".",
"Description",
",",
"e",
".",
"Checksum",
",",
"e",
".",
"AppliedAt",
".",
"Unix",
"(",
")",
",",
"e",
".",
"ExecutionTime",
",",
")",
"\n",
"return",
"err",
"\n",
"}",
")",
"\n\n",
"return",
"err",
"\n",
"}"
] | // Insert insert a migration entry into database | [
"Insert",
"insert",
"a",
"migration",
"entry",
"into",
"database"
] | 86919dfcf80873d58ea2e527c15b1e02a5636ead | https://github.com/GuiaBolso/darwin/blob/86919dfcf80873d58ea2e527c15b1e02a5636ead/driver.go#L57-L71 |
11,132 | GuiaBolso/darwin | driver.go | All | func (m *GenericDriver) All() ([]MigrationRecord, error) {
entries := []MigrationRecord{}
rows, err := m.DB.Query(m.Dialect.AllSQL())
if err != nil {
return []MigrationRecord{}, err
}
for rows.Next() {
var (
version float64
description string
checksum string
appliedAt int64
executionTime float64
)
rows.Scan(
&version,
&description,
&checksum,
&appliedAt,
&executionTime,
)
entry := MigrationRecord{
Version: version,
Description: description,
Checksum: checksum,
AppliedAt: time.Unix(appliedAt, 0),
ExecutionTime: time.Duration(executionTime),
}
entries = append(entries, entry)
}
rows.Close()
return entries, nil
} | go | func (m *GenericDriver) All() ([]MigrationRecord, error) {
entries := []MigrationRecord{}
rows, err := m.DB.Query(m.Dialect.AllSQL())
if err != nil {
return []MigrationRecord{}, err
}
for rows.Next() {
var (
version float64
description string
checksum string
appliedAt int64
executionTime float64
)
rows.Scan(
&version,
&description,
&checksum,
&appliedAt,
&executionTime,
)
entry := MigrationRecord{
Version: version,
Description: description,
Checksum: checksum,
AppliedAt: time.Unix(appliedAt, 0),
ExecutionTime: time.Duration(executionTime),
}
entries = append(entries, entry)
}
rows.Close()
return entries, nil
} | [
"func",
"(",
"m",
"*",
"GenericDriver",
")",
"All",
"(",
")",
"(",
"[",
"]",
"MigrationRecord",
",",
"error",
")",
"{",
"entries",
":=",
"[",
"]",
"MigrationRecord",
"{",
"}",
"\n\n",
"rows",
",",
"err",
":=",
"m",
".",
"DB",
".",
"Query",
"(",
"m",
".",
"Dialect",
".",
"AllSQL",
"(",
")",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"[",
"]",
"MigrationRecord",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"for",
"rows",
".",
"Next",
"(",
")",
"{",
"var",
"(",
"version",
"float64",
"\n",
"description",
"string",
"\n",
"checksum",
"string",
"\n",
"appliedAt",
"int64",
"\n",
"executionTime",
"float64",
"\n",
")",
"\n\n",
"rows",
".",
"Scan",
"(",
"&",
"version",
",",
"&",
"description",
",",
"&",
"checksum",
",",
"&",
"appliedAt",
",",
"&",
"executionTime",
",",
")",
"\n\n",
"entry",
":=",
"MigrationRecord",
"{",
"Version",
":",
"version",
",",
"Description",
":",
"description",
",",
"Checksum",
":",
"checksum",
",",
"AppliedAt",
":",
"time",
".",
"Unix",
"(",
"appliedAt",
",",
"0",
")",
",",
"ExecutionTime",
":",
"time",
".",
"Duration",
"(",
"executionTime",
")",
",",
"}",
"\n\n",
"entries",
"=",
"append",
"(",
"entries",
",",
"entry",
")",
"\n",
"}",
"\n\n",
"rows",
".",
"Close",
"(",
")",
"\n\n",
"return",
"entries",
",",
"nil",
"\n",
"}"
] | // All returns all migrations applied | [
"All",
"returns",
"all",
"migrations",
"applied"
] | 86919dfcf80873d58ea2e527c15b1e02a5636ead | https://github.com/GuiaBolso/darwin/blob/86919dfcf80873d58ea2e527c15b1e02a5636ead/driver.go#L74-L114 |
11,133 | GuiaBolso/darwin | driver.go | Exec | func (m *GenericDriver) Exec(script string) (time.Duration, error) {
start := time.Now()
err := transaction(m.DB, func(tx *sql.Tx) error {
_, err := tx.Exec(script)
return err
})
return time.Since(start), err
} | go | func (m *GenericDriver) Exec(script string) (time.Duration, error) {
start := time.Now()
err := transaction(m.DB, func(tx *sql.Tx) error {
_, err := tx.Exec(script)
return err
})
return time.Since(start), err
} | [
"func",
"(",
"m",
"*",
"GenericDriver",
")",
"Exec",
"(",
"script",
"string",
")",
"(",
"time",
".",
"Duration",
",",
"error",
")",
"{",
"start",
":=",
"time",
".",
"Now",
"(",
")",
"\n\n",
"err",
":=",
"transaction",
"(",
"m",
".",
"DB",
",",
"func",
"(",
"tx",
"*",
"sql",
".",
"Tx",
")",
"error",
"{",
"_",
",",
"err",
":=",
"tx",
".",
"Exec",
"(",
"script",
")",
"\n",
"return",
"err",
"\n",
"}",
")",
"\n\n",
"return",
"time",
".",
"Since",
"(",
"start",
")",
",",
"err",
"\n",
"}"
] | // Exec execute sql scripts into database | [
"Exec",
"execute",
"sql",
"scripts",
"into",
"database"
] | 86919dfcf80873d58ea2e527c15b1e02a5636ead | https://github.com/GuiaBolso/darwin/blob/86919dfcf80873d58ea2e527c15b1e02a5636ead/driver.go#L117-L126 |
11,134 | GuiaBolso/darwin | darwin.go | Checksum | func (m Migration) Checksum() string {
return fmt.Sprintf("%x", md5.Sum([]byte(m.Script)))
} | go | func (m Migration) Checksum() string {
return fmt.Sprintf("%x", md5.Sum([]byte(m.Script)))
} | [
"func",
"(",
"m",
"Migration",
")",
"Checksum",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"md5",
".",
"Sum",
"(",
"[",
"]",
"byte",
"(",
"m",
".",
"Script",
")",
")",
")",
"\n",
"}"
] | // Checksum calculate the Script md5 | [
"Checksum",
"calculate",
"the",
"Script",
"md5"
] | 86919dfcf80873d58ea2e527c15b1e02a5636ead | https://github.com/GuiaBolso/darwin/blob/86919dfcf80873d58ea2e527c15b1e02a5636ead/darwin.go#L51-L53 |
11,135 | GuiaBolso/darwin | darwin.go | Migrate | func (d Darwin) Migrate() error {
return Migrate(d.driver, d.migrations, d.infoChan)
} | go | func (d Darwin) Migrate() error {
return Migrate(d.driver, d.migrations, d.infoChan)
} | [
"func",
"(",
"d",
"Darwin",
")",
"Migrate",
"(",
")",
"error",
"{",
"return",
"Migrate",
"(",
"d",
".",
"driver",
",",
"d",
".",
"migrations",
",",
"d",
".",
"infoChan",
")",
"\n",
"}"
] | // Migrate executes the missing migrations in database | [
"Migrate",
"executes",
"the",
"missing",
"migrations",
"in",
"database"
] | 86919dfcf80873d58ea2e527c15b1e02a5636ead | https://github.com/GuiaBolso/darwin/blob/86919dfcf80873d58ea2e527c15b1e02a5636ead/darwin.go#L76-L78 |
11,136 | GuiaBolso/darwin | darwin.go | New | func New(driver Driver, migrations []Migration, infoChan chan MigrationInfo) Darwin {
return Darwin{
driver: driver,
migrations: migrations,
infoChan: infoChan,
}
} | go | func New(driver Driver, migrations []Migration, infoChan chan MigrationInfo) Darwin {
return Darwin{
driver: driver,
migrations: migrations,
infoChan: infoChan,
}
} | [
"func",
"New",
"(",
"driver",
"Driver",
",",
"migrations",
"[",
"]",
"Migration",
",",
"infoChan",
"chan",
"MigrationInfo",
")",
"Darwin",
"{",
"return",
"Darwin",
"{",
"driver",
":",
"driver",
",",
"migrations",
":",
"migrations",
",",
"infoChan",
":",
"infoChan",
",",
"}",
"\n",
"}"
] | // New returns a new Darwin struct | [
"New",
"returns",
"a",
"new",
"Darwin",
"struct"
] | 86919dfcf80873d58ea2e527c15b1e02a5636ead | https://github.com/GuiaBolso/darwin/blob/86919dfcf80873d58ea2e527c15b1e02a5636ead/darwin.go#L86-L92 |
11,137 | GuiaBolso/darwin | darwin.go | Validate | func Validate(d Driver, migrations []Migration) error {
sort.Sort(byMigrationVersion(migrations))
if version, invalid := isInvalidVersion(migrations); invalid {
return IllegalMigrationVersionError{Version: version}
}
if version, dup := isDuplicated(migrations); dup {
return DuplicateMigrationVersionError{Version: version}
}
applied, err := d.All()
if err != nil {
return err
}
if version, removed := wasRemovedMigration(applied, migrations); removed {
return RemovedMigrationError{Version: version}
}
if version, invalid := isInvalidChecksumMigration(applied, migrations); invalid {
return InvalidChecksumError{Version: version}
}
return nil
} | go | func Validate(d Driver, migrations []Migration) error {
sort.Sort(byMigrationVersion(migrations))
if version, invalid := isInvalidVersion(migrations); invalid {
return IllegalMigrationVersionError{Version: version}
}
if version, dup := isDuplicated(migrations); dup {
return DuplicateMigrationVersionError{Version: version}
}
applied, err := d.All()
if err != nil {
return err
}
if version, removed := wasRemovedMigration(applied, migrations); removed {
return RemovedMigrationError{Version: version}
}
if version, invalid := isInvalidChecksumMigration(applied, migrations); invalid {
return InvalidChecksumError{Version: version}
}
return nil
} | [
"func",
"Validate",
"(",
"d",
"Driver",
",",
"migrations",
"[",
"]",
"Migration",
")",
"error",
"{",
"sort",
".",
"Sort",
"(",
"byMigrationVersion",
"(",
"migrations",
")",
")",
"\n\n",
"if",
"version",
",",
"invalid",
":=",
"isInvalidVersion",
"(",
"migrations",
")",
";",
"invalid",
"{",
"return",
"IllegalMigrationVersionError",
"{",
"Version",
":",
"version",
"}",
"\n",
"}",
"\n\n",
"if",
"version",
",",
"dup",
":=",
"isDuplicated",
"(",
"migrations",
")",
";",
"dup",
"{",
"return",
"DuplicateMigrationVersionError",
"{",
"Version",
":",
"version",
"}",
"\n",
"}",
"\n\n",
"applied",
",",
"err",
":=",
"d",
".",
"All",
"(",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"version",
",",
"removed",
":=",
"wasRemovedMigration",
"(",
"applied",
",",
"migrations",
")",
";",
"removed",
"{",
"return",
"RemovedMigrationError",
"{",
"Version",
":",
"version",
"}",
"\n",
"}",
"\n\n",
"if",
"version",
",",
"invalid",
":=",
"isInvalidChecksumMigration",
"(",
"applied",
",",
"migrations",
")",
";",
"invalid",
"{",
"return",
"InvalidChecksumError",
"{",
"Version",
":",
"version",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Validate if the database migrations are applied and consistent | [
"Validate",
"if",
"the",
"database",
"migrations",
"are",
"applied",
"and",
"consistent"
] | 86919dfcf80873d58ea2e527c15b1e02a5636ead | https://github.com/GuiaBolso/darwin/blob/86919dfcf80873d58ea2e527c15b1e02a5636ead/darwin.go#L131-L157 |
11,138 | GuiaBolso/darwin | darwin.go | Migrate | func Migrate(d Driver, migrations []Migration, infoChan chan MigrationInfo) error {
mutex.Lock()
defer mutex.Unlock()
err := d.Create()
if err != nil {
return err
}
err = Validate(d, migrations)
if err != nil {
return err
}
planned, err := planMigration(d, migrations)
if err != nil {
return err
}
for _, migration := range planned {
dur, err := d.Exec(migration.Script)
if err != nil {
notify(err, migration, infoChan)
return err
}
err = d.Insert(MigrationRecord{
Version: migration.Version,
Description: migration.Description,
Checksum: migration.Checksum(),
AppliedAt: time.Now(),
ExecutionTime: dur,
})
notify(err, migration, infoChan)
if err != nil {
return err
}
}
return nil
} | go | func Migrate(d Driver, migrations []Migration, infoChan chan MigrationInfo) error {
mutex.Lock()
defer mutex.Unlock()
err := d.Create()
if err != nil {
return err
}
err = Validate(d, migrations)
if err != nil {
return err
}
planned, err := planMigration(d, migrations)
if err != nil {
return err
}
for _, migration := range planned {
dur, err := d.Exec(migration.Script)
if err != nil {
notify(err, migration, infoChan)
return err
}
err = d.Insert(MigrationRecord{
Version: migration.Version,
Description: migration.Description,
Checksum: migration.Checksum(),
AppliedAt: time.Now(),
ExecutionTime: dur,
})
notify(err, migration, infoChan)
if err != nil {
return err
}
}
return nil
} | [
"func",
"Migrate",
"(",
"d",
"Driver",
",",
"migrations",
"[",
"]",
"Migration",
",",
"infoChan",
"chan",
"MigrationInfo",
")",
"error",
"{",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"err",
":=",
"d",
".",
"Create",
"(",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"Validate",
"(",
"d",
",",
"migrations",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"planned",
",",
"err",
":=",
"planMigration",
"(",
"d",
",",
"migrations",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"migration",
":=",
"range",
"planned",
"{",
"dur",
",",
"err",
":=",
"d",
".",
"Exec",
"(",
"migration",
".",
"Script",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"notify",
"(",
"err",
",",
"migration",
",",
"infoChan",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"d",
".",
"Insert",
"(",
"MigrationRecord",
"{",
"Version",
":",
"migration",
".",
"Version",
",",
"Description",
":",
"migration",
".",
"Description",
",",
"Checksum",
":",
"migration",
".",
"Checksum",
"(",
")",
",",
"AppliedAt",
":",
"time",
".",
"Now",
"(",
")",
",",
"ExecutionTime",
":",
"dur",
",",
"}",
")",
"\n\n",
"notify",
"(",
"err",
",",
"migration",
",",
"infoChan",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Migrate executes the missing migrations in database. | [
"Migrate",
"executes",
"the",
"missing",
"migrations",
"in",
"database",
"."
] | 86919dfcf80873d58ea2e527c15b1e02a5636ead | https://github.com/GuiaBolso/darwin/blob/86919dfcf80873d58ea2e527c15b1e02a5636ead/darwin.go#L206-L253 |
11,139 | paulmach/go.geo | path.go | NewPathPreallocate | func NewPathPreallocate(length, capacity int) *Path {
return &Path{PointSet(*NewPointSetPreallocate(length, capacity))}
} | go | func NewPathPreallocate(length, capacity int) *Path {
return &Path{PointSet(*NewPointSetPreallocate(length, capacity))}
} | [
"func",
"NewPathPreallocate",
"(",
"length",
",",
"capacity",
"int",
")",
"*",
"Path",
"{",
"return",
"&",
"Path",
"{",
"PointSet",
"(",
"*",
"NewPointSetPreallocate",
"(",
"length",
",",
"capacity",
")",
")",
"}",
"\n",
"}"
] | // NewPathPreallocate creates a new path with points array of the given size. | [
"NewPathPreallocate",
"creates",
"a",
"new",
"path",
"with",
"points",
"array",
"of",
"the",
"given",
"size",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/path.go#L23-L25 |
11,140 | paulmach/go.geo | path.go | NewPathFromFlatXYData | func NewPathFromFlatXYData(data []float64) *Path {
if len(data)%2 != 0 {
panic("Flat path requires an even number of coordinates")
}
p := NewPathPreallocate(0, len(data)/2)
for i := 0; i < len(data)/2; i++ {
p.PointSet = append(p.PointSet, Point{data[2*i], data[2*i+1]})
}
return p
} | go | func NewPathFromFlatXYData(data []float64) *Path {
if len(data)%2 != 0 {
panic("Flat path requires an even number of coordinates")
}
p := NewPathPreallocate(0, len(data)/2)
for i := 0; i < len(data)/2; i++ {
p.PointSet = append(p.PointSet, Point{data[2*i], data[2*i+1]})
}
return p
} | [
"func",
"NewPathFromFlatXYData",
"(",
"data",
"[",
"]",
"float64",
")",
"*",
"Path",
"{",
"if",
"len",
"(",
"data",
")",
"%",
"2",
"!=",
"0",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"p",
":=",
"NewPathPreallocate",
"(",
"0",
",",
"len",
"(",
"data",
")",
"/",
"2",
")",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"data",
")",
"/",
"2",
";",
"i",
"++",
"{",
"p",
".",
"PointSet",
"=",
"append",
"(",
"p",
".",
"PointSet",
",",
"Point",
"{",
"data",
"[",
"2",
"*",
"i",
"]",
",",
"data",
"[",
"2",
"*",
"i",
"+",
"1",
"]",
"}",
")",
"\n",
"}",
"\n\n",
"return",
"p",
"\n",
"}"
] | // NewPathFromFlatXYData creates a path from a slice of float64 values
// representing horizontal, vertical type data.
// Coordinates in even positions correspond to X values. Coordinates in odd positions correspond to Y values | [
"NewPathFromFlatXYData",
"creates",
"a",
"path",
"from",
"a",
"slice",
"of",
"float64",
"values",
"representing",
"horizontal",
"vertical",
"type",
"data",
".",
"Coordinates",
"in",
"even",
"positions",
"correspond",
"to",
"X",
"values",
".",
"Coordinates",
"in",
"odd",
"positions",
"correspond",
"to",
"Y",
"values"
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/path.go#L92-L103 |
11,141 | paulmach/go.geo | path.go | Transform | func (p *Path) Transform(projector Projector) *Path {
for i := range p.PointSet {
projector(&p.PointSet[i])
}
return p
} | go | func (p *Path) Transform(projector Projector) *Path {
for i := range p.PointSet {
projector(&p.PointSet[i])
}
return p
} | [
"func",
"(",
"p",
"*",
"Path",
")",
"Transform",
"(",
"projector",
"Projector",
")",
"*",
"Path",
"{",
"for",
"i",
":=",
"range",
"p",
".",
"PointSet",
"{",
"projector",
"(",
"&",
"p",
".",
"PointSet",
"[",
"i",
"]",
")",
"\n",
"}",
"\n\n",
"return",
"p",
"\n",
"}"
] | // Transform applies a given projection or inverse projection to all
// the points in the path. | [
"Transform",
"applies",
"a",
"given",
"projection",
"or",
"inverse",
"projection",
"to",
"all",
"the",
"points",
"in",
"the",
"path",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/path.go#L162-L168 |
11,142 | paulmach/go.geo | path.go | Encode | func (p *Path) Encode(factor ...int) string {
f := 1.0e5
if len(factor) != 0 {
f = float64(factor[0])
}
var pLat int
var pLng int
var result bytes.Buffer
scratch1 := make([]byte, 0, 50)
scratch2 := make([]byte, 0, 50)
for _, p := range p.PointSet {
lat5 := int(math.Floor(p.Lat()*f + 0.5))
lng5 := int(math.Floor(p.Lng()*f + 0.5))
deltaLat := lat5 - pLat
deltaLng := lng5 - pLng
pLat = lat5
pLng = lng5
result.Write(append(encodeSignedNumber(deltaLat, scratch1), encodeSignedNumber(deltaLng, scratch2)...))
scratch1 = scratch1[:0]
scratch2 = scratch2[:0]
}
return result.String()
} | go | func (p *Path) Encode(factor ...int) string {
f := 1.0e5
if len(factor) != 0 {
f = float64(factor[0])
}
var pLat int
var pLng int
var result bytes.Buffer
scratch1 := make([]byte, 0, 50)
scratch2 := make([]byte, 0, 50)
for _, p := range p.PointSet {
lat5 := int(math.Floor(p.Lat()*f + 0.5))
lng5 := int(math.Floor(p.Lng()*f + 0.5))
deltaLat := lat5 - pLat
deltaLng := lng5 - pLng
pLat = lat5
pLng = lng5
result.Write(append(encodeSignedNumber(deltaLat, scratch1), encodeSignedNumber(deltaLng, scratch2)...))
scratch1 = scratch1[:0]
scratch2 = scratch2[:0]
}
return result.String()
} | [
"func",
"(",
"p",
"*",
"Path",
")",
"Encode",
"(",
"factor",
"...",
"int",
")",
"string",
"{",
"f",
":=",
"1.0e5",
"\n",
"if",
"len",
"(",
"factor",
")",
"!=",
"0",
"{",
"f",
"=",
"float64",
"(",
"factor",
"[",
"0",
"]",
")",
"\n",
"}",
"\n\n",
"var",
"pLat",
"int",
"\n",
"var",
"pLng",
"int",
"\n\n",
"var",
"result",
"bytes",
".",
"Buffer",
"\n",
"scratch1",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
",",
"50",
")",
"\n",
"scratch2",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
",",
"50",
")",
"\n\n",
"for",
"_",
",",
"p",
":=",
"range",
"p",
".",
"PointSet",
"{",
"lat5",
":=",
"int",
"(",
"math",
".",
"Floor",
"(",
"p",
".",
"Lat",
"(",
")",
"*",
"f",
"+",
"0.5",
")",
")",
"\n",
"lng5",
":=",
"int",
"(",
"math",
".",
"Floor",
"(",
"p",
".",
"Lng",
"(",
")",
"*",
"f",
"+",
"0.5",
")",
")",
"\n\n",
"deltaLat",
":=",
"lat5",
"-",
"pLat",
"\n",
"deltaLng",
":=",
"lng5",
"-",
"pLng",
"\n\n",
"pLat",
"=",
"lat5",
"\n",
"pLng",
"=",
"lng5",
"\n\n",
"result",
".",
"Write",
"(",
"append",
"(",
"encodeSignedNumber",
"(",
"deltaLat",
",",
"scratch1",
")",
",",
"encodeSignedNumber",
"(",
"deltaLng",
",",
"scratch2",
")",
"...",
")",
")",
"\n\n",
"scratch1",
"=",
"scratch1",
"[",
":",
"0",
"]",
"\n",
"scratch2",
"=",
"scratch2",
"[",
":",
"0",
"]",
"\n",
"}",
"\n\n",
"return",
"result",
".",
"String",
"(",
")",
"\n",
"}"
] | // Encode converts the path to a string using the Google Maps Polyline Encoding method.
// Factor defaults to 1.0e5, the same used by Google for polyline encoding. | [
"Encode",
"converts",
"the",
"path",
"to",
"a",
"string",
"using",
"the",
"Google",
"Maps",
"Polyline",
"Encoding",
"method",
".",
"Factor",
"defaults",
"to",
"1",
".",
"0e5",
"the",
"same",
"used",
"by",
"Google",
"for",
"polyline",
"encoding",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/path.go#L177-L207 |
11,143 | paulmach/go.geo | path.go | Distance | func (p *Path) Distance() float64 {
sum := 0.0
loopTo := len(p.PointSet) - 1
for i := 0; i < loopTo; i++ {
sum += p.PointSet[i].DistanceFrom(&p.PointSet[i+1])
}
return sum
} | go | func (p *Path) Distance() float64 {
sum := 0.0
loopTo := len(p.PointSet) - 1
for i := 0; i < loopTo; i++ {
sum += p.PointSet[i].DistanceFrom(&p.PointSet[i+1])
}
return sum
} | [
"func",
"(",
"p",
"*",
"Path",
")",
"Distance",
"(",
")",
"float64",
"{",
"sum",
":=",
"0.0",
"\n\n",
"loopTo",
":=",
"len",
"(",
"p",
".",
"PointSet",
")",
"-",
"1",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"loopTo",
";",
"i",
"++",
"{",
"sum",
"+=",
"p",
".",
"PointSet",
"[",
"i",
"]",
".",
"DistanceFrom",
"(",
"&",
"p",
".",
"PointSet",
"[",
"i",
"+",
"1",
"]",
")",
"\n",
"}",
"\n\n",
"return",
"sum",
"\n",
"}"
] | // Distance computes the total distance in the units of the points. | [
"Distance",
"computes",
"the",
"total",
"distance",
"in",
"the",
"units",
"of",
"the",
"points",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/path.go#L225-L234 |
11,144 | paulmach/go.geo | path.go | GeoDistance | func (p *Path) GeoDistance(haversine ...bool) float64 {
yesgeo := yesHaversine(haversine)
sum := 0.0
loopTo := len(p.PointSet) - 1
for i := 0; i < loopTo; i++ {
sum += p.PointSet[i].GeoDistanceFrom(&p.PointSet[i+1], yesgeo)
}
return sum
} | go | func (p *Path) GeoDistance(haversine ...bool) float64 {
yesgeo := yesHaversine(haversine)
sum := 0.0
loopTo := len(p.PointSet) - 1
for i := 0; i < loopTo; i++ {
sum += p.PointSet[i].GeoDistanceFrom(&p.PointSet[i+1], yesgeo)
}
return sum
} | [
"func",
"(",
"p",
"*",
"Path",
")",
"GeoDistance",
"(",
"haversine",
"...",
"bool",
")",
"float64",
"{",
"yesgeo",
":=",
"yesHaversine",
"(",
"haversine",
")",
"\n",
"sum",
":=",
"0.0",
"\n\n",
"loopTo",
":=",
"len",
"(",
"p",
".",
"PointSet",
")",
"-",
"1",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"loopTo",
";",
"i",
"++",
"{",
"sum",
"+=",
"p",
".",
"PointSet",
"[",
"i",
"]",
".",
"GeoDistanceFrom",
"(",
"&",
"p",
".",
"PointSet",
"[",
"i",
"+",
"1",
"]",
",",
"yesgeo",
")",
"\n",
"}",
"\n\n",
"return",
"sum",
"\n",
"}"
] | // GeoDistance computes the total distance using spherical geometry. | [
"GeoDistance",
"computes",
"the",
"total",
"distance",
"using",
"spherical",
"geometry",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/path.go#L237-L247 |
11,145 | paulmach/go.geo | path.go | Measure | func (p *Path) Measure(point *Point) float64 {
minDistance := math.Inf(1)
measure := math.Inf(-1)
sum := 0.0
seg := &Line{}
for i := 0; i < len(p.PointSet)-1; i++ {
seg.a = p.PointSet[i]
seg.b = p.PointSet[i+1]
distanceToLine := seg.SquaredDistanceFrom(point)
if distanceToLine < minDistance {
minDistance = distanceToLine
measure = sum + seg.Measure(point)
}
sum += seg.Distance()
}
return measure
} | go | func (p *Path) Measure(point *Point) float64 {
minDistance := math.Inf(1)
measure := math.Inf(-1)
sum := 0.0
seg := &Line{}
for i := 0; i < len(p.PointSet)-1; i++ {
seg.a = p.PointSet[i]
seg.b = p.PointSet[i+1]
distanceToLine := seg.SquaredDistanceFrom(point)
if distanceToLine < minDistance {
minDistance = distanceToLine
measure = sum + seg.Measure(point)
}
sum += seg.Distance()
}
return measure
} | [
"func",
"(",
"p",
"*",
"Path",
")",
"Measure",
"(",
"point",
"*",
"Point",
")",
"float64",
"{",
"minDistance",
":=",
"math",
".",
"Inf",
"(",
"1",
")",
"\n",
"measure",
":=",
"math",
".",
"Inf",
"(",
"-",
"1",
")",
"\n",
"sum",
":=",
"0.0",
"\n\n",
"seg",
":=",
"&",
"Line",
"{",
"}",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"p",
".",
"PointSet",
")",
"-",
"1",
";",
"i",
"++",
"{",
"seg",
".",
"a",
"=",
"p",
".",
"PointSet",
"[",
"i",
"]",
"\n",
"seg",
".",
"b",
"=",
"p",
".",
"PointSet",
"[",
"i",
"+",
"1",
"]",
"\n",
"distanceToLine",
":=",
"seg",
".",
"SquaredDistanceFrom",
"(",
"point",
")",
"\n",
"if",
"distanceToLine",
"<",
"minDistance",
"{",
"minDistance",
"=",
"distanceToLine",
"\n",
"measure",
"=",
"sum",
"+",
"seg",
".",
"Measure",
"(",
"point",
")",
"\n",
"}",
"\n",
"sum",
"+=",
"seg",
".",
"Distance",
"(",
")",
"\n",
"}",
"\n",
"return",
"measure",
"\n",
"}"
] | // Measure computes the distance along this path to the point nearest the given point. | [
"Measure",
"computes",
"the",
"distance",
"along",
"this",
"path",
"to",
"the",
"point",
"nearest",
"the",
"given",
"point",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/path.go#L300-L317 |
11,146 | paulmach/go.geo | path.go | Interpolate | func (p *Path) Interpolate(percent float64) *Point {
if percent <= 0 {
return p.First()
} else if percent >= 1 {
return p.Last()
}
destination := p.Distance() * percent
travelled := 0.0
for i := 0; i < len(p.PointSet)-1; i++ {
seg := NewLine(&p.PointSet[i], &p.PointSet[i+1])
segDistance := seg.Distance()
if (travelled + segDistance) > destination {
var remainder = destination - travelled
return seg.Interpolate(remainder / segDistance)
}
travelled += segDistance
}
return p.First()
} | go | func (p *Path) Interpolate(percent float64) *Point {
if percent <= 0 {
return p.First()
} else if percent >= 1 {
return p.Last()
}
destination := p.Distance() * percent
travelled := 0.0
for i := 0; i < len(p.PointSet)-1; i++ {
seg := NewLine(&p.PointSet[i], &p.PointSet[i+1])
segDistance := seg.Distance()
if (travelled + segDistance) > destination {
var remainder = destination - travelled
return seg.Interpolate(remainder / segDistance)
}
travelled += segDistance
}
return p.First()
} | [
"func",
"(",
"p",
"*",
"Path",
")",
"Interpolate",
"(",
"percent",
"float64",
")",
"*",
"Point",
"{",
"if",
"percent",
"<=",
"0",
"{",
"return",
"p",
".",
"First",
"(",
")",
"\n",
"}",
"else",
"if",
"percent",
">=",
"1",
"{",
"return",
"p",
".",
"Last",
"(",
")",
"\n",
"}",
"\n\n",
"destination",
":=",
"p",
".",
"Distance",
"(",
")",
"*",
"percent",
"\n",
"travelled",
":=",
"0.0",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"p",
".",
"PointSet",
")",
"-",
"1",
";",
"i",
"++",
"{",
"seg",
":=",
"NewLine",
"(",
"&",
"p",
".",
"PointSet",
"[",
"i",
"]",
",",
"&",
"p",
".",
"PointSet",
"[",
"i",
"+",
"1",
"]",
")",
"\n",
"segDistance",
":=",
"seg",
".",
"Distance",
"(",
")",
"\n",
"if",
"(",
"travelled",
"+",
"segDistance",
")",
">",
"destination",
"{",
"var",
"remainder",
"=",
"destination",
"-",
"travelled",
"\n",
"return",
"seg",
".",
"Interpolate",
"(",
"remainder",
"/",
"segDistance",
")",
"\n",
"}",
"\n",
"travelled",
"+=",
"segDistance",
"\n",
"}",
"\n\n",
"return",
"p",
".",
"First",
"(",
")",
"\n",
"}"
] | // Interpolate performs a linear interpolation along the path | [
"Interpolate",
"performs",
"a",
"linear",
"interpolation",
"along",
"the",
"path"
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/path.go#L320-L342 |
11,147 | paulmach/go.geo | path.go | Project | func (p *Path) Project(point *Point) float64 {
return p.Measure(point) / p.Distance()
} | go | func (p *Path) Project(point *Point) float64 {
return p.Measure(point) / p.Distance()
} | [
"func",
"(",
"p",
"*",
"Path",
")",
"Project",
"(",
"point",
"*",
"Point",
")",
"float64",
"{",
"return",
"p",
".",
"Measure",
"(",
"point",
")",
"/",
"p",
".",
"Distance",
"(",
")",
"\n",
"}"
] | // Project computes the measure along this path closest to the given point,
// normalized to the length of the path. | [
"Project",
"computes",
"the",
"measure",
"along",
"this",
"path",
"closest",
"to",
"the",
"given",
"point",
"normalized",
"to",
"the",
"length",
"of",
"the",
"path",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/path.go#L346-L348 |
11,148 | paulmach/go.geo | path.go | IntersectsPath | func (p *Path) IntersectsPath(path *Path) bool {
// TODO: done some sort of line sweep here if p.Length() is big enough
for i := 0; i < len(p.PointSet)-1; i++ {
pLine := NewLine(&p.PointSet[i], &p.PointSet[i+1])
for j := 0; j < len(path.PointSet)-1; j++ {
pathLine := NewLine(&path.PointSet[j], &path.PointSet[j+1])
if pLine.Intersects(pathLine) {
return true
}
}
}
return false
} | go | func (p *Path) IntersectsPath(path *Path) bool {
// TODO: done some sort of line sweep here if p.Length() is big enough
for i := 0; i < len(p.PointSet)-1; i++ {
pLine := NewLine(&p.PointSet[i], &p.PointSet[i+1])
for j := 0; j < len(path.PointSet)-1; j++ {
pathLine := NewLine(&path.PointSet[j], &path.PointSet[j+1])
if pLine.Intersects(pathLine) {
return true
}
}
}
return false
} | [
"func",
"(",
"p",
"*",
"Path",
")",
"IntersectsPath",
"(",
"path",
"*",
"Path",
")",
"bool",
"{",
"// TODO: done some sort of line sweep here if p.Length() is big enough",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"p",
".",
"PointSet",
")",
"-",
"1",
";",
"i",
"++",
"{",
"pLine",
":=",
"NewLine",
"(",
"&",
"p",
".",
"PointSet",
"[",
"i",
"]",
",",
"&",
"p",
".",
"PointSet",
"[",
"i",
"+",
"1",
"]",
")",
"\n\n",
"for",
"j",
":=",
"0",
";",
"j",
"<",
"len",
"(",
"path",
".",
"PointSet",
")",
"-",
"1",
";",
"j",
"++",
"{",
"pathLine",
":=",
"NewLine",
"(",
"&",
"path",
".",
"PointSet",
"[",
"j",
"]",
",",
"&",
"path",
".",
"PointSet",
"[",
"j",
"+",
"1",
"]",
")",
"\n\n",
"if",
"pLine",
".",
"Intersects",
"(",
"pathLine",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] | // IntersectsPath takes a Path and checks if it intersects with the path. | [
"IntersectsPath",
"takes",
"a",
"Path",
"and",
"checks",
"if",
"it",
"intersects",
"with",
"the",
"path",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/path.go#L437-L452 |
11,149 | paulmach/go.geo | path.go | IntersectsLine | func (p *Path) IntersectsLine(line *Line) bool {
for i := 0; i < len(p.PointSet)-1; i++ {
pTest := NewLine(&p.PointSet[i], &p.PointSet[i+1])
if pTest.Intersects(line) {
return true
}
}
return false
} | go | func (p *Path) IntersectsLine(line *Line) bool {
for i := 0; i < len(p.PointSet)-1; i++ {
pTest := NewLine(&p.PointSet[i], &p.PointSet[i+1])
if pTest.Intersects(line) {
return true
}
}
return false
} | [
"func",
"(",
"p",
"*",
"Path",
")",
"IntersectsLine",
"(",
"line",
"*",
"Line",
")",
"bool",
"{",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"p",
".",
"PointSet",
")",
"-",
"1",
";",
"i",
"++",
"{",
"pTest",
":=",
"NewLine",
"(",
"&",
"p",
".",
"PointSet",
"[",
"i",
"]",
",",
"&",
"p",
".",
"PointSet",
"[",
"i",
"+",
"1",
"]",
")",
"\n",
"if",
"pTest",
".",
"Intersects",
"(",
"line",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] | // IntersectsLine takes a Line and checks if it intersects with the path. | [
"IntersectsLine",
"takes",
"a",
"Line",
"and",
"checks",
"if",
"it",
"intersects",
"with",
"the",
"path",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/path.go#L455-L464 |
11,150 | paulmach/go.geo | path.go | SetAt | func (p *Path) SetAt(index int, point *Point) *Path {
(&p.PointSet).SetAt(index, point)
return p
} | go | func (p *Path) SetAt(index int, point *Point) *Path {
(&p.PointSet).SetAt(index, point)
return p
} | [
"func",
"(",
"p",
"*",
"Path",
")",
"SetAt",
"(",
"index",
"int",
",",
"point",
"*",
"Point",
")",
"*",
"Path",
"{",
"(",
"&",
"p",
".",
"PointSet",
")",
".",
"SetAt",
"(",
"index",
",",
"point",
")",
"\n",
"return",
"p",
"\n",
"}"
] | // SetAt updates a position at i along the path.
// Panics if index is out of range. | [
"SetAt",
"updates",
"a",
"position",
"at",
"i",
"along",
"the",
"path",
".",
"Panics",
"if",
"index",
"is",
"out",
"of",
"range",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/path.go#L491-L494 |
11,151 | paulmach/go.geo | path.go | GetAt | func (p *Path) GetAt(i int) *Point {
return p.PointSet.GetAt(i)
} | go | func (p *Path) GetAt(i int) *Point {
return p.PointSet.GetAt(i)
} | [
"func",
"(",
"p",
"*",
"Path",
")",
"GetAt",
"(",
"i",
"int",
")",
"*",
"Point",
"{",
"return",
"p",
".",
"PointSet",
".",
"GetAt",
"(",
"i",
")",
"\n",
"}"
] | // GetAt returns the pointer to the Point in the path.
// This function is good for modifying values in place.
// Returns nil if index is out of range. | [
"GetAt",
"returns",
"the",
"pointer",
"to",
"the",
"Point",
"in",
"the",
"path",
".",
"This",
"function",
"is",
"good",
"for",
"modifying",
"values",
"in",
"place",
".",
"Returns",
"nil",
"if",
"index",
"is",
"out",
"of",
"range",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/path.go#L499-L501 |
11,152 | paulmach/go.geo | path.go | InsertAt | func (p *Path) InsertAt(index int, point *Point) *Path {
(&p.PointSet).InsertAt(index, point)
return p
} | go | func (p *Path) InsertAt(index int, point *Point) *Path {
(&p.PointSet).InsertAt(index, point)
return p
} | [
"func",
"(",
"p",
"*",
"Path",
")",
"InsertAt",
"(",
"index",
"int",
",",
"point",
"*",
"Point",
")",
"*",
"Path",
"{",
"(",
"&",
"p",
".",
"PointSet",
")",
".",
"InsertAt",
"(",
"index",
",",
"point",
")",
"\n",
"return",
"p",
"\n",
"}"
] | // InsertAt inserts a Point at i along the path.
// Panics if index is out of range. | [
"InsertAt",
"inserts",
"a",
"Point",
"at",
"i",
"along",
"the",
"path",
".",
"Panics",
"if",
"index",
"is",
"out",
"of",
"range",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/path.go#L505-L508 |
11,153 | paulmach/go.geo | path.go | RemoveAt | func (p *Path) RemoveAt(index int) *Path {
(&p.PointSet).RemoveAt(index)
return p
} | go | func (p *Path) RemoveAt(index int) *Path {
(&p.PointSet).RemoveAt(index)
return p
} | [
"func",
"(",
"p",
"*",
"Path",
")",
"RemoveAt",
"(",
"index",
"int",
")",
"*",
"Path",
"{",
"(",
"&",
"p",
".",
"PointSet",
")",
".",
"RemoveAt",
"(",
"index",
")",
"\n",
"return",
"p",
"\n",
"}"
] | // RemoveAt removes a Point at i along the path.
// Panics if index is out of range. | [
"RemoveAt",
"removes",
"a",
"Point",
"at",
"i",
"along",
"the",
"path",
".",
"Panics",
"if",
"index",
"is",
"out",
"of",
"range",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/path.go#L512-L515 |
11,154 | paulmach/go.geo | path.go | Push | func (p *Path) Push(point *Point) *Path {
(&p.PointSet).Push(point)
return p
} | go | func (p *Path) Push(point *Point) *Path {
(&p.PointSet).Push(point)
return p
} | [
"func",
"(",
"p",
"*",
"Path",
")",
"Push",
"(",
"point",
"*",
"Point",
")",
"*",
"Path",
"{",
"(",
"&",
"p",
".",
"PointSet",
")",
".",
"Push",
"(",
"point",
")",
"\n",
"return",
"p",
"\n",
"}"
] | // Push appends a point to the end of the path. | [
"Push",
"appends",
"a",
"point",
"to",
"the",
"end",
"of",
"the",
"path",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/path.go#L518-L521 |
11,155 | paulmach/go.geo | path.go | Equals | func (p *Path) Equals(path *Path) bool {
return (&p.PointSet).Equals(&path.PointSet)
} | go | func (p *Path) Equals(path *Path) bool {
return (&p.PointSet).Equals(&path.PointSet)
} | [
"func",
"(",
"p",
"*",
"Path",
")",
"Equals",
"(",
"path",
"*",
"Path",
")",
"bool",
"{",
"return",
"(",
"&",
"p",
".",
"PointSet",
")",
".",
"Equals",
"(",
"&",
"path",
".",
"PointSet",
")",
"\n",
"}"
] | // Equals compares two paths. Returns true if lengths are the same
// and all points are Equal. | [
"Equals",
"compares",
"two",
"paths",
".",
"Returns",
"true",
"if",
"lengths",
"are",
"the",
"same",
"and",
"all",
"points",
"are",
"Equal",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/path.go#L535-L537 |
11,156 | paulmach/go.geo | path.go | ToGeoJSON | func (p *Path) ToGeoJSON() *geojson.Feature {
coords := make([][]float64, 0, len(p.PointSet))
for _, p := range p.PointSet {
coords = append(coords, []float64{p[0], p[1]})
}
return geojson.NewLineStringFeature(coords)
} | go | func (p *Path) ToGeoJSON() *geojson.Feature {
coords := make([][]float64, 0, len(p.PointSet))
for _, p := range p.PointSet {
coords = append(coords, []float64{p[0], p[1]})
}
return geojson.NewLineStringFeature(coords)
} | [
"func",
"(",
"p",
"*",
"Path",
")",
"ToGeoJSON",
"(",
")",
"*",
"geojson",
".",
"Feature",
"{",
"coords",
":=",
"make",
"(",
"[",
"]",
"[",
"]",
"float64",
",",
"0",
",",
"len",
"(",
"p",
".",
"PointSet",
")",
")",
"\n\n",
"for",
"_",
",",
"p",
":=",
"range",
"p",
".",
"PointSet",
"{",
"coords",
"=",
"append",
"(",
"coords",
",",
"[",
"]",
"float64",
"{",
"p",
"[",
"0",
"]",
",",
"p",
"[",
"1",
"]",
"}",
")",
"\n",
"}",
"\n\n",
"return",
"geojson",
".",
"NewLineStringFeature",
"(",
"coords",
")",
"\n",
"}"
] | // ToGeoJSON creates a new geojson feature with a linestring geometry
// containing all the points. | [
"ToGeoJSON",
"creates",
"a",
"new",
"geojson",
"feature",
"with",
"a",
"linestring",
"geometry",
"containing",
"all",
"the",
"points",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/path.go#L546-L554 |
11,157 | paulmach/go.geo | point_set.go | NewPointSetPreallocate | func NewPointSetPreallocate(length, capacity int) *PointSet {
if length > capacity {
capacity = length
}
ps := make([]Point, length, capacity)
p := PointSet(ps)
return &p
} | go | func NewPointSetPreallocate(length, capacity int) *PointSet {
if length > capacity {
capacity = length
}
ps := make([]Point, length, capacity)
p := PointSet(ps)
return &p
} | [
"func",
"NewPointSetPreallocate",
"(",
"length",
",",
"capacity",
"int",
")",
"*",
"PointSet",
"{",
"if",
"length",
">",
"capacity",
"{",
"capacity",
"=",
"length",
"\n",
"}",
"\n\n",
"ps",
":=",
"make",
"(",
"[",
"]",
"Point",
",",
"length",
",",
"capacity",
")",
"\n",
"p",
":=",
"PointSet",
"(",
"ps",
")",
"\n",
"return",
"&",
"p",
"\n",
"}"
] | // NewPointSetPreallocate simply creates a new point set with points array of the given size. | [
"NewPointSetPreallocate",
"simply",
"creates",
"a",
"new",
"point",
"set",
"with",
"points",
"array",
"of",
"the",
"given",
"size",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/point_set.go#L20-L28 |
11,158 | paulmach/go.geo | point_set.go | Clone | func (ps PointSet) Clone() *PointSet {
points := make([]Point, len(ps))
copy(points, ps)
nps := PointSet(points)
return &nps
} | go | func (ps PointSet) Clone() *PointSet {
points := make([]Point, len(ps))
copy(points, ps)
nps := PointSet(points)
return &nps
} | [
"func",
"(",
"ps",
"PointSet",
")",
"Clone",
"(",
")",
"*",
"PointSet",
"{",
"points",
":=",
"make",
"(",
"[",
"]",
"Point",
",",
"len",
"(",
"ps",
")",
")",
"\n",
"copy",
"(",
"points",
",",
"ps",
")",
"\n\n",
"nps",
":=",
"PointSet",
"(",
"points",
")",
"\n",
"return",
"&",
"nps",
"\n",
"}"
] | // Clone returns a new copy of the point set. | [
"Clone",
"returns",
"a",
"new",
"copy",
"of",
"the",
"point",
"set",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/point_set.go#L31-L37 |
11,159 | paulmach/go.geo | point_set.go | DistanceFrom | func (ps PointSet) DistanceFrom(point *Point) (float64, int) {
dist := math.Inf(1)
index := 0
for i := range ps {
if d := ps[i].SquaredDistanceFrom(point); d < dist {
dist = d
index = i
}
}
return math.Sqrt(dist), index
} | go | func (ps PointSet) DistanceFrom(point *Point) (float64, int) {
dist := math.Inf(1)
index := 0
for i := range ps {
if d := ps[i].SquaredDistanceFrom(point); d < dist {
dist = d
index = i
}
}
return math.Sqrt(dist), index
} | [
"func",
"(",
"ps",
"PointSet",
")",
"DistanceFrom",
"(",
"point",
"*",
"Point",
")",
"(",
"float64",
",",
"int",
")",
"{",
"dist",
":=",
"math",
".",
"Inf",
"(",
"1",
")",
"\n",
"index",
":=",
"0",
"\n\n",
"for",
"i",
":=",
"range",
"ps",
"{",
"if",
"d",
":=",
"ps",
"[",
"i",
"]",
".",
"SquaredDistanceFrom",
"(",
"point",
")",
";",
"d",
"<",
"dist",
"{",
"dist",
"=",
"d",
"\n",
"index",
"=",
"i",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"math",
".",
"Sqrt",
"(",
"dist",
")",
",",
"index",
"\n",
"}"
] | // DistanceFrom returns the minimum euclidean distance from the point set. | [
"DistanceFrom",
"returns",
"the",
"minimum",
"euclidean",
"distance",
"from",
"the",
"point",
"set",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/point_set.go#L82-L94 |
11,160 | paulmach/go.geo | point_set.go | GeoDistanceFrom | func (ps PointSet) GeoDistanceFrom(point *Point) (float64, int) {
dist := math.Inf(1)
index := 0
for i := range ps {
if d := ps[i].GeoDistanceFrom(point); d < dist {
dist = d
index = i
}
}
return dist, index
} | go | func (ps PointSet) GeoDistanceFrom(point *Point) (float64, int) {
dist := math.Inf(1)
index := 0
for i := range ps {
if d := ps[i].GeoDistanceFrom(point); d < dist {
dist = d
index = i
}
}
return dist, index
} | [
"func",
"(",
"ps",
"PointSet",
")",
"GeoDistanceFrom",
"(",
"point",
"*",
"Point",
")",
"(",
"float64",
",",
"int",
")",
"{",
"dist",
":=",
"math",
".",
"Inf",
"(",
"1",
")",
"\n",
"index",
":=",
"0",
"\n\n",
"for",
"i",
":=",
"range",
"ps",
"{",
"if",
"d",
":=",
"ps",
"[",
"i",
"]",
".",
"GeoDistanceFrom",
"(",
"point",
")",
";",
"d",
"<",
"dist",
"{",
"dist",
"=",
"d",
"\n",
"index",
"=",
"i",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"dist",
",",
"index",
"\n",
"}"
] | // GeoDistanceFrom returns the minimum geo distance from the point set,
// along with the index of the point with minimum index. | [
"GeoDistanceFrom",
"returns",
"the",
"minimum",
"geo",
"distance",
"from",
"the",
"point",
"set",
"along",
"with",
"the",
"index",
"of",
"the",
"point",
"with",
"minimum",
"index",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/point_set.go#L98-L110 |
11,161 | paulmach/go.geo | point_set.go | Bound | func (ps PointSet) Bound() *Bound {
if len(ps) == 0 {
return NewBound(0, 0, 0, 0)
}
minX := math.Inf(1)
minY := math.Inf(1)
maxX := math.Inf(-1)
maxY := math.Inf(-1)
for _, v := range ps {
minX = math.Min(minX, v.X())
minY = math.Min(minY, v.Y())
maxX = math.Max(maxX, v.X())
maxY = math.Max(maxY, v.Y())
}
return NewBound(maxX, minX, maxY, minY)
} | go | func (ps PointSet) Bound() *Bound {
if len(ps) == 0 {
return NewBound(0, 0, 0, 0)
}
minX := math.Inf(1)
minY := math.Inf(1)
maxX := math.Inf(-1)
maxY := math.Inf(-1)
for _, v := range ps {
minX = math.Min(minX, v.X())
minY = math.Min(minY, v.Y())
maxX = math.Max(maxX, v.X())
maxY = math.Max(maxY, v.Y())
}
return NewBound(maxX, minX, maxY, minY)
} | [
"func",
"(",
"ps",
"PointSet",
")",
"Bound",
"(",
")",
"*",
"Bound",
"{",
"if",
"len",
"(",
"ps",
")",
"==",
"0",
"{",
"return",
"NewBound",
"(",
"0",
",",
"0",
",",
"0",
",",
"0",
")",
"\n",
"}",
"\n\n",
"minX",
":=",
"math",
".",
"Inf",
"(",
"1",
")",
"\n",
"minY",
":=",
"math",
".",
"Inf",
"(",
"1",
")",
"\n\n",
"maxX",
":=",
"math",
".",
"Inf",
"(",
"-",
"1",
")",
"\n",
"maxY",
":=",
"math",
".",
"Inf",
"(",
"-",
"1",
")",
"\n\n",
"for",
"_",
",",
"v",
":=",
"range",
"ps",
"{",
"minX",
"=",
"math",
".",
"Min",
"(",
"minX",
",",
"v",
".",
"X",
"(",
")",
")",
"\n",
"minY",
"=",
"math",
".",
"Min",
"(",
"minY",
",",
"v",
".",
"Y",
"(",
")",
")",
"\n\n",
"maxX",
"=",
"math",
".",
"Max",
"(",
"maxX",
",",
"v",
".",
"X",
"(",
")",
")",
"\n",
"maxY",
"=",
"math",
".",
"Max",
"(",
"maxY",
",",
"v",
".",
"Y",
"(",
")",
")",
"\n",
"}",
"\n\n",
"return",
"NewBound",
"(",
"maxX",
",",
"minX",
",",
"maxY",
",",
"minY",
")",
"\n",
"}"
] | // Bound returns a bound around the point set. Simply uses rectangular coordinates. | [
"Bound",
"returns",
"a",
"bound",
"around",
"the",
"point",
"set",
".",
"Simply",
"uses",
"rectangular",
"coordinates",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/point_set.go#L113-L133 |
11,162 | paulmach/go.geo | point_set.go | SetAt | func (ps *PointSet) SetAt(index int, point *Point) *PointSet {
deref := *ps
if index >= len(deref) || index < 0 {
panic(fmt.Sprintf("geo: set index out of range, requested: %d, length: %d", index, len(deref)))
}
deref[index] = *point
*ps = deref
return ps
} | go | func (ps *PointSet) SetAt(index int, point *Point) *PointSet {
deref := *ps
if index >= len(deref) || index < 0 {
panic(fmt.Sprintf("geo: set index out of range, requested: %d, length: %d", index, len(deref)))
}
deref[index] = *point
*ps = deref
return ps
} | [
"func",
"(",
"ps",
"*",
"PointSet",
")",
"SetAt",
"(",
"index",
"int",
",",
"point",
"*",
"Point",
")",
"*",
"PointSet",
"{",
"deref",
":=",
"*",
"ps",
"\n",
"if",
"index",
">=",
"len",
"(",
"deref",
")",
"||",
"index",
"<",
"0",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"index",
",",
"len",
"(",
"deref",
")",
")",
")",
"\n",
"}",
"\n",
"deref",
"[",
"index",
"]",
"=",
"*",
"point",
"\n",
"*",
"ps",
"=",
"deref",
"\n",
"return",
"ps",
"\n",
"}"
] | // SetAt updates a position at i in the point set | [
"SetAt",
"updates",
"a",
"position",
"at",
"i",
"in",
"the",
"point",
"set"
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/point_set.go#L136-L144 |
11,163 | paulmach/go.geo | point_set.go | GetAt | func (ps *PointSet) GetAt(i int) *Point {
deref := *ps
if i >= len(deref) || i < 0 {
return nil
}
return &deref[i]
} | go | func (ps *PointSet) GetAt(i int) *Point {
deref := *ps
if i >= len(deref) || i < 0 {
return nil
}
return &deref[i]
} | [
"func",
"(",
"ps",
"*",
"PointSet",
")",
"GetAt",
"(",
"i",
"int",
")",
"*",
"Point",
"{",
"deref",
":=",
"*",
"ps",
"\n",
"if",
"i",
">=",
"len",
"(",
"deref",
")",
"||",
"i",
"<",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"&",
"deref",
"[",
"i",
"]",
"\n",
"}"
] | // GetAt returns the pointer to the Point in the page.
// This function is good for modifying values in place.
// Returns nil if index is out of range. | [
"GetAt",
"returns",
"the",
"pointer",
"to",
"the",
"Point",
"in",
"the",
"page",
".",
"This",
"function",
"is",
"good",
"for",
"modifying",
"values",
"in",
"place",
".",
"Returns",
"nil",
"if",
"index",
"is",
"out",
"of",
"range",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/point_set.go#L149-L156 |
11,164 | paulmach/go.geo | point_set.go | Last | func (ps PointSet) Last() *Point {
if len(ps) == 0 {
return nil
}
return &ps[len(ps)-1]
} | go | func (ps PointSet) Last() *Point {
if len(ps) == 0 {
return nil
}
return &ps[len(ps)-1]
} | [
"func",
"(",
"ps",
"PointSet",
")",
"Last",
"(",
")",
"*",
"Point",
"{",
"if",
"len",
"(",
"ps",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"&",
"ps",
"[",
"len",
"(",
"ps",
")",
"-",
"1",
"]",
"\n",
"}"
] | // Last returns the last point in the point set.
// Will return nil if there are no points in the set. | [
"Last",
"returns",
"the",
"last",
"point",
"in",
"the",
"point",
"set",
".",
"Will",
"return",
"nil",
"if",
"there",
"are",
"no",
"points",
"in",
"the",
"set",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/point_set.go#L170-L176 |
11,165 | paulmach/go.geo | point_set.go | InsertAt | func (ps *PointSet) InsertAt(index int, point *Point) *PointSet {
deref := *ps
if index > len(deref) || index < 0 {
panic(fmt.Sprintf("geo: insert index out of range, requested: %d, length: %d", index, len(deref)))
}
if index == len(deref) {
deref = append(deref, *point)
*ps = deref
return ps
}
deref = append(deref, Point{})
copy(deref[index+1:], deref[index:])
deref[index] = *point
*ps = deref
return ps
} | go | func (ps *PointSet) InsertAt(index int, point *Point) *PointSet {
deref := *ps
if index > len(deref) || index < 0 {
panic(fmt.Sprintf("geo: insert index out of range, requested: %d, length: %d", index, len(deref)))
}
if index == len(deref) {
deref = append(deref, *point)
*ps = deref
return ps
}
deref = append(deref, Point{})
copy(deref[index+1:], deref[index:])
deref[index] = *point
*ps = deref
return ps
} | [
"func",
"(",
"ps",
"*",
"PointSet",
")",
"InsertAt",
"(",
"index",
"int",
",",
"point",
"*",
"Point",
")",
"*",
"PointSet",
"{",
"deref",
":=",
"*",
"ps",
"\n",
"if",
"index",
">",
"len",
"(",
"deref",
")",
"||",
"index",
"<",
"0",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"index",
",",
"len",
"(",
"deref",
")",
")",
")",
"\n",
"}",
"\n\n",
"if",
"index",
"==",
"len",
"(",
"deref",
")",
"{",
"deref",
"=",
"append",
"(",
"deref",
",",
"*",
"point",
")",
"\n",
"*",
"ps",
"=",
"deref",
"\n",
"return",
"ps",
"\n",
"}",
"\n\n",
"deref",
"=",
"append",
"(",
"deref",
",",
"Point",
"{",
"}",
")",
"\n",
"copy",
"(",
"deref",
"[",
"index",
"+",
"1",
":",
"]",
",",
"deref",
"[",
"index",
":",
"]",
")",
"\n",
"deref",
"[",
"index",
"]",
"=",
"*",
"point",
"\n",
"*",
"ps",
"=",
"deref",
"\n",
"return",
"ps",
"\n",
"}"
] | // InsertAt inserts a Point at i in the point set.
// Panics if index is out of range. | [
"InsertAt",
"inserts",
"a",
"Point",
"at",
"i",
"in",
"the",
"point",
"set",
".",
"Panics",
"if",
"index",
"is",
"out",
"of",
"range",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/point_set.go#L180-L197 |
11,166 | paulmach/go.geo | point_set.go | RemoveAt | func (ps *PointSet) RemoveAt(index int) *PointSet {
deref := *ps
if index >= len(deref) || index < 0 {
panic(fmt.Sprintf("geo: remove index out of range, requested: %d, length: %d", index, len(deref)))
}
deref = append(deref[:index], deref[index+1:]...)
*ps = deref
return ps
} | go | func (ps *PointSet) RemoveAt(index int) *PointSet {
deref := *ps
if index >= len(deref) || index < 0 {
panic(fmt.Sprintf("geo: remove index out of range, requested: %d, length: %d", index, len(deref)))
}
deref = append(deref[:index], deref[index+1:]...)
*ps = deref
return ps
} | [
"func",
"(",
"ps",
"*",
"PointSet",
")",
"RemoveAt",
"(",
"index",
"int",
")",
"*",
"PointSet",
"{",
"deref",
":=",
"*",
"ps",
"\n",
"if",
"index",
">=",
"len",
"(",
"deref",
")",
"||",
"index",
"<",
"0",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"index",
",",
"len",
"(",
"deref",
")",
")",
")",
"\n",
"}",
"\n\n",
"deref",
"=",
"append",
"(",
"deref",
"[",
":",
"index",
"]",
",",
"deref",
"[",
"index",
"+",
"1",
":",
"]",
"...",
")",
"\n",
"*",
"ps",
"=",
"deref",
"\n",
"return",
"ps",
"\n",
"}"
] | // RemoveAt removes a Point at i in the point set.
// Panics if index is out of range. | [
"RemoveAt",
"removes",
"a",
"Point",
"at",
"i",
"in",
"the",
"point",
"set",
".",
"Panics",
"if",
"index",
"is",
"out",
"of",
"range",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/point_set.go#L201-L210 |
11,167 | paulmach/go.geo | point_set.go | Push | func (ps *PointSet) Push(point *Point) *PointSet {
*ps = append(*ps, *point)
return ps
} | go | func (ps *PointSet) Push(point *Point) *PointSet {
*ps = append(*ps, *point)
return ps
} | [
"func",
"(",
"ps",
"*",
"PointSet",
")",
"Push",
"(",
"point",
"*",
"Point",
")",
"*",
"PointSet",
"{",
"*",
"ps",
"=",
"append",
"(",
"*",
"ps",
",",
"*",
"point",
")",
"\n",
"return",
"ps",
"\n",
"}"
] | // Push appends a point to the end of the point set. | [
"Push",
"appends",
"a",
"point",
"to",
"the",
"end",
"of",
"the",
"point",
"set",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/point_set.go#L213-L216 |
11,168 | paulmach/go.geo | point_set.go | Pop | func (ps *PointSet) Pop() *Point {
deref := *ps
if len(deref) == 0 {
return nil
}
x := deref[len(deref)-1]
*ps = deref[:len(deref)-1]
return &x
} | go | func (ps *PointSet) Pop() *Point {
deref := *ps
if len(deref) == 0 {
return nil
}
x := deref[len(deref)-1]
*ps = deref[:len(deref)-1]
return &x
} | [
"func",
"(",
"ps",
"*",
"PointSet",
")",
"Pop",
"(",
")",
"*",
"Point",
"{",
"deref",
":=",
"*",
"ps",
"\n",
"if",
"len",
"(",
"deref",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"x",
":=",
"deref",
"[",
"len",
"(",
"deref",
")",
"-",
"1",
"]",
"\n",
"*",
"ps",
"=",
"deref",
"[",
":",
"len",
"(",
"deref",
")",
"-",
"1",
"]",
"\n\n",
"return",
"&",
"x",
"\n",
"}"
] | // Pop removes and returns the last point in the point set | [
"Pop",
"removes",
"and",
"returns",
"the",
"last",
"point",
"in",
"the",
"point",
"set"
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/point_set.go#L219-L229 |
11,169 | paulmach/go.geo | point_set.go | Equals | func (ps PointSet) Equals(pointSet *PointSet) bool {
if (ps).Length() != (*pointSet).Length() {
return false
}
for i, v := range ps {
if !v.Equals((*pointSet).GetAt(i)) {
return false
}
}
return true
} | go | func (ps PointSet) Equals(pointSet *PointSet) bool {
if (ps).Length() != (*pointSet).Length() {
return false
}
for i, v := range ps {
if !v.Equals((*pointSet).GetAt(i)) {
return false
}
}
return true
} | [
"func",
"(",
"ps",
"PointSet",
")",
"Equals",
"(",
"pointSet",
"*",
"PointSet",
")",
"bool",
"{",
"if",
"(",
"ps",
")",
".",
"Length",
"(",
")",
"!=",
"(",
"*",
"pointSet",
")",
".",
"Length",
"(",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"for",
"i",
",",
"v",
":=",
"range",
"ps",
"{",
"if",
"!",
"v",
".",
"Equals",
"(",
"(",
"*",
"pointSet",
")",
".",
"GetAt",
"(",
"i",
")",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
"}"
] | // Equals compares two point sets. Returns true if lengths are the same
// and all points are Equal | [
"Equals",
"compares",
"two",
"point",
"sets",
".",
"Returns",
"true",
"if",
"lengths",
"are",
"the",
"same",
"and",
"all",
"points",
"are",
"Equal"
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/point_set.go#L244-L256 |
11,170 | paulmach/go.geo | point_set.go | ToGeoJSON | func (ps PointSet) ToGeoJSON() *geojson.Feature {
f := geojson.NewMultiPointFeature()
for _, v := range ps {
f.Geometry.MultiPoint = append(f.Geometry.MultiPoint, []float64{v[0], v[1]})
}
return f
} | go | func (ps PointSet) ToGeoJSON() *geojson.Feature {
f := geojson.NewMultiPointFeature()
for _, v := range ps {
f.Geometry.MultiPoint = append(f.Geometry.MultiPoint, []float64{v[0], v[1]})
}
return f
} | [
"func",
"(",
"ps",
"PointSet",
")",
"ToGeoJSON",
"(",
")",
"*",
"geojson",
".",
"Feature",
"{",
"f",
":=",
"geojson",
".",
"NewMultiPointFeature",
"(",
")",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"ps",
"{",
"f",
".",
"Geometry",
".",
"MultiPoint",
"=",
"append",
"(",
"f",
".",
"Geometry",
".",
"MultiPoint",
",",
"[",
"]",
"float64",
"{",
"v",
"[",
"0",
"]",
",",
"v",
"[",
"1",
"]",
"}",
")",
"\n",
"}",
"\n\n",
"return",
"f",
"\n",
"}"
] | // ToGeoJSON creates a new geojson feature with a multipoint geometry
// containing all the points. | [
"ToGeoJSON",
"creates",
"a",
"new",
"geojson",
"feature",
"with",
"a",
"multipoint",
"geometry",
"containing",
"all",
"the",
"points",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/point_set.go#L260-L267 |
11,171 | paulmach/go.geo | clustering/cluster.go | NewCluster | func NewCluster(pointers ...geo.Pointer) *Cluster {
var (
sumX, sumY float64
count int
)
c := &Cluster{
Pointers: pointers,
}
if len(pointers) == 0 {
c.Centroid = geo.NewPoint(0, 0)
return c
}
if len(pointers) == 1 {
c.Centroid = pointers[0].Point().Clone()
return c
}
// find the center/centroid of multiple points
for _, pointer := range c.Pointers {
cp := pointer.Point()
sumX += cp.X()
sumY += cp.Y()
count++
}
c.Centroid = geo.NewPoint(sumX/float64(count), sumY/float64(count))
return c
} | go | func NewCluster(pointers ...geo.Pointer) *Cluster {
var (
sumX, sumY float64
count int
)
c := &Cluster{
Pointers: pointers,
}
if len(pointers) == 0 {
c.Centroid = geo.NewPoint(0, 0)
return c
}
if len(pointers) == 1 {
c.Centroid = pointers[0].Point().Clone()
return c
}
// find the center/centroid of multiple points
for _, pointer := range c.Pointers {
cp := pointer.Point()
sumX += cp.X()
sumY += cp.Y()
count++
}
c.Centroid = geo.NewPoint(sumX/float64(count), sumY/float64(count))
return c
} | [
"func",
"NewCluster",
"(",
"pointers",
"...",
"geo",
".",
"Pointer",
")",
"*",
"Cluster",
"{",
"var",
"(",
"sumX",
",",
"sumY",
"float64",
"\n",
"count",
"int",
"\n",
")",
"\n\n",
"c",
":=",
"&",
"Cluster",
"{",
"Pointers",
":",
"pointers",
",",
"}",
"\n\n",
"if",
"len",
"(",
"pointers",
")",
"==",
"0",
"{",
"c",
".",
"Centroid",
"=",
"geo",
".",
"NewPoint",
"(",
"0",
",",
"0",
")",
"\n",
"return",
"c",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"pointers",
")",
"==",
"1",
"{",
"c",
".",
"Centroid",
"=",
"pointers",
"[",
"0",
"]",
".",
"Point",
"(",
")",
".",
"Clone",
"(",
")",
"\n",
"return",
"c",
"\n",
"}",
"\n\n",
"// find the center/centroid of multiple points",
"for",
"_",
",",
"pointer",
":=",
"range",
"c",
".",
"Pointers",
"{",
"cp",
":=",
"pointer",
".",
"Point",
"(",
")",
"\n\n",
"sumX",
"+=",
"cp",
".",
"X",
"(",
")",
"\n",
"sumY",
"+=",
"cp",
".",
"Y",
"(",
")",
"\n",
"count",
"++",
"\n",
"}",
"\n",
"c",
".",
"Centroid",
"=",
"geo",
".",
"NewPoint",
"(",
"sumX",
"/",
"float64",
"(",
"count",
")",
",",
"sumY",
"/",
"float64",
"(",
"count",
")",
")",
"\n\n",
"return",
"c",
"\n",
"}"
] | // NewCluster creates the point cluster and finds the center of the given pointers. | [
"NewCluster",
"creates",
"the",
"point",
"cluster",
"and",
"finds",
"the",
"center",
"of",
"the",
"given",
"pointers",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/clustering/cluster.go#L13-L44 |
11,172 | paulmach/go.geo | clustering/cluster.go | NewClusterWithCentroid | func NewClusterWithCentroid(centroid *geo.Point, pointers ...geo.Pointer) *Cluster {
return &Cluster{
Centroid: centroid.Clone(),
Pointers: pointers,
}
} | go | func NewClusterWithCentroid(centroid *geo.Point, pointers ...geo.Pointer) *Cluster {
return &Cluster{
Centroid: centroid.Clone(),
Pointers: pointers,
}
} | [
"func",
"NewClusterWithCentroid",
"(",
"centroid",
"*",
"geo",
".",
"Point",
",",
"pointers",
"...",
"geo",
".",
"Pointer",
")",
"*",
"Cluster",
"{",
"return",
"&",
"Cluster",
"{",
"Centroid",
":",
"centroid",
".",
"Clone",
"(",
")",
",",
"Pointers",
":",
"pointers",
",",
"}",
"\n",
"}"
] | // NewClusterWithCentroid creates a point cluster stub from the given centroid
// and optional pointers. | [
"NewClusterWithCentroid",
"creates",
"a",
"point",
"cluster",
"stub",
"from",
"the",
"given",
"centroid",
"and",
"optional",
"pointers",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/clustering/cluster.go#L48-L53 |
11,173 | paulmach/go.geo | clustering/distance.go | ClusterDistance | func (cd CentroidDistance) ClusterDistance(c1, c2 *Cluster) float64 {
return c1.Centroid.DistanceFrom(c2.Centroid)
} | go | func (cd CentroidDistance) ClusterDistance(c1, c2 *Cluster) float64 {
return c1.Centroid.DistanceFrom(c2.Centroid)
} | [
"func",
"(",
"cd",
"CentroidDistance",
")",
"ClusterDistance",
"(",
"c1",
",",
"c2",
"*",
"Cluster",
")",
"float64",
"{",
"return",
"c1",
".",
"Centroid",
".",
"DistanceFrom",
"(",
"c2",
".",
"Centroid",
")",
"\n",
"}"
] | // ClusterDistance computes the distance between the cluster centroids. | [
"ClusterDistance",
"computes",
"the",
"distance",
"between",
"the",
"cluster",
"centroids",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/clustering/distance.go#L13-L15 |
11,174 | paulmach/go.geo | clustering/distance.go | ClusterDistance | func (csd CentroidSquaredDistance) ClusterDistance(c1, c2 *Cluster) float64 {
// save the function call, is this faster?
d0 := (c1.Centroid[0] - c2.Centroid[0])
d1 := (c1.Centroid[1] - c2.Centroid[1])
return d0*d0 + d1*d1
} | go | func (csd CentroidSquaredDistance) ClusterDistance(c1, c2 *Cluster) float64 {
// save the function call, is this faster?
d0 := (c1.Centroid[0] - c2.Centroid[0])
d1 := (c1.Centroid[1] - c2.Centroid[1])
return d0*d0 + d1*d1
} | [
"func",
"(",
"csd",
"CentroidSquaredDistance",
")",
"ClusterDistance",
"(",
"c1",
",",
"c2",
"*",
"Cluster",
")",
"float64",
"{",
"// save the function call, is this faster?",
"d0",
":=",
"(",
"c1",
".",
"Centroid",
"[",
"0",
"]",
"-",
"c2",
".",
"Centroid",
"[",
"0",
"]",
")",
"\n",
"d1",
":=",
"(",
"c1",
".",
"Centroid",
"[",
"1",
"]",
"-",
"c2",
".",
"Centroid",
"[",
"1",
"]",
")",
"\n",
"return",
"d0",
"*",
"d0",
"+",
"d1",
"*",
"d1",
"\n",
"}"
] | // ClusterDistance computes the squared euclidean distance between the cluster centroids. | [
"ClusterDistance",
"computes",
"the",
"squared",
"euclidean",
"distance",
"between",
"the",
"cluster",
"centroids",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/clustering/distance.go#L23-L28 |
11,175 | paulmach/go.geo | clustering/distance.go | ClusterDistance | func (cgd CentroidGeoDistance) ClusterDistance(c1, c2 *Cluster) float64 {
return c1.Centroid.GeoDistanceFrom(c2.Centroid)
} | go | func (cgd CentroidGeoDistance) ClusterDistance(c1, c2 *Cluster) float64 {
return c1.Centroid.GeoDistanceFrom(c2.Centroid)
} | [
"func",
"(",
"cgd",
"CentroidGeoDistance",
")",
"ClusterDistance",
"(",
"c1",
",",
"c2",
"*",
"Cluster",
")",
"float64",
"{",
"return",
"c1",
".",
"Centroid",
".",
"GeoDistanceFrom",
"(",
"c2",
".",
"Centroid",
")",
"\n",
"}"
] | // ClusterDistance computes the geo distance between the cluster centroids. | [
"ClusterDistance",
"computes",
"the",
"geo",
"distance",
"between",
"the",
"cluster",
"centroids",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/clustering/distance.go#L37-L39 |
11,176 | paulmach/go.geo | reducers/visvalingam.go | NewVisvalingamReducer | func NewVisvalingamReducer(threshold float64, minPointsToKeep int) *VisvalingamReducer {
return &VisvalingamReducer{
Threshold: threshold,
ToKeep: minPointsToKeep,
}
} | go | func NewVisvalingamReducer(threshold float64, minPointsToKeep int) *VisvalingamReducer {
return &VisvalingamReducer{
Threshold: threshold,
ToKeep: minPointsToKeep,
}
} | [
"func",
"NewVisvalingamReducer",
"(",
"threshold",
"float64",
",",
"minPointsToKeep",
"int",
")",
"*",
"VisvalingamReducer",
"{",
"return",
"&",
"VisvalingamReducer",
"{",
"Threshold",
":",
"threshold",
",",
"ToKeep",
":",
"minPointsToKeep",
",",
"}",
"\n",
"}"
] | // NewVisvalingamReducer creates a new VisvalingamReducer. | [
"NewVisvalingamReducer",
"creates",
"a",
"new",
"VisvalingamReducer",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/reducers/visvalingam.go#L17-L22 |
11,177 | paulmach/go.geo | reducers/visvalingam.go | Reduce | func (r VisvalingamReducer) Reduce(path *geo.Path) *geo.Path {
return Visvalingam(path, r.Threshold, r.ToKeep)
} | go | func (r VisvalingamReducer) Reduce(path *geo.Path) *geo.Path {
return Visvalingam(path, r.Threshold, r.ToKeep)
} | [
"func",
"(",
"r",
"VisvalingamReducer",
")",
"Reduce",
"(",
"path",
"*",
"geo",
".",
"Path",
")",
"*",
"geo",
".",
"Path",
"{",
"return",
"Visvalingam",
"(",
"path",
",",
"r",
".",
"Threshold",
",",
"r",
".",
"ToKeep",
")",
"\n",
"}"
] | // Reduce runs the Visvalingam reduction using the values of the Visvalingam. | [
"Reduce",
"runs",
"the",
"Visvalingam",
"reduction",
"using",
"the",
"values",
"of",
"the",
"Visvalingam",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/reducers/visvalingam.go#L25-L27 |
11,178 | paulmach/go.geo | reducers/visvalingam.go | VisvalingamThreshold | func VisvalingamThreshold(path *geo.Path, threshold float64) *geo.Path {
return Visvalingam(path, threshold, 0)
} | go | func VisvalingamThreshold(path *geo.Path, threshold float64) *geo.Path {
return Visvalingam(path, threshold, 0)
} | [
"func",
"VisvalingamThreshold",
"(",
"path",
"*",
"geo",
".",
"Path",
",",
"threshold",
"float64",
")",
"*",
"geo",
".",
"Path",
"{",
"return",
"Visvalingam",
"(",
"path",
",",
"threshold",
",",
"0",
")",
"\n",
"}"
] | // VisvalingamThreshold runs the Visvalingam-Whyatt algorithm removing
// triangles whose area is below the threshold. This function is here to simplify the interface.
// Returns a new path and DOES NOT modify the original. | [
"VisvalingamThreshold",
"runs",
"the",
"Visvalingam",
"-",
"Whyatt",
"algorithm",
"removing",
"triangles",
"whose",
"area",
"is",
"below",
"the",
"threshold",
".",
"This",
"function",
"is",
"here",
"to",
"simplify",
"the",
"interface",
".",
"Returns",
"a",
"new",
"path",
"and",
"DOES",
"NOT",
"modify",
"the",
"original",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/reducers/visvalingam.go#L42-L44 |
11,179 | paulmach/go.geo | reducers/visvalingam.go | VisvalingamKeep | func VisvalingamKeep(path *geo.Path, toKeep int) *geo.Path {
return Visvalingam(path, math.MaxFloat64, toKeep)
} | go | func VisvalingamKeep(path *geo.Path, toKeep int) *geo.Path {
return Visvalingam(path, math.MaxFloat64, toKeep)
} | [
"func",
"VisvalingamKeep",
"(",
"path",
"*",
"geo",
".",
"Path",
",",
"toKeep",
"int",
")",
"*",
"geo",
".",
"Path",
"{",
"return",
"Visvalingam",
"(",
"path",
",",
"math",
".",
"MaxFloat64",
",",
"toKeep",
")",
"\n",
"}"
] | // VisvalingamKeep runs the Visvalingam-Whyatt algorithm removing
// triangles of minimum area until we're down to `toKeep` number of points.
// Returns a new path and DOES NOT modify the original. | [
"VisvalingamKeep",
"runs",
"the",
"Visvalingam",
"-",
"Whyatt",
"algorithm",
"removing",
"triangles",
"of",
"minimum",
"area",
"until",
"we",
"re",
"down",
"to",
"toKeep",
"number",
"of",
"points",
".",
"Returns",
"a",
"new",
"path",
"and",
"DOES",
"NOT",
"modify",
"the",
"original",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/reducers/visvalingam.go#L49-L51 |
11,180 | paulmach/go.geo | clustering/helpers/rematch.go | RematchPointersToClusters | func RematchPointersToClusters(
clusters []*clustering.Cluster,
pointers []geo.Pointer,
distancer clustering.ClusterDistancer,
threshold float64,
) []*clustering.Cluster {
if len(clusters) == 0 {
return []*clustering.Cluster{}
}
newClusters := make([]*clustering.Cluster, 0, len(clusters))
// clear the current members
for _, c := range clusters {
newClusters = append(newClusters, clustering.NewClusterWithCentroid(c.Centroid))
}
// remap all the groupers to these new groups
for _, pointer := range pointers {
minDist := math.MaxFloat64
index := 0
pointerCluster := clustering.NewCluster(pointer)
// find the closest group
for i, c := range newClusters {
if d := distancer.ClusterDistance(c, pointerCluster); d < minDist {
minDist = d
index = i
}
}
if minDist < threshold {
// leaves the center as found by the previous clustering
newClusters[index].Pointers = append(newClusters[index].Pointers, pointer)
}
}
return newClusters
} | go | func RematchPointersToClusters(
clusters []*clustering.Cluster,
pointers []geo.Pointer,
distancer clustering.ClusterDistancer,
threshold float64,
) []*clustering.Cluster {
if len(clusters) == 0 {
return []*clustering.Cluster{}
}
newClusters := make([]*clustering.Cluster, 0, len(clusters))
// clear the current members
for _, c := range clusters {
newClusters = append(newClusters, clustering.NewClusterWithCentroid(c.Centroid))
}
// remap all the groupers to these new groups
for _, pointer := range pointers {
minDist := math.MaxFloat64
index := 0
pointerCluster := clustering.NewCluster(pointer)
// find the closest group
for i, c := range newClusters {
if d := distancer.ClusterDistance(c, pointerCluster); d < minDist {
minDist = d
index = i
}
}
if minDist < threshold {
// leaves the center as found by the previous clustering
newClusters[index].Pointers = append(newClusters[index].Pointers, pointer)
}
}
return newClusters
} | [
"func",
"RematchPointersToClusters",
"(",
"clusters",
"[",
"]",
"*",
"clustering",
".",
"Cluster",
",",
"pointers",
"[",
"]",
"geo",
".",
"Pointer",
",",
"distancer",
"clustering",
".",
"ClusterDistancer",
",",
"threshold",
"float64",
",",
")",
"[",
"]",
"*",
"clustering",
".",
"Cluster",
"{",
"if",
"len",
"(",
"clusters",
")",
"==",
"0",
"{",
"return",
"[",
"]",
"*",
"clustering",
".",
"Cluster",
"{",
"}",
"\n",
"}",
"\n\n",
"newClusters",
":=",
"make",
"(",
"[",
"]",
"*",
"clustering",
".",
"Cluster",
",",
"0",
",",
"len",
"(",
"clusters",
")",
")",
"\n\n",
"// clear the current members",
"for",
"_",
",",
"c",
":=",
"range",
"clusters",
"{",
"newClusters",
"=",
"append",
"(",
"newClusters",
",",
"clustering",
".",
"NewClusterWithCentroid",
"(",
"c",
".",
"Centroid",
")",
")",
"\n",
"}",
"\n\n",
"// remap all the groupers to these new groups",
"for",
"_",
",",
"pointer",
":=",
"range",
"pointers",
"{",
"minDist",
":=",
"math",
".",
"MaxFloat64",
"\n",
"index",
":=",
"0",
"\n\n",
"pointerCluster",
":=",
"clustering",
".",
"NewCluster",
"(",
"pointer",
")",
"\n\n",
"// find the closest group",
"for",
"i",
",",
"c",
":=",
"range",
"newClusters",
"{",
"if",
"d",
":=",
"distancer",
".",
"ClusterDistance",
"(",
"c",
",",
"pointerCluster",
")",
";",
"d",
"<",
"minDist",
"{",
"minDist",
"=",
"d",
"\n",
"index",
"=",
"i",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"minDist",
"<",
"threshold",
"{",
"// leaves the center as found by the previous clustering",
"newClusters",
"[",
"index",
"]",
".",
"Pointers",
"=",
"append",
"(",
"newClusters",
"[",
"index",
"]",
".",
"Pointers",
",",
"pointer",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"newClusters",
"\n",
"}"
] | // RematchPointersToClusters will take a set of pointers and map them to the closest cluster.
// Basically creates a new cluster from that one point and does the ClusterDistance between them.
// Will return a new list. | [
"RematchPointersToClusters",
"will",
"take",
"a",
"set",
"of",
"pointers",
"and",
"map",
"them",
"to",
"the",
"closest",
"cluster",
".",
"Basically",
"creates",
"a",
"new",
"cluster",
"from",
"that",
"one",
"point",
"and",
"does",
"the",
"ClusterDistance",
"between",
"them",
".",
"Will",
"return",
"a",
"new",
"list",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/clustering/helpers/rematch.go#L13-L52 |
11,181 | paulmach/go.geo | clustering/helpers/filter.go | FilterSmallClusters | func FilterSmallClusters(clusters []*clustering.Cluster, minPoints int) []*clustering.Cluster {
filtered := make([]*clustering.Cluster, 0, len(clusters))
for _, c := range clusters {
if len(c.Pointers) >= minPoints {
filtered = append(filtered, c)
}
}
return filtered
} | go | func FilterSmallClusters(clusters []*clustering.Cluster, minPoints int) []*clustering.Cluster {
filtered := make([]*clustering.Cluster, 0, len(clusters))
for _, c := range clusters {
if len(c.Pointers) >= minPoints {
filtered = append(filtered, c)
}
}
return filtered
} | [
"func",
"FilterSmallClusters",
"(",
"clusters",
"[",
"]",
"*",
"clustering",
".",
"Cluster",
",",
"minPoints",
"int",
")",
"[",
"]",
"*",
"clustering",
".",
"Cluster",
"{",
"filtered",
":=",
"make",
"(",
"[",
"]",
"*",
"clustering",
".",
"Cluster",
",",
"0",
",",
"len",
"(",
"clusters",
")",
")",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"clusters",
"{",
"if",
"len",
"(",
"c",
".",
"Pointers",
")",
">=",
"minPoints",
"{",
"filtered",
"=",
"append",
"(",
"filtered",
",",
"c",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"filtered",
"\n",
"}"
] | // FilterSmallClusters will remove points clusters with less than or equal to the minPoints. | [
"FilterSmallClusters",
"will",
"remove",
"points",
"clusters",
"with",
"less",
"than",
"or",
"equal",
"to",
"the",
"minPoints",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/clustering/helpers/filter.go#L6-L15 |
11,182 | paulmach/go.geo | quadtree/quadtree.go | New | func New(bound *geo.Bound, preallocateSize ...int) *Quadtree {
qt := &Quadtree{
Threshold: math.Max(bound.Width(), bound.Height()) / float64(1<<12),
bound: bound,
}
if len(preallocateSize) == 1 {
qt.freeNodes = make([]node, preallocateSize[0], preallocateSize[0])
}
return qt
} | go | func New(bound *geo.Bound, preallocateSize ...int) *Quadtree {
qt := &Quadtree{
Threshold: math.Max(bound.Width(), bound.Height()) / float64(1<<12),
bound: bound,
}
if len(preallocateSize) == 1 {
qt.freeNodes = make([]node, preallocateSize[0], preallocateSize[0])
}
return qt
} | [
"func",
"New",
"(",
"bound",
"*",
"geo",
".",
"Bound",
",",
"preallocateSize",
"...",
"int",
")",
"*",
"Quadtree",
"{",
"qt",
":=",
"&",
"Quadtree",
"{",
"Threshold",
":",
"math",
".",
"Max",
"(",
"bound",
".",
"Width",
"(",
")",
",",
"bound",
".",
"Height",
"(",
")",
")",
"/",
"float64",
"(",
"1",
"<<",
"12",
")",
",",
"bound",
":",
"bound",
",",
"}",
"\n",
"if",
"len",
"(",
"preallocateSize",
")",
"==",
"1",
"{",
"qt",
".",
"freeNodes",
"=",
"make",
"(",
"[",
"]",
"node",
",",
"preallocateSize",
"[",
"0",
"]",
",",
"preallocateSize",
"[",
"0",
"]",
")",
"\n\n",
"}",
"\n",
"return",
"qt",
"\n",
"}"
] | // New creates a new quadtree for the given bound. Added points
// must be within this bound. | [
"New",
"creates",
"a",
"new",
"quadtree",
"for",
"the",
"given",
"bound",
".",
"Added",
"points",
"must",
"be",
"within",
"this",
"bound",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/quadtree/quadtree.go#L53-L63 |
11,183 | paulmach/go.geo | quadtree/quadtree.go | NewFromPointSet | func NewFromPointSet(set *geo.PointSet) *Quadtree {
q := New(set.Bound(), set.Length())
ps := []geo.Point(*set)
for i := range ps {
q.Insert(&ps[i])
}
return q
} | go | func NewFromPointSet(set *geo.PointSet) *Quadtree {
q := New(set.Bound(), set.Length())
ps := []geo.Point(*set)
for i := range ps {
q.Insert(&ps[i])
}
return q
} | [
"func",
"NewFromPointSet",
"(",
"set",
"*",
"geo",
".",
"PointSet",
")",
"*",
"Quadtree",
"{",
"q",
":=",
"New",
"(",
"set",
".",
"Bound",
"(",
")",
",",
"set",
".",
"Length",
"(",
")",
")",
"\n\n",
"ps",
":=",
"[",
"]",
"geo",
".",
"Point",
"(",
"*",
"set",
")",
"\n",
"for",
"i",
":=",
"range",
"ps",
"{",
"q",
".",
"Insert",
"(",
"&",
"ps",
"[",
"i",
"]",
")",
"\n",
"}",
"\n\n",
"return",
"q",
"\n",
"}"
] | // NewFromPointSet creates a quadtree from a pointset.
// Copies the points into the quad tree. Modifying the points later
// will invalidate the quad tree and lead to unexpected result. | [
"NewFromPointSet",
"creates",
"a",
"quadtree",
"from",
"a",
"pointset",
".",
"Copies",
"the",
"points",
"into",
"the",
"quad",
"tree",
".",
"Modifying",
"the",
"points",
"later",
"will",
"invalidate",
"the",
"quad",
"tree",
"and",
"lead",
"to",
"unexpected",
"result",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/quadtree/quadtree.go#L68-L77 |
11,184 | paulmach/go.geo | quadtree/quadtree.go | NewFromPointers | func NewFromPointers(points []geo.Pointer) *Quadtree {
if len(points) == 0 {
// This is kind of meaningless but is what will happen
// if using an empty pointset above.
return New(geo.NewBound(0, 0, 0, 0))
}
b := geo.NewBoundFromPoints(points[0].Point(), points[0].Point())
for _, p := range points {
b.Extend(p.Point())
}
q := New(b, len(points))
for _, p := range points {
q.Insert(p)
}
return q
} | go | func NewFromPointers(points []geo.Pointer) *Quadtree {
if len(points) == 0 {
// This is kind of meaningless but is what will happen
// if using an empty pointset above.
return New(geo.NewBound(0, 0, 0, 0))
}
b := geo.NewBoundFromPoints(points[0].Point(), points[0].Point())
for _, p := range points {
b.Extend(p.Point())
}
q := New(b, len(points))
for _, p := range points {
q.Insert(p)
}
return q
} | [
"func",
"NewFromPointers",
"(",
"points",
"[",
"]",
"geo",
".",
"Pointer",
")",
"*",
"Quadtree",
"{",
"if",
"len",
"(",
"points",
")",
"==",
"0",
"{",
"// This is kind of meaningless but is what will happen",
"// if using an empty pointset above.",
"return",
"New",
"(",
"geo",
".",
"NewBound",
"(",
"0",
",",
"0",
",",
"0",
",",
"0",
")",
")",
"\n",
"}",
"\n\n",
"b",
":=",
"geo",
".",
"NewBoundFromPoints",
"(",
"points",
"[",
"0",
"]",
".",
"Point",
"(",
")",
",",
"points",
"[",
"0",
"]",
".",
"Point",
"(",
")",
")",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"points",
"{",
"b",
".",
"Extend",
"(",
"p",
".",
"Point",
"(",
")",
")",
"\n",
"}",
"\n\n",
"q",
":=",
"New",
"(",
"b",
",",
"len",
"(",
"points",
")",
")",
"\n\n",
"for",
"_",
",",
"p",
":=",
"range",
"points",
"{",
"q",
".",
"Insert",
"(",
"p",
")",
"\n",
"}",
"\n\n",
"return",
"q",
"\n",
"}"
] | // NewFromPointers creates a quadtree from a set of pointers. | [
"NewFromPointers",
"creates",
"a",
"quadtree",
"from",
"a",
"set",
"of",
"pointers",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/quadtree/quadtree.go#L80-L99 |
11,185 | paulmach/go.geo | quadtree/quadtree.go | Insert | func (q *Quadtree) Insert(p geo.Pointer) error {
if p == nil {
return nil
}
point := p.Point()
if point == nil {
return nil
}
if !q.bound.Contains(point) {
return ErrPointOutsideOfBounds
}
if q.root == nil {
q.root = &node{}
}
q.insert(q.root, p,
q.bound.Left(), q.bound.Right(),
q.bound.Bottom(), q.bound.Top(),
)
return nil
} | go | func (q *Quadtree) Insert(p geo.Pointer) error {
if p == nil {
return nil
}
point := p.Point()
if point == nil {
return nil
}
if !q.bound.Contains(point) {
return ErrPointOutsideOfBounds
}
if q.root == nil {
q.root = &node{}
}
q.insert(q.root, p,
q.bound.Left(), q.bound.Right(),
q.bound.Bottom(), q.bound.Top(),
)
return nil
} | [
"func",
"(",
"q",
"*",
"Quadtree",
")",
"Insert",
"(",
"p",
"geo",
".",
"Pointer",
")",
"error",
"{",
"if",
"p",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"point",
":=",
"p",
".",
"Point",
"(",
")",
"\n",
"if",
"point",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"!",
"q",
".",
"bound",
".",
"Contains",
"(",
"point",
")",
"{",
"return",
"ErrPointOutsideOfBounds",
"\n",
"}",
"\n\n",
"if",
"q",
".",
"root",
"==",
"nil",
"{",
"q",
".",
"root",
"=",
"&",
"node",
"{",
"}",
"\n",
"}",
"\n\n",
"q",
".",
"insert",
"(",
"q",
".",
"root",
",",
"p",
",",
"q",
".",
"bound",
".",
"Left",
"(",
")",
",",
"q",
".",
"bound",
".",
"Right",
"(",
")",
",",
"q",
".",
"bound",
".",
"Bottom",
"(",
")",
",",
"q",
".",
"bound",
".",
"Top",
"(",
")",
",",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Insert puts an object into the quad tree, must be within the quadtree bounds.
// If the pointer returns nil, the point will be ignored.
// This function is not thread-safe, ie. multiple goroutines cannot insert into
// a single quadtree. | [
"Insert",
"puts",
"an",
"object",
"into",
"the",
"quad",
"tree",
"must",
"be",
"within",
"the",
"quadtree",
"bounds",
".",
"If",
"the",
"pointer",
"returns",
"nil",
"the",
"point",
"will",
"be",
"ignored",
".",
"This",
"function",
"is",
"not",
"thread",
"-",
"safe",
"ie",
".",
"multiple",
"goroutines",
"cannot",
"insert",
"into",
"a",
"single",
"quadtree",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/quadtree/quadtree.go#L110-L134 |
11,186 | paulmach/go.geo | quadtree/quadtree.go | nextNode | func (q *Quadtree) nextNode() *node {
if l := len(q.freeNodes); q.freeIndex >= l {
// Exponentially decrease the preallocation size.
// On a handful of tests, number of nodes was about 1.5 times pointers.
l /= 2
// min size of the preallocation. I think this could be bigger as it's
// not that much memory overhead. Optimizing this more would need
// to be use case specific.
if l < 25 {
l = 25
}
q.freeNodes = make([]node, l, l)
q.freeIndex = 0
}
n := &q.freeNodes[q.freeIndex]
q.freeIndex++
return n
} | go | func (q *Quadtree) nextNode() *node {
if l := len(q.freeNodes); q.freeIndex >= l {
// Exponentially decrease the preallocation size.
// On a handful of tests, number of nodes was about 1.5 times pointers.
l /= 2
// min size of the preallocation. I think this could be bigger as it's
// not that much memory overhead. Optimizing this more would need
// to be use case specific.
if l < 25 {
l = 25
}
q.freeNodes = make([]node, l, l)
q.freeIndex = 0
}
n := &q.freeNodes[q.freeIndex]
q.freeIndex++
return n
} | [
"func",
"(",
"q",
"*",
"Quadtree",
")",
"nextNode",
"(",
")",
"*",
"node",
"{",
"if",
"l",
":=",
"len",
"(",
"q",
".",
"freeNodes",
")",
";",
"q",
".",
"freeIndex",
">=",
"l",
"{",
"// Exponentially decrease the preallocation size.",
"// On a handful of tests, number of nodes was about 1.5 times pointers.",
"l",
"/=",
"2",
"\n\n",
"// min size of the preallocation. I think this could be bigger as it's",
"// not that much memory overhead. Optimizing this more would need",
"// to be use case specific.",
"if",
"l",
"<",
"25",
"{",
"l",
"=",
"25",
"\n",
"}",
"\n\n",
"q",
".",
"freeNodes",
"=",
"make",
"(",
"[",
"]",
"node",
",",
"l",
",",
"l",
")",
"\n",
"q",
".",
"freeIndex",
"=",
"0",
"\n",
"}",
"\n\n",
"n",
":=",
"&",
"q",
".",
"freeNodes",
"[",
"q",
".",
"freeIndex",
"]",
"\n",
"q",
".",
"freeIndex",
"++",
"\n",
"return",
"n",
"\n",
"}"
] | // nextNode returns the next node from a preallocated list.
// This resulted in about 15% improvement in quadtree creation. | [
"nextNode",
"returns",
"the",
"next",
"node",
"from",
"a",
"preallocated",
"list",
".",
"This",
"resulted",
"in",
"about",
"15%",
"improvement",
"in",
"quadtree",
"creation",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/quadtree/quadtree.go#L138-L158 |
11,187 | paulmach/go.geo | quadtree/quadtree.go | InBoundMatching | func (q *Quadtree) InBoundMatching(b *geo.Bound, f Filter, buf ...[]geo.Pointer) []geo.Pointer {
if q.root == nil {
return nil
}
var p []geo.Pointer
if len(buf) > 0 {
p = buf[0][:0]
}
v := &inBoundVisitor{
bound: b,
pointers: p,
filter: f,
}
newVisit(v).Visit(q.root,
q.bound.Left(), q.bound.Right(),
q.bound.Bottom(), q.bound.Top(),
)
return v.pointers
} | go | func (q *Quadtree) InBoundMatching(b *geo.Bound, f Filter, buf ...[]geo.Pointer) []geo.Pointer {
if q.root == nil {
return nil
}
var p []geo.Pointer
if len(buf) > 0 {
p = buf[0][:0]
}
v := &inBoundVisitor{
bound: b,
pointers: p,
filter: f,
}
newVisit(v).Visit(q.root,
q.bound.Left(), q.bound.Right(),
q.bound.Bottom(), q.bound.Top(),
)
return v.pointers
} | [
"func",
"(",
"q",
"*",
"Quadtree",
")",
"InBoundMatching",
"(",
"b",
"*",
"geo",
".",
"Bound",
",",
"f",
"Filter",
",",
"buf",
"...",
"[",
"]",
"geo",
".",
"Pointer",
")",
"[",
"]",
"geo",
".",
"Pointer",
"{",
"if",
"q",
".",
"root",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"var",
"p",
"[",
"]",
"geo",
".",
"Pointer",
"\n",
"if",
"len",
"(",
"buf",
")",
">",
"0",
"{",
"p",
"=",
"buf",
"[",
"0",
"]",
"[",
":",
"0",
"]",
"\n",
"}",
"\n",
"v",
":=",
"&",
"inBoundVisitor",
"{",
"bound",
":",
"b",
",",
"pointers",
":",
"p",
",",
"filter",
":",
"f",
",",
"}",
"\n\n",
"newVisit",
"(",
"v",
")",
".",
"Visit",
"(",
"q",
".",
"root",
",",
"q",
".",
"bound",
".",
"Left",
"(",
")",
",",
"q",
".",
"bound",
".",
"Right",
"(",
")",
",",
"q",
".",
"bound",
".",
"Bottom",
"(",
")",
",",
"q",
".",
"bound",
".",
"Top",
"(",
")",
",",
")",
"\n\n",
"return",
"v",
".",
"pointers",
"\n",
"}"
] | // InBoundMatching returns a slice with all the pointers in the quadtree that are
// within the given bound and for which the given filter function returns true.
// An optional buffer parameter is provided to allow for the reuse of result slice memory.
// This function is thread safe. Multiple goroutines can read from a pre-created tree. | [
"InBoundMatching",
"returns",
"a",
"slice",
"with",
"all",
"the",
"pointers",
"in",
"the",
"quadtree",
"that",
"are",
"within",
"the",
"given",
"bound",
"and",
"for",
"which",
"the",
"given",
"filter",
"function",
"returns",
"true",
".",
"An",
"optional",
"buffer",
"parameter",
"is",
"provided",
"to",
"allow",
"for",
"the",
"reuse",
"of",
"result",
"slice",
"memory",
".",
"This",
"function",
"is",
"thread",
"safe",
".",
"Multiple",
"goroutines",
"can",
"read",
"from",
"a",
"pre",
"-",
"created",
"tree",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/quadtree/quadtree.go#L310-L331 |
11,188 | paulmach/go.geo | bound.go | NewBound | func NewBound(west, east, south, north float64) *Bound {
return &Bound{
sw: &Point{math.Min(east, west), math.Min(north, south)},
ne: &Point{math.Max(east, west), math.Max(north, south)},
}
} | go | func NewBound(west, east, south, north float64) *Bound {
return &Bound{
sw: &Point{math.Min(east, west), math.Min(north, south)},
ne: &Point{math.Max(east, west), math.Max(north, south)},
}
} | [
"func",
"NewBound",
"(",
"west",
",",
"east",
",",
"south",
",",
"north",
"float64",
")",
"*",
"Bound",
"{",
"return",
"&",
"Bound",
"{",
"sw",
":",
"&",
"Point",
"{",
"math",
".",
"Min",
"(",
"east",
",",
"west",
")",
",",
"math",
".",
"Min",
"(",
"north",
",",
"south",
")",
"}",
",",
"ne",
":",
"&",
"Point",
"{",
"math",
".",
"Max",
"(",
"east",
",",
"west",
")",
",",
"math",
".",
"Max",
"(",
"north",
",",
"south",
")",
"}",
",",
"}",
"\n",
"}"
] | // NewBound creates a new bound given the parameters. | [
"NewBound",
"creates",
"a",
"new",
"bound",
"given",
"the",
"parameters",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/bound.go#L16-L21 |
11,189 | paulmach/go.geo | bound.go | NewGeoBoundAroundPoint | func NewGeoBoundAroundPoint(center *Point, distance float64) *Bound {
if distance < 0 {
panic("invalid distance around center")
}
return geoBoundAroundPoint(center, distance)
} | go | func NewGeoBoundAroundPoint(center *Point, distance float64) *Bound {
if distance < 0 {
panic("invalid distance around center")
}
return geoBoundAroundPoint(center, distance)
} | [
"func",
"NewGeoBoundAroundPoint",
"(",
"center",
"*",
"Point",
",",
"distance",
"float64",
")",
"*",
"Bound",
"{",
"if",
"distance",
"<",
"0",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"geoBoundAroundPoint",
"(",
"center",
",",
"distance",
")",
"\n",
"}"
] | // NewGeoBoundAroundPoint creates a new bound given a center point,
// and a distance from the center point in meters | [
"NewGeoBoundAroundPoint",
"creates",
"a",
"new",
"bound",
"given",
"a",
"center",
"point",
"and",
"a",
"distance",
"from",
"the",
"center",
"point",
"in",
"meters"
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/bound.go#L37-L42 |
11,190 | paulmach/go.geo | bound.go | NewBoundFromMapTile | func NewBoundFromMapTile(x, y, z uint64) *Bound {
maxIndex := uint64(1) << z
if x < 0 || y < 0 || x >= maxIndex || y >= maxIndex {
panic("tile index out of range")
}
shift := 31 - z
if z > 31 {
shift = 0
}
lng1, lat1 := scalarMercatorInverse(x<<shift, y<<shift, 31)
lng2, lat2 := scalarMercatorInverse((x+1)<<shift, (y+1)<<shift, 31)
return &Bound{
sw: &Point{math.Min(lng1, lng2), math.Min(lat1, lat2)},
ne: &Point{math.Max(lng1, lng2), math.Max(lat1, lat2)},
}
} | go | func NewBoundFromMapTile(x, y, z uint64) *Bound {
maxIndex := uint64(1) << z
if x < 0 || y < 0 || x >= maxIndex || y >= maxIndex {
panic("tile index out of range")
}
shift := 31 - z
if z > 31 {
shift = 0
}
lng1, lat1 := scalarMercatorInverse(x<<shift, y<<shift, 31)
lng2, lat2 := scalarMercatorInverse((x+1)<<shift, (y+1)<<shift, 31)
return &Bound{
sw: &Point{math.Min(lng1, lng2), math.Min(lat1, lat2)},
ne: &Point{math.Max(lng1, lng2), math.Max(lat1, lat2)},
}
} | [
"func",
"NewBoundFromMapTile",
"(",
"x",
",",
"y",
",",
"z",
"uint64",
")",
"*",
"Bound",
"{",
"maxIndex",
":=",
"uint64",
"(",
"1",
")",
"<<",
"z",
"\n",
"if",
"x",
"<",
"0",
"||",
"y",
"<",
"0",
"||",
"x",
">=",
"maxIndex",
"||",
"y",
">=",
"maxIndex",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"shift",
":=",
"31",
"-",
"z",
"\n",
"if",
"z",
">",
"31",
"{",
"shift",
"=",
"0",
"\n",
"}",
"\n\n",
"lng1",
",",
"lat1",
":=",
"scalarMercatorInverse",
"(",
"x",
"<<",
"shift",
",",
"y",
"<<",
"shift",
",",
"31",
")",
"\n",
"lng2",
",",
"lat2",
":=",
"scalarMercatorInverse",
"(",
"(",
"x",
"+",
"1",
")",
"<<",
"shift",
",",
"(",
"y",
"+",
"1",
")",
"<<",
"shift",
",",
"31",
")",
"\n\n",
"return",
"&",
"Bound",
"{",
"sw",
":",
"&",
"Point",
"{",
"math",
".",
"Min",
"(",
"lng1",
",",
"lng2",
")",
",",
"math",
".",
"Min",
"(",
"lat1",
",",
"lat2",
")",
"}",
",",
"ne",
":",
"&",
"Point",
"{",
"math",
".",
"Max",
"(",
"lng1",
",",
"lng2",
")",
",",
"math",
".",
"Max",
"(",
"lat1",
",",
"lat2",
")",
"}",
",",
"}",
"\n",
"}"
] | // NewBoundFromMapTile creates a bound given an online map tile index.
// Panics if x or y is out of range for zoom level. | [
"NewBoundFromMapTile",
"creates",
"a",
"bound",
"given",
"an",
"online",
"map",
"tile",
"index",
".",
"Panics",
"if",
"x",
"or",
"y",
"is",
"out",
"of",
"range",
"for",
"zoom",
"level",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/bound.go#L46-L64 |
11,191 | paulmach/go.geo | bound.go | NewBoundFromGeoHash | func NewBoundFromGeoHash(hash string) *Bound {
west, east, south, north := geoHash2ranges(hash)
return NewBound(west, east, south, north)
} | go | func NewBoundFromGeoHash(hash string) *Bound {
west, east, south, north := geoHash2ranges(hash)
return NewBound(west, east, south, north)
} | [
"func",
"NewBoundFromGeoHash",
"(",
"hash",
"string",
")",
"*",
"Bound",
"{",
"west",
",",
"east",
",",
"south",
",",
"north",
":=",
"geoHash2ranges",
"(",
"hash",
")",
"\n",
"return",
"NewBound",
"(",
"west",
",",
"east",
",",
"south",
",",
"north",
")",
"\n",
"}"
] | // NewBoundFromGeoHash creates a new bound for the region defined by the GeoHash. | [
"NewBoundFromGeoHash",
"creates",
"a",
"new",
"bound",
"for",
"the",
"region",
"defined",
"by",
"the",
"GeoHash",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/bound.go#L67-L70 |
11,192 | paulmach/go.geo | bound.go | NewBoundFromGeoHashInt64 | func NewBoundFromGeoHashInt64(hash int64, bits int) *Bound {
west, east, south, north := geoHashInt2ranges(hash, bits)
return NewBound(west, east, south, north)
} | go | func NewBoundFromGeoHashInt64(hash int64, bits int) *Bound {
west, east, south, north := geoHashInt2ranges(hash, bits)
return NewBound(west, east, south, north)
} | [
"func",
"NewBoundFromGeoHashInt64",
"(",
"hash",
"int64",
",",
"bits",
"int",
")",
"*",
"Bound",
"{",
"west",
",",
"east",
",",
"south",
",",
"north",
":=",
"geoHashInt2ranges",
"(",
"hash",
",",
"bits",
")",
"\n",
"return",
"NewBound",
"(",
"west",
",",
"east",
",",
"south",
",",
"north",
")",
"\n",
"}"
] | // NewBoundFromGeoHashInt64 creates a new bound from the region defined by the GeoHesh.
// bits indicates the precision of the hash. | [
"NewBoundFromGeoHashInt64",
"creates",
"a",
"new",
"bound",
"from",
"the",
"region",
"defined",
"by",
"the",
"GeoHesh",
".",
"bits",
"indicates",
"the",
"precision",
"of",
"the",
"hash",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/bound.go#L74-L77 |
11,193 | paulmach/go.geo | bound.go | Set | func (b *Bound) Set(west, east, south, north float64) {
b.sw[0] = west
b.sw[1] = south
b.ne[0] = east
b.ne[1] = north
} | go | func (b *Bound) Set(west, east, south, north float64) {
b.sw[0] = west
b.sw[1] = south
b.ne[0] = east
b.ne[1] = north
} | [
"func",
"(",
"b",
"*",
"Bound",
")",
"Set",
"(",
"west",
",",
"east",
",",
"south",
",",
"north",
"float64",
")",
"{",
"b",
".",
"sw",
"[",
"0",
"]",
"=",
"west",
"\n",
"b",
".",
"sw",
"[",
"1",
"]",
"=",
"south",
"\n\n",
"b",
".",
"ne",
"[",
"0",
"]",
"=",
"east",
"\n",
"b",
".",
"ne",
"[",
"1",
"]",
"=",
"north",
"\n",
"}"
] | // Set allows for the modification of the bound values in place. | [
"Set",
"allows",
"for",
"the",
"modification",
"of",
"the",
"bound",
"values",
"in",
"place",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/bound.go#L170-L176 |
11,194 | paulmach/go.geo | bound.go | Union | func (b *Bound) Union(other *Bound) *Bound {
b.Extend(other.SouthWest())
b.Extend(other.NorthWest())
b.Extend(other.SouthEast())
b.Extend(other.NorthEast())
return b
} | go | func (b *Bound) Union(other *Bound) *Bound {
b.Extend(other.SouthWest())
b.Extend(other.NorthWest())
b.Extend(other.SouthEast())
b.Extend(other.NorthEast())
return b
} | [
"func",
"(",
"b",
"*",
"Bound",
")",
"Union",
"(",
"other",
"*",
"Bound",
")",
"*",
"Bound",
"{",
"b",
".",
"Extend",
"(",
"other",
".",
"SouthWest",
"(",
")",
")",
"\n",
"b",
".",
"Extend",
"(",
"other",
".",
"NorthWest",
"(",
")",
")",
"\n",
"b",
".",
"Extend",
"(",
"other",
".",
"SouthEast",
"(",
")",
")",
"\n",
"b",
".",
"Extend",
"(",
"other",
".",
"NorthEast",
"(",
")",
")",
"\n\n",
"return",
"b",
"\n",
"}"
] | // Union extends this bounds to contain the union of this and the given bounds. | [
"Union",
"extends",
"this",
"bounds",
"to",
"contain",
"the",
"union",
"of",
"this",
"and",
"the",
"given",
"bounds",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/bound.go#L196-L203 |
11,195 | paulmach/go.geo | bound.go | Center | func (b *Bound) Center() *Point {
p := &Point{}
p.SetX((b.ne.X() + b.sw.X()) / 2.0)
p.SetY((b.ne.Y() + b.sw.Y()) / 2.0)
return p
} | go | func (b *Bound) Center() *Point {
p := &Point{}
p.SetX((b.ne.X() + b.sw.X()) / 2.0)
p.SetY((b.ne.Y() + b.sw.Y()) / 2.0)
return p
} | [
"func",
"(",
"b",
"*",
"Bound",
")",
"Center",
"(",
")",
"*",
"Point",
"{",
"p",
":=",
"&",
"Point",
"{",
"}",
"\n",
"p",
".",
"SetX",
"(",
"(",
"b",
".",
"ne",
".",
"X",
"(",
")",
"+",
"b",
".",
"sw",
".",
"X",
"(",
")",
")",
"/",
"2.0",
")",
"\n",
"p",
".",
"SetY",
"(",
"(",
"b",
".",
"ne",
".",
"Y",
"(",
")",
"+",
"b",
".",
"sw",
".",
"Y",
"(",
")",
")",
"/",
"2.0",
")",
"\n\n",
"return",
"p",
"\n",
"}"
] | // Center returns the center of the bound. | [
"Center",
"returns",
"the",
"center",
"of",
"the",
"bound",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/bound.go#L235-L241 |
11,196 | paulmach/go.geo | bound.go | Pad | func (b *Bound) Pad(amount float64) *Bound {
b.sw.SetX(b.sw.X() - amount)
b.sw.SetY(b.sw.Y() - amount)
b.ne.SetX(b.ne.X() + amount)
b.ne.SetY(b.ne.Y() + amount)
return b
} | go | func (b *Bound) Pad(amount float64) *Bound {
b.sw.SetX(b.sw.X() - amount)
b.sw.SetY(b.sw.Y() - amount)
b.ne.SetX(b.ne.X() + amount)
b.ne.SetY(b.ne.Y() + amount)
return b
} | [
"func",
"(",
"b",
"*",
"Bound",
")",
"Pad",
"(",
"amount",
"float64",
")",
"*",
"Bound",
"{",
"b",
".",
"sw",
".",
"SetX",
"(",
"b",
".",
"sw",
".",
"X",
"(",
")",
"-",
"amount",
")",
"\n",
"b",
".",
"sw",
".",
"SetY",
"(",
"b",
".",
"sw",
".",
"Y",
"(",
")",
"-",
"amount",
")",
"\n\n",
"b",
".",
"ne",
".",
"SetX",
"(",
"b",
".",
"ne",
".",
"X",
"(",
")",
"+",
"amount",
")",
"\n",
"b",
".",
"ne",
".",
"SetY",
"(",
"b",
".",
"ne",
".",
"Y",
"(",
")",
"+",
"amount",
")",
"\n\n",
"return",
"b",
"\n",
"}"
] | // Pad expands the bound in all directions by the amount given. The amount must be
// in the units of the bounds. Technically one can pad with negative value,
// but no error checking is done. | [
"Pad",
"expands",
"the",
"bound",
"in",
"all",
"directions",
"by",
"the",
"amount",
"given",
".",
"The",
"amount",
"must",
"be",
"in",
"the",
"units",
"of",
"the",
"bounds",
".",
"Technically",
"one",
"can",
"pad",
"with",
"negative",
"value",
"but",
"no",
"error",
"checking",
"is",
"done",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/bound.go#L246-L254 |
11,197 | paulmach/go.geo | bound.go | SouthEast | func (b *Bound) SouthEast() *Point {
newP := &Point{}
newP.SetLat(b.sw.Lat()).SetLng(b.ne.Lng())
return newP
} | go | func (b *Bound) SouthEast() *Point {
newP := &Point{}
newP.SetLat(b.sw.Lat()).SetLng(b.ne.Lng())
return newP
} | [
"func",
"(",
"b",
"*",
"Bound",
")",
"SouthEast",
"(",
")",
"*",
"Point",
"{",
"newP",
":=",
"&",
"Point",
"{",
"}",
"\n",
"newP",
".",
"SetLat",
"(",
"b",
".",
"sw",
".",
"Lat",
"(",
")",
")",
".",
"SetLng",
"(",
"b",
".",
"ne",
".",
"Lng",
"(",
")",
")",
"\n",
"return",
"newP",
"\n",
"}"
] | // SouthEast returns the lower right corner of the bound. | [
"SouthEast",
"returns",
"the",
"lower",
"right",
"corner",
"of",
"the",
"bound",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/bound.go#L307-L311 |
11,198 | paulmach/go.geo | bound.go | Empty | func (b *Bound) Empty() bool {
return b.sw.X() >= b.ne.X() || b.sw.Y() >= b.ne.Y()
} | go | func (b *Bound) Empty() bool {
return b.sw.X() >= b.ne.X() || b.sw.Y() >= b.ne.Y()
} | [
"func",
"(",
"b",
"*",
"Bound",
")",
"Empty",
"(",
")",
"bool",
"{",
"return",
"b",
".",
"sw",
".",
"X",
"(",
")",
">=",
"b",
".",
"ne",
".",
"X",
"(",
")",
"||",
"b",
".",
"sw",
".",
"Y",
"(",
")",
">=",
"b",
".",
"ne",
".",
"Y",
"(",
")",
"\n",
"}"
] | // Empty returns true if it contains zero area or if
// it's in some malformed negative state where the left point is larger than the right.
// This can be caused by padding too much negative. | [
"Empty",
"returns",
"true",
"if",
"it",
"contains",
"zero",
"area",
"or",
"if",
"it",
"s",
"in",
"some",
"malformed",
"negative",
"state",
"where",
"the",
"left",
"point",
"is",
"larger",
"than",
"the",
"right",
".",
"This",
"can",
"be",
"caused",
"by",
"padding",
"too",
"much",
"negative",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/bound.go#L363-L365 |
11,199 | paulmach/go.geo | bound.go | Equals | func (b *Bound) Equals(c *Bound) bool {
if b.sw.Equals(c.sw) && b.ne.Equals(c.ne) {
return true
}
return false
} | go | func (b *Bound) Equals(c *Bound) bool {
if b.sw.Equals(c.sw) && b.ne.Equals(c.ne) {
return true
}
return false
} | [
"func",
"(",
"b",
"*",
"Bound",
")",
"Equals",
"(",
"c",
"*",
"Bound",
")",
"bool",
"{",
"if",
"b",
".",
"sw",
".",
"Equals",
"(",
"c",
".",
"sw",
")",
"&&",
"b",
".",
"ne",
".",
"Equals",
"(",
"c",
".",
"ne",
")",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] | // Equals returns if two bounds are equal. | [
"Equals",
"returns",
"if",
"two",
"bounds",
"are",
"equal",
"."
] | 22b514266d334aa8d88c792452195cbb2f670319 | https://github.com/paulmach/go.geo/blob/22b514266d334aa8d88c792452195cbb2f670319/bound.go#L368-L374 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.