code stringlengths 114 1.05M | path stringlengths 3 312 | quality_prob float64 0.5 0.99 | learning_prob float64 0.2 1 | filename stringlengths 3 168 | kind stringclasses 1
value |
|---|---|---|---|---|---|
package runtime
import (
"fmt"
"strings"
log "github.com/sirupsen/logrus"
)
// StmtType indicates the type of statement
type StmtType string
// Different statement types
const (
StmtTypeAssert StmtType = "assert"
StmtTypeAssign StmtType = "assign"
)
// Stmt statement interface
type Stmt interface {
Type() St... | internal/runtime/runtime_assertions.go | 0.540681 | 0.45744 | runtime_assertions.go | starcoder |
package ent
import (
"fmt"
"strings"
"time"
"entgo.io/ent/dialect/sql"
"github.com/vorteil/direktiv/ent/namespace"
)
// Namespace is the model entity for the Namespace schema.
type Namespace struct {
config `json:"-"`
// ID of the ent.
ID string `json:"id,omitempty"`
// Created holds the value of the "crea... | ent/namespace.go | 0.643217 | 0.438785 | namespace.go | starcoder |
package shapes
import (
. "github.com/gabz57/goledmatrix/canvas"
. "github.com/gabz57/goledmatrix/components"
)
type Circle struct {
*Graphic
center Point
radius int
fill bool
pixels []Pixel
}
func NewCircle(graphic *Graphic, center Point, radius int, fill bool) *Circle {
c := Circle{
Graphic: graphic,
... | components/shapes/circle.go | 0.723016 | 0.419113 | circle.go | starcoder |
package d10
import (
"math"
"sort"
"strings"
"github.com/jzimbel/adventofcode-go/solutions"
)
const (
// width and height of my puzzle input, used for some slight optimizations
width = 24
height = 24
)
var epsilon float64
type point struct {
x int
y int
}
type grid map[point]struct{}
// stores memoized... | solutions/y2019/d10/solution.go | 0.707708 | 0.408837 | solution.go | starcoder |
package types
import (
"github.com/PapaCharlie/go-restli/codegen/utils"
. "github.com/dave/jennifer/jen"
)
func AddEquals(def *Statement, receiver, typeName string, f func(other Code, def *Group)) *Statement {
other := Id("other")
otherInterface := Id("otherInterface")
rightHandType := Op("*").Id(typeName)
util... | codegen/types/record_equals.go | 0.631594 | 0.486697 | record_equals.go | starcoder |
package golem
import (
"fmt"
)
//////////// revisions to delta functions
func Delta_Ends(f []float64) float64 {
x := f[len(f) -1] - f[0]
return ZeroDiv(x, f[0],float64(1), float64(-1))
}
/*
*/
func Delta_Mean2End(f []float64) float64 {
mean := MeanIterable(f)
x := f[len(f) - 1] - mean
return ZeroDiv(x, mean... | golem/golem_base/ob_measure.go | 0.506836 | 0.465266 | ob_measure.go | starcoder |
package data_parser
import "math"
func Normalize(segments []Segment) (out []Segment) {
lastType := ""
cx := float64(0)
cy := float64(0)
subx := float64(0)
suby := float64(0)
lcx := float64(0)
lcy := float64(0)
for _, s := range segments {
switch s.Key {
case "M":
out = append(out, Segment{
Key: "... | data_parser/normalize.go | 0.508788 | 0.465995 | normalize.go | starcoder |
// Driver for ADAM-4000 series I/O Modules from Advantech
package adam4000
import (
"bufio"
"encoding/hex"
"fmt"
"strconv"
"strings"
"time"
)
func NewADAM4000(addr byte, rc *bufio.Reader, wc *bufio.Writer) *ADAM4000 {
var a ADAM4000
a.address = addr
a.rc = rc
a.wc = wc
a.Value = make([]float64, 8)
a.Ret... | adam4000.go | 0.555194 | 0.404713 | adam4000.go | starcoder |
package challenge16
import (
"crypto/aes"
"net/url"
"strings"
"github.com/esturcke/cryptopals-golang/bytes"
"github.com/esturcke/cryptopals-golang/crypt"
)
/*Solve challenge 16
CBC bitflipping attacks
See https://cryptopals.com/sets/2/challenges/16
Generate a random AES key.
Combine your padding code and CB... | challenge16/challenge16.go | 0.615319 | 0.441553 | challenge16.go | starcoder |
package script
// asSmallInt returns the passed opcode, which must be true according to
// isSmallInt(), as an integer.
func asSmallInt(op byte) int {
if op == OP_0 {
return 0
}
return int(op - (OP_1 - 1))
}
// isSmallInt returns whether or not the opcode is considered a small integer,
// which is an OP_0, or O... | script.go | 0.733356 | 0.412944 | script.go | starcoder |
package p1157
import "sort"
type Pair struct {
first int
second int
}
type Pairs []Pair
func (this Pairs) Len() int {
return len(this)
}
func (this Pairs) Less(i, j int) bool {
return this[i].second > this[j].second
}
func (this Pairs) Swap(i, j int) {
this[i], this[j] = this[j], this[i]
}
type Node struct... | src/leetcode/set1000/set1000/set1100/set1150/p1157/solution.go | 0.511229 | 0.467879 | solution.go | starcoder |
package dackbox
import (
clusterDackBox "github.com/stackrox/rox/central/cluster/dackbox"
cveDackBox "github.com/stackrox/rox/central/cve/dackbox"
deploymentDackBox "github.com/stackrox/rox/central/deployment/dackbox"
imageDackBox "github.com/stackrox/rox/central/image/dackbox"
componentDackBox "github.com/stackr... | central/dackbox/key_transformations.go | 0.563618 | 0.432123 | key_transformations.go | starcoder |
//go:generate genny -pkg=column -in=column_generate.go -out=column_numbers.go gen "number=float32,float64,int,int16,int32,int64,uint,uint16,uint32,uint64"
package column
import (
"fmt"
"reflect"
"sync"
"github.com/kelindar/bitmap"
"github.com/kelindar/column/commit"
)
// columnType represents a type of a colu... | column.go | 0.695235 | 0.470554 | column.go | starcoder |
package main
import (
"log"
"math"
"os"
"strconv"
"github.com/TomasCruz/projecteuler"
)
/*
Problem 62; Cubic permutations
The cube, 41063625 (345^3), can be permuted to produce two other cubes: 56623104 (384^3) and 66430125 (405^3).
In fact, 41063625 is the smallest cube which has exactly three permutations of... | 001-100/061-070/062/main.go | 0.66236 | 0.447098 | main.go | starcoder |
package tonacity
// Welcome to music theory, where nothing is unanimously agreed upon, there are multiple equivalent ways of saying the same thing, and the distance between two notes is a second.
// Evidence:
// - What physical frequency is a particular note?
// - Which C is middle C?
// - A𝄫 == G == F𝄪
// - B♭ ... | tonacity.go | 0.571647 | 0.75199 | tonacity.go | starcoder |
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed und... | stats/timeseries.go | 0.827096 | 0.513912 | timeseries.go | starcoder |
package main
import (
"fmt"
"io/ioutil"
"strings"
)
func parse(filename string) [][]byte {
bytes, err := ioutil.ReadFile(filename)
if err != nil {
panic(err)
}
lines := strings.Split(string(bytes), "\n")
result := [][]byte{}
for _, line := range lines {
result = append(result, []byte(line))
}
return... | week3/day19/main.go | 0.604282 | 0.404802 | main.go | starcoder |
package csg
import (
"fmt"
"io"
)
// NewTriangle creates a new polygon from 3 points
func NewTriangle(a *Vertex, b *Vertex, c *Vertex, plane *Plane) *Polygon {
return &Polygon{Vertices: []*Vertex{a, b, c}, Plane: plane}
}
// Polygon is a 3 dimensional polygon with 3 or more vertices
type Polygon struct {
Vertice... | csg/polygon.go | 0.774754 | 0.81409 | polygon.go | starcoder |
package codec
import (
"time"
"github.com/juju/errors"
"github.com/pingcap/tidb/mysql"
)
const (
nilFlag byte = iota
bytesFlag
compactBytesFlag
intFlag
uintFlag
floatFlag
decimalFlag
durationFlag
)
func encode(b []byte, vals []interface{}, comparable bool) ([]byte, error) {
for _, val := range vals {
... | vendor/github.com/pingcap/tidb/util/codec/codec.go | 0.550607 | 0.454291 | codec.go | starcoder |
package iterator
import (
"sync/atomic"
"github.com/apache/arrow/go/arrow"
"github.com/apache/arrow/go/arrow/array"
"github.com/go-bullseye/bullseye/internal/debug"
)
// Int64ChunkIterator is an iterator for reading an Arrow Column value by value.
type Int64ChunkIterator struct {
refCount int64
col *arra... | iterator/chunkiterator.gen.go | 0.688887 | 0.415907 | chunkiterator.gen.go | starcoder |
package simdjson
import (
"errors"
"fmt"
"math"
)
// Array represents a JSON array.
// There are methods that allows to get full arrays if the value type is the same.
// Otherwise an iterator can be retrieved.
type Array struct {
tape ParsedJson
off int
}
// Iter returns the array as an iterator.
// This can b... | parsed_array.go | 0.760295 | 0.459501 | parsed_array.go | starcoder |
package metadata
import (
"context"
"strconv"
"time"
"github.com/Netflix/p2plab/errdefs"
"github.com/pkg/errors"
bolt "go.etcd.io/bbolt"
)
type Scenario struct {
ID string
Definition ScenarioDefinition
Labels []string
CreatedAt, UpdatedAt time.Time
}
// ScenarioDefinition defines a scenario.
type Scen... | metadata/scenario.go | 0.652574 | 0.436142 | scenario.go | starcoder |
package output
import (
"github.com/Jeffail/benthos/v3/internal/docs"
"github.com/Jeffail/benthos/v3/lib/log"
"github.com/Jeffail/benthos/v3/lib/message/batch"
"github.com/Jeffail/benthos/v3/lib/metrics"
"github.com/Jeffail/benthos/v3/lib/output/writer"
"github.com/Jeffail/benthos/v3/lib/types"
sess "github.com... | lib/output/elasticsearch.go | 0.752104 | 0.497192 | elasticsearch.go | starcoder |
package math
import (
"time"
"math"
"math/rand"
"strconv"
)
// Abs
func Abs(number float64) float64 {
return math.Abs(number)
}
// Range: [0, 2147483647]
func Rand(min, max int) int {
if min > max {
// 替换
min, max = max, min
}
// 重设最大值
if int31 := 1<<31 - 1; max >... | pkg/lakego-pkg/lakego-doak/lakego/math/math.go | 0.569613 | 0.437643 | math.go | starcoder |
package cocoa
import "sync"
const SegmentCount = 64
type SegmentHashMap struct {
// length must be the power of 2
table []*Segment
// mast must be 2^n -1, for example: 0x00000000000000ff
mask int
}
func newSegmentHashMap() *SegmentHashMap {
m := &SegmentHashMap{
table: make([]*Segment, SegmentCount, SegmentC... | map.go | 0.570571 | 0.405566 | map.go | starcoder |
package core
import (
"github.com/btcsuite/btcutil/base58"
"nebulas-p2p/crypto/hash"
"nebulas-p2p/util/byteutils"
)
// AddressType address type
type AddressType byte
// address type enum
const (
AccountAddress AddressType = 0x57 + iota
ContractAddress
)
// const
const (
Padding byte = 0x19
NebulasFaith = '... | core/address.go | 0.689933 | 0.518424 | address.go | starcoder |
package encoding
// Generic converters for multibyte character sets.
// An mbcsTrie contains the data to convert from the character set to Unicode.
// If a character would be encoded as "\x01\x02\x03", its unicode value would be found at t.children[1].children[2].children[3].rune
// children either is nil or has 256 ... | mbcs.go | 0.654343 | 0.501587 | mbcs.go | starcoder |
package iconv
import (
"fmt"
"google.golang.org/protobuf/reflect/protoreflect"
"math"
"reflect"
"strconv"
)
// IsNil check interface value is nil
func IsNil(v interface{}) (isNil bool) {
if v == nil {
return true
}
vv := reflect.ValueOf(v)
switch vv.Kind() {
case
reflect.Chan,
reflect.Func,
reflect... | iconv/iconv.go | 0.53437 | 0.400691 | iconv.go | starcoder |
package behaviors
//--------------------
// IMPORTS
//--------------------
import (
"time"
"github.com/tideland/gocells/cells"
)
//--------------------
// CONSTANTS
//--------------------
const (
// TopicRate signals the rate of detected matching events.
TopicRate = "rate"
)
//--------------------
// RATE BE... | behaviors/rate.go | 0.821259 | 0.54583 | rate.go | starcoder |
package regex
import (
"fmt"
"io"
"netbsd.org/pkglint/histogram"
"regexp"
"time"
)
type Pattern string
type Registry struct {
res map[Pattern]*regexp.Regexp
rematch *histogram.Histogram
renomatch *histogram.Histogram
retime *histogram.Histogram
profiling bool
}
func NewRegistry() Registry {
re... | regex/regex.go | 0.519765 | 0.425009 | regex.go | starcoder |
package simulation
import "github.com/pointlesssoft/godevs/pkg/modeling"
type AbstractSimulator interface {
Initialize() // performs all the required operations before starting a simulation.
Exit() // performs all the required operations to exit after a simulation.
TA() floa... | pkg/simulation/abstract_simulator.go | 0.773302 | 0.450239 | abstract_simulator.go | starcoder |
package taleslabmappers
import (
"github.com/johnfercher/taleslab/internal/talespireadapter/talespirecontracts"
"github.com/johnfercher/taleslab/pkg/taleslab/taleslabdomain/taleslabconsts"
"github.com/johnfercher/taleslab/pkg/taleslab/taleslabdomain/taleslabentities"
)
func TaleSpireSlabFromAssets(assets taleslabe... | pkg/taleslab/taleslabmappers/slabmapper.go | 0.644673 | 0.426441 | slabmapper.go | starcoder |
package three
import (
"math"
"math/rand"
"strconv"
)
// NewVector3 :
func NewVector3(x, y, z float64) *Vector3 {
return &Vector3{x, y, z, true}
}
// Vector3 :
type Vector3 struct {
X float64
Y float64
Z float64
IsVector3 bool
}
var _vector3 = NewVector3(0, 0, 0)
var _quaternionV3 =... | server/three/vector3.go | 0.781289 | 0.638413 | vector3.go | starcoder |
package jade
import (
"fmt"
"runtime"
"strings"
)
// Tree is the representation of a single parsed template.
type tree struct {
Name string // name of the template represented by the tree.
ParseName string // name of the top-level template during parsing, for error messages.
Root *listNode // t... | vendor/github.com/Joker/jade/parse.go | 0.741861 | 0.417509 | parse.go | starcoder |
package waffleiron
import (
"github.com/pkg/errors"
"github.com/hashicorp/go-multierror"
)
// And returns a parser that runs p0 and then runs p1
func And[T, U any](p0 Parser[T], p1 Parser[U]) Parser[Tuple2[T, U]] {
return Parser[Tuple2[T, U]]{p: andParser[T, U]{p0, p1}}
}
type andParser[T, U any] struct {
p0 Pa... | combinator.go | 0.629205 | 0.440048 | combinator.go | starcoder |
package tester
import (
"errors"
"fmt"
"strconv"
"strings"
)
// Growth is used to determine what test should be ran next.
type Growth interface {
OnSuccess(test int) int
OnFail(test int) int
String() string
}
// LinearGrowth increases test by a specified amount with every successful test.
type LinearGrowth st... | tester/growth.go | 0.840619 | 0.430866 | growth.go | starcoder |
package fuzz
import (
"math/rand"
"time"
"github.com/go-spatial/tegola/geom"
)
func init() {
rand.Seed(time.Now().UnixNano())
}
func genNil(withNil bool) bool { return withNil && rand.Intn(100) < 2 }
// GenRandPoint will generate a random point. It is possible that the point may be nil.
func GenRandPoint() *ge... | geom/encoding/wkt/internal/cmd/fuzz/fuzz/fuzz.go | 0.601359 | 0.580084 | fuzz.go | starcoder |
package main
import (
"sync"
"github.com/dhconnelly/rtreego"
"github.com/gravestench/mathlib"
"github.com/hajimehoshi/ebiten/v2"
)
const (
fWidth = float64(Width)
fHeight = float64(Height)
)
type Game struct {
boidCount int
boids []*Boid
tick int
pixels []byte
}
func (g *Game) Update() error... | game.go | 0.593374 | 0.4474 | game.go | starcoder |
package algebra
import (
"fmt"
"image/color"
"math"
)
type Vector3 struct {
X MnFloat
Y MnFloat
Z MnFloat
}
var (
ZeroVector3 = Vector3{0, 0, 0}
UpVector3 = Vector3{0, 1, 0}
RightVector3 = Vector3{1, 0, 0}
ForwardVector3 = Vector3{0, 0, -1}
)
func (v Vector3) Dump() Vector3 {
fmt.Println(fmt.Sprintf("X... | algebra/vector3.go | 0.871461 | 0.688884 | vector3.go | starcoder |
package alt
import (
"strconv"
"time"
"github.com/ngjaying/ojg/gen"
)
// String converts the value provided to a string. If conversion is not
// possible such as if the provided value is an array then the first option
// default value is returned or if not provided and empty string is
// returned. If the type is... | alt/string.go | 0.547222 | 0.407157 | string.go | starcoder |
package mathg
import "math"
// Useful functions for physics/graphics
func QuadraticEaseOut(f float64) float64 {
return -f * (f - 2.)
}
func QuadraticEaseIn(f float64) float64 {
return f * f
}
func QuadraticEaseInOut(f float64) float64 {
a := 0.
if f < 0.5 {
a = 2. * f * f
} else {
a = -2.*f*f + 4.*f - 1.
... | ease.go | 0.801392 | 0.581184 | ease.go | starcoder |
package math
import (
stdmath "math"
"reflect"
"time"
)
// Mean returns the mean value from the array or slice of ints, floats, or durations.
// For durations, returns the average duration.
// For ints and floats, returns a float64.
func Mean(in interface{}) (interface{}, error) {
switch in := in.(type) {
case... | pkg/math/Mean.go | 0.759493 | 0.440469 | Mean.go | starcoder |
package main
import (
"fmt"
"io/ioutil"
"os"
"regexp"
"strings"
)
const WHITE = 0
const BLACK = 1
const SW = "sw"
const W = "w"
const NW = "nw"
const NE = "ne"
const E = "e"
const SE = "se"
type Hex struct {
id int
color int
neighbor map[string]*Hex
}
func NewHex() *Hex {
this :... | advent_of_code/2020/day-24b/day-24b.go | 0.640299 | 0.414247 | day-24b.go | starcoder |
package activation
import (
"math"
"math/rand"
"github.com/dowlandaiello/eve/common"
)
// Condition represents a type of condition regarding a link.
type Condition int
// ConditionalLinkInitializationOption is an initialization option used to
// modify a conditional link's behavior.
type ConditionalLinkInitializ... | activation/conditional_link.go | 0.799286 | 0.510252 | conditional_link.go | starcoder |
package main
//. Matches any character except a newline
//[.] Matches .
//* Matches the preceding pattern element >=0 times, the same as {1,}
//+ Matches the proceding pattern element >0 times, the same as {0,}
//? Matches the proceding pattern element 0 or 1 time, the same as {0,1}
//{M,N} Matches the proceding patte... | main/regex.go | 0.554712 | 0.523116 | regex.go | starcoder |
package graphsample4
import "github.com/wangyoucao577/algorithms_practice/graph"
/* This sample directed graph comes from
"Introduction to Algorithms - Third Edition" 22.5 strongly connected component
V = 8 (node count)
E = 13 (edge count)
define directed graph G(V,E) as below:
a(0) -> b(1) → c(2) ← → d(3)
... | graphsamples/graphsample4/sample4.go | 0.742515 | 0.454472 | sample4.go | starcoder |
package main
import (
"fmt"
"math"
"testing"
)
func floatify(value interface{}) float64 {
switch value.(type) {
case int:
return float64(value.(int))
case int16:
return float64(value.(int16))
case int32:
return float64(value.(int32))
case int64:
return float64(value.(int64))
case uint:
return float... | core/utilities.go | 0.683736 | 0.578835 | utilities.go | starcoder |
package hamming
import "strconv"
// References: check out Hacker's Delight, about p. 70
func table() [256]uint8 {
return [256]uint8{
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4... | popcount.go | 0.580828 | 0.742678 | popcount.go | starcoder |
package wavelettree
import (
"github.com/hillbig/rsdic"
"github.com/ugorji/go/codec"
)
func New() WaveletTree {
return &waveletMatrix{
layers: make([]rsdic.RSDic, 0),
dim: 0,
num: 0,
blen: 0}
}
type waveletMatrix struct {
layers []rsdic.RSDic
dim uint64
num uint64
blen uint64 // =len(... | waveletMatrix.go | 0.506591 | 0.730638 | waveletMatrix.go | starcoder |
package treap
import (
"constraints"
"github.com/Tv0ridobro/data-structure/math"
"math/rand"
)
// Treap represents a treap
// Zero value of Treap is invalid treap, should be used only with New() or NewWithSource()
type Treap[T any] struct {
comp func(T, T) int
rand *rand.Rand
root *Node[T]
}
// New returns an ... | treap/treap.go | 0.746971 | 0.479016 | treap.go | starcoder |
package toy
import (
"fmt"
"math/big"
C "github.com/armfazh/tozan-ecc/curve"
GF "github.com/armfazh/tozan-ecc/field"
)
// ID is an identifier of a toy curve.
type ID string
const (
W0 ID = "W0"
W1 ID = "W1"
W1ISO ID = "W1ISO"
W2 ID = "W2"
W3 ID = "W3"
W4 ID = "W4"
WC0 ID = "WC0"
M0 I... | curve/toy/toy.go | 0.680135 | 0.408395 | toy.go | starcoder |
package brotli
import "encoding/binary"
/* Copyright 2010 Google Inc. All Rights Reserved.
Distributed under MIT license.
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
*/
/* A (forgetful) hash table to the data seen by the compressor, to
help create backward references to previ... | vendor/github.com/andybalholm/brotli/h5.go | 0.640748 | 0.425426 | h5.go | starcoder |
package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
type cardinalDir int
const (
north cardinalDir = iota
east
south
west
)
type turn int
const (
left turn = iota
right
)
type position struct {
x int
y int
}
type ship struct {
curPos position
facing cardinalDir
}
func (s *ship) move(dir cardinalD... | day12/pt1.go | 0.561936 | 0.447279 | pt1.go | starcoder |
package matchers
import "bytes"
// Zip matches a zip archive.
func Zip(in []byte) bool {
return len(in) > 3 &&
in[0] == 0x50 && in[1] == 0x4B &&
(in[2] == 0x3 || in[2] == 0x5 || in[2] == 0x7) &&
(in[3] == 0x4 || in[3] == 0x6 || in[3] == 0x8)
}
// Odt matches an OpenDocument Text file.
func Odt(in []byte) bool... | vendor/github.com/gabriel-vasile/mimetype/internal/matchers/zip.go | 0.602997 | 0.466785 | zip.go | starcoder |
package mat
import (
"math"
)
// Vector4 is 1x4 matrix for 3D transformations and coordinate representation.
type Vector4 [4]float64
// Matrix4 is 4x4 matrix for 3D transformations.
type Matrix4 [16]float64
var Identity4 = Matrix4{
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1,
}
// DotMatrix calculates dot ... | pkg/mat/mat4.go | 0.771585 | 0.624379 | mat4.go | starcoder |
package mapping
import (
"fmt"
"github.com/Jeffail/benthos/v3/lib/bloblang/x/query"
"github.com/Jeffail/benthos/v3/lib/types"
"github.com/Jeffail/gabs/v2"
)
//------------------------------------------------------------------------------
// AssignmentContext contains references to all potential assignment
// de... | lib/bloblang/x/mapping/assignment.go | 0.558207 | 0.404155 | assignment.go | starcoder |
package canvas
import (
"fmt"
"math"
)
type vec [2]float64
func (v vec) String() string {
return fmt.Sprintf("[%f,%f]", v[0], v[1])
}
func (v vec) add(v2 vec) vec {
return vec{v[0] + v2[0], v[1] + v2[1]}
}
func (v vec) sub(v2 vec) vec {
return vec{v[0] - v2[0], v[1] - v2[1]}
}
func (v vec) mul(v2 vec) vec {
... | math.go | 0.804214 | 0.458409 | math.go | starcoder |
package rbxmk
import (
"fmt"
lua "github.com/anaminus/gopher-lua"
"github.com/anaminus/rbxmk/rtypes"
"github.com/robloxapi/types"
)
// FrameType indicates the kind of frame for a State.
type FrameType uint8
const (
// Frame is a regular function.
FunctionFrame FrameType = iota
// Frame is a method; exclude f... | state.go | 0.716119 | 0.468487 | state.go | starcoder |
package main
// Homework:
// Loading other kinds of images
// Add this to pong, use images for the paddles and ball
// See if you can speed up alphablending
import (
"fmt"
"github.com/jackmott/noise"
"github.com/veandco/go-sdl2/sdl"
"image/png"
"os"
"time"
)
const winWidth, winHeight int = 800, 600
type textu... | balloons/balloons.go | 0.676086 | 0.465691 | balloons.go | starcoder |
package expression
import (
"fmt"
"time"
)
type expr interface {
exprNode()
KernelString() string
String() string
}
type (
identExpr struct {
name string
}
valueExpr struct {
v interface{}
}
binaryExpr struct {
x expr
y expr
op binaryOp
}
unaryExpr struct {
x expr
op unaryOp
}
)
f... | pkg/expression/ast.go | 0.574156 | 0.422922 | ast.go | starcoder |
package oak
import (
"image"
"image/draw"
)
// A Background can be used as a background draw layer. Backgrounds will be drawn as the first
// element in each frame, and are expected to cover up data drawn on the previous frame.
type Background interface {
GetRGBA() *image.RGBA
}
// DrawLoop
// Unless told to stop... | drawLoop.go | 0.615666 | 0.472501 | drawLoop.go | starcoder |
package neural
// Layer is a set of neurons + config
type Layer struct {
// Amount of inputs (default is previous layer units)
Inputs int `json:"-"`
Units int `json:"-"`
Neurons []*Neuron `json:"Neurons"`
// Default activation is sigmoid
Activation string `json:"Activation,omitempty"`
Forward... | layer.go | 0.830113 | 0.44059 | layer.go | starcoder |
package genfuncs
import (
"strings"
)
// All returns true if all elements of slice match the predicate.
func All[T any](slice []T, predicate Predicate[T]) bool {
for _, e := range slice {
if !predicate(e) {
return false
}
}
return true
}
// Any returns true if any element of the slice matches the predicat... | slice.go | 0.865309 | 0.505188 | slice.go | starcoder |
package onshape
import (
"encoding/json"
)
// BTSMDefinitionEntityTypeFilter1651 struct for BTSMDefinitionEntityTypeFilter1651
type BTSMDefinitionEntityTypeFilter1651 struct {
BTQueryFilter183
BtType *string `json:"btType,omitempty"`
SmDefinitionEntityType *string `json:"smDefinitionEntityType,omitempty"`
}
// N... | onshape/model_btsm_definition_entity_type_filter_1651.go | 0.690559 | 0.432902 | model_btsm_definition_entity_type_filter_1651.go | starcoder |
package ast
import (
"bytes"
"github.com/butlermatt/monlox/token"
"strings"
)
// Node is a node within the AST tree.
type Node interface {
// TokenLiteral returns the string literal of the token associated with this ast node.
TokenLiteral() string
String() string
}
// Statement represents an AST statement nod... | ast/ast.go | 0.841956 | 0.440469 | ast.go | starcoder |
package set
// Clone returns a new Set with the same contents as this one.
func (s Set[T]) Clone() Set[T] {
ns := New[T]()
for k := range s {
ns[k] = struct{}{}
}
return ns
}
// Add adds the given value to the Set.
func (s Set[T]) Add(v T) {
s[v] = struct{}{}
}
// Remove removes the given value from the Set.
... | collections/set/methods.go | 0.872102 | 0.563738 | methods.go | starcoder |
package main
import (
"fmt"
"io/ioutil"
"log"
"strings"
"strconv"
"math"
)
type Pair struct {
X, Y int64
}
func main() {
// read input
data, err := ioutil.ReadFile("input.txt")
handleError(err)
// parse input
wires := strings.Split(string(data), "\n")
wire1 := wires[0]
wire2 := wires[1]
... | 2019/3/part2/main.go | 0.50293 | 0.428532 | main.go | starcoder |
package entity
import "time"
type User struct {
ID uint64 `json:"id"`
Name string `json:"name"`
Sex string `json:"sex"`
Age int `json:"age"`
SkillID uint64 `json:"skillID"`
SkillRank int `json:"skillRank"`
GroupID uint64 `json:"groupID"`
WorldID uint64... | _example/04_dao_plugin/entity/user.go | 0.571527 | 0.438244 | user.go | starcoder |
package kgo
import (
"encoding/json"
"fmt"
"log"
"strconv"
"strings"
"text/template"
"time"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
)
func inc(i int) int {
return i + 1
}
func dec(i int) int {
return i - 1
}
func mod(i, d int) int {
return i % d
}
func fmul(x, y... | api.go | 0.536313 | 0.434281 | api.go | starcoder |
package tokei
import (
"sort"
"time"
)
// Schedule represents the schedule on which the job will fire for a given timezone.
type Schedule struct {
location *time.Location
// Cache these ranges on creation to avoid allocations in Next()
month, dayOfMonth, dayOfWeek, hours, minutes []int
}
// NewSchedule creates... | schedule.go | 0.788868 | 0.534612 | schedule.go | starcoder |
package path
import (
"path/filepath"
"strings"
)
// Path is a slice of string segments, representing a filesystem path.
type Path []string
// Split cleans and splits the system-delimited filesystem path.
func New(s string) Path {
s = filepath.ToSlash(filepath.Clean(s))
switch {
case s == "", s == ".":
return... | path/path.go | 0.645567 | 0.445952 | path.go | starcoder |
package actions
import (
"github.com/LindsayBradford/crem/internal/pkg/model/action"
"github.com/LindsayBradford/crem/internal/pkg/model/planningunit"
)
const RiverBankRestorationType action.ManagementActionType = "RiverBankRestoration"
func NewRiverBankRestoration() *RiverBankRestoration {
return new(RiverBankR... | internal/pkg/model/models/catchment/actions/RiverBankRestoration.go | 0.769773 | 0.64197 | RiverBankRestoration.go | starcoder |
package geojson
import (
"fmt"
"math"
)
func decodeBoundingBox(bb interface{}) ([]float64, error) {
if bb == nil {
return nil, nil
}
switch f := bb.(type) {
case []float64:
return f, nil
case []interface{}:
bb := make([]float64, 0, 4)
for _, v := range f {
switch c := v.(type) {
case float64:
... | boundingbox.go | 0.70791 | 0.440108 | boundingbox.go | starcoder |
package impl
import (
"bytes"
"math"
)
// This defines the constant margin of error when transforming possible float
// values into another kind.
const dynintEpsilon = 1e-9
// LudwiegDynInt is used to represent an integer field with varying size,
// automatically setting its precision on-the-fly.
type LudwiegDynIn... | impl/type_dynint.go | 0.73914 | 0.411879 | type_dynint.go | starcoder |
package unionfind
// UnionFind is the interface a union-find data type.
type UnionFind interface {
Union(int, int)
Find(int) (int, bool)
IsConnected(int, int) bool
Count() int
}
type quickFind struct {
count int // number of components (equivalence classes)
id []int // determines component IDs (class repre... | unionfind/unionfind.go | 0.794863 | 0.483526 | unionfind.go | starcoder |
package phomath
import "math"
type Vector4Like interface {
Vector2Like
Vector3Like
XYZW() (x, y, z, w float64)
}
// static check that Vector4 is Vector4Like
var _ Vector4Like = &Vector4{}
// NewVector4 creates a new Vector4
func NewVector4(x, y, z, w float64) *Vector4 {
return &Vector4{
X: x,
Y: y,
Z: z,
... | phomath/vector4.go | 0.921481 | 0.810066 | vector4.go | starcoder |
package iavl
import (
"bytes"
"github.com/pkg/errors"
)
// PathToKey represents an inner path to a leaf node.
// Note that the nodes are ordered such that the last one is closest
// to the root of the tree.
type PathToKey struct {
InnerNodes []proofInnerNode `json:"inner_nodes"`
}
func (p *PathToKey) String() st... | .vendor/src/github.com/tendermint/iavl/path.go | 0.743913 | 0.52342 | path.go | starcoder |
package graphql
// UnionConfig provides specification to define a Union type. It is served as a convenient way to
// create a UnionTypeDefinition for creating a union type.
type UnionConfig struct {
ThisIsTypeDefinition
// Name of the defining Union
Name string
// Description for the Union type
Description stri... | graphql/union.go | 0.860589 | 0.492859 | union.go | starcoder |
package machine
import (
"fmt"
"math/rand"
)
// Default values for rotor properties.
const (
DefaultPosition = 0
DefaultStep = 1
DefaultCycle = 26
)
// Rotor represents a mechanical rotor used in xenigma. A rotor contains connections
// used to make electric pathways and generate a path through the machi... | pkg/machine/rotor.go | 0.824709 | 0.446495 | rotor.go | starcoder |
package entity
import (
"go.knocknote.io/rapidash"
"golang.org/x/xerrors"
"time"
)
type User struct {
ID uint64 `json:"id"`
Name string `json:"name"`
Sex string `json:"sex"`
Age int `json:"age"`
SkillID uint64 `json:"skillID"`
SkillRank int `json:"skillRank"... | _example/05_rapidash_plugin/entity/user.go | 0.538012 | 0.426083 | user.go | starcoder |
package ast
// Node is the interface implemented by all nodes in the AST. It
// provides information about the span of this AST node in terms
// of location in the source file. It also provides information
// about all prior comments (attached as leading comments) and
// optional subsequent comments (attached as trail... | ast/node.go | 0.565539 | 0.558086 | node.go | starcoder |
package xxtea
import (
"encoding/binary"
"errors"
)
const (
_Delta = 0x9e3779b9
)
// Decrypt is used to decode data stream from key
func Decrypt(data []byte, key []byte) ([]byte, error) {
if data == nil || key == nil || len(data) == 0 || len(key) == 0 {
return nil, errors.New("data or key is nill or 0-length")... | xxtea.go | 0.500732 | 0.413536 | xxtea.go | starcoder |
package data
import (
"encoding/json"
"errors"
)
// MappingType is an enum for possible MappingDef Types
type MappingType int
const (
// MtAssign denotes an attribute to attribute assignment
MtAssign MappingType = 1
// MtLiteral denotes a literal to attribute assignment
MtLiteral MappingType = 2
// MtExpres... | core/data/mapping.go | 0.662687 | 0.430866 | mapping.go | starcoder |
package algorithms
import (
"sort"
)
// Interface is the interface used by the algorithms.
type Interface interface {
sort.Interface
// Set stores the value located at b[j] to a[i].
Set(i int, a Interface, j int, b Interface)
// Slice returns a slice (e.g., s[i:j]) of the object.
Slice(i, j int) Interface
... | pkg/kf/algorithms/algorithms.go | 0.792825 | 0.40645 | algorithms.go | starcoder |
package tree
/*
# Number of Islands
# https://leetcode.com/explore/interview/card/top-interview-questions-medium/108/trees-and-graphs/792/
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or verti... | interview/medium/tree/graphs.go | 0.78037 | 0.492127 | graphs.go | starcoder |
package token
type Type int
const (
InvalidType Type = 1 << iota
KeywordType // keyword, e.g. "function", "end"
LiteralType // literal, e.g. 2.34, "a string", false
MarkerType // marker for tables, groupings, etc; e.g. {, (
OperatorType // operator, e.g. +, ==, &
IdentifierType // identifier, e.g. ... | token/types.go | 0.506591 | 0.433682 | types.go | starcoder |
package values
import "math"
func Add(a, b Scalar) Scalar {
if a.IsFloat() || b.IsFloat() {
return ScFloat(a.Float()+b.Float())
} else {
return ScInt(a.Integer()+b.Integer())
}
}
func Sub(a, b Scalar) Scalar {
if a.IsFloat() || b.IsFloat() {
return ScFloat(a.Float()-b.Float())
} else {
return ScInt(a.In... | values/funcs.go | 0.663778 | 0.642517 | funcs.go | starcoder |
package reflect
import (
"bytes"
"reflect"
)
// IsBlank defined
func IsBlank(value reflect.Value) bool {
switch value.Kind() {
case reflect.String:
return value.Len() == 0
case reflect.Bool:
return !value.Bool()
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return value.Int(... | platform/util/reflect/reflect.go | 0.544317 | 0.574007 | reflect.go | starcoder |
package points
import (
"math"
"sort"
"github.com/go-spatial/tegola/maths"
)
// Extent describes a retangular region.
type Extent [2][2]float64
func (e Extent) TopLeft() [2]float64 { return e[0] }
func (e Extent) TopRight() [2]float64 { return [2]float64{e[1][0], e[0][1]} }
func (e Extent) LowerRight() [2]f... | maths/points/extent.go | 0.76145 | 0.677452 | extent.go | starcoder |
package main
import (
"flag"
"fmt"
"image"
"image/color"
"image/png"
"log"
"os"
"strconv"
"github.com/llgcode/draw2d/draw2dimg"
)
const docString = `
funnel creates a scaled funnel graph based on percentage sizes by segment.
USAGE: funnel -width [width] -height [height] -out [filename] [entries...]
PARAM... | funnel.go | 0.601711 | 0.434281 | funnel.go | starcoder |
package zostate
// EventType represents all events that exist in the state machine.
type EventType string
// StateType represents all states that exist in the state machine.
type StateType string
// state represents the configuration of a state in the machine, one of which is the transitions.
type state struct {
//... | zostate.go | 0.848251 | 0.794982 | zostate.go | starcoder |
package scene
import (
"encoding/json"
"fmt"
"io/ioutil"
"math"
"github.com/ProjectMOA/goraytrace/camera"
"github.com/ProjectMOA/goraytrace/image"
"github.com/ProjectMOA/goraytrace/lighting"
"github.com/ProjectMOA/goraytrace/maputil"
"github.com/ProjectMOA/goraytrace/math3d"
"github.com/ProjectMOA/goraytrac... | scene/scene.go | 0.758332 | 0.48249 | scene.go | starcoder |
package expression
import "github.com/juju/errors"
// Visitor represents a visitor pattern.
type Visitor interface {
// VisitBetween visits Between expression.
VisitBetween(b *Between) (Expression, error)
// VisitBinaryOperation visits BinaryOperation expression.
VisitBinaryOperation(o *BinaryOperation) (Expres... | expression/visitor.go | 0.71889 | 0.487795 | visitor.go | starcoder |
package techan
import "github.com/sdcoffey/big"
// Position is a pair of two Order objects
type Position struct {
orders [2]*Order
stopLossPrice big.Decimal
takeProfitPrice big.Decimal
}
// NewPosition returns a new Position with the passed-in order as the open order
func NewPosition(openOrder Order, s... | position.go | 0.752104 | 0.433742 | position.go | starcoder |
package graph
import (
"sort"
"github.com/charypar/monobuild/set"
)
// Graph is a DAG with string labeled vertices and int colored edges
type Graph struct {
edges map[string]Edges
}
// New creates a new Graph from a map of the shape
// string: Edge
// where Edge is a struct with a Label and a Colour
func New(gra... | graph/graph.go | 0.781997 | 0.590189 | graph.go | starcoder |
package main
import (
"log"
"fmt"
"os"
)
func parabola(x float64) float64 {
return x * x
}
func line(x float64) float64 {
return 2 - x
}
func main() {
var x float64 = 1.0
var y float64 = 1.0
log.Println("Enter X")
fmt.Fscan(os.Stdin, &x)
log.Println("Enter Y")
fmt.Fscan(os.... | sasha.go | 0.63409 | 0.47384 | sasha.go | starcoder |
package gobits
import (
"encoding/binary"
"math"
)
type pos struct {
byteOffset int64
bitOffset byte
}
type PosWrapper struct {
pos
}
type BitStream struct {
ba ByteAccessor
pos
}
func lowerBits(byt, count byte) byte {
return byt & ((1 << count) - 1)
}
func higherBits(byt, count byte) byte {
shift := 8 ... | bitstream.go | 0.596433 | 0.408631 | bitstream.go | starcoder |
package strformat
import (
"math"
"strconv"
"strings"
)
/*
StrFormat package -> Numerals
ver 1.0 - 2019-03-18
by <NAME>
This package contains useful function to print number to text
*/
type Numeral struct {
// SplitDigit is how many digits will be taken until the conversion repeat
SplitDigit int
// Conver... | strformat/numerals.go | 0.586996 | 0.580887 | numerals.go | starcoder |
package model
import (
"fmt"
"math/rand"
"time"
)
/***** Constants *****/
const (
// BoardSize is the default size of the board
BoardSize = 4
)
/***** Types *****/
// Tile represents a single tile value on the board.
type Tile uint32
// Score represents the user's score
type Score uint32
// Grid represents ... | src/g048/model/board.go | 0.735926 | 0.576125 | board.go | starcoder |
package rgo
// CreateZeros creates a matrix of the given dimensions in which every element is 0. If the given dimensions
// are nonsensical (negative, for example) it will return an InvalidIndex error.
func CreateZeros(Nrow, Ncol int) (*Matrix, error) {
if Nrow <= 0 || Ncol <= 0 {
return nil, InvalidIndex
}
//cre... | matrixCreation.go | 0.824674 | 0.808748 | matrixCreation.go | starcoder |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.