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 key
import (
"encoding/hex"
"errors"
"github.com/incognitochain/incognito-chain/privacy/operation"
)
func SliceToArray(slice []byte) [operation.Ed25519KeySize]byte {
var array [operation.Ed25519KeySize]byte
copy(array[:], slice)
return array
}
func ArrayToSlice(array [operation.Ed25519KeySize]byte) []b... | privacy/key/key.go | 0.7696 | 0.434341 | key.go | starcoder |
package searchmatrix
/*
* @lc app=leetcode id=74 lang=golang
*
* [74] Search a 2D Matrix
*
* https://leetcode.com/problems/search-a-2d-matrix/description/
*
* algorithms
* Medium (34.75%)
* Total Accepted: 215.1K
* Total Submissions: 618.9K
* Testcase Example: '[[1,3,5,7],[10,11,16,20],[23,30,34,50]]\n3... | 074-searchmatrix/searchmatrix.go | 0.87247 | 0.429489 | searchmatrix.go | starcoder |
package goimagemerge
import (
"errors"
"image"
"image/color"
"image/draw"
"image/jpeg"
"image/png"
"os"
"path"
"path/filepath"
"strings"
)
// Specifies how the grid pixel size should be calculated
type gridSizeMode int
const (
// The size in pixels is fixed for all the grids
fixedGridSize gridSizeMode = ... | go-image-merge.go | 0.699973 | 0.433442 | go-image-merge.go | starcoder |
package set
// node (Private) - Defines the structure for each individual node in a linked list
type node struct {
data string // Value of Node
right, left *node // Pointers to the next left or right node
}
// compareTo (Private) - Custom compareTo method to compare if two strings are the same
// 0 == equal... | set/set.go | 0.728941 | 0.66687 | set.go | starcoder |
package geodesic
import (
"math"
)
type Node struct {
Neighbors []int `json:"Neighbors"`
}
type Edge struct {
L int `json:"L"`
R int `json:"R"`
}
// Geodesic represents a geodesic sphere.
type Geodesic struct {
// Centers is a list of vectors representing the center of every face of the
// geodesic sphere.
C... | pkg/geodesic/graph.go | 0.804137 | 0.512083 | graph.go | starcoder |
package cgo
// This file implements a parser of a subset of the C language, just enough to
// parse common #define statements to Go constant expressions.
import (
"fmt"
"go/ast"
"go/scanner"
"go/token"
"strings"
)
var (
prefixParseFns map[token.Token]func(*tokenizer) (ast.Expr, *scanner.Error)
precedences ... | cgo/const.go | 0.669745 | 0.412501 | const.go | starcoder |
package kdtree
import (
"encoding/json"
"sort"
)
type KdTree struct {
Left, Right *KdTree
Dim int
Point []uint32
}
func Create(points [][]uint32, depth int) *KdTree {
tree := new(KdTree)
tree.Dim = depth % len(points[0])
sort.SliceStable(points, func(i, j int) bool {
return points[i][tree.Di... | kdtree.go | 0.581778 | 0.410815 | kdtree.go | starcoder |
package tflite
import (
flatbuffers "github.com/google/flatbuffers/go"
)
type TensorT struct {
Shape []int32
Type TensorType
Buffer uint32
Name string
Quantization *QuantizationParametersT
IsVariable bool
Sparsity *SparsityParametersT
ShapeSignature []int32
}
func (t *TensorT) Pack(builder *flatbuffers.Bui... | Tensor.go | 0.703244 | 0.431464 | Tensor.go | starcoder |
package bindings
import (
"encoding/binary"
"fmt"
"math"
"mojo/public/go/system"
)
// Decoder is a helper to decode mojo complex elements from mojo archive format.
type Decoder struct {
// Buffer containing data to decode.
buf []byte
// Index of the first unclaimed byte in buf.
end int
// Array containin... | third_party/mojo/src/mojo/public/go/bindings/decoder.go | 0.779657 | 0.477981 | decoder.go | starcoder |
package log
import (
"io/ioutil"
"os"
"regexp"
"strings"
"testing"
"vincent.click/pkg/preflight/expect"
)
// Expectations is a set of expectations about a log
type Expectations struct {
Time expect.Expectation
Name expect.Expectation
Level expect.Expectation
Fields expect.Expectation
Message ... | preflight/log/log.go | 0.718594 | 0.46223 | log.go | starcoder |
package neuralnet
import (
"fmt"
"math"
"os"
)
type WeightVector []float64
type XVector []float64
type YVector []float64
type XSample []XVector
type YSample []YVector
type NNOrder struct {
D int
M []int
K int
}
type NNStructure struct {
NNOrder
H func(float64) float64
H_prim func(float64... | src/neuralnet/structure.go | 0.694717 | 0.55917 | structure.go | starcoder |
// Package horn provides an implementation of Higher Order Recurrent Neural Networks (HORN).
package horn
import (
"encoding/gob"
"github.com/nlpodyssey/spago/ag"
"github.com/nlpodyssey/spago/mat"
"github.com/nlpodyssey/spago/nn"
)
var _ nn.Model[float32] = &Model[float32]{}
// Model contains the serializable ... | nn/recurrent/horn/horn.go | 0.830009 | 0.562657 | horn.go | starcoder |
package zcapld
const (
w3idOrgSecurityV1 = `{
"@context": {
"id": "@id",
"type": "@type",
"dc": "http://purl.org/dc/terms/",
"sec": "https://w3id.org/security#",
"xsd": "http://www.w3.org/2001/XMLSchema#",
"EcdsaKoblitzSignature2016": "sec:EcdsaKoblitzSignature2016",
"Ed25519Signature2... | pkg/auth/zcapld/context.go | 0.551574 | 0.442757 | context.go | starcoder |
package benchmark
import (
"reflect"
"testing"
)
func isBoolToIntFuncCalibrated(supplier func() bool) bool {
return isCalibrated(reflect.Bool, reflect.Int, reflect.ValueOf(supplier).Pointer())
}
func isIntToIntFuncCalibrated(supplier func() int) bool {
return isCalibrated(reflect.Int, reflect.Int, reflect.ValueO... | common/benchmark/02_to_int_func.go | 0.687525 | 0.758645 | 02_to_int_func.go | starcoder |
package interval
import "sort"
// intersection holds the full set of calculated information when testing for
// list intersections
type intersection struct {
overlap int // the count of intervals that overlap the span
lowIndex int // the index of the low interval
low U64Span // the... | core/math/interval/algorithm.go | 0.721154 | 0.523664 | algorithm.go | starcoder |
package p5
import (
"image/color"
"log"
)
// Push saves the current drawing style settings and transformations.
func Push() {
gproc.Push()
}
// Pop restores the previous drawing style settings and transformations.
func Pop() {
gproc.Pop()
}
// Canvas defines the dimensions of the painting area, in pixels.
func... | api.go | 0.807992 | 0.574992 | api.go | starcoder |
package main
import (
"encoding/json"
"fmt"
"log"
"math"
"os"
)
// Given the Go data structure, Message,
type Message struct {
Name string
Body string
Time int64
}
// Encoding
func init() {
// To encode JSON data we use the Marshal function.
// func Marshal(v interface{}) ([]byte, error)
// and an instanc... | 01 | Go by Example/internal/49_JSON/ref/JSON and Go/main.go | 0.516839 | 0.422505 | main.go | starcoder |
package result
import (
"strings"
)
// Symbol is a code symbol.
type Symbol struct {
Name string
Path string
Line int
Kind string
Language string
Parent string
ParentKind string
Signature string
Pattern string
FileLimited bool
}
// Symbols is the result of a search on th... | internal/search/result/symbol.go | 0.567937 | 0.415551 | symbol.go | starcoder |
package iex
// HistoricalTimeFrame enum for selecting time frame of historical data
type HistoricalTimeFrame string
const (
// OneMonthHistorical One month (default) historically adjusted market-wide data
OneMonthHistorical HistoricalTimeFrame = "1m"
// ThreeMonthHistorical Three months historically adjusted marke... | historical.go | 0.764716 | 0.597197 | historical.go | starcoder |
package fastbytes
import (
"reflect"
)
type bytes struct {
p provider
rotate bool
}
// FromI8 converts and copies bytes from `src` into `dst`.
// The number of bytes copied is min(len(src), len(dst))
func (b *bytes) FromI8(src []int8, dst []byte) (n int) { return b.p.FromI8(src, dst) }
// FromI16 converts a... | bytes_impl.go | 0.760117 | 0.405508 | bytes_impl.go | starcoder |
package imagecollage
import (
"math"
"sort"
)
// https://github.com/semibran/pack
// weights: greater side length produces more square-like output
const WHITESPACE_WEIGHT = 1
const SIDE_LENGTH_WEIGHT = 20
type Position struct {
x, y int64
}
type Size struct {
width, height int64
}
func max(a, b int64) int64 {... | pkg/imagecollage/semibranPack.go | 0.823293 | 0.546799 | semibranPack.go | starcoder |
package resize
import (
"image"
"image/color"
)
// average convert the sums to averages and returns the result.
func average(sum []uint64, w, h int, n uint64) *image.RGBA {
ret := image.NewRGBA(image.Rect(0, 0, w, h))
for y := 0; y < h; y++ {
for x := 0; x < w; x++ {
index := 4 * (y*w + x)
pix := ret.Pix... | vendor/github.com/mattermost/rsc/qr/web/resize/resize.go | 0.754734 | 0.560614 | resize.go | starcoder |
package ion
import (
"math/big"
"time"
)
// uintLen pre-calculates the length, in bytes, of the given uint value.
func uintLen(v uint64) uint64 {
len := uint64(1)
v >>= 8
for v > 0 {
len++
v >>= 8
}
return len
}
// appendUint appends a uint value to the given slice. The reader is
// expected to know how... | bits.go | 0.794106 | 0.571288 | bits.go | starcoder |
package alice
import (
"errors"
"github.com/streadway/amqp"
)
// Exchange models a RabbitMQ exchange
type Exchange struct {
name string // Name of the exchange
exchangeType ExchangeType // Type of the exchange
durable bool // Does the exchange persist during broker restarts?
autoDele... | exchange.go | 0.719778 | 0.427994 | exchange.go | starcoder |
package commands
import (
"../CmdProcessor"
"../Api"
"../Common"
"github.com/wcharczuk/go-chart"
"bytes"
"fmt"
"time"
"github.com/wcharczuk/go-chart/drawing"
"strings"
)
type CmdSensorsGraph struct {
}
func NewCmdSensorsGraph() ( *CmdSensorsGraph ) {
this := &CmdSensorsGraph {}
return this
}
ty... | Commands/SensorsGraph.go | 0.540681 | 0.422803 | SensorsGraph.go | starcoder |
package locationmanager
import (
"math"
"github.com/DiscoViking/goBrains/entity"
)
// Calculation of whether a co-ordinate is within a circular hitbox.
func (hb *circleHitbox) isInside(loc coord) bool {
// A radius of zero means that a hitbox is unhittable.
if hb.radius == 0 {
return false
}
dX := hb.centr... | locationmanager/hitbox.go | 0.886672 | 0.424233 | hitbox.go | starcoder |
package jodatime
import "time"
// absWeekday is like Weekday but operates on an absolute time.
func absWeekday(abs uint64) time.Weekday {
// January 1 of the absolute year, like January 1 of 2001, was a Monday.
sec := (abs + uint64(time.Monday)*secondsPerDay) % secondsPerWeek
return time.Weekday(int(sec) / seconds... | jodatime.go | 0.7696 | 0.417212 | jodatime.go | starcoder |
package main
import (
"fmt"
"strconv"
"strings"
"github.com/fancxxy/algo/list"
)
/*
f1(x) = 5x^2 + 4x^1 + 2
f2(x) = 5x^1 + 5
f1(x) + f2(x) = 5x^2 + 9x^1 +7
f1(x) * f2(x) = 25x^3 + 45x^2 + 30x^1 + 10
*/
type polynomial struct {
Coefficient int
Exponent int
}
func (p *polynomial) String() stri... | examples/list/polynomial/main.go | 0.559049 | 0.413892 | main.go | starcoder |
package poisson
import (
"math"
)
//Grid is a structure that holds information about points inside of grid
type Grid struct {
cols int
rows int
cellSize float64
points []*Point
}
//NewGrid returns Grid with cols x rows dimension and size of cell equals to cellSize
func NewGrid(cols, rows int, cellSize... | grid.go | 0.894879 | 0.681718 | grid.go | starcoder |
package day14
import (
"fmt"
"strconv"
"strings"
)
type Mask struct {
andMask, orMask uint64
}
func (m *Mask) Apply(val uint64) uint64 {
val &= m.andMask
val |= m.orMask
return val
}
type ParseMaskFunc func(mask string) ([]Mask, error)
func Part1(in []string) (uint64, error) {
return sumMemoryValues(in, pa... | day14/day14.go | 0.555435 | 0.404155 | day14.go | starcoder |
package vm
import "github.com/joushou/gocnc/gcode"
import "math"
import "fmt"
// Converts the arguments to mm if necessary
func (vm *Machine) axesToMetric(x, y, z float64) (float64, float64, float64) {
if vm.Imperial {
x *= 25.4
y *= 25.4
z *= 25.4
}
return x, y, z
}
// Retrieves position from top of stack
... | vm/positioning.go | 0.786049 | 0.42662 | positioning.go | starcoder |
package geocube
import (
"fmt"
"math"
pb "github.com/airbusgeo/geocube/internal/pb"
"github.com/airbusgeo/geocube/internal/utils"
)
// DataFormat describes the internal format of a raster
type DataFormat struct {
DType DType
NoData float64
Range Range
}
// DataMapping describes the mapping between an inter... | internal/geocube/dataformat.go | 0.811974 | 0.697564 | dataformat.go | starcoder |
package matcher
import (
"fmt"
utils "./utils"
)
// PathSegment represents a node in registered paths tree that is being matched against other paths to find endpint which will handle request
type PathSegment struct {
Name string
Children map[string]*PathSegment
Path *Path
}
// NewPathSegment creates a ... | go-url-path-matcher/pathsegment.go | 0.777638 | 0.487551 | pathsegment.go | starcoder |
package assets
import (
"fmt"
"github.com/tokenized/pkg/bitcoin"
"github.com/pkg/errors"
)
const (
max1ByteInteger = 255
max2ByteInteger = 65535
max4ByteInteger = 4294967295
maxArticleDepth = 4
)
func (a *Membership) Validate() error {
if a == nil {
return errors.New("Empty")
}
// Field AgeRestrictio... | dist/golang/assets/validate.go | 0.686475 | 0.476641 | validate.go | starcoder |
package xin
import (
"math"
"math/rand"
)
func mathRandForm(fr *Frame, args []Value, node *astNode) (Value, InterpreterError) {
return FracValue(rand.Float64()), nil
}
func mathSinForm(fr *Frame, args []Value, node *astNode) (Value, InterpreterError) {
if len(args) < 1 {
return nil, IncorrectNumberOfArgsError{... | pkg/xin/math.go | 0.601008 | 0.437283 | math.go | starcoder |
package instanceselector
const awsInstanceJson = `
{
"us-east-1": [
{
"baseline": 0.1,
"generation": "current",
"price": 0.0052,
"memory": 0.5,
"instanceType": "t3.nano",
"burstable": true,
"gpu": 0,
"cpu": 2
... | pkg/util/instanceselector/aws_instance_data.go | 0.691289 | 0.611556 | aws_instance_data.go | starcoder |
package ch04
import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"strconv"
"strings"
"unicode"
"unicode/utf8"
)
func Version() string {
return "chapter-04"
}
// AtomKind is an enum for the type of data stored in an Atom.
// enums for AtomKind
// Atom is our most primitive unit of storage.
// Pair is a "cons" ce... | ch04/lisp.go | 0.666931 | 0.61299 | lisp.go | starcoder |
package esbuilder
// snippetNode defines a snippet of code as an expression.
type snippetNode struct {
// code is the code to emit.
code string
}
// identifierNode defines a named identifier in the AST.
type identifierNode struct {
// name is the name of the identifier.
name string
}
// memberNode defines a mem... | generator/escommon/esbuilder/expressions_base.go | 0.67854 | 0.533276 | expressions_base.go | starcoder |
package cron
import (
"math"
"math/bits"
"time"
)
const (
sixyPositions = uint64(0xfffffffffffffff)
twentyFourPositions = uint32(0xffffff)
)
// Count gives us a count of the number of calls Parsed.Next would take to iterate though the time interval [from, to).
// We try to be O(1) where possible. However... | vendor/github.com/influxdata/cron/count.go | 0.60743 | 0.57072 | count.go | starcoder |
package main
import (
//"fmt"
"math"
"math/rand"
//v "github.com/MauriceGit/mtVector"
//sc "mtSweepCircle"
sc "github.com/MauriceGit/sweepcircle"
)
func calcExpectedRadius(count int, rangeX, rangeY, margin float64) float64 {
ratio := (rangeX - 2*margin) / (rangeY - 2*margin)
square := (rangeX - 2*margin) / ... | pointDistribution.go | 0.619471 | 0.415254 | pointDistribution.go | starcoder |
package main
import (
"errors"
"fmt"
"strconv"
"strings"
)
// see the color codes
// http://i.stack.imgur.com/UQVe5.png
func Fg(code int) string {
colored := []string{"\x1b[38;5;", strconv.Itoa(code), "m"}
return strings.Join(colored, "")
}
func Bg(code int) string {
colored := []string{"\x1b[48;5;", strconv... | colors.go | 0.597843 | 0.439627 | colors.go | starcoder |
package ewkb
import (
"encoding/binary"
"errors"
"math"
"github.com/kcasctiv/go-ewkb/geo"
)
func readHeader(data []byte) (header, binary.ByteOrder, int) {
byteOrder := getBinaryByteOrder(data[0])
offset := 1
wkbType := byteOrder.Uint32(data[offset:])
var h header
h.byteOrder = data[0]
h.wkbType = wkbType
... | reading.go | 0.632276 | 0.431524 | reading.go | starcoder |
package models
import (
i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91 "github.com/microsoft/kiota-abstractions-go/serialization"
)
// ObjectMapping
type ObjectMapping struct {
// Stores additional data not described in the OpenAPI description found when deserializing. Can be used for seri... | models/object_mapping.go | 0.665411 | 0.538316 | object_mapping.go | starcoder |
package indicators
import (
"errors"
"github.com/thetruetrade/gotrade"
)
// An Average True Range Indicator (Atr), no storage, for use in other indicators
type AtrWithoutStorage struct {
*baseIndicatorWithFloatBounds
// private variables
trueRange *TrueRangeWithoutStorage
sma *SmaWi... | indicators/atr.go | 0.742235 | 0.438304 | atr.go | starcoder |
package solver
import (
"github.com/mokiat/gomath/sprec"
"github.com/mokiat/lacking/game/physics"
)
var _ physics.DBConstraintSolver = (*MatchRotation)(nil)
// NewMatchRotation creates a new MatchRotation constraint solver.
func NewMatchRotation() *MatchRotation {
return &MatchRotation{
xAxis: NewMatchAxis().
... | game/physics/solver/match_rotation.go | 0.804021 | 0.510374 | match_rotation.go | starcoder |
package types
type Nat struct{}
func (Nat) Hash() []byte {
return TypeHash([]byte(TypeNat))
}
func (Nat) TypeName() string {
return TypeNat
}
type Int struct{}
func (Int) Hash() []byte {
return TypeHash([]byte(TypeInt))
}
func (Int) TypeName() string {
return TypeInt
}
type String struct{}
func (String) Ha... | pkg/ast/types/builtin.go | 0.635788 | 0.437703 | builtin.go | starcoder |
package terminal
import (
. "math"
. "tri/geom"
)
type Position struct {
X, Y int
}
func (t *Terminal) CSI(format string, a ...interface{}) {
t.Write("\x1b[")
t.Write(format, a...)
}
func (t *Terminal) Left(amount int) {
if amount == 1 {
t.CSI("D")
} else if amount > 1 {
t.CSI("%dD", amount)
} else if a... | terminal/drawing.go | 0.517327 | 0.499817 | drawing.go | starcoder |
package menge
import (
"fmt"
"strings"
)
// UIntPtrSet represents a set of uintptr elements.
type UIntPtrSet map[uintptr]struct{}
// Add adds zero or more elements to the set.
func (s UIntPtrSet) Add(elems ...uintptr) {
for _, e := range elems {
s[e] = struct{}{}
}
}
// Remove removes zero or more elements fr... | uintptr.go | 0.614278 | 0.416263 | uintptr.go | starcoder |
package nlp
import (
"math"
"github.com/james-bowman/sparse"
"gonum.org/v1/gonum/mat"
)
// Transformer provides a common interface for transformer steps.
type Transformer interface {
Fit(mat.Matrix) Transformer
Transform(mat mat.Matrix) (mat.Matrix, error)
FitTransform(mat mat.Matrix) (mat.Matrix, error)
}
//... | vendor/github.com/james-bowman/nlp/weightings.go | 0.791338 | 0.661906 | weightings.go | starcoder |
package command
import (
"github.com/spf13/cobra"
"github.com/pyroscope-io/pyroscope/pkg/adhoc"
"github.com/pyroscope-io/pyroscope/pkg/cli"
"github.com/pyroscope-io/pyroscope/pkg/config"
)
func newAdhocCmd(cfg *config.Adhoc) *cobra.Command {
vpr := newViper()
cmd := &cobra.Command{
Use: "adhoc [flags] [<a... | cmd/pyroscope/command/adhoc.go | 0.612657 | 0.403273 | adhoc.go | starcoder |
package channels
import "reflect"
// BufferCap represents the capacity of the buffer backing a channel. Valid values consist of all
// positive integers, as well as the special values below.
type BufferCap int
const (
// None is the capacity for channels that have no buffer at all.
None BufferCap = 0
// Infinity ... | vendor/github.com/eapache/channels/channels.go | 0.686685 | 0.63768 | channels.go | starcoder |
package ui
import (
"github.com/jonas747/discorder/common"
"github.com/jonas747/termbox-go"
)
// Unity3d like UI transform (minus scale, pivot and rotation)
type Transform struct {
AnchorMin common.Vector2F
AnchorMax common.Vector2F
Position common.Vector2F
Size common.Vector2F
Top, Bottom, Left, Right i... | ui/transform.go | 0.500977 | 0.612252 | transform.go | starcoder |
package heap
type
// A BinaryHeapInt implements the binary heap data structure
// see: wikipedia.org/wiki/Binary_heap
BinaryHeapInt struct {
less func(x, y int) bool
elements []int
}
type
// A BinaryHeapInt8 implements the binary heap data structure
// see: wikipedia.org/wiki/Binary_heap
BinaryHeapInt8 struct... | heap/reified_binaryheap.go | 0.891549 | 0.505371 | reified_binaryheap.go | starcoder |
package kamakiri
import "math"
// XY is a physics point.
type XY struct {
X float64
Y float64
}
// Clip calculates clipping based on the normal v and two faces.
func (v XY) Clip(clip float64, a, b XY) (XY, XY, int) {
sp := 0
out := [2]XY{a, b}
// Retrieve distances from each endpoint to the line
distanceA := ... | xy.go | 0.908098 | 0.658356 | xy.go | starcoder |
package null
// Bool is used to represent a bool that may be null
type Bool struct {
Valid bool
Bool bool
}
// NewBool turns a bool into a valid null.Bool
func NewBool(value bool) Bool {
return Bool{Valid: true, Bool: value}
}
// Byte is used to represent a byte that may be null
type Byte struct {
Valid bool
B... | pkg/null/null.go | 0.863809 | 0.406803 | null.go | starcoder |
package assert
import (
"context"
"errors"
"fmt"
"os"
"reflect"
"strings"
"testing"
"time"
)
func mustBeFunction(v interface{}) {
if reflect.TypeOf(v).Kind() != reflect.Func {
panic("Value is not a function")
}
}
func describe(v interface{}) string {
value := reflect.ValueOf(v)
if v == nil {
return ... | expect.go | 0.636692 | 0.413211 | expect.go | starcoder |
package matrix
import "math"
type InsightsMatrix struct {
_m int
_n int
_data [][]float64
_valid bool
// Secondary
_cholZero bool
_cholPos bool
_cholNeg bool
_cholD []float64
_cholL [][]float64
}
func NewInsightsMatrixWithData(data [][]float64, makeDeepCopy bool) *InsightsMatrix {
matrix... | arima/matrix/insight_matrix.go | 0.531939 | 0.531817 | insight_matrix.go | starcoder |
package gonvert
import (
"fmt"
"reflect"
"strconv"
"strings"
)
func ToString(value interface{}) (string, error) {
switch v := value.(type) {
case nil:
return "", nil
case string:
return v, nil
case []byte:
return string(v), nil
case float32, float64:
intVal, err := ToInt(value)
if err == nil {
r... | gonvert.go | 0.580114 | 0.410225 | gonvert.go | starcoder |
package main
import (
"fmt"
"math/rand"
"strconv"
"github.com/SolarLune/resolv/resolv"
"github.com/veandco/go-sdl2/sdl"
)
type World1 struct {
DrawInfo bool
}
type Bouncer struct {
Rect *resolv.Rectangle
SpeedX float32
SpeedY float32
BounceFrame float32
}
var squares []*Bouncer
func Mak... | world1.go | 0.567697 | 0.451145 | world1.go | starcoder |
package gobasis
import (
"fmt"
)
// BSplineBasis object
type BSplineBasis struct {
order int
knts []float64
}
// Create BSplineBasis object
func Create(knots []float64, order int) (*BSplineBasis, error) {
var prev float64 = knots[0]
// check minimum size
if len(knots) < 2*order {
return nil, fmt.Errorf("k... | bsplinebasis.go | 0.731634 | 0.455562 | bsplinebasis.go | starcoder |
package inbloom
import (
"errors"
"hash"
"hash/fnv"
"math"
"strings"
)
//ProbabilisticSet represents an abstraction of a Probabilistic
type ProbabilisticSet interface {
Add(obj *[]byte) error
PoFP() float64
Test(obj *[]byte) (bool, error)
}
//BloomFilter is a space-efficient probabilistic data structure, co... | bloomfilter.go | 0.747339 | 0.481515 | bloomfilter.go | starcoder |
package mysql
import (
"encoding/json"
)
// Capability is a capability composite flag field.
// Each bit represents an optional feature of the protocol.
// Both the client and server send these.
type Capability uint32
// Capability Flags
const (
CapabilityLongPassword Capability = 1 << 0
CapabilityF... | pkg/mysql/flags.go | 0.52683 | 0.471467 | flags.go | starcoder |
package corridor
import (
"github.com/gonum/matrix/mat64"
"github.com/satori/go.uuid"
)
/* parameters are comprised of fixed input avlues that are
unique to the problem specification that are referenced
by the algorithm at various stage of the solution process */
type Parameters struct {
SrcSubs []int // source ... | types.go | 0.558086 | 0.447219 | types.go | starcoder |
package geometry
import (
"github.com/hecate-tech/engine/gls"
"github.com/hecate-tech/engine/math32"
"math"
)
// NewDisk creates a disk (filled circle) geometry with the specified
// radius and number of radial segments/triangles (minimum 3).
func NewDisk(radius float64, segments int) *Geometry {
ret... | geometry/disk.go | 0.708616 | 0.423518 | disk.go | starcoder |
package expire
import (
"math"
"sort"
"github.com/omniscale/imposm3/geom/geojson"
)
// Calculate all tiles covered by the linear rings of the polygon
// and the tiles enclosed by it
func CoverPolygon(poly geojson.Polygon, zoom int) TileHash {
if len(poly) == 0 {
return TileHash{}
}
intersections := []TileFr... | expire/cover.go | 0.667473 | 0.529507 | cover.go | starcoder |
package base
import (
"fmt"
"strings"
"time"
"github.com/Jeffail/gabs/v2"
"github.com/stackpulse/steps-sdk-go/env"
"github.com/stackpulse/steps-sdk-go/filter"
"github.com/stackpulse/steps-sdk-go/log"
"github.com/stackpulse/steps-sdk-go/sort"
"maze.io/x/duration.v1"
)
const ItemsArrayName = "items"
type Jso... | steps/kubectl/base/output.go | 0.738763 | 0.424531 | output.go | starcoder |
package types
import (
"io"
"fmt"
"reflect"
"strconv"
"github.com/lyraproj/pcore/px"
)
type NumericType struct{}
var numericTypeDefault = &NumericType{}
var NumericMetaType px.ObjectType
func init() {
NumericMetaType = newObjectType(`Pcore::NumericType`, `Pcore::ScalarDataType {}`, func(ctx px.Context, arg... | types/numerictype.go | 0.654011 | 0.463444 | numerictype.go | starcoder |
package core
import (
"strings"
"time"
"github.com/luispcosta/go-tt/utils"
)
// Period represents a time period
type Period struct {
Sd time.Time
Ed time.Time
}
// NumberOfDays returns the number of days in the period
func (period *Period) NumberOfDays() int {
if dateEqual(period.Sd, period.Ed) {
return 1
... | core/period.go | 0.838878 | 0.583025 | period.go | starcoder |
package kml
import "strconv"
// Angles are strings because Go's `xml:",omitempty"` tags prevent the output
// of "empty" vales, (e.g. 0, nil, false, "", etc.), and some of the default
// values of some floats are 0.0. Leaving these as floats would cause some
// valid values to be suppressed.
type angle interface {
... | basic_types.go | 0.727879 | 0.522446 | basic_types.go | starcoder |
package brodal
type HeapElement interface {
Value() int
}
/*
"Heap" is a wrapper around "HeapNode". This structure is defines an entrypoint for a Brodal-Okasaki heap and
implements the priority queue interface using operations defined for "HeapNode" structure.
*/
type Heap struct {
root *HeapNode
size int
}
/*
Cr... | vendor/github.com/contribsys/faktory/storage/brodal/heap.go | 0.728459 | 0.519521 | heap.go | starcoder |
package graph
import (
"math"
"github.com/heustis/tsp-solver-go/model"
)
// BuildPerimiter produces the smallest convex perimeter that can encompass all the vertices in the supplied array.
// This returns both the edges comprising the convex perimeter and the set of unattached (interior) vertices.
// This will pan... | graph/perimeterbuildergraph.go | 0.799286 | 0.790611 | perimeterbuildergraph.go | starcoder |
package rowscanner
import "reflect"
func isKnownType(k reflect.Kind) bool {
switch k {
case
reflect.Bool,
reflect.Int,
reflect.Int8,
reflect.Int16,
reflect.Int32,
reflect.Int64,
reflect.Uint,
reflect.Uint8,
reflect.Uint16,
reflect.Uint32,
reflect.Uint64,
reflect.Float32,
reflect.Float64,
... | database/rowscanner/scan.go | 0.520984 | 0.476397 | scan.go | starcoder |
package main
import (
. "github.com/9d77v/leetcode/pkg/algorithm/unionfind"
)
/*
题目:岛屿数量
给你一个由 '1'(陆地)和 '0'(水)组成的的二维网格,请你计算网格中岛屿的数量。
岛屿总是被水包围,并且每座岛屿只能由水平方向和/或竖直方向上相邻的陆地连接形成。
此外,你可以假设该网格的四条边均被水包围。
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/number-of-islands
*/
/*
方法一:并查集
时间复杂度:О(nmɑ(MN))
空间复杂度:О(nm)
运行时间... | internal/leetcode/200.number-of-islands/main.go | 0.527317 | 0.421195 | main.go | starcoder |
package process
import (
"encoding/binary"
"math"
)
type TagEncoder interface {
// Buffer returns the underlying byte buffer that the tags were encoded in to
Buffer() []byte
// Encode encodes the given tags in to the buffer and returns the index in the buffer where the data begins
Encode(tags []string) int
}
... | process/tags.go | 0.731155 | 0.425009 | tags.go | starcoder |
package gmodel
import (
"fmt"
"github.com/onsi/gomega/types"
"github.com/thediveo/lxkns/model"
"github.com/thediveo/lxkns/species"
)
// BeSameNamespace returns a GomegaMatcher which compares an actual namespace
// to an expected namespace. A namespace is anything supporting at least the
// model.Namespace inter... | nstest/gmodel/be_same_namespace.go | 0.736685 | 0.531574 | be_same_namespace.go | starcoder |
package lmath
import (
//"fmt"
"math"
)
// A Vector 3 containing the three components
// X, Y, Z
type Vec3 struct {
X, Y, Z float64
}
var (
Vec3Right = Vec3{1, 0, 0}
Vec3Up = Vec3{0, 1, 0}
Vec3Forward = Vec3{0, 0, 1}
Vec3Zero = Vec3{0, 0, 0}
)
// Returns a new vector which is the result of adding '... | lmath/vec3.go | 0.888384 | 0.684928 | vec3.go | starcoder |
package assert
import (
http "net/http"
url "net/url"
time "time"
)
// Condition uses a Comparison to assert a complex condition.
func (a *Assertions) Condition(comp Comparison, msgAndArgs ...interface{}) bool {
return Condition(a.t, comp, msgAndArgs...)
}
// Contains asserts that the specified string, list(a... | vendor/src/github.com/crossdock/crossdock-go/assert/assertion_forward.go | 0.782496 | 0.472075 | assertion_forward.go | starcoder |
package f5api
// This describes a message sent to or received from some operations
type LtmMonitorHttp struct {
// Specifies the user name if the monitored target requires authentication.
Username string `json:"username,omitempty"`
// The application service to which the object belongs.
AppService string `json:"... | ltm_monitor_http.go | 0.88521 | 0.533337 | ltm_monitor_http.go | starcoder |
package fractales
import (
"image"
"image/color"
"image/png"
"math"
"os"
"github.com/Balise42/marzipango/params"
)
type Orbit interface {
getOrbitFastValue(z complex128) float64
getOrbitValue(v float64) float64
}
type PointOrbit struct {
X float64
Y float64
Translation float64
Factor... | fractales/orbit.go | 0.794225 | 0.455683 | orbit.go | starcoder |
package openapi
import (
"encoding/json"
"fmt"
"net/url"
"strings"
"github.com/NellybettIrahola/twilio-go/client"
)
// Optional parameters for the method 'ListAvailablePhoneNumberNational'
type ListAvailablePhoneNumberNationalParams struct {
// The SID of the [Account](https://www.twilio.com/docs/iam/api/acc... | rest/api/v2010/accounts_available_phone_numbers_national.go | 0.764276 | 0.622545 | accounts_available_phone_numbers_national.go | starcoder |
package main
import (
"fmt"
"image/color"
"math"
"math/rand"
"os"
"runtime"
"time"
"github.com/veandco/go-sdl2/sdl"
"github.com/xyproto/pixelpusher"
"github.com/xyproto/sdl2utils"
)
const (
// Size of "worldspace pixels", measured in "screenspace pixels"
pixelscale = 4
// The resolution (worldspace)
w... | cmd/butterfly/main.go | 0.670824 | 0.429848 | main.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"
)
//------------... | lib/output/azure_table_storage.go | 0.726523 | 0.747363 | azure_table_storage.go | starcoder |
package sqlgen
import (
"strings"
"github.com/doug-martin/goqu/v9/exp"
"github.com/doug-martin/goqu/v9/internal/errors"
"github.com/doug-martin/goqu/v9/internal/sb"
)
type (
// An adapter interface to be used by a Dataset to generate SQL for a specific dialect.
// See DefaultAdapter for a concrete implementati... | sqlgen/insert_sql_generator.go | 0.627152 | 0.427038 | insert_sql_generator.go | starcoder |
package proxy
import (
"fmt"
"math"
"strings"
ant_ast "github.com/antonmedv/expr/ast"
ant_parser "github.com/antonmedv/expr/parser"
"github.com/milvus-io/milvus/internal/proto/planpb"
"github.com/milvus-io/milvus/internal/proto/schemapb"
"github.com/milvus-io/milvus/internal/util/typeutil"
)
type parserCont... | internal/proxy/plan_parser.go | 0.502686 | 0.50415 | plan_parser.go | starcoder |
package cmd
import (
"fmt"
"regexp"
"strconv"
"github.com/jaredbancroft/aoc2020/pkg/helpers"
"github.com/jaredbancroft/aoc2020/pkg/navigation"
"github.com/spf13/cobra"
)
// day12Cmd represents the day12 command
var day12Cmd = &cobra.Command{
Use: "day12",
Short: "Advent of Code 2020 - Day12: Rain Risk",
L... | cmd/day12.go | 0.738669 | 0.529811 | day12.go | starcoder |
package gomcts
// TicTacToeBoardGameAction - action on a tic tac toe board game
type TicTacToeBoardGameAction struct {
xCoord uint8
yCoord uint8
value int8
}
// ApplyTo - TicTacToeBoardGameAction implementation of ApplyTo method of Action interface
func (a TicTacToeBoardGameAction) ApplyTo(s GameState) GameState ... | tictactoe.go | 0.630116 | 0.455804 | tictactoe.go | starcoder |
package bacnet
type BACNET_TIME struct {
Hours byte
Minutes byte
Seconds byte
Hundredths byte
}
type BACNET_DATE struct {
Year uint16
Month byte
Day byte
Weekday byte
}
type BACNET_DATE_TIME struct {
Date BACNET_DATE
Time BACNET_TIME
}
type BACNET_TIMESTAMP struct {
Tag byte
... | src/bac_time.go | 0.546496 | 0.485112 | bac_time.go | starcoder |
package builtins
import (
"errors"
"fmt"
"math"
"go.spiff.io/skim/lisp/interp"
"go.spiff.io/skim/lisp/skim"
)
// Binary operator functions
type binopFunc func(l, r skim.Numeric) (skim.Numeric, error)
func sum(l, r skim.Numeric) (skim.Numeric, error) {
float := l.IsFloat() || r.IsFloat()
if float {
l, ok :... | lisp/builtins/arith.go | 0.561575 | 0.521837 | arith.go | starcoder |
package chipmunk
import (
"github.com/vova616/chipmunk/vect"
)
/*
SimpleMotor represents a joint that will rotate an object relative to another while also correctly moving it forward.
Most useful for turning wheels.
*/
type SimpleMotor struct {
BasicConstraint
iSum vect.Float
jAcc vect.Float
rate vec... | motor.go | 0.808521 | 0.444083 | motor.go | starcoder |
package bird_data_guessing
import (
"sort"
"testing"
"github.com/gbdubs/inference"
)
// float64
type testFloat64Case struct {
name string
expected float64
}
type testFloat64Behavior func(englishOrLatinName string) *inference.Float64
func float64Case(englishOrLatinName string, expectedResult float64) test... | testing_float.go | 0.589598 | 0.589982 | testing_float.go | starcoder |
package sort
// CountingSort is a O(n+r) stable sorting algorithm just for a collection of small integers;
func CountingSort(data []int) []int {
mlo, mhi := 0, 0
for _, v := range data {
mhi = max(v, mhi)
mlo = min(v, mlo)
}
buckets := make([]int, mhi-mlo+1)
sorted := make([]int, len(data))
for _, v := range... | algorithms/sort/countingsort.go | 0.752831 | 0.59514 | countingsort.go | starcoder |
package main
import (
"math"
"math/rand"
"runtime"
"time"
sf "github.com/manyminds/gosfml"
)
func init() {
runtime.LockOSThread()
}
func main() {
const (
paddleSpeed = float32(400)
ballSpeed = float32(400)
)
var (
gameWidth uint = 800
gameHeight uint = 600
paddleSize sf.Vector2... | samples/sfmlPong/main.go | 0.710427 | 0.414662 | main.go | starcoder |
package option
import "errors"
type Option[T any] struct {
Ok *T
}
// Some returns an Option of some value
func Some[T any](value T) Option[T] {
return Option[T]{Ok: &value}
}
// None returns an empty optional
func None[T any]() Option[T] {
return Option[T]{}
}
// IsSome returns true when the optional contains ... | option/option.go | 0.833799 | 0.415966 | option.go | starcoder |
package aggregaterange
import (
"github.com/incognitochain/incognito-chain/privacy"
"github.com/pkg/errors"
)
// This protocol proves in zero-knowledge that a list of committed values falls in [0, 2^64)
type AggregatedRangeWitness struct {
values []uint64
rands []*privacy.Scalar
}
type AggregatedRangeProof str... | privacy/zeroknowledge/aggregaterange/aggregaterange.go | 0.554229 | 0.423786 | aggregaterange.go | starcoder |
package ctl
import "github.com/graniticio/granitic/v2/ws"
// A Command represents an instruction that can be sent to Granitic to operate on a running instance of an application.
type Command interface {
// ExecuteCommand is called when grnc-ctl is used to invoke a command that matches this Command's Name() method.
... | ctl/command.go | 0.824356 | 0.446796 | command.go | starcoder |
package _d
import (
"thelark.cn/geometry.v1/angle"
"math"
)
/**
* 三角形
*/
type Triangle struct {
P [3]*Point
}
/**
* 获取所有点
*/
func (d *Triangle) Points() []*Point {
return []*Point{d.P[0], d.P[1], d.P[2]}
}
/**
* 获取所有边 顺序是从 [0] 开始
*/
func (d *Triangle) Lines() []*Vector {
lines := make([]*Vector, 0)
for ... | 2d/triangle.go | 0.502197 | 0.430447 | triangle.go | starcoder |
package gasstation
/*
* @lc app=leetcode id=134 lang=golang
*
* [134] Gas Station
*
* https://leetcode.com/problems/gas-station/description/
*
* algorithms
* Medium (33.28%)
* Total Accepted: 139.2K
* Total Submissions: 415.9K
* Testcase Example: '[1,2,3,4,5]\n[3,4,5,1,2]'
*
* There are N gas stations... | 134-cancompletecircuit/134.gas-station.go | 0.876931 | 0.464476 | 134.gas-station.go | starcoder |
package day11
import (
"fmt"
"math"
"strconv"
"strings"
)
// Part1 returns the max-sum 3x3 square in the grid.
func Part1(input string) (string, error) {
serialNumber, err := strconv.Atoi(strings.TrimSpace(input))
if err != nil {
return "", err
}
x, y := max3x3Square(serialNumber, 300, 300)
return fmt.Spr... | internal/day11/day11.go | 0.61173 | 0.432663 | day11.go | starcoder |
package table
import (
"bytes"
"github.com/dgraph-io/badger/v3/y"
)
// MergeIterator merges multiple iterators.
// NOTE: MergeIterator owns the array of iterators and is responsible for closing them.
type MergeIterator struct {
left node
right node
small *node
curKey []byte
reverse bool
}
type node struct... | table/merge_iterator.go | 0.734881 | 0.407628 | merge_iterator.go | starcoder |
package did
const (
schemaV1 = `{
"required": [
"@context",
"id"
],
"properties": {
"@context": {
"oneOf": [
{
"type": "string",
"pattern": "^https://(w3id.org|www.w3.org/ns)/did/v1$"
},
{
"type": "array",
"items": [
{
"type... | pkg/doc/did/schema.go | 0.758242 | 0.484868 | schema.go | starcoder |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.