_id
stringlengths 2
7
| title
stringlengths 1
118
| partition
stringclasses 3
values | text
stringlengths 52
85.5k
| language
stringclasses 1
value | meta_information
dict |
|---|---|---|---|---|---|
q6000
|
NewStaticCall
|
train
|
func NewStaticCall(Class node.Node, Call node.Node, ArgumentList *node.ArgumentList) *StaticCall {
return &StaticCall{
FreeFloating: nil,
Class: Class,
Call: Call,
ArgumentList: ArgumentList,
}
}
|
go
|
{
"resource": ""
}
|
q6001
|
NewNotEqual
|
train
|
func NewNotEqual(Variable node.Node, Expression node.Node) *NotEqual {
return &NotEqual{
FreeFloating: nil,
Left: Variable,
Right: Expression,
}
}
|
go
|
{
"resource": ""
}
|
q6002
|
NewAltElseIf
|
train
|
func NewAltElseIf(Cond node.Node, Stmt node.Node) *AltElseIf {
return &AltElseIf{
FreeFloating: nil,
Cond: Cond,
Stmt: Stmt,
}
}
|
go
|
{
"resource": ""
}
|
q6003
|
NewTraitUsePrecedence
|
train
|
func NewTraitUsePrecedence(Ref node.Node, Insteadof []node.Node) *TraitUsePrecedence {
return &TraitUsePrecedence{
FreeFloating: nil,
Ref: Ref,
Insteadof: Insteadof,
}
}
|
go
|
{
"resource": ""
}
|
q6004
|
NewInstanceOf
|
train
|
func NewInstanceOf(Expr node.Node, Class node.Node) *InstanceOf {
return &InstanceOf{
FreeFloating: nil,
Expr: Expr,
Class: Class,
}
}
|
go
|
{
"resource": ""
}
|
q6005
|
NewAltIf
|
train
|
func NewAltIf(Cond node.Node, Stmt node.Node, ElseIf []node.Node, Else node.Node) *AltIf {
return &AltIf{
FreeFloating: nil,
Cond: Cond,
Stmt: Stmt,
ElseIf: ElseIf,
Else: Else,
}
}
|
go
|
{
"resource": ""
}
|
q6006
|
SetElse
|
train
|
func (n *AltIf) SetElse(Else node.Node) node.Node {
n.Else = Else
return n
}
|
go
|
{
"resource": ""
}
|
q6007
|
NewStaticPropertyFetch
|
train
|
func NewStaticPropertyFetch(Class node.Node, Property node.Node) *StaticPropertyFetch {
return &StaticPropertyFetch{
FreeFloating: nil,
Class: Class,
Property: Property,
}
}
|
go
|
{
"resource": ""
}
|
q6008
|
NewClassMethod
|
train
|
func NewClassMethod(MethodName node.Node, Modifiers []node.Node, ReturnsRef bool, Params []node.Node, ReturnType node.Node, Stmt node.Node, PhpDocComment string) *ClassMethod {
return &ClassMethod{
FreeFloating: nil,
ReturnsRef: ReturnsRef,
PhpDocComment: PhpDocComment,
MethodName: MethodName,
Modifiers: Modifiers,
Params: Params,
ReturnType: ReturnType,
Stmt: Stmt,
}
}
|
go
|
{
"resource": ""
}
|
q6009
|
NewBreak
|
train
|
func NewBreak(Expr node.Node) *Break {
return &Break{
FreeFloating: nil,
Expr: Expr,
}
}
|
go
|
{
"resource": ""
}
|
q6010
|
NewGreaterOrEqual
|
train
|
func NewGreaterOrEqual(Variable node.Node, Expression node.Node) *GreaterOrEqual {
return &GreaterOrEqual{
FreeFloating: nil,
Left: Variable,
Right: Expression,
}
}
|
go
|
{
"resource": ""
}
|
q6011
|
NewInt
|
train
|
func NewInt(Expr node.Node) *Int {
return &Int{
FreeFloating: nil,
Expr: Expr,
}
}
|
go
|
{
"resource": ""
}
|
q6012
|
NewClosure
|
train
|
func NewClosure(Params []node.Node, ClosureUse *ClosureUse, ReturnType node.Node, Stmts []node.Node, Static bool, ReturnsRef bool, PhpDocComment string) *Closure {
return &Closure{
FreeFloating: nil,
ReturnsRef: ReturnsRef,
Static: Static,
PhpDocComment: PhpDocComment,
Params: Params,
ClosureUse: ClosureUse,
ReturnType: ReturnType,
Stmts: Stmts,
}
}
|
go
|
{
"resource": ""
}
|
q6013
|
Attributes
|
train
|
func (n *Closure) Attributes() map[string]interface{} {
return map[string]interface{}{
"ReturnsRef": n.ReturnsRef,
"Static": n.Static,
"PhpDocComment": n.PhpDocComment,
}
}
|
go
|
{
"resource": ""
}
|
q6014
|
NewUse
|
train
|
func NewUse(UseType node.Node, use node.Node, Alias node.Node) *Use {
return &Use{
FreeFloating: nil,
UseType: UseType,
Use: use,
Alias: Alias,
}
}
|
go
|
{
"resource": ""
}
|
q6015
|
NewPrint
|
train
|
func NewPrint(Expression node.Node) *Print {
return &Print{
FreeFloating: nil,
Expr: Expression,
}
}
|
go
|
{
"resource": ""
}
|
q6016
|
NewArgument
|
train
|
func NewArgument(Expression Node, Variadic bool, IsReference bool) *Argument {
return &Argument{
FreeFloating: nil,
Variadic: Variadic,
IsReference: IsReference,
Expr: Expression,
}
}
|
go
|
{
"resource": ""
}
|
q6017
|
NewIncludeOnce
|
train
|
func NewIncludeOnce(Expression node.Node) *IncludeOnce {
return &IncludeOnce{
FreeFloating: nil,
Expr: Expression,
}
}
|
go
|
{
"resource": ""
}
|
q6018
|
NewStatic
|
train
|
func NewStatic(Vars []node.Node) *Static {
return &Static{
FreeFloating: nil,
Vars: Vars,
}
}
|
go
|
{
"resource": ""
}
|
q6019
|
NewYield
|
train
|
func NewYield(Key node.Node, Value node.Node) *Yield {
return &Yield{
FreeFloating: nil,
Key: Key,
Value: Value,
}
}
|
go
|
{
"resource": ""
}
|
q6020
|
NewShiftLeft
|
train
|
func NewShiftLeft(Variable node.Node, Expression node.Node) *ShiftLeft {
return &ShiftLeft{
FreeFloating: nil,
Left: Variable,
Right: Expression,
}
}
|
go
|
{
"resource": ""
}
|
q6021
|
NewElse
|
train
|
func NewElse(Stmt node.Node) *Else {
return &Else{
FreeFloating: nil,
Stmt: Stmt,
}
}
|
go
|
{
"resource": ""
}
|
q6022
|
NewShellExec
|
train
|
func NewShellExec(Parts []node.Node) *ShellExec {
return &ShellExec{
FreeFloating: nil,
Parts: Parts,
}
}
|
go
|
{
"resource": ""
}
|
q6023
|
NewPreInc
|
train
|
func NewPreInc(Variable node.Node) *PreInc {
return &PreInc{
FreeFloating: nil,
Variable: Variable,
}
}
|
go
|
{
"resource": ""
}
|
q6024
|
NewPlus
|
train
|
func NewPlus(Variable node.Node, Expression node.Node) *Plus {
return &Plus{
FreeFloating: nil,
Left: Variable,
Right: Expression,
}
}
|
go
|
{
"resource": ""
}
|
q6025
|
NewBool
|
train
|
func NewBool(Expr node.Node) *Bool {
return &Bool{
FreeFloating: nil,
Expr: Expr,
}
}
|
go
|
{
"resource": ""
}
|
q6026
|
AddNamespacedName
|
train
|
func (nsr *NamespaceResolver) AddNamespacedName(nn node.Node, nodeName string) {
if nsr.Namespace.Namespace == "" {
nsr.ResolvedNames[nn] = nodeName
} else {
nsr.ResolvedNames[nn] = nsr.Namespace.Namespace + "\\" + nodeName
}
}
|
go
|
{
"resource": ""
}
|
q6027
|
ResolveName
|
train
|
func (nsr *NamespaceResolver) ResolveName(nameNode node.Node, aliasType string) {
resolved, err := nsr.Namespace.ResolveName(nameNode, aliasType)
if err == nil {
nsr.ResolvedNames[nameNode] = resolved
}
}
|
go
|
{
"resource": ""
}
|
q6028
|
ResolveType
|
train
|
func (nsr *NamespaceResolver) ResolveType(n node.Node) {
switch nn := n.(type) {
case *node.Nullable:
nsr.ResolveType(nn.Expr)
case name.Names:
nsr.ResolveName(n, "")
}
}
|
go
|
{
"resource": ""
}
|
q6029
|
ResolveName
|
train
|
func (ns *Namespace) ResolveName(nameNode node.Node, aliasType string) (string, error) {
switch n := nameNode.(type) {
case *name.FullyQualified:
// Fully qualifid name is already resolved
return concatNameParts(n.Parts), nil
case *name.Relative:
if ns.Namespace == "" {
return concatNameParts(n.Parts), nil
}
return ns.Namespace + "\\" + concatNameParts(n.Parts), nil
case *name.Name:
if aliasType == "const" && len(n.Parts) == 1 {
part := strings.ToLower(n.Parts[0].(*name.NamePart).Value)
if part == "true" || part == "false" || part == "null" {
return part, nil
}
}
if aliasType == "" && len(n.Parts) == 1 {
part := strings.ToLower(n.Parts[0].(*name.NamePart).Value)
switch part {
case "self":
fallthrough
case "static":
fallthrough
case "parent":
fallthrough
case "int":
fallthrough
case "float":
fallthrough
case "bool":
fallthrough
case "string":
fallthrough
case "void":
fallthrough
case "iterable":
fallthrough
case "object":
return part, nil
}
}
aliasName, err := ns.ResolveAlias(nameNode, aliasType)
if err != nil {
// resolve as relative name if alias not found
if ns.Namespace == "" {
return concatNameParts(n.Parts), nil
}
return ns.Namespace + "\\" + concatNameParts(n.Parts), nil
}
if len(n.Parts) > 1 {
// if name qualified, replace first part by alias
return aliasName + "\\" + concatNameParts(n.Parts[1:]), nil
}
return aliasName, nil
}
return "", errors.New("must be instance of name.Names")
}
|
go
|
{
"resource": ""
}
|
q6030
|
ResolveAlias
|
train
|
func (ns *Namespace) ResolveAlias(nameNode node.Node, aliasType string) (string, error) {
aliasType = strings.ToLower(aliasType)
nameParts := nameNode.(*name.Name).Parts
firstPartStr := nameParts[0].(*name.NamePart).Value
if len(nameParts) > 1 { // resolve aliases for qualified names, always against class alias type
firstPartStr = strings.ToLower(firstPartStr)
aliasType = ""
} else {
if aliasType != "const" { // constants are case-sensitive
firstPartStr = strings.ToLower(firstPartStr)
}
}
aliasName, ok := ns.Aliases[aliasType][firstPartStr]
if !ok {
return "", errors.New("Not found")
}
return aliasName, nil
}
|
go
|
{
"resource": ""
}
|
q6031
|
NewTraitUseAlias
|
train
|
func NewTraitUseAlias(Ref node.Node, Modifier node.Node, Alias node.Node) *TraitUseAlias {
return &TraitUseAlias{
FreeFloating: nil,
Ref: Ref,
Modifier: Modifier,
Alias: Alias,
}
}
|
go
|
{
"resource": ""
}
|
q6032
|
NewEqual
|
train
|
func NewEqual(Variable node.Node, Expression node.Node) *Equal {
return &Equal{
FreeFloating: nil,
Left: Variable,
Right: Expression,
}
}
|
go
|
{
"resource": ""
}
|
q6033
|
NewClone
|
train
|
func NewClone(Expression node.Node) *Clone {
return &Clone{
FreeFloating: nil,
Expr: Expression,
}
}
|
go
|
{
"resource": ""
}
|
q6034
|
NewMul
|
train
|
func NewMul(Variable node.Node, Expression node.Node) *Mul {
return &Mul{
FreeFloating: nil,
Left: Variable,
Right: Expression,
}
}
|
go
|
{
"resource": ""
}
|
q6035
|
NewEval
|
train
|
func NewEval(Expression node.Node) *Eval {
return &Eval{
FreeFloating: nil,
Expr: Expression,
}
}
|
go
|
{
"resource": ""
}
|
q6036
|
NewCaseList
|
train
|
func NewCaseList(Cases []node.Node) *CaseList {
return &CaseList{
FreeFloating: nil,
Cases: Cases,
}
}
|
go
|
{
"resource": ""
}
|
q6037
|
Rune2Class
|
train
|
func Rune2Class(r rune) int {
if r >= 0 && r < 0x80 { // Keep ASCII as it is.
return int(r)
}
if unicode.IsLetter(r) {
return classUnicodeLeter
}
if unicode.IsDigit(r) {
return classUnicodeDigit
}
if unicode.IsGraphic(r) {
return classUnicodeGraphic
}
if r == lex.RuneEOF {
return int(r)
}
return classOther
}
|
go
|
{
"resource": ""
}
|
q6038
|
NewLexer
|
train
|
func NewLexer(src io.Reader, fName string) *Lexer {
file := t.NewFileSet().AddFile(fName, -1, 1<<31-3)
lx, err := lex.New(file, bufio.NewReader(src), lex.RuneClass(Rune2Class))
if err != nil {
panic(err)
}
return &Lexer{
Lexer: lx,
StateStack: []int{0},
PhpDocComment: "",
FreeFloating: nil,
heredocLabel: "",
tokenBytesBuf: &bytes.Buffer{},
TokenPool: &TokenPool{},
}
}
|
go
|
{
"resource": ""
}
|
q6039
|
addFreeFloating
|
train
|
func (l *Lexer) addFreeFloating(t freefloating.StringType, chars []lex.Char) {
if !l.WithFreeFloating {
return
}
firstChar := chars[0]
lastChar := chars[len(chars)-1]
pos := position.NewPosition(
l.File.Line(firstChar.Pos()),
l.File.Line(lastChar.Pos()),
int(firstChar.Pos()),
int(lastChar.Pos()),
)
l.FreeFloating = append(l.FreeFloating, freefloating.String{
StringType: t,
Value: l.tokenString(chars),
Position: pos,
})
}
|
go
|
{
"resource": ""
}
|
q6040
|
NewList
|
train
|
func NewList(Items []node.Node) *List {
return &List{
FreeFloating: nil,
Items: Items,
}
}
|
go
|
{
"resource": ""
}
|
q6041
|
NewBitwiseAnd
|
train
|
func NewBitwiseAnd(Variable node.Node, Expression node.Node) *BitwiseAnd {
return &BitwiseAnd{
FreeFloating: nil,
Left: Variable,
Right: Expression,
}
}
|
go
|
{
"resource": ""
}
|
q6042
|
NewTernary
|
train
|
func NewTernary(Condition node.Node, IfTrue node.Node, IfFalse node.Node) *Ternary {
return &Ternary{
FreeFloating: nil,
Condition: Condition,
IfTrue: IfTrue,
IfFalse: IfFalse,
}
}
|
go
|
{
"resource": ""
}
|
q6043
|
NewPrettyPrinter
|
train
|
func NewPrettyPrinter(w io.Writer, indentStr string) *PrettyPrinter {
return &PrettyPrinter{
w: w,
indentStr: indentStr,
indentDepth: 0,
}
}
|
go
|
{
"resource": ""
}
|
q6044
|
NewNamespace
|
train
|
func NewNamespace(NamespaceName node.Node, Stmts []node.Node) *Namespace {
return &Namespace{
FreeFloating: nil,
NamespaceName: NamespaceName,
Stmts: Stmts,
}
}
|
go
|
{
"resource": ""
}
|
q6045
|
NewRequire
|
train
|
func NewRequire(Expression node.Node) *Require {
return &Require{
FreeFloating: nil,
Expr: Expression,
}
}
|
go
|
{
"resource": ""
}
|
q6046
|
NewForeach
|
train
|
func NewForeach(Expr node.Node, Key node.Node, Variable node.Node, Stmt node.Node) *Foreach {
return &Foreach{
FreeFloating: nil,
Expr: Expr,
Key: Key,
Variable: Variable,
Stmt: Stmt,
}
}
|
go
|
{
"resource": ""
}
|
q6047
|
NewCoalesce
|
train
|
func NewCoalesce(Variable node.Node, Expression node.Node) *Coalesce {
return &Coalesce{
FreeFloating: nil,
Left: Variable,
Right: Expression,
}
}
|
go
|
{
"resource": ""
}
|
q6048
|
NewSmaller
|
train
|
func NewSmaller(Variable node.Node, Expression node.Node) *Smaller {
return &Smaller{
FreeFloating: nil,
Left: Variable,
Right: Expression,
}
}
|
go
|
{
"resource": ""
}
|
q6049
|
NewStmtList
|
train
|
func NewStmtList(Stmts []node.Node) *StmtList {
return &StmtList{
FreeFloating: nil,
Stmts: Stmts,
}
}
|
go
|
{
"resource": ""
}
|
q6050
|
NewConcat
|
train
|
func NewConcat(Variable node.Node, Expression node.Node) *Concat {
return &Concat{
FreeFloating: nil,
Left: Variable,
Right: Expression,
}
}
|
go
|
{
"resource": ""
}
|
q6051
|
NewAltSwitch
|
train
|
func NewAltSwitch(Cond node.Node, CaseList *CaseList) *AltSwitch {
return &AltSwitch{
FreeFloating: nil,
Cond: Cond,
CaseList: CaseList,
}
}
|
go
|
{
"resource": ""
}
|
q6052
|
NewElseIf
|
train
|
func NewElseIf(Cond node.Node, Stmt node.Node) *ElseIf {
return &ElseIf{
FreeFloating: nil,
Cond: Cond,
Stmt: Stmt,
}
}
|
go
|
{
"resource": ""
}
|
q6053
|
NewDeclare
|
train
|
func NewDeclare(Consts []node.Node, Stmt node.Node, alt bool) *Declare {
return &Declare{
FreeFloating: nil,
Consts: Consts,
Stmt: Stmt,
Alt: alt,
}
}
|
go
|
{
"resource": ""
}
|
q6054
|
NewMinus
|
train
|
func NewMinus(Variable node.Node, Expression node.Node) *Minus {
return &Minus{
FreeFloating: nil,
Left: Variable,
Right: Expression,
}
}
|
go
|
{
"resource": ""
}
|
q6055
|
NewRelative
|
train
|
func NewRelative(Parts []node.Node) *Relative {
return &Relative{
FreeFloating: nil,
Parts: Parts,
}
}
|
go
|
{
"resource": ""
}
|
q6056
|
NewContinue
|
train
|
func NewContinue(Expr node.Node) *Continue {
return &Continue{
FreeFloating: nil,
Expr: Expr,
}
}
|
go
|
{
"resource": ""
}
|
q6057
|
NewArrayDimFetch
|
train
|
func NewArrayDimFetch(Variable node.Node, Dim node.Node) *ArrayDimFetch {
return &ArrayDimFetch{
FreeFloating: nil,
Variable: Variable,
Dim: Dim,
}
}
|
go
|
{
"resource": ""
}
|
q6058
|
NewGlobal
|
train
|
func NewGlobal(Vars []node.Node) *Global {
return &Global{
FreeFloating: nil,
Vars: Vars,
}
}
|
go
|
{
"resource": ""
}
|
q6059
|
NewPosition
|
train
|
func NewPosition(StartLine int, EndLine int, StartPos int, EndPos int) *Position {
return &Position{
StartLine: StartLine,
EndLine: EndLine,
StartPos: StartPos,
EndPos: EndPos,
}
}
|
go
|
{
"resource": ""
}
|
q6060
|
NewPostInc
|
train
|
func NewPostInc(Variable node.Node) *PostInc {
return &PostInc{
FreeFloating: nil,
Variable: Variable,
}
}
|
go
|
{
"resource": ""
}
|
q6061
|
NewAltForeach
|
train
|
func NewAltForeach(Expr node.Node, Key node.Node, Variable node.Node, Stmt node.Node) *AltForeach {
return &AltForeach{
FreeFloating: nil,
Expr: Expr,
Key: Key,
Variable: Variable,
Stmt: Stmt,
}
}
|
go
|
{
"resource": ""
}
|
q6062
|
NewGoto
|
train
|
func NewGoto(Label node.Node) *Goto {
return &Goto{
FreeFloating: nil,
Label: Label,
}
}
|
go
|
{
"resource": ""
}
|
q6063
|
Invert
|
train
|
func Invert() Filter {
return &colorchanFilter{
fn: func(x float32) float32 {
return 1 - x
},
lut: false,
}
}
|
go
|
{
"resource": ""
}
|
q6064
|
ColorspaceSRGBToLinear
|
train
|
func ColorspaceSRGBToLinear() Filter {
return &colorchanFilter{
fn: func(x float32) float32 {
if x <= 0.04045 {
return x / 12.92
}
return float32(math.Pow(float64((x+0.055)/1.055), 2.4))
},
lut: true,
}
}
|
go
|
{
"resource": ""
}
|
q6065
|
Gamma
|
train
|
func Gamma(gamma float32) Filter {
e := 1 / maxf32(gamma, 1.0e-5)
return &colorchanFilter{
fn: func(x float32) float32 {
return powf32(x, e)
},
lut: true,
}
}
|
go
|
{
"resource": ""
}
|
q6066
|
Grayscale
|
train
|
func Grayscale() Filter {
return &colorFilter{
fn: func(px pixel) pixel {
y := 0.299*px.r + 0.587*px.g + 0.114*px.b
return pixel{y, y, y, px.a}
},
}
}
|
go
|
{
"resource": ""
}
|
q6067
|
Add
|
train
|
func (g *GIFT) Add(filters ...Filter) {
g.Filters = append(g.Filters, filters...)
}
|
go
|
{
"resource": ""
}
|
q6068
|
Draw
|
train
|
func (g *GIFT) Draw(dst draw.Image, src image.Image) {
if len(g.Filters) == 0 {
copyimage(dst, src, &g.Options)
return
}
first, last := 0, len(g.Filters)-1
var tmpIn image.Image
var tmpOut draw.Image
for i, f := range g.Filters {
if i == first {
tmpIn = src
} else {
tmpIn = tmpOut
}
if i == last {
tmpOut = dst
} else {
tmpOut = createTempImage(f.Bounds(tmpIn.Bounds()))
}
f.Draw(tmpOut, tmpIn, &g.Options)
}
}
|
go
|
{
"resource": ""
}
|
q6069
|
prepareConvolutionWeights1d
|
train
|
func prepareConvolutionWeights1d(kernel []float32) (int, []uweight) {
size := len(kernel)
if size%2 == 0 {
size--
}
if size < 1 {
return 0, []uweight{}
}
center := size / 2
weights := []uweight{}
for i := 0; i < size; i++ {
w := float32(0)
if i < len(kernel) {
w = kernel[i]
}
if w != 0 {
weights = append(weights, uweight{i - center, w})
}
}
return size, weights
}
|
go
|
{
"resource": ""
}
|
q6070
|
convolveLine
|
train
|
func convolveLine(dstBuf []pixel, srcBuf []pixel, weights []uweight) {
max := len(srcBuf) - 1
if max < 0 {
return
}
for dstu := 0; dstu < len(srcBuf); dstu++ {
var r, g, b, a float32
for _, w := range weights {
k := dstu + w.u
if k < 0 {
k = 0
} else if k > max {
k = max
}
c := srcBuf[k]
wa := c.a * w.weight
r += c.r * wa
g += c.g * wa
b += c.b * wa
a += wa
}
if a != 0 {
r /= a
g /= a
b /= a
}
dstBuf[dstu] = pixel{r, g, b, a}
}
}
|
go
|
{
"resource": ""
}
|
q6071
|
convolve1dv
|
train
|
func convolve1dv(dst draw.Image, src image.Image, kernel []float32, options *Options) {
srcb := src.Bounds()
dstb := dst.Bounds()
if srcb.Dx() <= 0 || srcb.Dy() <= 0 {
return
}
if kernel == nil || len(kernel) < 1 {
copyimage(dst, src, options)
return
}
_, weights := prepareConvolutionWeights1d(kernel)
pixGetter := newPixelGetter(src)
pixSetter := newPixelSetter(dst)
parallelize(options.Parallelization, srcb.Min.X, srcb.Max.X, func(start, stop int) {
srcBuf := make([]pixel, srcb.Dy())
dstBuf := make([]pixel, srcb.Dy())
for x := start; x < stop; x++ {
pixGetter.getPixelColumn(x, &srcBuf)
convolveLine(dstBuf, srcBuf, weights)
pixSetter.setPixelColumn(dstb.Min.X+x-srcb.Min.X, dstBuf)
}
})
}
|
go
|
{
"resource": ""
}
|
q6072
|
convolve1dh
|
train
|
func convolve1dh(dst draw.Image, src image.Image, kernel []float32, options *Options) {
srcb := src.Bounds()
dstb := dst.Bounds()
if srcb.Dx() <= 0 || srcb.Dy() <= 0 {
return
}
if kernel == nil || len(kernel) < 1 {
copyimage(dst, src, options)
return
}
_, weights := prepareConvolutionWeights1d(kernel)
pixGetter := newPixelGetter(src)
pixSetter := newPixelSetter(dst)
parallelize(options.Parallelization, srcb.Min.Y, srcb.Max.Y, func(start, stop int) {
srcBuf := make([]pixel, srcb.Dx())
dstBuf := make([]pixel, srcb.Dx())
for y := start; y < stop; y++ {
pixGetter.getPixelRow(y, &srcBuf)
convolveLine(dstBuf, srcBuf, weights)
pixSetter.setPixelRow(dstb.Min.Y+y-srcb.Min.Y, dstBuf)
}
})
}
|
go
|
{
"resource": ""
}
|
q6073
|
CropToSize
|
train
|
func CropToSize(width, height int, anchor Anchor) Filter {
return &cropToSizeFilter{
w: width,
h: height,
anchor: anchor,
}
}
|
go
|
{
"resource": ""
}
|
q6074
|
parallelize
|
train
|
func parallelize(enabled bool, start, stop int, fn func(start, stop int)) {
procs := 1
if enabled {
procs = runtime.GOMAXPROCS(0)
}
var wg sync.WaitGroup
splitRange(start, stop, procs, func(pstart, pstop int) {
wg.Add(1)
go func() {
defer wg.Done()
fn(pstart, pstop)
}()
})
wg.Wait()
}
|
go
|
{
"resource": ""
}
|
q6075
|
splitRange
|
train
|
func splitRange(start, stop, n int, fn func(pstart, pstop int)) {
count := stop - start
if count < 1 {
return
}
if n < 1 {
n = 1
}
if n > count {
n = count
}
div := count / n
mod := count % n
for i := 0; i < n; i++ {
fn(
start+i*div+minint(i, mod),
start+(i+1)*div+minint(i+1, mod),
)
}
}
|
go
|
{
"resource": ""
}
|
q6076
|
isOpaque
|
train
|
func isOpaque(img image.Image) bool {
type opaquer interface {
Opaque() bool
}
if o, ok := img.(opaquer); ok {
return o.Opaque()
}
return false
}
|
go
|
{
"resource": ""
}
|
q6077
|
genDisk
|
train
|
func genDisk(ksize int) []float32 {
if ksize%2 == 0 {
ksize--
}
if ksize < 1 {
return []float32{}
}
disk := make([]float32, ksize*ksize)
kcenter := ksize / 2
for i := 0; i < ksize; i++ {
for j := 0; j < ksize; j++ {
x := kcenter - i
y := kcenter - j
r := math.Sqrt(float64(x*x + y*y))
if r <= float64(ksize/2) {
disk[j*ksize+i] = 1
}
}
}
return disk
}
|
go
|
{
"resource": ""
}
|
q6078
|
Set
|
train
|
func Set(ptr interface{}) error {
if reflect.TypeOf(ptr).Kind() != reflect.Ptr {
return errInvalidType
}
v := reflect.ValueOf(ptr).Elem()
t := v.Type()
if t.Kind() != reflect.Struct {
return errInvalidType
}
for i := 0; i < t.NumField(); i++ {
if defaultVal := t.Field(i).Tag.Get(fieldName); defaultVal != "-" {
if err := setField(v.Field(i), defaultVal); err != nil {
return err
}
}
}
return nil
}
|
go
|
{
"resource": ""
}
|
q6079
|
SetLogOutput
|
train
|
func SetLogOutput(w io.Writer) {
logger = log.New(w, "http: ", log.LstdFlags|log.Lmicroseconds)
}
|
go
|
{
"resource": ""
}
|
q6080
|
SetCacheMaxSize
|
train
|
func SetCacheMaxSize(sizeInMB int64) {
if sizeInMB > 0 {
iconCache = groupcache.NewGroup("icons", sizeInMB<<20, groupcache.GetterFunc(generatorFunc))
} else {
iconCache = nil
}
}
|
go
|
{
"resource": ""
}
|
q6081
|
ParseSizeRange
|
train
|
func ParseSizeRange(s string) (*SizeRange, error) {
parts := strings.SplitN(s, "..", 3)
switch len(parts) {
case 1:
size, ok := parseSize(parts[0])
if !ok {
return nil, errBadSize
}
return &SizeRange{size, size, MaxIconSize}, nil
case 3:
n1, ok1 := parseSize(parts[0])
n2, ok2 := parseSize(parts[1])
n3, ok3 := parseSize(parts[2])
if !ok1 || !ok2 || !ok3 {
return nil, errBadSize
}
if !((n1 <= n2) && (n2 <= n3)) {
return nil, errBadSize
}
return &SizeRange{n1, n2, n3}, nil
}
return nil, errBadSize
}
|
go
|
{
"resource": ""
}
|
q6082
|
FindMainColor
|
train
|
func (cf *ColorFinder) FindMainColor(img image.Image) (color.RGBA, error) {
cf.img = img
colorMap := cf.buildColorMap()
sRGB := cf.findMainColor(colorMap, 6, nil)
sRGB = cf.findMainColor(colorMap, 4, &sRGB)
sRGB = cf.findMainColor(colorMap, 2, &sRGB)
sRGB = cf.findMainColor(colorMap, 0, &sRGB)
return sRGB.rgb, nil
}
|
go
|
{
"resource": ""
}
|
q6083
|
ParseIco
|
train
|
func ParseIco(r io.Reader) (*icondir, error) {
dir := icondir{}
var err error
err = binary.Read(r, binary.LittleEndian, &dir.Reserved)
if err != nil {
return nil, err
}
err = binary.Read(r, binary.LittleEndian, &dir.Type)
if err != nil {
return nil, err
}
err = binary.Read(r, binary.LittleEndian, &dir.Count)
if err != nil {
return nil, err
}
for i := uint16(0); i < dir.Count; i++ {
entry := icondirEntry{}
e := parseIcondirEntry(r, &entry)
if e != nil {
return nil, e
}
dir.Entries = append(dir.Entries, entry)
}
return &dir, err
}
|
go
|
{
"resource": ""
}
|
q6084
|
DecodeConfig
|
train
|
func DecodeConfig(r io.Reader) (image.Config, error) {
dir, err := ParseIco(r)
if err != nil {
return image.Config{}, err
}
best := dir.FindBestIcon()
if best == nil {
return image.Config{}, errInvalid
}
return image.Config{Width: best.width(), Height: best.height()}, nil
}
|
go
|
{
"resource": ""
}
|
q6085
|
Decode
|
train
|
func Decode(r io.Reader) (image.Image, error) {
icoBytes, err := ioutil.ReadAll(r)
if err != nil {
return nil, err
}
r = bytes.NewReader(icoBytes)
dir, err := ParseIco(r)
if err != nil {
return nil, errInvalid
}
best := dir.FindBestIcon()
if best == nil {
return nil, errInvalid
}
return parseImage(best, icoBytes)
}
|
go
|
{
"resource": ""
}
|
q6086
|
RandSource
|
train
|
func (f *Fuzzer) RandSource(s rand.Source) *Fuzzer {
f.r = rand.New(s)
return f
}
|
go
|
{
"resource": ""
}
|
q6087
|
NumElements
|
train
|
func (f *Fuzzer) NumElements(atLeast, atMost int) *Fuzzer {
if atLeast > atMost {
panic("atLeast must be <= atMost")
}
if atLeast < 0 {
panic("atLeast must be >= 0")
}
f.minElements = atLeast
f.maxElements = atMost
return f
}
|
go
|
{
"resource": ""
}
|
q6088
|
MaxDepth
|
train
|
func (f *Fuzzer) MaxDepth(d int) *Fuzzer {
f.maxDepth = d
return f
}
|
go
|
{
"resource": ""
}
|
q6089
|
tryCustom
|
train
|
func (fc *fuzzerContext) tryCustom(v reflect.Value) bool {
// First: see if we have a fuzz function for it.
doCustom, ok := fc.fuzzer.fuzzFuncs[v.Type()]
if !ok {
// Second: see if it can fuzz itself.
if v.CanInterface() {
intf := v.Interface()
if fuzzable, ok := intf.(Interface); ok {
fuzzable.Fuzz(Continue{fc: fc, Rand: fc.fuzzer.r})
return true
}
}
// Finally: see if there is a default fuzz function.
doCustom, ok = fc.fuzzer.defaultFuzzFuncs[v.Type()]
if !ok {
return false
}
}
switch v.Kind() {
case reflect.Ptr:
if v.IsNil() {
if !v.CanSet() {
return false
}
v.Set(reflect.New(v.Type().Elem()))
}
case reflect.Map:
if v.IsNil() {
if !v.CanSet() {
return false
}
v.Set(reflect.MakeMap(v.Type()))
}
default:
return false
}
doCustom.Call([]reflect.Value{v, reflect.ValueOf(Continue{
fc: fc,
Rand: fc.fuzzer.r,
})})
return true
}
|
go
|
{
"resource": ""
}
|
q6090
|
Fuzz
|
train
|
func (c Continue) Fuzz(obj interface{}) {
v := reflect.ValueOf(obj)
if v.Kind() != reflect.Ptr {
panic("needed ptr!")
}
v = v.Elem()
c.fc.doFuzz(v, 0)
}
|
go
|
{
"resource": ""
}
|
q6091
|
choose
|
train
|
func (r *charRange) choose(rand *rand.Rand) rune {
count := int64(r.last - r.first)
return r.first + rune(rand.Int63n(count))
}
|
go
|
{
"resource": ""
}
|
q6092
|
randUint64
|
train
|
func randUint64(r *rand.Rand) uint64 {
return uint64(r.Uint32())<<32 | uint64(r.Uint32())
}
|
go
|
{
"resource": ""
}
|
q6093
|
Update
|
train
|
func (c *cache) Update(req *pb.FindFullHashesRequest, resp *pb.FindFullHashesResponse) {
c.Lock()
defer c.Unlock()
now := c.now()
if c.pttls == nil {
c.pttls = make(map[hashPrefix]map[ThreatDescriptor]time.Time)
c.nttls = make(map[hashPrefix]time.Time)
}
// Insert each threat match into the cache by full hash.
for _, tm := range resp.GetMatches() {
fullHash := hashPrefix(tm.GetThreat().Hash)
if !fullHash.IsFull() {
continue
}
if c.pttls[fullHash] == nil {
c.pttls[fullHash] = make(map[ThreatDescriptor]time.Time)
}
var dur time.Duration
if tmCacheDur := tm.GetCacheDuration(); tmCacheDur != nil {
dur = time.Duration(tm.GetCacheDuration().Seconds) * time.Second
} else {
dur = 0
}
td := ThreatDescriptor{
ThreatType: ThreatType(tm.ThreatType),
PlatformType: PlatformType(tm.PlatformType),
ThreatEntryType: ThreatEntryType(tm.ThreatEntryType),
}
c.pttls[fullHash][td] = now.Add(dur)
}
// Insert negative TTLs for partial hashes.
if resp.GetNegativeCacheDuration() != nil {
dur := time.Duration(resp.GetNegativeCacheDuration().Seconds) * time.Second
nttl := now.Add(dur)
for _, te := range req.GetThreatInfo().GetThreatEntries() {
partialHash := hashPrefix(te.Hash)
c.nttls[partialHash] = nttl
}
}
}
|
go
|
{
"resource": ""
}
|
q6094
|
Lookup
|
train
|
func (c *cache) Lookup(hash hashPrefix) (map[ThreatDescriptor]bool, cacheResult) {
if !hash.IsFull() {
panic("hash is not full")
}
c.Lock()
defer c.Unlock()
now := c.now()
// Check all entries to see if there *is* a threat.
threats := make(map[ThreatDescriptor]bool)
threatTTLs := c.pttls[hash]
for td, pttl := range threatTTLs {
if pttl.After(now) {
threats[td] = true
} else {
// The PTTL has expired, we should ask the server what's going on.
return nil, cacheMiss
}
}
if len(threats) > 0 {
// So long as there are valid threats, we report them. The positive TTL
// takes precedence over the negative TTL at the partial hash level.
return threats, positiveCacheHit
}
// Check the negative TTLs to see if there are *no* threats.
for i := minHashPrefixLength; i <= maxHashPrefixLength; i++ {
if nttl, ok := c.nttls[hash[:i]]; ok {
if nttl.After(now) {
return nil, negativeCacheHit
}
}
}
// The cache has no information; it is a *possible* threat.
return nil, cacheMiss
}
|
go
|
{
"resource": ""
}
|
q6095
|
Purge
|
train
|
func (c *cache) Purge() {
c.Lock()
defer c.Unlock()
now := c.now()
// Nuke all threat entries based on their positive TTL.
for fullHash, threatTTLs := range c.pttls {
for td, pttl := range threatTTLs {
if now.After(pttl) {
del := true
for i := minHashPrefixLength; i <= maxHashPrefixLength; i++ {
if nttl, ok := c.nttls[fullHash[:i]]; ok {
if nttl.After(pttl) {
del = false
break
}
}
}
if del {
delete(threatTTLs, td)
}
}
}
if len(threatTTLs) == 0 {
delete(c.pttls, fullHash)
}
}
// Nuke all partial hashes based on their negative TTL.
for partialHash, nttl := range c.nttls {
if now.After(nttl) {
delete(c.nttls, partialHash)
}
}
}
|
go
|
{
"resource": ""
}
|
q6096
|
Init
|
train
|
func (db *database) Init(config *Config, logger *log.Logger) bool {
db.mu.Lock()
defer db.mu.Unlock()
db.setError(errors.New("not intialized"))
db.config = config
db.log = logger
if db.config.DBPath == "" {
db.log.Printf("no database file specified")
db.setError(errors.New("no database loaded"))
return false
}
dbf, err := loadDatabase(db.config.DBPath)
if err != nil {
db.log.Printf("load failure: %v", err)
db.setError(err)
return false
}
// Validate that the database threat list stored on disk is not too stale.
if db.isStale(dbf.Time) {
db.log.Printf("database loaded is stale")
db.ml.Lock()
defer db.ml.Unlock()
db.setStale()
return false
}
// Validate that the database threat list stored on disk is at least a
// superset of the specified configuration.
tfuNew := make(threatsForUpdate)
for _, td := range db.config.ThreatLists {
if row, ok := dbf.Table[td]; ok {
tfuNew[td] = row
} else {
db.log.Printf("database configuration mismatch, missing %v", td)
db.setError(errors.New("database configuration mismatch"))
return false
}
}
db.tfu = tfuNew
db.generateThreatsForLookups(dbf.Time)
return true
}
|
go
|
{
"resource": ""
}
|
q6097
|
Status
|
train
|
func (db *database) Status() error {
db.ml.RLock()
defer db.ml.RUnlock()
if db.err != nil {
return db.err
}
if db.isStale(db.last) {
db.setStale()
return db.err
}
return nil
}
|
go
|
{
"resource": ""
}
|
q6098
|
UpdateLag
|
train
|
func (db *database) UpdateLag() time.Duration {
lag := db.SinceLastUpdate()
if lag < db.config.UpdatePeriod {
return 0
}
return lag - db.config.UpdatePeriod
}
|
go
|
{
"resource": ""
}
|
q6099
|
SinceLastUpdate
|
train
|
func (db *database) SinceLastUpdate() time.Duration {
db.ml.RLock()
defer db.ml.RUnlock()
return db.config.now().Sub(db.last)
}
|
go
|
{
"resource": ""
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.