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 assert
import (
"testing"
)
// Assertion是对testing.T进行了简单的封装。
// 可以以对象的方式调用包中的各个断言函数,
// 减少了参数t的传递。
type Assertion struct {
t *testing.T
}
// 返回Assertion对象。
func New(t *testing.T) *Assertion {
return &Assertion{t: t}
}
// 返回testing.T对象
func (a *Assertion) T() *testing.T {
return a.t
}
func (a *Assertio... | at-web/vendor/github.com/caixw/lib.go/assert/assertion.go | 0.507324 | 0.481393 | assertion.go | starcoder |
package ast
// Visitor defines the interface for iterating AST elements. The Visit function
// can return a Visitor w which will be used to visit the children of the AST
// element v. If the Visit function returns nil, the children will not be
// visited.
type Visitor interface {
Visit(v interface{}) (w Visitor)
}
... | vendor/github.com/open-policy-agent/opa/ast/visit.go | 0.722135 | 0.576184 | visit.go | starcoder |
Vitess
Vitess is an SQL middleware which turns MySQL/MariaDB into a fast, scalable and
highly-available distributed database.
For more information, visit http://www.vitess.io.
Example
Using this SQL driver is as simple as:
import (
"time"
"github.com/gitql/vitess/go/vt/vitessdriver"
)
func main() {
... | go/vt/vitessdriver/doc.go | 0.842215 | 0.656823 | doc.go | starcoder |
package qb
import (
"bytes"
)
// op specifies Cmd operation type.
type op byte
const (
eq op = iota
lt
leq
gt
geq
in
cnt
cntKey
like
)
// Cmp if a filtering comparator that is used in WHERE and IF clauses.
type Cmp struct {
op op
column string
value value
}
func (c Cmp) writeCql(cql *bytes.Buffe... | qb/cmp.go | 0.613237 | 0.417093 | cmp.go | starcoder |
package flate
// We limit how far copy back-references can go, the same as the C++ code.
const maxOffset = 1 << 15
// emitLiteral writes a literal chunk and returns the number of bytes written.
func emitLiteral(dst *tokens, lit []byte) {
ol := dst.n
for i, v := range lit {
dst.tokens[i+ol] = token(v)
}
dst.n +... | Godeps/_workspace/src/github.com/klauspost/compress/flate/snappy.go | 0.72086 | 0.538437 | snappy.go | starcoder |
以下为基本格式,
File header section
The file header contains the basic properties of the image.
Table 2–7: File header
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Length | Name | Descri... | imageviewer/psdReader.go | 0.58261 | 0.605391 | psdReader.go | starcoder |
package SQLParser
func (this *StatementsParse) Accept(visitor IMSTreeVisitor) interface{} {
switch t := visitor.(type) {
case ISQLQueryTreeVisitor:
return t.VisitStatementsParse(this)
default:
return t.VisitChildren(this)
}
}
func (this *StatementParse) Accept(visitor IMSTreeVisitor) interface{} {
switch t :=... | SQLParser/visitorcodegenerated.go | 0.661267 | 0.441191 | visitorcodegenerated.go | starcoder |
package redis
import (
_mock "github.com/stretchr/testify/mock"
)
type Mock struct {
_mock.Mock
}
func (r *Mock) Ping() error {
return r.Called().Error(0)
}
//--- Keys
func (r *Mock) Exists(key string) bool {
return r.Called(key).Bool(0)
}
func (r *Mock) Keys(pattern string) []string {
return r.Called(patter... | cache/redis/redis_mock.go | 0.7874 | 0.487612 | redis_mock.go | starcoder |
package pixelate
import (
"image"
"image/color"
"math"
"hawx.me/code/img/channel"
"hawx.me/code/img/utils"
)
// Vxl pixelates the Image into isometric cubes. It averages the colours and
// naïvely darkens and lightens the colours to mimic highlight and shade.
func Vxl(img image.Image, height int, flip bool, top... | pixelate/vxl.go | 0.724481 | 0.495911 | vxl.go | starcoder |
package iso20022
// Specifies rates related to a corporate action option.
type CorporateActionRate5 struct {
// Rate used for additional tax that cannot be categorised.
AdditionalTax *RateAndAmountFormat3Choice `xml:"AddtlTax,omitempty"`
// Rate used to calculate the amount of the charges/fees that cannot be cate... | CorporateActionRate5.go | 0.895717 | 0.58818 | CorporateActionRate5.go | starcoder |
package benchmark
import (
"reflect"
"testing"
)
func isBoolToUint8FuncCalibrated(supplier func() bool) bool {
return isCalibrated(reflect.Bool, reflect.Uint8, reflect.ValueOf(supplier).Pointer())
}
func isIntToUint8FuncCalibrated(supplier func() int) bool {
return isCalibrated(reflect.Int, reflect.Uint8, reflec... | common/benchmark/08_to_uint8_func.go | 0.708717 | 0.612484 | 08_to_uint8_func.go | starcoder |
package faker
import (
"math"
"reflect"
"time"
)
type Date struct {
time.Time
}
// Past_ Generate past date It takes two argument yearsAgo and ref date
func (d *Date) Pastʹ(params ...interface{}) time.Time {
//years, ref := d.validate(params...)
years := 1
ref := time.Now()
types := typeOf(params...)
if ... | date.go | 0.626924 | 0.469277 | date.go | starcoder |
package mem
import (
"errors"
"io"
)
// MultiPager is a memory device that can be composed of multiple memory devices.
type MultiPager struct {
rws []io.ReadWriteSeeker
devMax []int
devLastPos int
devPos int
devIdx int
pos int
maxLen int
}
// Join will join the given memory devices into a single devi... | driver/mem/multipager.go | 0.559049 | 0.42925 | multipager.go | starcoder |
package react
// basic represents a simple value with no other properties
type basic struct {
value int // the value of this given cell
e *engine // the pointer back to our main engine
}
// Value simply returns the set value for this basic cell
func (b basic) Value() int {
return b.value
}
// input repre... | react/cells.go | 0.826712 | 0.532425 | cells.go | starcoder |
package storetest
import (
"math/rand"
"reflect"
"testing"
"time"
"github.com/savaki/kstreams"
"github.com/tj/assert"
)
const (
letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
)
func init() {
rand.Seed(time.Now().UnixNano())
}
func alphaN(n int) string {
b := make([]byte, n)
for i := ra... | storetest/storetest.go | 0.623148 | 0.664357 | storetest.go | starcoder |
package scene
import "github.com/mokiat/gomath/dprec"
type Triangle struct {
P1 dprec.Vec3
P2 dprec.Vec3
P3 dprec.Vec3
TextureName string
}
func (t Triangle) Line1() Line {
return Line{
P1: t.P1,
P2: t.P2,
}
}
func (t Triangle) Line2() Line {
return Line{
P1: t.P2,
P2: t.P3... | cmd/softgfx-lvlgen/internal/scene/triangle.go | 0.80502 | 0.658352 | triangle.go | starcoder |
package text
import (
"bufio"
"bytes"
"fmt"
"io"
"strings"
)
type Cell struct {
contents string
feed bool
}
type GridWriter struct {
ColumnPadding int
MinWidth int
Grid [][]Cell
CurrentRow int
colWidths []int
}
func max(a, b int) int {
if a > b {
return a
}
return b
}
// i... | src/mongo/gotools/common/text/grid.go | 0.63273 | 0.420838 | grid.go | starcoder |
package main
import (
"fmt"
"strings"
)
//Index returns the first index of the target string, or -1 if no match is found.
func Index(values []string, target string) int {
for index, value := range values {
if value == target {
return index
}
}
return -1
}
//Include ret... | 41-collection-functions.go | 0.845481 | 0.48054 | 41-collection-functions.go | starcoder |
package pair
import (
"fmt"
"reflect"
"sort"
)
// Pair is a struct combines two variables
// variables could be distinct type
// motivation comes from pair in STL utility in C++
type Pair struct {
First interface{}
Second interface{}
}
// Pairs is a wrapper for slice of pair
// has basic sort method
type Pairs... | pair.go | 0.669637 | 0.402451 | pair.go | starcoder |
package tilepix
import (
"fmt"
"math"
"github.com/faiface/pixel"
)
/*
_____ _ _
|_ _(_) |___
| | | | / -_)
|_| |_|_\___|
*/
// Tile is a TMX file structure which holds a Tiled tile.
type Tile struct {
ID ID `xml:"id,attr"`
Image *Image `xml:"image"`
// ObjectGroup is set if objects have been... | tile.go | 0.757077 | 0.463019 | tile.go | starcoder |
package engine
import "time"
var (
position1FEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
position1Table = []PerftData{
PerftData{depth: 0, nodes: 1, captures: 0, enPassants: 0, castles: 0, promotions: 0, checks: 0, mates: 0},
PerftData{depth: 1, nodes: 20, captures: 0, enPassants: 0, castle... | engine/perft.go | 0.620047 | 0.483587 | perft.go | starcoder |
package executetest
import (
"errors"
"github.com/influxdata/flux"
"github.com/influxdata/flux/execute"
"github.com/influxdata/flux/plan"
)
// ToTestKind represents an side-effect producing kind for testing
const ToTestKind = "to-test"
// ToProcedureSpec defines an output operation. That is, an
// operation tha... | execute/executetest/output.go | 0.701406 | 0.455986 | output.go | starcoder |
package draw2d
import (
"code.google.com/p/freetype-go/freetype/raster"
)
type VertexAdder struct {
command VertexCommand
adder raster.Adder
}
func NewVertexAdder(adder raster.Adder) *VertexAdder {
return &VertexAdder{VertexNoCommand, adder}
}
func (vertexAdder *VertexAdder) NextCommand(cmd VertexCommand) {
... | draw2d/path_adder.go | 0.582966 | 0.428473 | path_adder.go | starcoder |
package inference
// Simple internationalization, get TB description.
func getTBDescription(locale string) string {
if locale == "id" {
return "Tuberculosis (TB) adalah infeksi bakteri yang menyebar dengan cara menghirup droplet ringan dari bekas batuk atau bersin dari seseorang yang sudah terinfeksi. Biasanya, TB ... | pkg/inference/knowledge.go | 0.589244 | 0.412353 | knowledge.go | starcoder |
package bif
import "github.com/zzossig/rabbit/object"
func opNumericEqual(ctx *object.Context, args ...object.Item) object.Item {
arg1 := args[0]
arg2 := args[1]
switch {
case arg1.Type() == object.IntegerType && arg2.Type() == object.IntegerType:
leftVal := arg1.(*object.Integer).Value()
rightVal := arg2.(*... | bif/bif_4.3.go | 0.644896 | 0.532425 | bif_4.3.go | starcoder |
package advent2021
import (
"sort"
)
// Stack used as our Stack construct
type Stack struct {
stack []rune
}
// Push adds a new value to the Stack
func (s *Stack) Push(value rune) {
s.stack = append(s.stack, value)
}
// Pop returns the last value on the Stack and updates to reomve the value from the Stack
func (... | internal/pkg/advent2021/day10.go | 0.679391 | 0.605916 | day10.go | starcoder |
package xmorph
import (
"fmt"
"math"
"strconv"
"strings"
)
// A Point is a float64-valued (x, y) coordinate. The axes increase right and
// down.
type Point struct {
X float64
Y float64
}
// Add adds one Point to another to produce a third Point.
func (p Point) Add(q Point) Point {
return Point{
X: p.X + ... | point.go | 0.881806 | 0.503174 | point.go | starcoder |
package mp4
import (
"encoding/binary"
"errors"
)
// SliceReader - read integers from a slice
type SliceReader struct {
slice []byte
pos int
}
// NewSliceReader - create a new slice reader reading from data
func NewSliceReader(data []byte) *SliceReader {
return &SliceReader{
slice: data,
pos: 0,
}
}
/... | mp4/slicereader.go | 0.731251 | 0.420897 | slicereader.go | starcoder |
package gm
import (
"math"
"github.com/cpmech/gosl/chk"
"github.com/cpmech/gosl/num"
)
// BezierQuad implements a quadratic Bezier curve
// C(t) = (1-t)² Q0 + 2 t (1-t) Q1 + t² Q2
// = t² A + 2 t B + Q0
// A = Q2 - 2 Q1 + Q0
// B = Q1 - Q0
type BezierQuad struct {
// input
Q [][]float64 // co... | gm/bezier.go | 0.672224 | 0.515498 | bezier.go | starcoder |
package image
import (
"image"
"github.com/goplus/interp"
)
func init() {
interp.RegisterPackage("image", extMap, typList)
}
var extMap = map[string]interface{}{
"(*image.Alpha).AlphaAt": (*image.Alpha).AlphaAt,
"(*image.Alpha).At": (*image.Alpha).At,
"(*image.Alpha).Bounds": ... | pkg/image/export.go | 0.539469 | 0.605595 | export.go | starcoder |
package testdata
//GPS is a binary encoded GPS 3D point of interest
var gpsSlice = []byte{
/* Fix3D */ 0x03,
/* Latitude: float32(55.69147) -> 0x42, 0x5e, 0xc4, 0x11 */
0x42, 0x5e, 0xc4, 0x11,
/* Longitude: float32(12.61681) -> 0x41, 0x49, 0xde, 0x74 */
0x41, 0x49, 0xde, 0x74,
/* Altitude: float32(2.01) -> 0x40,... | testdata/message-octets.go | 0.665519 | 0.418222 | message-octets.go | starcoder |
package calldata
import (
"fmt"
"math/rand"
"strconv"
"time"
"github.com/Pallinder/go-randomdata"
"github.com/google/uuid"
)
const (
minLen = 2
maxLen = 64
defaultCharset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
)
type Func struct {
Name string
Desc string
Func ... | internal/calldata/functions.go | 0.542379 | 0.434341 | functions.go | starcoder |
package sims
import (
"fmt"
"math"
"github.com/NebulousLabs/Sia/siacrypto"
)
// bucketSim helps try to answer the question of variance between results when
// trying to determine what percentage of a data set someone is storing.
func bucketSim() {
fmt.Println("Bucket Variance Sim")
// Create N buckets and fill... | sims/proofofcapacity.go | 0.66628 | 0.403802 | proofofcapacity.go | starcoder |
package assert
import (
"fmt"
"github.com/kr/pretty"
"reflect"
"runtime"
"strings"
"testing"
"time"
)
var errorPrefix = "\U0001F4A9 "
// -- Assertion handlers
func assert(t *testing.T, success bool, f func(), callDepth int) {
if !success {
_, file, line, _ := runtime.Caller(callDepth + 1)
t.Errorf("%s:%... | _workspace/src/github.com/stvp/assert/assert.go | 0.601008 | 0.523968 | assert.go | starcoder |
package tavis
import (
"context"
"os"
"os/signal"
"time"
"github.com/noriah/tavis/fftw"
"github.com/noriah/tavis/portaudio"
"github.com/pkg/errors"
)
type Device struct {
// Name is the name of the Device we want to listen to
Name string
// SampleRate is the rate at which samples are read
SampleRate float... | tavis.go | 0.58522 | 0.421076 | tavis.go | starcoder |
package env
import (
"strconv"
"github.com/go-pogo/errors"
)
type Value string
// Bool tries to parse Value as a bool with strconv.ParseBool and returns it
// and any errors that occur.
func (v Value) Bool() (bool, error) {
b, err := strconv.ParseBool(string(v))
return b, errors.Trace(err)
}
// Int tries to p... | env/value.go | 0.746786 | 0.601242 | value.go | starcoder |
package lpd
// the descriptions copied from https://www.ietf.org/rfc/rfc1179.txt
var (
Separator = " "
LineEnding = "\n"
)
var (
// the server has to acknowledge all commands with a octet of zero bytes
Acknowledge byte = 0x0
)
type DaemonCommand byte
const (
/*
+----+-------+----+
| 01 | Queue |... | constants.go | 0.531453 | 0.500305 | constants.go | starcoder |
package main
import (
"math"
"math/rand"
)
type Material interface {
Scatter(ray Ray, hit *Hit) (Vec3, Ray)
}
/**
From Wikipedia:
Lambertian reflectance is the property that defines an ideal "matte" or diffusely reflecting surface.
The apparent brightness of a Lambertian surface to an observer is the same regardl... | cmd/weekend/material.go | 0.872293 | 0.494812 | material.go | starcoder |
package auth0fga
import (
"encoding/json"
)
// TypeDefinitions struct for TypeDefinitions
type TypeDefinitions struct {
TypeDefinitions *[]TypeDefinition `json:"type_definitions,omitempty"`
}
// NewTypeDefinitions instantiates a new TypeDefinitions object
// This constructor will assign default values to propertie... | model_type_definitions.go | 0.706798 | 0.49292 | model_type_definitions.go | starcoder |
package convutil
import (
"fmt"
"github.com/ghetzel/go-stockutil/mathutil"
"github.com/ghetzel/go-stockutil/stringutil"
"github.com/martinlindhe/unit"
)
var ConvertRoundToPlaces = 6
func parseUnit(in interface{}) Unit {
out := Invalid
if v, ok := in.(Unit); ok {
out = v
} else if vS, ok := in.(string); ok... | convutil/convutil.go | 0.694303 | 0.432902 | convutil.go | starcoder |
package template
import (
"fmt"
"html/template"
"os"
"path"
"regexp"
"strings"
m "github.com/gsiems/db-dictionary/model"
)
// T contains the tempate snippets that get concatenated to create the page template
type T struct {
sectionCount int
snippets []string
}
// C is the empty interface used for allow... | template/template.go | 0.512205 | 0.4436 | template.go | starcoder |
package layout
import (
"fmt"
"gomatcha.io/matcha/comm"
pblayout "gomatcha.io/matcha/proto/layout"
)
// Axis represents a direction along the coordinate plane.
type Axis int
const (
AxisY Axis = 1 << iota
AxisX
)
// Edge represents a side of a rectangle.
type Edge int
const (
EdgeTop Edge = 1 << iota
EdgeB... | layout/geometry.go | 0.86891 | 0.506469 | geometry.go | starcoder |
package spogoto
import (
"regexp"
"strings"
)
// Instruction is a unit of code signifying the type it operates on,
// the value literal of the instruction, the function to call if present,
// and the number of runs or executions that the instruction has been called.
type Instruction struct {
Type string
Value... | parser.go | 0.629319 | 0.418935 | parser.go | starcoder |
package half
import (
"errors"
"math"
"strconv"
)
// A Float16 represents a 16-bit floating point number.
type Float16 uint16
//String satisfies the fmt Stringer interface
func (f Float16) String() string {
return strconv.FormatFloat(float64(f.Float32()), 'f', -1, 32)
}
// NewFloat16 allocates and returns a new... | float16.go | 0.695958 | 0.41117 | float16.go | starcoder |
package challenge
import (
"encoding/base64"
"sort"
)
// HammingDistance takes two strings and returns the number of bits
// that differ in their byte representation.
func HammingDistance(left, right string) int {
dist := 0
if len(left) > len(right) {
dist += (len(left) - len(right)) * ByteBitSize
left = lef... | set/1/challenge/6.go | 0.831793 | 0.59972 | 6.go | starcoder |
package ggrenderer
import (
"github.com/EngoEngine/glm"
"github.com/oyberntzen/gogame/ggdebug"
)
type OrthographicCamera struct {
projectionMatrix glm.Mat4
viewMatrix glm.Mat4
viewProjectionMatrix glm.Mat4
position glm.Vec3
rotation float32
}
func NewOrthographicCamera(left, right, bottom, top ... | ggrenderer/orthographicCamera.go | 0.756537 | 0.448245 | orthographicCamera.go | starcoder |
package analyze
import (
"math"
intr "github.com/phil-mansfield/shellfish/math/interpolate"
)
var (
kernels = make(map[int]*intr.Kernel)
derivKernels = make(map[int]*intr.Kernel)
)
type smoothParams struct {
vals, derivs []float64
}
type internalSmoothOption func(*smoothParams)
// SmoothOption is an abs... | los/analyze/smooth.go | 0.697403 | 0.442757 | smooth.go | starcoder |
package rest
import (
"fmt"
"time"
)
// Payload is the unmarshalled request body.
type Payload map[string]interface{}
// Get returns the value with the given key as an interface{}. If the key doesn't
// exist, nil is returned with an error.
func (p Payload) Get(key string) (interface{}, error) {
if value, ok := p... | rest/payload.go | 0.781539 | 0.417925 | payload.go | starcoder |
package jsonpath
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"github.com/PaesslerAG/jsonpath"
"io"
"io/ioutil"
"reflect"
"strings"
)
func Contains(expression string, expected interface{}, data io.Reader) error {
value, err := JsonPath(data, expression)
if err != nil {
return err
}
ok, found := Incl... | vendor/github.com/steinfletcher/apitest-jsonpath/jsonpath/jsonpath.go | 0.539226 | 0.475605 | jsonpath.go | starcoder |
package machine_learning
import (
"os"
"bufio"
"strings"
"strconv"
"sort"
"math"
"math/rand"
"time"
stat "github.com/gonum/stat"
)
//----------------------------------------------------------------------------------------------------------------------
type DataSet struct {
Sa... | machine_learning/data_set.go | 0.702836 | 0.434161 | data_set.go | starcoder |
package ish
import "image"
// Lookup tables using BT.601 constants for colour channel to grayscale
// conversion.
var redToGray = grayscaleTable(0.2989)
var greenToGray = grayscaleTable(0.5870)
var blueToGray = grayscaleTable(0.1140)
// Grayscale converts an image to the grayscale colour space, using optimised
// al... | grayscale.go | 0.833189 | 0.627124 | grayscale.go | starcoder |
package series
import (
"github.com/WinPooh32/math"
)
// Mean returns mean of data's values.
func Mean(data Data) float32 {
var (
count int
mean float32
items = data.Data()
inv = 1.0 / float32(len(items))
)
for _, v := range items {
if math.IsNaN(v) {
continue
}
mean += v * inv
count++
}
i... | aggregation.go | 0.774583 | 0.480966 | aggregation.go | starcoder |
package pearl
import (
"math"
"reflect"
)
// The Vector2 struct
type Vector2 struct {
X float64
Y float64
}
// Returns the magnitude of a Vector2 type
func (v *Vector2) Magnitude() float64 {
return math.Sqrt(v.X * v.X + v.Y * v.Y)
}
// Normalizes Vector2
func (v *Vector2) Normalize() {
magnitude := v.Magnit... | vector2.go | 0.889583 | 0.760517 | vector2.go | starcoder |
package proto
import (
"bytes"
"errors"
"io"
"math"
"github.com/google/uuid"
)
// Type represents a Minecraft protocol data type.
// Implements io.ReaderFrom and io.WriterTo.
type Type interface {
io.ReaderFrom
io.WriterTo
}
// --- Boolean ---
// Boolean is either false or true.
// Implements proto.Type int... | type.go | 0.770767 | 0.424054 | type.go | starcoder |
package ring
import (
"fmt"
"image/color"
"math"
)
// Layer represents a drawable layer of the LED ring.
type Layer struct {
pixels []color.Color
pixArc float64 // pixel arc in radians
rotFloat float64 // float part of rotation in radians
rotInt int // integer part of rotation in radians
opt *Lay... | layer.go | 0.865124 | 0.551936 | layer.go | starcoder |
package world
import (
"github.com/go-gl/glfw/v3.3/glfw"
"github.com/go-gl/mathgl/mgl32"
)
type Movement int
var PlayerID = int32(1)
const (
MoveForward Movement = iota
MoveBackward
MoveLeft
MoveRight
)
type AI interface {
Think(p *Player)
}
type Physics interface {
GetSpeed() mgl32.Vec3
Speed(a mgl32.Ve... | world/player.go | 0.620966 | 0.478224 | player.go | starcoder |
package calculator
import (
"errors"
"fmt"
"math"
"strings"
)
// Add takes two or more float64 values and returns their sum.
func Add(a float64, b float64, nums ...float64) float64 {
sum := a + b
for _, n := range nums {
sum += n
}
return sum
}
// Subtract takes two or more float64 values and returns the r... | calculator.go | 0.796094 | 0.624723 | calculator.go | starcoder |
package types
import (
"errors"
"io"
"sync"
"runtime"
"github.com/attic-labs/noms/go/d"
)
// Blob represents a list of Blobs.
type Blob struct {
sequence
}
func newBlob(seq sequence) Blob {
return Blob{seq}
}
func NewEmptyBlob(vrw ValueReadWriter) Blob {
return Blob{newBlobLeafSequence(vrw, []byte{})}
}
... | go/types/blob.go | 0.542136 | 0.431944 | blob.go | starcoder |
package ast
import (
"fmt"
"strconv"
)
type Program struct {
Assignments []Assignment
}
func (p Program) String() string {
var s string
for _, a := range p.Assignments {
s += a.String() + "\n"
}
return s
}
type Assignment struct {
LHS Variable
RHS Expression
}
func (a Assignment) String() string {
retu... | efd/op3/ast/ast.go | 0.669745 | 0.437884 | ast.go | starcoder |
package v1
import (
"encoding/json"
)
// BgpSessionNeighbors struct for BgpSessionNeighbors
type BgpSessionNeighbors struct {
// A list of BGP session neighbor data
BgpNeighbors *[]BgpNeighborData `json:"bgp_neighbors,omitempty"`
}
// NewBgpSessionNeighbors instantiates a new BgpSessionNeighbors object
// This c... | v1/model_bgp_session_neighbors.go | 0.789193 | 0.511778 | model_bgp_session_neighbors.go | starcoder |
package geometry
import (
"math"
)
// 2d vector
type Vector struct {
X, Y float64
}
var (
// Zero Vector
ZeroVector = Vector{0, 0}
)
// Check if v1 is Equals to v2
func (v1 Vector) Equals(v2 Vector) bool {
return v1.X == v2.X && v1.Y == v2.Y
}
// Check if v1 is Nearly Equals to v2 (against an epsilon defined... | geometry/vector.go | 0.90377 | 0.714117 | vector.go | starcoder |
package chacha20
import (
"encoding/binary"
"errors"
"unsafe"
)
func Encrypt(plain []byte, key []byte, nonce []byte) ([]byte, error) {
if len(key) != 32 {
return nil, errors.New("unexpected key length")
}
if len(nonce) != 12 {
return nil, errors.New("unexpected nonce length")
}
var counter uint32
encryp... | chacha20/chacha20.go | 0.512693 | 0.423935 | chacha20.go | starcoder |
package main
import (
"errors"
"fmt"
"log"
"sort"
"strconv"
"github.com/theatlasroom/advent-of-code/go/2019/utils"
)
/**
--- Day 5: Binary Boarding ---
You board your plane only to discover a new problem: you dropped your boarding pass!
You aren't sure which seat is yours, and all of the flight attendants are... | go/2020/5.go | 0.615203 | 0.605158 | 5.go | starcoder |
package pars
import (
"bytes"
"errors"
"io"
)
const (
bufferReadSize = 4096
)
// State represents a parser state, which is a convenience wrapper for an
// io.Reader object with buffering and backtracking.
type State struct {
rd io.Reader
buf []byte
off int
end int
err error
pos Position
stk *stack
}
// ... | state.go | 0.688364 | 0.452415 | state.go | starcoder |
package ipv6
import (
"encoding/csv"
"fmt"
"io"
"regexp"
"strconv"
"strings"
"github.com/pkg/errors"
"github.com/tidwall/buntdb"
)
const collection = "address"
const expectedCSVColumns = 10
const coordinatePrecision = "%f"
var data map[string]int32 // lat,long:count
var buntdbValueRegex = regexp.MustCompil... | internal/ipv6/ipv6.go | 0.7413 | 0.403949 | ipv6.go | starcoder |
package crc16
import (
"errors"
"hash"
)
// Hash16 is the common interface implemented by all 16-bit hash functions.
type Hash16 interface {
hash.Hash
Sum16() uint16
}
// New creates a new Hash16 computing the CRC-16 checksum
// using the polynomial represented by the Table.
func New(tab *Table) Hash16 { return... | vendor/github.com/howeyc/crc16/hash.go | 0.681727 | 0.420719 | hash.go | starcoder |
package hyperbolic
import (
"math"
"github.com/calummccain/coxeter/vector"
)
type HPoint struct {
H vector.Vec4
K vector.Vec3
P vector.Vec3
U vector.Vec3
Norm float64
}
func InitHPoint(w, x, y, z float64) HPoint {
return HPoint{H: vector.Vec4{W: w, X: x, Y: y, Z: z}}
}
func InitHPointVec4(v vec... | hyperbolic/hyperbolicPoint.go | 0.636918 | 0.750587 | hyperbolicPoint.go | starcoder |
package gglm
import (
"fmt"
"math"
)
var _ Mat = &TrMat{}
var _ fmt.Stringer = &TrMat{}
//TrMat represents a transformation matrix
type TrMat struct {
Mat4
}
//Translate adds v to the translation components of the transformation matrix
func (t *TrMat) Translate(v *Vec3) *TrMat {
t.Data[3][0] += v.Data[0]
t.Dat... | gglm/transform.go | 0.732783 | 0.58519 | transform.go | starcoder |
Currently it makes not much sense to try to solve the problem
as it obviousely needs something like the math/big package.
The current solution works for sequences up to S(49) only.
However, I'll keep this for further investigations.
*/
package main
import (
"fmt"
)
// main is the entry point of the clocksequ... | problem_506/main.go | 0.580352 | 0.450601 | main.go | starcoder |
package floatgeom
import (
"github.com/oakmound/oak/v3/alg"
)
// A Polygon2 is a series of points in 2D space.
type Polygon2 struct {
// Bounding is a cached bounding box calculated from the input points
// It is exported for convenience, but should be modified with care
Bounding Rect2
// The component points of... | alg/floatgeom/polygon.go | 0.734024 | 0.659433 | polygon.go | starcoder |
package iso20022
// Amount of money for which goods or services are offered, sold, or bought.
type UnitPrice6 struct {
// Type and information about a price.
Type *PriceType2 `xml:"Tp"`
// Type of pricing calculation method.
PriceMethod *PriceMethod1Code `xml:"PricMtd,omitempty"`
// Value of the price, eg, as ... | UnitPrice6.go | 0.79649 | 0.486697 | UnitPrice6.go | starcoder |
package helpers
import (
"fmt"
"strings"
"github.com/noxer/tinkerforge"
)
// Version represents a bricklet version number
type Version [3]byte
// NewVersion creates a new Version array
func NewVersion(main, sub, patch byte) Version {
return Version{main, sub, patch}
}
// String prints a version array
func (v V... | helpers/helpers.go | 0.603698 | 0.555194 | helpers.go | starcoder |
This implementation draws from the Daisuke Maki's Perl module, which itself is
based on the original libketama code. That code was licensed under the GPLv2,
and thus so is this.
The major API change from libketama is that Algorithm::ConsistentHash::Ketama allows hashing
arbitrary strings, instead of just memcached se... | sharded/distribution/ketama.go | 0.828315 | 0.486575 | ketama.go | starcoder |
// In alcuni linguaggi è idiomatico l'utilizzo di
// strutture di dati e algoritmi [generici](http://en.wikipedia.org/wiki/Generic_programming).
// Go non supporta algoritmi/strutture generiche: in
// genere si forniscono funzioni per collezioni se sono
// specificamente necessari per il tuo programma e per i
// tuoi ... | examples/funzioni-per-collezioni/funzioni-per-collezioni.go | 0.574395 | 0.451266 | funzioni-per-collezioni.go | starcoder |
package packed
// Efficient sequential read/write of packed integers.
type BulkOperationPacked7 struct {
*BulkOperationPacked
}
func newBulkOperationPacked7() BulkOperation {
return &BulkOperationPacked7{newBulkOperationPacked(7)}
}
func (op *BulkOperationPacked7) decodeLongToInt(blocks []int64, values []int3... | vendor/github.com/balzaczyy/golucene/core/util/packed/bulkOperation7.go | 0.52975 | 0.702517 | bulkOperation7.go | starcoder |
package wirepath
import "google.golang.org/protobuf/reflect/protoreflect"
// Value is like protoreflect.Value, but it preserves the protobuf kind of the
// value.
type Value struct {
kind protoreflect.Kind
v protoreflect.Value
}
func ValueOf(v interface{}, kind protoreflect.Kind) Value {
panic("unsupported")
}... | wirepath/wirepath_value.go | 0.742235 | 0.499512 | wirepath_value.go | starcoder |
package main
import (
"fmt"
"math"
)
// Node is a node in a tree
type Node struct {
value int
freq int
height int
left *Node
right *Node
}
// AVLTree is Avl tree implementation
type AVLTree struct {
root *Node
}
// Height returs the height of a node
func Height(node *Node) int {
if node == nil {
re... | trees/avl_tree_using_ll/avl_tree_using_ll.go | 0.728941 | 0.480174 | avl_tree_using_ll.go | starcoder |
package tool
import (
"math"
"strconv"
"strings"
"time"
)
// DateFormat pattern rules.
// Golang 格式化时间默认字符 2006-01-02 15:04:05
var datePatterns = []string{
// year
"Y", "2006", // A full numeric representation of a year, 4 digits Examples: 1999 or 2003
"y", "06", //A two digit representation of a year Exam... | utils/tool/time.go | 0.516352 | 0.55911 | time.go | starcoder |
package geojson
import (
"encoding/binary"
"math"
"strconv"
"unsafe"
"github.com/tidwall/gjson"
"github.com/quesurifn/tile38/pkg/geojson/geo"
"github.com/quesurifn/tile38/pkg/geojson/poly"
)
const sizeofPosition = 24 // (X,Y,Z) * 8
// Position is a simple point
type Position poly.Point
func pointPositions(p... | pkg/geojson/position.go | 0.701713 | 0.483039 | position.go | starcoder |
package fp
func (a BoolOption) Equals(b BoolOption) bool {
if a.IsDefined() {
if b.IsDefined() {
return BoolEquals(Bool(*a.value), Bool(*b.value))
} else { return false}
} else if b.IsDefined() { return false } else { return true } }
func (a StringOption) Equals(b StringOption) bool {
if a.IsDefi... | fp/bootstrap_option_equals.go | 0.669096 | 0.424173 | bootstrap_option_equals.go | starcoder |
package utils
import (
"fmt"
"reflect"
"github.com/Applifier/go-tensorflow/internal/typeconv"
"github.com/Applifier/go-tensorflow/types/tensorflow/core/example"
)
// An Example is a mostly-normalized data format for storing data for
// training and inference. It contains a key-value store (features); where
// e... | utils/example.go | 0.601008 | 0.506774 | example.go | starcoder |
package quadtree
import "math"
// Undilate deinterleaves word using shift-or algorithm.
func Undilate(x uint32) uint32 {
x = (x | (x >> 1)) & 0x33333333
x = (x | (x >> 2)) & 0x0F0F0F0F
x = (x | (x >> 4)) & 0x00FF00FF
x = (x | (x >> 8)) & 0x0000FFFF
return (x & 0x0000FFFF)
}
// Decode retrieves column major posi... | quadtree/quadtree.go | 0.847684 | 0.765133 | quadtree.go | starcoder |
package fmts
import "github.com/google/gapid/core/stream"
var (
RGBA_U4_NORM = &stream.Format{
Components: []*stream.Component{{
DataType: &stream.U4,
Sampling: stream.LinearNormalized,
Channel: stream.Channel_Red,
}, {
DataType: &stream.U4,
Sampling: stream.LinearNormalized,
Channel: stream... | core/stream/fmts/rgba.go | 0.541651 | 0.452536 | rgba.go | starcoder |
package main
import (
"fmt"
"math"
)
// d = x^y
// p(n;d) ~ 1-((d-1)/d)^n(n-1)/2
// p(n;d) is the probability that at least two numbers are the same.
func collisionP(n, x, y float64) (p float64, d float64, err error) {
errPrefix := "can't calculate the probability of at least 2 elements colliding"
if n <= 0 {
r... | bday.go | 0.652684 | 0.511412 | bday.go | starcoder |
package gohome
import (
"github.com/PucklaMotzer09/mathgl/mgl32"
)
// The different parts of a shader
const (
VERTEX uint8 = 0
FRAGMENT uint8 = 1
GEOMETRY uint8 = 2
TESSELLETION uint8 = 3
EVELUATION uint8 = 4
COMPUTE uint8 = 5
)
// A shader controls how a mesh is rendered
type Shader inte... | src/gohome/shader.go | 0.713631 | 0.474266 | shader.go | starcoder |
package assert
import (
"reflect"
"github.com/google/gapid/core/data/compare"
)
// OnMap is the result of calling ThatMap on an Assertion.
// It provides assertion tests that are specific to map types.
type OnMap struct {
Assertion
mp interface{}
}
// ThatMap returns an OnMap for assertions on map type objects... | core/assert/map.go | 0.725649 | 0.465813 | map.go | starcoder |
package chart
import (
"fmt"
)
// Interface Assertions.
var (
_ Series = (*LinearSeries)(nil)
_ FirstValuesProvider = (*LinearSeries)(nil)
_ LastValuesProvider = (*LinearSeries)(nil)
)
// LinearSeries is a series that plots a line in a given domain.
type LinearSeries struct {
Name string
Style S... | vendor/github.com/wcharczuk/go-chart/v2/linear_series.go | 0.844249 | 0.646544 | linear_series.go | starcoder |
* ============================================================================
* Usage:
* $ curl -sO http://rgolubtsov.github.io/srcs/find_equil_index.go && \
chmod 700 find_equil_index.go && \
./find_equil_index.go; echo $?
* =... | content/src/find_equil_index.go | 0.756088 | 0.602179 | find_equil_index.go | starcoder |
package format
import (
"strings"
"github.com/bvaudour/kcp/pkgbuild/atom"
"github.com/bvaudour/kcp/pkgbuild/standard"
)
//MapFunc is a function which apply
//transformations to a slice of atoms
//and returns the result of these transformations.
type MapFunc func(atom.Slice) atom.Slice
//Formatter is an interface... | pkgbuild/format/format.go | 0.58747 | 0.458591 | format.go | starcoder |
package main
import (
"log"
"os"
"sort"
"strconv"
"github.com/TomasCruz/projecteuler"
)
/*
Distinct powers
Problem 29
Consider all integer combinations of a^b for 2 ≤ a ≤ 5 and 2 ≤ b ≤ 5:
2^2=4, 2^3=8, 2^4=16, 2^5=32
3^2=9, 3^3=27, 3^4=81, 3^5=243
4^2=16, 4^3=64, 4^4=256, 4^5=1024
5^2=25, 5^3=... | 001-100/021-030/029/main.go | 0.548674 | 0.414543 | main.go | starcoder |
package weathercloud
import (
"github.com/ebarkie/http/query"
"github.com/ebarkie/weatherlink/units"
)
// Wx represents weather observations.
type Wx struct {
query.Data
}
func tens(f float64) int {
return int(f * 10.0)
}
// Bar is atmospheric pressure in inches.
func (w *Wx) Bar(in float64) {
w.SetInt("bar",... | wx.go | 0.806586 | 0.646083 | wx.go | starcoder |
package samples
func init() {
sampleDataProposalCreateOperation[51] = `{
"expiration_time": "2016-09-19T23:18:14",
"extensions": [],
"fee": {
"amount": 2420020,
"asset_id": "1.3.0"
},
"fee_paying_account": "1.2.125573",
"proposed_ops": [
{
"op": [
6,
{
"accoun... | gen/samples/proposalcreateoperation_51.go | 0.566139 | 0.438424 | proposalcreateoperation_51.go | starcoder |
package goflat
import (
"sort"
"strconv"
"strings"
)
// UMap takes a flattened map and recreates it with nested objects and lists.
// Remember to use the same delimiter when you first flattened it.
// If the options parameter is nil or delimiter is an empty string this method will use the default delimiter ".".
fu... | unflat.go | 0.620852 | 0.447702 | unflat.go | starcoder |
package strings
type inflection struct {
rule string
replacement string
}
type inflections struct{}
func (i *inflections) plural() []inflection {
return []inflection{
inflection{rule: `$`, replacement: "s"},
inflection{rule: `(?i)s$`, replacement: "s"},
inflection{rule: `(?i)^(ax|test)is$`, replaceme... | strings/inflections.go | 0.529507 | 0.486819 | inflections.go | starcoder |
package slicex
//合并
func MergeComplex64(slices ...[]complex64) []complex64 {
ln := len(slices)
index := 0
total := 0
for index < ln {
total += len(slices[index])
index++
}
rs := make([]complex64, total)
rsIndex := 0
for index = 0; index < ln; index++ {
copy(rs[rsIndex:], slices[index])
rsIndex += len(s... | slicex/slicecomplex64.go | 0.508788 | 0.613526 | slicecomplex64.go | starcoder |
package validation
import (
"math"
"reflect"
"regexp"
"strings"
"github.com/pkg/errors"
)
// CompareFunc is the function definition of test comparator without type-system
type CompareFunc func(value interface{}, expected interface{}) error
// Comparators is a collection of compare functions
type Comparators st... | ucloud/utest/validation/comparators.go | 0.687315 | 0.419826 | comparators.go | starcoder |
package datamodel
import (
"bytes"
"strconv"
)
type CustomDataType interface {
getLength() int
writeToBytes(b []byte) int
Copy() CustomDataType
}
type DataNull interface {
CustomDataType
isNull()
}
type DataBool interface {
CustomDataType
Get() bool
Set(Value bool)
}
type DataInt interface {
CustomDataT... | datamodel/model.go | 0.503174 | 0.478894 | model.go | starcoder |
package core
import (
"fmt"
"github.com/j3ssie/osmedeus/execution"
"github.com/j3ssie/osmedeus/utils"
"github.com/robertkrimen/otto"
"path"
"time"
)
func (r *Runner) LoadExternalScripts() string {
var output string
vm := r.VM
// special scripts
vm.Set(Cleaning, func(call otto.... | core/external.go | 0.521715 | 0.424293 | external.go | starcoder |
package objs
import (
"fmt"
"strconv"
)
func ParseBool(data []byte) (bool, error) {
if len(data) == 0 {
return false, nil
}
if data[0] == 0x00 {
return false, nil
}
if data[0] == 0x01 {
return true, nil
}
return strconv.ParseBool(string(data))
}
// float32 - 3.14 => float64 - 3.140000104904175
func... | objs/parse.go | 0.546254 | 0.478712 | parse.go | starcoder |
package TestUtils
import (
"YusLabCore/src/ObjectModule"
"math"
"reflect"
)
const float64EqualityThreshold = 1e-4 // this value can't be too precise, as the excel calculation has different precision.
func AlmostEqualsInputSheet(a ObjectModule.InputDataSheet, b ObjectModule.InputDataSheet) bool {
return reflect.D... | src/TestUtils/utils.go | 0.667148 | 0.632389 | utils.go | starcoder |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.