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 parser
import (
"RenG/src/config"
"RenG/src/lang/ast"
"RenG/src/lang/token"
"strconv"
)
func (p *Parser) parseScreenExpression() ast.Expression {
exp := &ast.ScreenExpression{Token: p.curToken}
p.nextToken()
exp.Name = &ast.Identifier{Token: p.curToken, Value: p.curToken.Literal}
if !p.expectPeek(t... | src/lang/parser/rengExpression.go | 0.596433 | 0.484014 | rengExpression.go | starcoder |
package xtime
import "time"
const (
DateFormat = "2006-01-02"
DateTimeFormat = "2006-01-02 15:04:05"
)
type Time struct {
time.Time
}
// Now return current locale time
func Now() *Time {
return &Time{
Time: time.Now(),
}
}
// GetCurrentUnixTime return current unix seconds
func (t *Time) CurrentUnixTime(... | pkg/utils/xtime/time.go | 0.79799 | 0.470615 | time.go | starcoder |
package kalman
import (
"math"
"github.com/regnull/kalman/geo"
)
const (
_LAT = 0
_LNG = 1
_ALTITUDE = 2
_VLAT = 3
_VLNG = 4
minSpeedAccuracy = 0.1 // Meters per second.
incline = 5 // Degrees, used to estimate altitude random step.
)
var sqrt... | geo_filter.go | 0.821653 | 0.611179 | geo_filter.go | starcoder |
package stats
import (
"time"
"github.com/blend/go-sdk/timeutil"
)
// Assert that the mock collector implements Collector.
var (
_ Collector = (*MockCollector)(nil)
)
// NewMockCollector returns a new mock collector.
func NewMockCollector(capacity int) *MockCollector {
return &MockCollector{
Metrics: make... | stats/mock_collector.go | 0.880013 | 0.505432 | mock_collector.go | starcoder |
package query
import (
"errors"
"fmt"
"github.com/Peripli/service-manager/pkg/types"
"github.com/Peripli/service-manager/pkg/util"
"github.com/tidwall/gjson"
)
// LabelOperation is an operation to be performed on labels
type LabelOperation string
const (
// AddLabelOperation takes a label and adds it to the... | pkg/query/update.go | 0.741674 | 0.414425 | update.go | starcoder |
package models
import (
i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91 "github.com/microsoft/kiota-abstractions-go/serialization"
)
// AttackSimulationRepeatOffender
type AttackSimulationRepeatOffender struct {
// Stores additional data not described in the OpenAPI description found when d... | models/attack_simulation_repeat_offender.go | 0.663778 | 0.501221 | attack_simulation_repeat_offender.go | starcoder |
package trie
type trieNode struct {
isEnd bool
next map[rune]*trieNode
}
type Trie struct {
nodes map[rune]*trieNode
}
/** Initialize your data structure here. */
func NewTrie() Trie {
return Trie{
nodes: make(map[rune]*trieNode, 0),
}
}
/** Inserts a word into the trie. */
func (this *Trie) Insert(word str... | trie/trie.go | 0.617974 | 0.662442 | trie.go | starcoder |
package primitive
import (
"errors"
"fmt"
"io"
)
type ValueType = int32
const (
ValueTypeRegular = ValueType(0)
ValueTypeNull = ValueType(-1)
ValueTypeUnset = ValueType(-2)
)
// Value models the [value] protocol primitive structure
type Value struct {
Type ValueType
Contents []byte
}
func NewValu... | primitive/values.go | 0.639736 | 0.446072 | values.go | starcoder |
package pulse
import "math"
type FindNumberFunc func(n Number, prevDelta, nextDelta uint16) bool
type Range interface {
// Left bound of the range. It may be an expected pulse.
LeftPrevDelta() uint16
LeftBoundNumber() Number
// Right bound of the range. MUST be a valid pulse data.
RightBoundData() Data
// I... | pulse/pulse_range.go | 0.795499 | 0.707986 | pulse_range.go | starcoder |
package layout
import (
"github.com/lysrt/bro/css"
"github.com/lysrt/bro/style"
)
const (
BlockNode BoxType = iota
InlineNode
AnonymousBlock
)
type BoxType int
// LayoutBox is the building block of the layout tree, associated to one StyleNode
type LayoutBox struct {
// Dimensions is the box position, size, ma... | layout/layout.go | 0.641535 | 0.562056 | layout.go | starcoder |
package plugin
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/thoas/go-funk"
"go.blockdaemon.com/bpm/sdk/pkg/node"
)
// ParameterValidator provides a function to validate the node parameters
type ParameterValidator interface {
// ValidateParameters validates the ndoe parameters
ValidateParameters(cu... | pkg/plugin/plugin.go | 0.632276 | 0.434401 | plugin.go | starcoder |
package parsers
import (
"errors"
"strings"
m "github.com/NumberXNumbers/types/gc/matrices"
gcv "github.com/NumberXNumbers/types/gc/values"
)
// Matrix takes a string and returns a matrix if string is
// of matrix format, else error.
// Example of matrix format: [1 2 3: 2+2i 2 0: 3.0 2.3 0+3i]
// [1 2 3: 2+2i 2 ... | utils/parsers/parse_matrix.go | 0.742048 | 0.570989 | parse_matrix.go | starcoder |
package main
import (
"errors"
"fmt"
"image"
"io"
"os"
"os/exec"
"path/filepath"
"strings"
"time"
)
// Graph is a collection of pixels to draw.
type Graph struct {
bounds image.Rectangle
pixels []GraphPixel
}
// GraphPixel is a single pixel to draw.
type GraphPixel struct {
daysAgo int
darkness int
}
... | git.go | 0.639511 | 0.40695 | git.go | starcoder |
package elasticsearch
import (
"strings"
"k8s.io/heapster/metrics/core"
)
func MetricFamilyTimestamp(metricFamily core.MetricFamily) string {
return strings.Title(string(metricFamily)) + "MetricsTimestamp"
}
func metricFamilySchema(metricFamily core.MetricFamily) string {
metricSchemas := []string{}
for _, metr... | heapster-1.3.0/common/elasticsearch/mapping.go | 0.796649 | 0.417153 | mapping.go | starcoder |
package gl
import (
"github.com/cloudprivacylabs/lsa/pkg/ls"
)
// NodeValue is zero or mode nodes on the stack
type NodeValue struct {
basicValue
Nodes ls.NodeSet
}
func NewNodeValue(nodes ...ls.Node) NodeValue {
return NodeValue{Nodes: ls.NewNodeSet(nodes...)}
}
func (n NodeValue) oneNode() (ls.Node, error) {
... | pkg/gl/nodevalue.go | 0.500244 | 0.447702 | nodevalue.go | starcoder |
package eval
import "github.com/elves/elvish/parse"
func (cp *compiler) chunkOp(n *parse.Chunk) effectOp {
cp.compiling(n)
return effectOp{cp.chunk(n), n.Range().From, n.Range().To}
}
func (cp *compiler) chunkOps(ns []*parse.Chunk) []effectOp {
ops := make([]effectOp, len(ns))
for i, n := range ns {
ops[i] = c... | eval/boilerplate.go | 0.556641 | 0.410225 | boilerplate.go | starcoder |
package gqlmodel
import (
"net/url"
"strings"
"github.com/reearth/reearth-backend/pkg/value"
)
func valueInterfaceToGqlValue(v interface{}) interface{} {
if v == nil {
return nil
}
switch v2 := v.(type) {
case bool:
return v2
case float64:
return v2
case string:
return v2
case *url.URL:
return v2... | internal/adapter/gql/gqlmodel/convert_value.go | 0.517327 | 0.48377 | convert_value.go | starcoder |
package algs4
// BSTNode ...
type BSTNode struct {
key Key // defined in st.go
val interface{}
left, right *BSTNode
n int
}
// BST is symbol table implemented by a binary tree
type BST struct {
root *BSTNode
}
// NewBST returns an bst with init capcity
func NewBST() *BST {
return &BST... | algs4/bst.go | 0.759582 | 0.451931 | bst.go | starcoder |
package lshIndex
import (
//"errors"
"github.com/orcaman/concurrent-map"
)
// set to 2/4/8 for 16bit/32bit/64bit hash values
const HASH_SIZE = 8
// integration precision for optimising number of bands + hash functions in LSH Forest
const PRECISION = 0.01
// number of partitions and maxK to use in LSH Ensemble (TODO... | src/lshIndex/lshIndex.go | 0.519278 | 0.453201 | lshIndex.go | starcoder |
package filter
import (
"fmt"
)
// Field represents an SQL field
type Field string
// Operator represents an SQL operator
type Operator string
const (
// OperatorEqual represents an SQL operator of the same name
OperatorEqual Operator = "eq"
// OperatorNot represents an SQL operator of the same name
OperatorNo... | backend/util/filter/filter.go | 0.758689 | 0.594434 | filter.go | starcoder |
package audio
import "math"
// PCMDataFormat is an enum type to indicate the underlying data format used.
type PCMDataFormat uint8
const (
// DataTypeUnknown refers to an unknown format
DataTypeUnknown PCMDataFormat = iota
// DataTypeI8 indicates that the content of the audio buffer made of 8-bit integers.
DataT... | vendor/github.com/go-audio/audio/pcm_buffer.go | 0.724286 | 0.567877 | pcm_buffer.go | starcoder |
package mysorts
// HeapSort implements Sort by MaxHeap in-place
func HeapSort(in myInterface) {
if in.Len() <= 1 {
return
}
bh := binaryHeap{}
bh.maxHeapity = bh.maxHeapityLoopBased //switch loop or rescurse based maxheapity here
bh.buildMaxHeap(in) // first build max heap
for i := in.Len(); i >= 2; i-- { /... | mysorts/heap_sort.go | 0.662687 | 0.416441 | heap_sort.go | starcoder |
package models
import (
i336074805fc853987abe6f7fe3ad97a6a6f3077a16391fec744f671a015fbd7e "time"
i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91 "github.com/microsoft/kiota-abstractions-go/serialization"
)
// GovernanceRoleAssignment
type GovernanceRoleAssignment struct {
Entity
// ... | models/governance_role_assignment.go | 0.619701 | 0.573141 | governance_role_assignment.go | starcoder |
package hlopt
import "github.com/koron/csvim/internal/highlight"
// Coloring defines an interface to unify color number and name.
type Coloring interface {
ColorNr() highlight.ColorNr
ColorName() highlight.ColorName
}
// CTermFg returns Option to apply a color to CTermFg field of Group.
func CTermFg(c Coloring) hi... | internal/hlopt/color.go | 0.811863 | 0.482795 | color.go | starcoder |
package discovery_docs
var AutoscalerV1beta2 = `
{
"kind": "discovery#restDescription",
"discoveryVersion": "v1",
"id": "autoscaler:v1beta2",
"name": "autoscaler",
"version": "v1beta2",
"revision": "20141002",
"title": "Google Compute Engine Autoscaler API",
"description": "The Google Compute Engine Autoscaler... | gcloud_apis/discovery_docs/autoscaler_v1beta2.json.go | 0.881373 | 0.447762 | autoscaler_v1beta2.json.go | starcoder |
package js
type Error struct {
Value
}
func (e Error) Error() string {
return ""
}
type Type int
const (
TypeUndefined Type = iota
TypeNull
TypeBoolean
TypeNumber
TypeString
TypeSymbol
TypeObject
TypeFunction
)
func Release(v Value) {
v.release()
}
func (t Type) String() string {
return ""
}
type Typ... | js/js.go | 0.59749 | 0.469946 | js.go | starcoder |
package hitmap
import (
"log"
"math"
"sort"
"github.com/go-spatial/geom"
"github.com/go-spatial/geom/planar"
)
func asGeomExtent(e [4]float64) *geom.Extent {
ee := geom.Extent(e)
return &ee
}
const (
Inside Always = Always(planar.Inside)
Outside Always = Always(planar.Outside)
)
// always will return t... | planar/makevalid/hitmap/hitmap.go | 0.651244 | 0.441372 | hitmap.go | starcoder |
package layout
import (
"math"
"time"
s3mfile "github.com/heucuva/goaudiofile/music/tracked/s3m"
"github.com/heucuva/gomixing/sampling"
"github.com/heucuva/gomixing/volume"
"gotracker/internal/format/s3m/playback/opl2"
"gotracker/internal/format/s3m/playback/util"
"gotracker/internal/player/intf"
"gotracker... | internal/format/s3m/layout/instrument_opl2.go | 0.614625 | 0.403302 | instrument_opl2.go | starcoder |
package titles
import (
"sort"
)
type ResultSet map[AID]Anime // Mapping of AIDs to Anime
type Results []Anime
// Returns a slice with the AIDs of all anime in the Results.
func (res Results) AIDList() (aid []AID) {
aid = make([]AID, 0, len(res))
for _, r := range res {
aid = append(aid, r.AID)
}
return
}
//... | titles/result.go | 0.750553 | 0.449936 | result.go | starcoder |
package gis
import (
"bytes"
"math"
)
const (
// EarthRadius is the radius of the earth.
EarthRadius float64 = 6378137
// MinLatitude is the min latitude of the bing map.
MinLatitude float64 = -85.05112878
// MaxLatitude is the max latitude of the bing map.
MaxLatitude float64 = 85.05112878
// MinLongitude ... | server/server/gis/tile_system.go | 0.807764 | 0.761583 | tile_system.go | starcoder |
package main
// O(n^3) time | O(n^2) space - where N is the height and width of the matrix
func SquareOfZeroes(matrix [][]int) bool {
infoMatrix := preComputeNumOfZeroes(matrix)
n := len(matrix)
for topRow := 0; topRow < n; topRow++ {
for leftCol := 0; leftCol < n; leftCol++ {
squareLen := 2
for squareLen <... | src/dynamic-programming/extreme/square-of-zeroes/go/pre-compute.go | 0.674479 | 0.492798 | pre-compute.go | starcoder |
package planar
import (
"github.com/smyrman/units/linear"
)
// Units for Area values. Always multiply with a unit when setting the initial value like you would for
// time.Time. This prevents you from having to worry about the internal storage format.
const (
SquearNanometer Area = 1e-36
SquearMicrometer Area = ... | planar/area_generated.go | 0.928943 | 0.663069 | area_generated.go | starcoder |
package validator
import (
"fmt"
"math/big"
"github.com/hyperledger/burrow/crypto"
"github.com/tendermint/tendermint/types"
)
// Safety margin determined by Tendermint (see comment on source constant)
var maxTotalVotingPower = big.NewInt(types.MaxTotalVotingPower)
type Bucket struct {
// Delta tracks the chang... | evmcc/vendor/github.com/hyperledger/burrow/acm/validator/bucket.go | 0.660501 | 0.41834 | bucket.go | starcoder |
package frames
import "fmt"
// Segment divides signatures into signature segments.
// This separation happens on wildcards or when the distance between frames is deemed too great.
// E.g. a signature of [BOF 0: "ABCD"][PREV 0-20: "EFG"][PREV Wild: "HI"][EOF 0: "XYZ"]
// has three segments:
// 1. [BOF 0: "ABCD"][PREV... | internal/bytematcher/frames/segments.go | 0.643665 | 0.436742 | segments.go | starcoder |
package rfc3464
import (
"net/textproto"
"strings"
)
/*
DSN is RFC3464 Delivery Status Notifications (DSN)
Some fields of a DSN apply to all of the delivery attempts described
by that DSN. At most, these fields may appear once in any DSN.
These fields are used to correlate the DSN with the original message
tr... | rfc3464/DSN.go | 0.528533 | 0.472136 | DSN.go | starcoder |
package queensproblembitarraysolver
import (
"bytes"
"io"
"time"
ba "github.com/golang-collections/go-datastructures/bitarray"
)
func getIndex(x byte, y byte, sideLength byte) uint64 {
// Note: No semicolons ;-)
return (uint64)(y*sideLength + x)
}
func hasQueen(board ba.BitArray, sideLength byte, x byte, y by... | queens-problem/queens-problem-bitarray-solver/queens-problem-bitarray-solver.go | 0.852445 | 0.435361 | queens-problem-bitarray-solver.go | starcoder |
package strdist
import (
"strings"
"unicode/utf8"
"github.com/nickwells/golem/mathutil"
)
// DfltLevenshteinFinder is a Finder with some suitable default values
// suitable for a Levenshtein algorithm already set.
var DfltLevenshteinFinder *Finder
// CaseBlindLevenshteinFinder is a Finder with some suitable defa... | strdist/levenshtein.go | 0.611962 | 0.467332 | levenshtein.go | starcoder |
package Alien_Dictionary
import (
"strings"
)
/*
* Alien Dictionary
There is a dictionary containing words from an alien language for which we don’t know the ordering of the alphabets.
Write a method to find the correct order of the alphabets in the alien language.
It is given that the input is a valid dictionary an... | Pattern16 - Topological Sort/Alien_Dictionary/solution.go | 0.628977 | 0.587204 | solution.go | starcoder |
package iso20022
// Provides information and details on the status of a trade.
type TradeData11 struct {
// Represents the original reference of the instruction for which the status is given, as assigned by the participant that submitted the foreign exchange trade.
OriginatorReference *Max35Text `xml:"OrgtrRef,omit... | TradeData11.go | 0.744471 | 0.516961 | TradeData11.go | starcoder |
package scanner
import (
"bufio"
"bytes"
"errors"
"fmt"
"io"
"strings"
"sql/token"
"sql/tools"
)
type Scanner interface {
// Scan reads the next token from the scanner.
Scan() (pos token.Pos, tok token.Token, lit string)
// ScanRegex reads a regex token from the scanner.
ScanRegex() (pos token.Pos, tok t... | scanner/scanner.go | 0.675229 | 0.426859 | scanner.go | starcoder |
package dilithium
import (
"golang.org/x/crypto/sha3"
)
//Poly represents a polynomial of deg n with coefs in [0, Q)
type Poly [n]int32
//freeze calls Freeze on each coef
func (a *Poly) freeze() {
for i := 0; i < n; i++ {
a[i] = freeze(a[i])
}
}
//reduce calls Reduce32 on each coef
func (a *Poly) reduce() {
f... | crystals-dilithium/poly.go | 0.719778 | 0.431285 | poly.go | starcoder |
package cios
import (
"encoding/json"
)
// SeriesDataLocation デバイス位置情報。コレクションの定義に依存。schema.location_typeが”POINT“の場合必須、”NONE”の場合はlocationをリクエストに含めることはできない
type SeriesDataLocation struct {
// Point固定
Type string `json:"type"`
Coordinates []float32 `json:"coordinates"`
}
// NewSeriesDataLocation instantiates a new... | cios/model_series_data_location.go | 0.70416 | 0.456228 | model_series_data_location.go | starcoder |
package zkbpp
//This file contains declaration for all basic gates for Z2
import "math/big"
func mpcZ2Xor(x, y []*big.Int, c *Circuit) (z []*big.Int) {
z = []*big.Int{big.NewInt(0), big.NewInt(0), big.NewInt(0)}
z[0] = Xor(x[0], y[0])
z[1] = Xor(x[1], y[1])
z[2] = Xor(x[2], y[2])
return
}
func mpcZ2XorVerif(... | CRISP_go/zkbpp/gates_z2_basic.go | 0.521715 | 0.607983 | gates_z2_basic.go | starcoder |
package cxgo
import (
"go/ast"
"go/token"
"github.com/gotranspile/cxgo/types"
)
// BoolExpr is a expression that returns a bool value.
type BoolExpr interface {
Expr
// Negate a bool expression. Alternative of !x, but for any expression.
// It may invert the comparison operator or just return !x.
Negate() Boo... | bools.go | 0.672332 | 0.455441 | bools.go | starcoder |
package allot
import (
"regexp"
"strconv"
"strings"
)
var regexpMapping = map[string]string{
RemaingStringType: `([\s\S]*)`,
StringType: `([^\s]+)`,
OptionalStringType: `(\s?[^\s]+)?`,
IntegerType: `([0-9]+)`,
OptionalIntegerType: `(\s?[0-9]+)?`,
}
// GetRegexpExpression returns the regex... | pkg/parameter.go | 0.743634 | 0.436502 | parameter.go | starcoder |
package cluster
import (
"encoding/json"
"fmt"
"github.com/flexiant/concerto/api/types"
"github.com/flexiant/concerto/utils"
"github.com/stretchr/testify/assert"
"testing"
)
// GetClusterListMocked test mocked function
func GetClusterListMocked(t *testing.T, clustersIn *[]types.Cluster) *[]types.Cluster {
ass... | api/cluster/cluster_api_mocked.go | 0.704668 | 0.509154 | cluster_api_mocked.go | starcoder |
package command
import (
"fmt"
"io"
"github.com/inkyblackness/res/geometry"
"github.com/inkyblackness/res/serial"
)
// LoadModel tries to decode a geometry model from a serialized list of model
// commands.
func LoadModel(source io.ReadSeeker) (model geometry.Model, err error) {
defer func() {
if r := recover... | geometry/command/LoadModel.go | 0.802903 | 0.463444 | LoadModel.go | starcoder |
package render
import (
"image"
"image/draw"
"github.com/oakmound/oak/alg/floatgeom"
"github.com/oakmound/oak/render/mod"
)
// CompositeM Types display all of their parts at the same time,
// and respect the positions of their parts as relative to the
// position of the composite itself
type CompositeM struct {
... | render/compositeM.go | 0.752468 | 0.504394 | compositeM.go | starcoder |
package config
/**
* Configuration for rewrite action resource.
*/
type Rewriteaction struct {
/**
* Name for the user-defined rewrite action. Must begin with a letter, number, or the underscore character (_), and must contain only letters, numbers, and the hyphen (-), period (.) hash (#), space ( ), at (@), equals... | resource/config/rewriteaction.go | 0.760206 | 0.482612 | rewriteaction.go | starcoder |
package Euler2D
type PartitionMap struct {
MaxIndex int // MaxIndex is partitioned into ParallelDegree partitions
ParallelDegree int
Partitions [][2]int // Beginning and end index of partitions
}
func NewPartitionMap(ParallelDegree, maxIndex int) (pm *PartitionMap) {
pm = &PartitionMap{
MaxIndex: ... | model_problems/Euler2D/indexing.go | 0.544559 | 0.580174 | indexing.go | starcoder |
package concurrent
import . "github.com/zx80live/gofp/fp"
func (f BoolFuture) FlatMapBool(t func(Bool) BoolFuture) BoolFuture {
return MkBoolFuture(func() Bool {
return <- t( <- f.ch).ch
})
}
func (f BoolFuture) FlatMapString(t func(Bool) StringFuture) StringFuture {
return MkStringFuture(func() String {
retu... | fp/concurrent/bootstrap_future_flatmap.go | 0.580114 | 0.469459 | bootstrap_future_flatmap.go | starcoder |
package main
import (
"math"
. "github.com/jakecoffman/cp"
"github.com/jakecoffman/cp/examples"
)
const (
PLAYER_VELOCITY = 500.0
PLAYER_GROUND_ACCEL_TIME = 0.1
PLAYER_GROUND_ACCEL = PLAYER_VELOCITY / PLAYER_GROUND_ACCEL_TIME
PLAYER_AIR_ACCEL_TIME = 0.25
PLAYER_AIR_ACCEL = PLAYER_VELOCITY / PLAYE... | examples/player/player.go | 0.586523 | 0.445771 | player.go | starcoder |
package gripql
import (
"errors"
"fmt"
"sort"
"strings"
"github.com/bmeg/grip/protoutil"
structpb "github.com/golang/protobuf/ptypes/struct"
)
// GetDataMap obtains data attached to vertex in the form of a map
func (vertex *Vertex) GetDataMap() map[string]interface{} {
return protoutil.AsMap(vertex.Data)
}
/... | gripql/util.go | 0.747708 | 0.486027 | util.go | starcoder |
package stats
import (
"math"
)
// Values presents a set of data values as an array, for the purposes of aggregation
type Values interface {
// Len returns the number of values present
Len() int
// ValueAt returns the value at the nth element
ValueAt(n int) float64
}
// MutableValues is a set of data values t... | src/query/graphite/stats/statistics.go | 0.847527 | 0.757346 | statistics.go | starcoder |
package cameras
import (
"github.com/nuberu/engine/core"
"github.com/nuberu/engine/math"
)
type orthographicView struct {
enabled bool
fullWidth float32
fullHeight float32
offsetX float32
offsetY float32
width float32
height float32
}
func newOrthographicView() *orthographicView {
return... | cameras/orthographic.go | 0.826747 | 0.47859 | orthographic.go | starcoder |
package temple
// taken straight out of https://github.com/hashicorp/consul-template/blob/master/template/funcs.go
// to support the "math" function
// licensed under MPL-2.0
import (
"fmt"
"reflect"
)
// add returns the sum of a and b.
func add(b, a interface{}) (interface{}, error) {
av := reflect.ValueOf(a)
b... | temple/consul-math.go | 0.864511 | 0.569673 | consul-math.go | starcoder |
package thl
import (
"errors"
"math"
"sort"
"time"
)
/***********************
*** General Helpers ***
***********************/
// Internal structure used for sorting slices of dates
type timeSort []time.Time
func (ts timeSort) Len() int {
return len(ts)
}
func (ts timeSort) Less(i, j int) bool {
return ts[... | thl.go | 0.766381 | 0.412619 | thl.go | starcoder |
package bitarray
import (
"math/bits"
)
// Reverse returns the bit array with its bits in reversed order.
func (ba *BitArray) Reverse() *BitArray {
switch {
case ba.IsZero():
return zeroBitArray
case ba.Len() == 1, ba.b == nil:
return ba
}
buf := make([]byte, len(ba.b))
for i, o := range ba.b {
buf[len(... | bitarray_shift.go | 0.822724 | 0.568476 | bitarray_shift.go | starcoder |
package main
import (
"fmt"
"./fakeassembly"
)
func main() {
input1 := fakeassembly.ReadInputToStruct("input.txt")
// input := parse.ReadInputToStruct("example.txt") // alternately, test on example code
sum1, _ := getSum(input1)
fmt.Println("1. Sum:", sum1)
// Reading in again because we've mutated the origin... | day8/main.go | 0.613584 | 0.50769 | main.go | starcoder |
package refconv
import (
"fmt"
"math"
"reflect"
"strconv"
"github.com/cstockton/go-conv/internal/refutil"
)
var (
mathMaxInt int64
mathMinInt int64
mathMaxUint uint64
mathIntSize = strconv.IntSize
)
func initIntSizes(size int) {
switch size {
case 64:
mathMaxInt = math.MaxInt64
mathMinInt = math.Mi... | vendor/github.com/cstockton/go-conv/internal/refconv/int.go | 0.67822 | 0.442757 | int.go | starcoder |
package clientbrownfield
import (
"encoding/json"
"fmt"
"testing"
"github.com/ingrammicro/cio/api/types"
"github.com/ingrammicro/cio/utils"
"github.com/stretchr/testify/assert"
)
// ImportServersMocked test mocked function
func ImportServersMocked(t *testing.T, cloudAccountIn *types.CloudAccount, cloudAccount... | api/clientbrownfield/import_api_mocked.go | 0.696578 | 0.444625 | import_api_mocked.go | starcoder |
// This package contains a new set of interfacs for hash functions.
// It also implements the Go streaming hash interface as HashStream.
// It is an experiment.
package nhash
import (
"io"
)
// Interface HashFunction requires 4 methods that return the
// size of the hasg function in bytes and bits. Probably wiil
/... | vendor/github.com/gxed/hashland/nhash/nhash.go | 0.63624 | 0.511656 | nhash.go | starcoder |
package pool
import (
"io"
"sync"
)
var BS *ByteSlicePool
type sliceHeader struct {
offset, len int
}
// ByteSlice 用于存储一维数组,可以区分 空数组和nil
type ByteSlice struct {
released bool
data []byte
elems []sliceHeader
}
func (b *ByteSlice)Grow(dataCap, elemCap int) {
dataLen := len(b.data)
da... | pool/byteslice.go | 0.517571 | 0.498535 | byteslice.go | starcoder |
package collection
// Deque is a generic double-ended queue based on a double-linked list. The
// zero value is can be used without any further initialization. The
// implementation is heavily inspired by the standard container/list package.
type Deque[T any] struct {
root element[T]
len int
}
// Len returns the n... | deque.go | 0.797557 | 0.478651 | deque.go | starcoder |
package math
import (
"math"
"math/rand"
"time"
)
// Standard math package for most common mathematical operations
type i interface{}
func init() {
rand.Seed(time.Hour.Milliseconds())
}
/* func sin(num float64) float64 */
func Sin(num float64) (val i, err error) {
return math.Sin(num), err
}
/* func cos(num ... | lib/math/math.go | 0.66628 | 0.452657 | math.go | starcoder |
package vm
import (
"fmt"
"reflect"
"strconv"
)
var hexdigits = []byte("0123456789ABCDEF")
func escapeUri(thing []byte) []byte {
ret := make([]byte, 0, len(thing))
for _, v := range thing {
if !shouldEscapeUri(v) {
ret = append(ret, v)
} else {
ret = append(ret, '%')
ret = append(ret, hexdigits[v&0... | vm/util.go | 0.677261 | 0.421552 | util.go | starcoder |
package p432
import "math"
/**
Implement a data structure supporting the following operations:
Inc(Key) - Inserts a new key with value 1. Or increments an existing key by 1. Key is guaranteed to be a non-empty string.
Dec(Key) - If Key's value is 1, remove it from the data structure. Otherwise decrements an existing... | algorithms/p432/432.go | 0.795698 | 0.615203 | 432.go | starcoder |
package network
/**
* Binding class showing the interface that can be bound to channel.
*/
type Channelinterfacebinding struct {
/**
* Interfaces to be bound to the LA channel of a Citrix ADC or to the LA channel of a cluster configuration.
For an LA channel of a Citrix ADC, specify an interface in C/U notation (f... | resource/config/network/channel_interface_binding.go | 0.708818 | 0.476275 | channel_interface_binding.go | starcoder |
package gographviz
import (
"fmt"
"strings"
)
// Graph is the analysed representation of the Graph parsed from the DOT format.
type Graph struct {
Attrs Attrs
Name string
Directed bool
Strict bool
Nodes *Nodes
Edges *Edges
SubGraphs *SubGraphs
Relations *Relations
}
// NewGraph create... | vendor/github.com/awalterschulze/gographviz/graph.go | 0.68616 | 0.4184 | graph.go | starcoder |
package reflect
import (
"fmt"
"reflect"
"strconv"
"strings"
)
// CopyHelper helps to reflect copy (inject) some values
func CopyHelper(key string, from, to interface{}) error {
// Checking reference type {to}
typeOfTo := reflect.TypeOf(to)
if typeOfTo.Kind() != reflect.Ptr {
return fmt.Errorf(
"Target mu... | reflect/copy.go | 0.589362 | 0.406685 | copy.go | starcoder |
package gogol
// State is an instance of the Game of Life
type State struct {
width int
height int
world [][]bool
previousWorld [][]bool
neighbourRadius int
}
// NewState creates a new Game of Life State
func NewState(width, height, neighbourRadius int) *State {
state := new(State... | state.go | 0.849191 | 0.631296 | state.go | starcoder |
package prototest
import (
"bytes"
"io"
"reflect"
"time"
"github.com/rbisecke/kafka-go/protocol"
)
func deepEqual(x1, x2 interface{}) bool {
if x1 == nil {
return x2 == nil
}
if r1, ok := x1.(protocol.RecordReader); ok {
if r2, ok := x2.(protocol.RecordReader); ok {
return deepEqualRecords(r1, r2)
}... | protocol/prototest/prototest.go | 0.549641 | 0.469338 | prototest.go | starcoder |
package match
import (
"fmt"
"reflect"
"strings"
"github.com/wallix/awless/cloud"
)
type and struct {
matchers []cloud.Matcher
}
func (m and) Match(r cloud.Resource) bool {
for _, match := range m.matchers {
if !match.Match(r) {
return false
}
}
return len(m.matchers) > 0
}
func And(matchers ...clou... | cloud/match/matchers.go | 0.621196 | 0.427875 | matchers.go | starcoder |
package decorator
import (
"fmt"
"github.com/swamp/compiler/src/ast"
"github.com/swamp/compiler/src/decorated/decshared"
"github.com/swamp/compiler/src/decorated/dtype"
decorated "github.com/swamp/compiler/src/decorated/expression"
dectype "github.com/swamp/compiler/src/decorated/types"
"github.com/swamp/compi... | src/decorated/convert/decorate_binary_operator.go | 0.617513 | 0.416797 | decorate_binary_operator.go | starcoder |
package check
import (
"math"
"sort"
)
// AreEqualSlicesFloat64 compares two float64 slices.
// The Epsilon parameter sets the accuracy of the comparison of two floats.
// The function ignores sorting, so compares both values and sorting of the slices.
// Thus, if the slices have the same values but diffe... | equalslices.go | 0.675765 | 0.633042 | equalslices.go | starcoder |
package common
import (
"github.com/Symantec/Dominator/lib/log"
"github.com/Symantec/proxima/config"
"github.com/influxdata/influxdb/client/v2"
"github.com/influxdata/influxdb/influxql"
"time"
)
// Influx represents a single influx backend.
type Influx struct {
data config.Influx
dbQueryer dbQueryerType
}... | common/api.go | 0.847211 | 0.406185 | api.go | starcoder |
package types
import (
"bytes"
"sort"
"github.com/spacemeshos/go-spacemesh/codec"
"github.com/spacemeshos/go-spacemesh/log"
)
const (
// BlockIDSize in bytes.
// FIXME(dshulyak) why do we cast to hash32 when returning bytes?
// probably required for fetching by hash between peers.
BlockIDSize = Hash32Length
... | common/types/block.go | 0.568176 | 0.437463 | block.go | starcoder |
package skynode
import (
"fmt"
)
// NodeInfo structure stores of JSON response from /conn/getAll API
type NodeInfo struct {
Key string `json:"key"`
Conntype string `json:"type"`
SendBytes int `json:"send_bytes"`
RecvBytes int `json:"recv_bytes"`
LastAckTime int `json:"last_ack_time"`
St... | src/skynode/skynode.go | 0.636466 | 0.495178 | skynode.go | starcoder |
package spouttest
import (
"fmt"
"net/http"
"strconv"
"strings"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// AssertRecv checks that a specific string has been received from a
// channel. The check times out after LongWait.
func AssertRecv(t *testing.T, ch <... | spouttest/asserts.go | 0.710327 | 0.496338 | asserts.go | starcoder |
// Package fft provides forward and inverse fast Fourier transform functions.
package fft
import "currents/internal/dsp"
// FFTReal returns the forward FFT of the real-valued slice.
func FFTReal(x []float32) []complex64 {
return FFT(dsp.ToComplex(x))
}
// IFFTReal returns the inverse FFT of the real-valued slice.
... | internal/fft/fft.go | 0.75985 | 0.614249 | fft.go | starcoder |
package graphsample1
import "github.com/wangyoucao577/algorithms_practice/graph"
/* This sample undirected graph comes from
"Introduction to Algorithms - Third Edition" 22.2 BFS
V = 8 (node count)
E = 9 (edge count)
define undirected graph G(V,E) as below (`s` is the source node):
r(0) - s(1) t(2) - u(3)
... | graphsamples/graphsample1/sample1.go | 0.730386 | 0.445349 | sample1.go | starcoder |
package fun
// Ordered encompasses commonly used types that can be used in eq/gt/lt operations.
type Ordered interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 |
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
~float32 | ~float64 | ~string
}
// ForEach applies the specified return-less function to eve... | fun.go | 0.872592 | 0.455744 | fun.go | starcoder |
package timeseries
import (
"github.com/K-Phoen/grabana/alert"
"github.com/K-Phoen/grabana/timeseries/axis"
"github.com/K-Phoen/sdk"
)
// Option represents an option that can be used to configure a graph panel.
type Option func(timeseries *TimeSeries)
// TooltipMode configures which series will be displayed in th... | vendor/github.com/K-Phoen/grabana/timeseries/timeseries.go | 0.788543 | 0.566618 | timeseries.go | starcoder |
package texture
import (
g2d "github.com/jphsd/graphics2d"
"image/color"
"image/draw"
"math"
)
// Halftone renders colored halftone dots into the destination image. Line separation, rotation
// and percentage fill with a point offset (from {0, 0}) control the dot locations.
func Halftone(dst draw.Image, c color.C... | image/texture/halftone.go | 0.708818 | 0.458773 | halftone.go | starcoder |
package plan
import (
"fmt"
"github.com/m3db/m3/src/query/parser"
)
// LogicalPlan converts a DAG into a list of steps to be executed in order
type LogicalPlan struct {
Steps map[parser.NodeID]LogicalStep
Pipeline []parser.NodeID // Ordered list of steps to be performed
}
// LogicalStep is a single step in ... | src/query/plan/logical.go | 0.682468 | 0.565239 | logical.go | starcoder |
// Package atomic provides simple wrappers around numerics to enforce atomic
// access.
package atomic
import (
"math"
"sync/atomic"
"time"
)
// Int32 is an atomic wrapper around an int32.
type Int32 struct{ v int32 }
// NewInt32 creates an Int32.
func NewInt32(i int32) *Int32 {
return &Int32{i}
}
// Load atom... | vendor/go.uber.org/atomic/atomic.go | 0.873674 | 0.500366 | atomic.go | starcoder |
package coldata
import (
"time"
"github.com/cockroachdb/apd/v2"
"github.com/cockroachdb/cockroach/pkg/util/duration"
)
// Bools is a slice of bool.
type Bools []bool
// Int16s is a slice of int16.
type Int16s []int16
// Int32s is a slice of int32.
type Int32s []int32
// Int64s is a slice of int64.
type Int64s... | pkg/col/coldata/native_types.go | 0.788868 | 0.520435 | native_types.go | starcoder |
package packed
// Efficient sequential read/write of packed integers.
type BulkOperationPacked3 struct {
*BulkOperationPacked
}
func newBulkOperationPacked3() BulkOperation {
return &BulkOperationPacked3{newBulkOperationPacked(3)}
}
func (op *BulkOperationPacked3) decodeLongToInt(blocks []int64, values []int32, i... | core/util/packed/bulkOperation3.go | 0.568056 | 0.722282 | bulkOperation3.go | starcoder |
package math
import (
"math"
"github.com/tdhite/kwite/internal/tplfunc/funcs"
)
func E() float64 {
return math.E
}
func Pi() float64 {
return math.Pi
}
func Phi() float64 {
return math.Phi
}
func Sqrt2() float64 {
return math.Sqrt2
}
func SqrtE() float64 {
return math.SqrtE
}
func SqrtPi() float64 {
ret... | internal/tplfunc/math/math.go | 0.726717 | 0.499878 | math.go | starcoder |
package bo
import (
"math"
"math/rand"
)
// SampleTries is the number of tries a sample function should try before
// truncating the samples to the boundaries.
var SampleTries = 1000
// Param represents a parameter that can be optimized.
type Param interface {
// GetName returns the name of the parameter.
GetNam... | param.go | 0.868548 | 0.6137 | param.go | starcoder |
package compoundInterest
import (
"math"
"time"
)
const numberOfMonthsInYear float64 = 12
type compoundInterest struct {
params Params
countMonthDeposit int
percentMonth float64
coefficient float64
month int
}
type Predictor interface {
Calculate() []Prediction
getDate(co... | compoundInterest.go | 0.772187 | 0.544559 | compoundInterest.go | starcoder |
package ws281x
import (
"bytes"
)
// FBS can be used to implement a frame buffer for SPI based WS281x driver. FBS
// encoding uses one byte of memory to encode two WS281x bits (12 bytes/pixel).
type FBS struct {
data []byte
}
// MakeFBS allocates memory for string of n pixels.
func MakeFBS(n int) FBS {
return FBS... | egpath/src/ws281x/fbs.go | 0.725357 | 0.445107 | fbs.go | starcoder |
package node
type Trie struct {
data any
path string
children []*Trie
lookup []byte
isWildcard bool
}
func (trie *Trie) Add(path string, data any) error {
if trie.path == "" || trie.path == path {
return trie.set(path, data)
}
current := trie
commonIdx := commonPrefix(path, current.path)... | internal/node/trie.go | 0.521471 | 0.438064 | trie.go | starcoder |
// Test concurrency primitives: power series.
package ps
// ===========================================================================
// Specific power series
/*
--- https://en.wikipedia.org/wiki/Formal_power_series
1 / (1-x) <=> a(n) = 1
1 / (1+x) <=> a(n) = (-1)^n
x / (1-x)^2 <=> a(n) = n
--- e^x
U := a0 a1 a... | series.go | 0.792585 | 0.651909 | series.go | starcoder |
package data
import (
"fmt"
"github.com/foxcapades/lib-go-discord/v0/tools/fields/internal/types"
)
const (
soEqual = "ShouldEqual"
soResemble = "ShouldResemble"
soAlmost = "ShouldAlmostEqual"
)
func wrapString(i string) string {
return fmt.Sprintf("string(%s)", i)
}
func wrapFloat32(i string) string {
... | v0/tools/fields/internal/data/MultiTypes.go | 0.510496 | 0.490175 | MultiTypes.go | starcoder |
package symbols
import (
"fmt"
"github.com/shanzi/gexpr/types"
"github.com/shanzi/gexpr/values"
)
type _operators struct{}
var operators_singleton = &_operators{}
func Operators() values.OperatorInterface {
return operators_singleton
}
func (self *_operators) ADD(a, b values.Value) values.Value {
if types.As... | symbols/operators.go | 0.757525 | 0.472805 | operators.go | starcoder |
package main
import (
"fmt"
"sort"
fuzz "github.com/google/gofuzz"
)
// merge combines element in slice[p:q] &
// slice[q+1:r] back in slice[p:r] but in
// sorted order
func merge(slice []int64, p, q, r int) {
// n1 & n2, contain the number of elements
// slice[p:q] & slice[q+1:r] respectively
n1 := q - p + 1
... | merge-sort/main.go | 0.651687 | 0.432782 | main.go | starcoder |
package onshape
import (
"encoding/json"
)
// BTPArgumentDeclaration232AllOf struct for BTPArgumentDeclaration232AllOf
type BTPArgumentDeclaration232AllOf struct {
BtType *string `json:"btType,omitempty"`
Name *BTPIdentifier8 `json:"name,omitempty"`
StandardType *string `json:"standardType,omitempty"`
Type *BTPT... | onshape/model_btp_argument_declaration_232_all_of.go | 0.769254 | 0.491578 | model_btp_argument_declaration_232_all_of.go | starcoder |
package column
// Row represents a cursor at a particular row offest in the transaction.
type Row struct {
txn *Txn
}
// --------------------------- Numbers ----------------------------
// Int loads a int value at a particular column
func (r Row) Int(columnName string) (v int, ok bool) {
return intRea... | txn_row.go | 0.750187 | 0.662626 | txn_row.go | starcoder |
package volume
import (
"math"
"math/rand"
)
// NewDimensions creates a new Dimension struct
func NewDimensions(x, y, z int) Dimensions {
return Dimensions{x, y, z}
}
// Dimensions represents the volumetric size of the data.
type Dimensions struct {
X, Y, Z int
}
// Size returns the number of elements.
func (d ... | volume/vol.go | 0.912034 | 0.684944 | vol.go | starcoder |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.