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 zgraph
import (
"errors"
"image"
"image/color"
"math"
)
// ColorChannel is used to distinguish color channel (RGBA) for ZGraph functions
type ColorChannel int
const (
// ChannelR the Red channel of the pixel
ChannelR ColorChannel = 0
// ChannelG the Green channel of the pixel
ChannelG ColorChannel = 1
// ChannelB the Blue channel of the pixel
ChannelB ColorChannel = 2
// ChannelA the Alpha channel of the pixel
ChannelA ColorChannel = 3
)
// ZGraph is used to create 2D graph
type ZGraph struct {
// Image is the image object of this graph
Image image.RGBA
// DataBounds is the bound of the data represented on the image
DataBounds image.Rectangle
// ImageBounds is the bound of the image
ImageBounds image.Rectangle
// Func1D is the function to generate y data from point x in dataSeries
Func1D func(x float64, dataSeries int) float64
// Func2D is the function to generate color channel strength from point (x,y). Should only return 0.0~1.0
Func2D func(x float64, y float64, channel ColorChannel) float64
// Series1DColors is a map of color used by Func1D graphs
Series1DColors []color.RGBA
// ThreadCount specifies how many threads to create for drawing the graphs
ThreadCount int
}
// Init will initialize the ZGraph
func (z *ZGraph) Init(bounds image.Rectangle, dataBounds image.Rectangle) {
z.Image = *image.NewRGBA(bounds)
z.ImageBounds = bounds
z.DataBounds = dataBounds
z.ThreadCount = 4
}
func (z *ZGraph) dataBoundToPixel(x, y float64) (int, int) {
var imW = z.ImageBounds.Max.X - z.ImageBounds.Min.X
var imH = z.ImageBounds.Max.Y - z.ImageBounds.Min.Y
var dbW = z.DataBounds.Max.X - z.DataBounds.Min.X
var dbH = z.DataBounds.Max.Y - z.DataBounds.Min.Y
var dbX = x - float64(z.DataBounds.Min.X)
var dbY = y - float64(z.DataBounds.Min.Y)
var pxX = dbX*float64(imW)/float64(dbW) + float64(z.ImageBounds.Min.X)
var pxY = float64(z.ImageBounds.Max.Y) - dbY*float64(imH)/float64(dbH)
return int(math.Round(pxX)), int(math.Round(pxY))
}
func (z *ZGraph) pixelToDataBound(x, y int) (float64, float64) {
var imW = z.ImageBounds.Max.X - z.ImageBounds.Min.X
var imH = z.ImageBounds.Max.Y - z.ImageBounds.Min.Y
var dbW = z.DataBounds.Max.X - z.DataBounds.Min.X
var dbH = z.DataBounds.Max.Y - z.DataBounds.Min.Y
var pxX = float64(x - z.ImageBounds.Min.X)
var pxY = float64(y - z.ImageBounds.Min.Y)
var dbX = pxX*float64(dbW)/float64(imW) + float64(z.DataBounds.Min.X)
var dbY = float64(z.DataBounds.Max.Y) - pxY*float64(dbH)/float64(imH)
return dbX, dbY
}
// Set1DSeriesColor will set the color of the series that is contained in 1D graph
// It is also defines the number of series it has
func (z *ZGraph) Set1DSeriesColor(colors ...color.RGBA) {
z.Series1DColors = colors
}
// Draw1D draws a graph based on function, the func1D must return value between 0..1 inclusive
func (z *ZGraph) Draw1D(func1D func(x float64, dataSeries int) float64) (*image.RGBA, error) {
var f = func1D
if f == nil {
f = z.Func1D
}
if f == nil {
return nil, errors.New("Func1D is not set")
}
var series = len(z.Series1DColors)
if series == 0 {
return nil, errors.New("Series is not set")
}
var thCount = 0
if z.ThreadCount <= 0 {
z.ThreadCount = 1
}
var chans = make(chan interface{}, z.ThreadCount)
for x := z.ImageBounds.Min.X; x <= z.ImageBounds.Max.X; x++ {
dbX, _ := z.pixelToDataBound(x, 0)
if thCount < z.ThreadCount {
chans <- z.plot1D(f, dbX)
} else {
_ = <-chans
chans <- z.plot1D(f, dbX)
}
}
for thCount > 0 {
_ = <-chans
thCount--
}
return &z.Image, nil
}
func (z *ZGraph) plot1D(f func(x float64, dataSeries int) float64, dataX float64) interface{} {
for s := 0; s < len(z.Series1DColors); s++ {
dataY := f(dataX, s)
pxX, pxY := z.dataBoundToPixel(dataX, dataY)
serie := z.Series1DColors[s]
z.Image.SetRGBA(pxX, pxY, serie)
}
return nil
}
// Draw2D draws a 2D image based on function, the func2D must return value between 0..1 inclusive
func (z *ZGraph) Draw2D(func2D func(x float64, y float64, channel ColorChannel) float64) (image.Image, error) {
var f = func2D
if f == nil {
f = z.Func2D
}
if f == nil {
return nil, errors.New("Func2D is not set")
}
var thCount = 0
if z.ThreadCount <= 0 {
z.ThreadCount = 1
}
var chans = make(chan interface{}, z.ThreadCount)
for y := z.ImageBounds.Min.Y; y <= z.ImageBounds.Max.Y; y++ {
for x := z.ImageBounds.Min.X; x <= z.ImageBounds.Max.X; x++ {
dbX, dbY := z.pixelToDataBound(x, y)
if thCount < z.ThreadCount {
chans <- z.plot2D(f, dbX, dbY)
thCount++
} else {
_ = <-chans
chans <- z.plot2D(f, dbX, dbY)
}
}
}
for thCount > 0 {
_ = <-chans
thCount--
}
return &z.Image, nil
}
func (z *ZGraph) plot2D(f func(x float64, y float64, channel ColorChannel) float64, dataX float64, dataY float64) interface{} {
pxX, pxY := z.dataBoundToPixel(dataX, dataY)
var col = color.RGBA{
A: uint8(f(dataX, dataY, ChannelA) * 255),
R: uint8(f(dataX, dataY, ChannelR) * 255),
G: uint8(f(dataX, dataY, ChannelG) * 255),
B: uint8(f(dataX, dataY, ChannelB) * 255),
}
z.Image.SetRGBA(pxX, pxY, col)
return nil
} | zgraph/zgraph.go | 0.774498 | 0.658596 | zgraph.go | starcoder |
package sql
import (
"fmt"
"golang.org/x/net/context"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/pkg/errors"
)
// collectSpans collects the upper bound set of read and write spans that the
// planNode expects to touch when executed. The two sets do not need to be
// disjoint, and any span in the write set will be implicitly considered in
// the read set as well. There is also no guarantee that Spans within either
// set are disjoint. It is an error for a planNode to touch any span outside
// those that it reports from this method, but a planNode is not required to
// touch all spans that it reports.
func collectSpans(ctx context.Context, plan planNode) (reads, writes roachpb.Spans, err error) {
switch n := plan.(type) {
case
*valueGenerator,
*valuesNode,
*emptyNode:
return nil, nil, nil
case *scanNode:
return n.spans, nil, nil
case *updateNode:
return n.run.collectSpans(ctx)
case *insertNode:
return n.run.collectSpans(ctx)
case *deleteNode:
return n.run.collectSpans(ctx)
case *delayedNode:
return collectSpans(ctx, n.plan)
case *distinctNode:
return collectSpans(ctx, n.plan)
case *explainDistSQLNode:
return collectSpans(ctx, n.plan)
case *explainPlanNode:
return collectSpans(ctx, n.plan)
case *traceNode:
return collectSpans(ctx, n.plan)
case *limitNode:
return collectSpans(ctx, n.plan)
case *sortNode:
return collectSpans(ctx, n.plan)
case *groupNode:
return collectSpans(ctx, n.plan)
case *windowNode:
return collectSpans(ctx, n.plan)
case *ordinalityNode:
return collectSpans(ctx, n.source)
case *filterNode:
return collectSpans(ctx, n.source.plan)
case *renderNode:
return collectSpans(ctx, n.source.plan)
case *indexJoinNode:
return indexJoinSpans(ctx, n)
case *joinNode:
return concatSpans(ctx, n.left.plan, n.right.plan)
case *unionNode:
return concatSpans(ctx, n.left, n.right)
}
panic(fmt.Sprintf("don't know how to collect spans for node %T", plan))
}
func indexJoinSpans(
ctx context.Context, n *indexJoinNode,
) (reads, writes roachpb.Spans, err error) {
indexReads, indexWrites, err := collectSpans(ctx, n.index)
if err != nil {
return nil, nil, err
}
if len(indexWrites) > 0 {
return nil, nil, errors.Errorf("unexpected index scan span writes: %v", indexWrites)
}
// We can not be sure which spans in the table we will read based only on the
// initial index span because we will dynamically lookup rows in the table based
// on the result of the index scan. We conservatively report that we will read the
// index span and the entire span for the table's primary index.
primaryReads := n.table.desc.PrimaryIndexSpan()
return append(indexReads, primaryReads), nil, nil
}
func concatSpans(
ctx context.Context, left, right planNode,
) (reads, writes roachpb.Spans, err error) {
leftReads, leftWrites, err := collectSpans(ctx, left)
if err != nil {
return nil, nil, err
}
rightReads, rightWrites, err := collectSpans(ctx, right)
if err != nil {
return nil, nil, err
}
return append(leftReads, rightReads...), append(leftWrites, rightWrites...), nil
} | pkg/sql/plan_spans.go | 0.729712 | 0.425187 | plan_spans.go | starcoder |
package simpletime
import "time"
// Range is a simple tuple of earliest and latest time
type Range struct {
Start time.Time
End time.Time
}
// Duration returns the duration between start and end of the range
func (r Range) Duration() time.Duration {
return r.End.Sub(r.Start)
}
// Combine returns a Range which spans all the given ranges. The final range will be the earliest and latest value
// of all provided ranges.
func (r Range) Combine(others ...Range) Range {
combined := r
for _, other := range append(others, r) {
// We need to watch out for zero value Earliest times
if (other.Start.Before(combined.Start) || combined.Start.IsZero()) && !other.Start.IsZero() {
combined.Start = other.Start
}
if other.End.After(combined.End) {
combined.End = other.End
}
}
return combined
}
// Contains checks whether the given time is within the range. If `inclusive` is set true, the edges of the range are
// included in the contains logic.
func (r Range) Contains(t time.Time, inclusive bool) bool {
left := r.Start.Before(t)
if inclusive {
left = left || r.Start.Equal(t)
}
right := r.End.After(t)
if inclusive {
right = right || r.End.Equal(t)
}
return right && left
}
/*
ContainsRange returns whether the receiver range contains the other range. The `inclusive` flag determines if the
extents on the ranges are considered to be contained if they are equal in value.
Example of `r` contains `other`:
r: |-----------------------------|
other: |-----------|
*/
func (r Range) ContainsRange(other Range, inclusive bool) bool {
left := r.Start.Before(other.Start)
if inclusive {
left = left || r.Start.Equal(other.Start)
}
right := r.End.After(other.End)
if inclusive {
right = right || r.End.Equal(other.End)
}
return left && right
}
/*
Overlaps returns whether the receiver range overlaps the other range. The `inclusive` flag determines if the
extents on the ranges are considered to be overlapped if they are equal in value.
Example of `r` contains `other`:
r: |---------|
other: |-----------|
*/
func (r Range) Overlaps(other Range, inclusive bool) bool {
return r.overlapsLeft(other, inclusive) || r.overlapsRight(other, inclusive) || r.ContainsRange(other, inclusive)
}
/*
r: |-------------|
other: |-------------|
*/
func (r Range) overlapsLeft(other Range, inclusive bool) bool {
overlap := r.Start.Before(other.Start)
if inclusive {
overlap = overlap && (r.End.After(other.Start) || r.End.Equal(other.Start))
} else {
overlap = overlap && r.End.After(other.Start)
}
return overlap
}
/*
r: |-------------|
other: |-------------|
*/
func (r Range) overlapsRight(other Range, inclusive bool) bool {
overlap := r.End.After(other.End)
if inclusive {
overlap = overlap && (r.Start.Before(other.End) || r.Start.Equal(other.End))
} else {
overlap = overlap && r.Start.Before(other.End)
}
return overlap
}
// Iterate returns an iterator that uses the extents of the Range.
func (r Range) Iterate(step time.Duration) *Iterator {
return NewIterator(r.Start, r.End, step)
}
// IterateDays returns an iterator function that returns the nth day (n >= 1) and a boolean that signals that the iterator is done
func (r Range) IterateDays(n int) *Iterator {
return r.IterateHours(n * 24)
}
func (r Range) IterateHours(n int) *Iterator {
return r.Iterate(time.Duration(n) * time.Hour)
}
func (r Range) IterateMinutes(n int) *Iterator {
return r.Iterate(time.Duration(n) * time.Minute)
}
func (r Range) IterateSeconds(n int) *Iterator {
return r.Iterate(time.Duration(n) * time.Second)
} | time/range.go | 0.901105 | 0.665336 | range.go | starcoder |
package brotli
import "encoding/binary"
/* Copyright 2016 Google Inc. All Rights Reserved.
Distributed under MIT license.
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
*/
func (*h10) HashTypeLength() uint {
return 4
}
func (*h10) StoreLookahead() uint {
return 128
}
func hashBytesH10(data []byte) uint32 {
var h uint32 = binary.LittleEndian.Uint32(data) * kHashMul32
/* The higher bits contain more mixture from the multiplication,
so we take our results from there. */
return h >> (32 - 17)
}
/* A (forgetful) hash table where each hash bucket contains a binary tree of
sequences whose first 4 bytes share the same hash code.
Each sequence is 128 long and is identified by its starting
position in the input data. The binary tree is sorted by the lexicographic
order of the sequences, and it is also a max-heap with respect to the
starting positions. */
type h10 struct {
hasherCommon
window_mask_ uint
buckets_ [1 << 17]uint32
invalid_pos_ uint32
forest []uint32
}
func (h *h10) Initialize(params *encoderParams) {
h.window_mask_ = (1 << params.lgwin) - 1
h.invalid_pos_ = uint32(0 - h.window_mask_)
var num_nodes uint = uint(1) << params.lgwin
h.forest = make([]uint32, 2*num_nodes)
}
func (h *h10) Prepare(one_shot bool, input_size uint, data []byte) {
var invalid_pos uint32 = h.invalid_pos_
var i uint32
for i = 0; i < 1<<17; i++ {
h.buckets_[i] = invalid_pos
}
}
func leftChildIndexH10(self *h10, pos uint) uint {
return 2 * (pos & self.window_mask_)
}
func rightChildIndexH10(self *h10, pos uint) uint {
return 2*(pos&self.window_mask_) + 1
}
/* Stores the hash of the next 4 bytes and in a single tree-traversal, the
hash bucket's binary tree is searched for matches and is re-rooted at the
current position.
If less than 128 data is available, the hash bucket of the
current position is searched for matches, but the state of the hash table
is not changed, since we can not know the final sorting order of the
current (incomplete) sequence.
This function must be called with increasing cur_ix positions. */
func storeAndFindMatchesH10(self *h10, data []byte, cur_ix uint, ring_buffer_mask uint, max_length uint, max_backward uint, best_len *uint, matches []backwardMatch) []backwardMatch {
var cur_ix_masked uint = cur_ix & ring_buffer_mask
var max_comp_len uint = brotli_min_size_t(max_length, 128)
var should_reroot_tree bool = (max_length >= 128)
var key uint32 = hashBytesH10(data[cur_ix_masked:])
var forest []uint32 = self.forest
var prev_ix uint = uint(self.buckets_[key])
var node_left uint = leftChildIndexH10(self, cur_ix)
var node_right uint = rightChildIndexH10(self, cur_ix)
var best_len_left uint = 0
var best_len_right uint = 0
var depth_remaining uint
/* The forest index of the rightmost node of the left subtree of the new
root, updated as we traverse and re-root the tree of the hash bucket. */
/* The forest index of the leftmost node of the right subtree of the new
root, updated as we traverse and re-root the tree of the hash bucket. */
/* The match length of the rightmost node of the left subtree of the new
root, updated as we traverse and re-root the tree of the hash bucket. */
/* The match length of the leftmost node of the right subtree of the new
root, updated as we traverse and re-root the tree of the hash bucket. */
if should_reroot_tree {
self.buckets_[key] = uint32(cur_ix)
}
for depth_remaining = 64; ; depth_remaining-- {
var backward uint = cur_ix - prev_ix
var prev_ix_masked uint = prev_ix & ring_buffer_mask
if backward == 0 || backward > max_backward || depth_remaining == 0 {
if should_reroot_tree {
forest[node_left] = self.invalid_pos_
forest[node_right] = self.invalid_pos_
}
break
}
{
var cur_len uint = brotli_min_size_t(best_len_left, best_len_right)
var len uint
assert(cur_len <= 128)
len = cur_len + findMatchLengthWithLimit(data[cur_ix_masked+cur_len:], data[prev_ix_masked+cur_len:], max_length-cur_len)
if matches != nil && len > *best_len {
*best_len = uint(len)
initBackwardMatch(&matches[0], backward, uint(len))
matches = matches[1:]
}
if len >= max_comp_len {
if should_reroot_tree {
forest[node_left] = forest[leftChildIndexH10(self, prev_ix)]
forest[node_right] = forest[rightChildIndexH10(self, prev_ix)]
}
break
}
if data[cur_ix_masked+len] > data[prev_ix_masked+len] {
best_len_left = uint(len)
if should_reroot_tree {
forest[node_left] = uint32(prev_ix)
}
node_left = rightChildIndexH10(self, prev_ix)
prev_ix = uint(forest[node_left])
} else {
best_len_right = uint(len)
if should_reroot_tree {
forest[node_right] = uint32(prev_ix)
}
node_right = leftChildIndexH10(self, prev_ix)
prev_ix = uint(forest[node_right])
}
}
}
return matches
}
/* Finds all backward matches of &data[cur_ix & ring_buffer_mask] up to the
length of max_length and stores the position cur_ix in the hash table.
Sets *num_matches to the number of matches found, and stores the found
matches in matches[0] to matches[*num_matches - 1]. The matches will be
sorted by strictly increasing length and (non-strictly) increasing
distance. */
func findAllMatchesH10(handle *h10, dictionary *encoderDictionary, data []byte, ring_buffer_mask uint, cur_ix uint, max_length uint, max_backward uint, gap uint, params *encoderParams, matches []backwardMatch) uint {
var orig_matches []backwardMatch = matches
var cur_ix_masked uint = cur_ix & ring_buffer_mask
var best_len uint = 1
var short_match_max_backward uint
if params.quality != hqZopflificationQuality {
short_match_max_backward = 16
} else {
short_match_max_backward = 64
}
var stop uint = cur_ix - short_match_max_backward
var dict_matches [maxStaticDictionaryMatchLen + 1]uint32
var i uint
if cur_ix < short_match_max_backward {
stop = 0
}
for i = cur_ix - 1; i > stop && best_len <= 2; i-- {
var prev_ix uint = i
var backward uint = cur_ix - prev_ix
if backward > max_backward {
break
}
prev_ix &= ring_buffer_mask
if data[cur_ix_masked] != data[prev_ix] || data[cur_ix_masked+1] != data[prev_ix+1] {
continue
}
{
var len uint = findMatchLengthWithLimit(data[prev_ix:], data[cur_ix_masked:], max_length)
if len > best_len {
best_len = uint(len)
initBackwardMatch(&matches[0], backward, uint(len))
matches = matches[1:]
}
}
}
if best_len < max_length {
matches = storeAndFindMatchesH10(handle, data, cur_ix, ring_buffer_mask, max_length, max_backward, &best_len, matches)
}
for i = 0; i <= maxStaticDictionaryMatchLen; i++ {
dict_matches[i] = kInvalidMatch
}
{
var minlen uint = brotli_max_size_t(4, best_len+1)
if findAllStaticDictionaryMatches(dictionary, data[cur_ix_masked:], minlen, max_length, dict_matches[0:]) {
var maxlen uint = brotli_min_size_t(maxStaticDictionaryMatchLen, max_length)
var l uint
for l = minlen; l <= maxlen; l++ {
var dict_id uint32 = dict_matches[l]
if dict_id < kInvalidMatch {
var distance uint = max_backward + gap + uint(dict_id>>5) + 1
if distance <= params.dist.max_distance {
initDictionaryBackwardMatch(&matches[0], distance, l, uint(dict_id&31))
matches = matches[1:]
}
}
}
}
}
return uint(-cap(matches) + cap(orig_matches))
}
/* Stores the hash of the next 4 bytes and re-roots the binary tree at the
current sequence, without returning any matches.
REQUIRES: ix + 128 <= end-of-current-block */
func (h *h10) Store(data []byte, mask uint, ix uint) {
var max_backward uint = h.window_mask_ - windowGap + 1
/* Maximum distance is window size - 16, see section 9.1. of the spec. */
storeAndFindMatchesH10(h, data, ix, mask, 128, max_backward, nil, nil)
}
func (h *h10) StoreRange(data []byte, mask uint, ix_start uint, ix_end uint) {
var i uint = ix_start
var j uint = ix_start
if ix_start+63 <= ix_end {
i = ix_end - 63
}
if ix_start+512 <= i {
for ; j < i; j += 8 {
h.Store(data, mask, j)
}
}
for ; i < ix_end; i++ {
h.Store(data, mask, i)
}
}
func (h *h10) StitchToPreviousBlock(num_bytes uint, position uint, ringbuffer []byte, ringbuffer_mask uint) {
if num_bytes >= h.HashTypeLength()-1 && position >= 128 {
var i_start uint = position - 128 + 1
var i_end uint = brotli_min_size_t(position, i_start+num_bytes)
/* Store the last `128 - 1` positions in the hasher.
These could not be calculated before, since they require knowledge
of both the previous and the current block. */
var i uint
for i = i_start; i < i_end; i++ {
/* Maximum distance is window size - 16, see section 9.1. of the spec.
Furthermore, we have to make sure that we don't look further back
from the start of the next block than the window size, otherwise we
could access already overwritten areas of the ring-buffer. */
var max_backward uint = h.window_mask_ - brotli_max_size_t(windowGap-1, position-i)
/* We know that i + 128 <= position + num_bytes, i.e. the
end of the current block and that we have at least
128 tail in the ring-buffer. */
storeAndFindMatchesH10(h, ringbuffer, i, ringbuffer_mask, 128, max_backward, nil, nil)
}
}
}
/* MAX_NUM_MATCHES == 64 + MAX_TREE_SEARCH_DEPTH */
const maxNumMatchesH10 = 128
func (*h10) FindLongestMatch(dictionary *encoderDictionary, data []byte, ring_buffer_mask uint, distance_cache []int, cur_ix uint, max_length uint, max_backward uint, gap uint, max_distance uint, out *hasherSearchResult) {
panic("unimplemented")
}
func (*h10) PrepareDistanceCache(distance_cache []int) {
panic("unimplemented")
} | vendor/github.com/andybalholm/brotli/h10.go | 0.721841 | 0.447762 | h10.go | starcoder |
package parametric2d
import (
"math"
"github.com/gmlewis/go-poly2tri"
"github.com/gmlewis/go3d/float64/vec2"
"github.com/gmlewis/go3d/float64/vec3"
)
// Line represents a straight line segment and implements interface T.
type Line struct {
p0, p1 vec2.T
bbox vec2.Rect
}
// NewLine returns a new 2D Line from two points.
func NewLine(p0, p1 vec2.T) Line {
ll := vec2.Min(&p0, &p1)
ur := vec2.Max(&p0, &p1)
return Line{p0: p0, p1: p1, bbox: vec2.Rect{Min: ll, Max: ur}}
}
// BBox returns the minimum bounding box of the Line.
func (s Line) BBox() vec2.Rect {
return s.bbox
}
// At returns the point on the Line at the given position (0 <= t <= 1).
func (s Line) At(t float64) vec2.T {
return vec2.Interpolate(&s.p0, &s.p1, t)
}
// Tangent returns the tangent to the Line
// at the given position (0 <= t <= 1).
func (s Line) Tangent(t float64) vec2.T {
return vec2.Sub(&s.p1, &s.p0)
}
// NTangent returns the normalized tangent to the Line
// at the given position (0 <= t <= 1).
func (s Line) NTangent(t float64) vec2.T {
v := s.Tangent(t)
return *v.Normalize()
}
// Normal returns the normal to the Line
// at the given position (0 <= t <= 1).
func (s Line) Normal(t float64) vec2.T {
v := s.Tangent(t)
return *v.Rotate90DegLeft()
}
// NNormal returns the normalized normal to the Line
// at the given position (0 <= t <= 1).
func (s Line) NNormal(t float64) vec2.T {
v := s.Normal(t)
return *v.Normalize()
}
// Wall extrudes a line into a 3D wall. `maxDegrees` is ignored.
func (s Line) Wall(height, maxDegrees float64, flipNormals bool) ([]Triangle3D, poly2tri.PointArray) {
p0 := s.At(0)
p1 := s.At(1)
t0 := Triangle3D{
vec3.T{p0[0], p0[1], 0},
vec3.T{p1[0], p1[1], height},
vec3.T{p0[0], p0[1], height},
}
if flipNormals {
t0[1], t0[2] = t0[2], t0[1]
}
t1 := Triangle3D{
vec3.T{p0[0], p0[1], 0},
vec3.T{p1[0], p1[1], 0},
vec3.T{p1[0], p1[1], height},
}
if flipNormals {
t1[1], t1[2] = t1[2], t1[1]
}
return []Triangle3D{t0, t1}, poly2tri.PointArray{poly2tri.NewPoint(p1[0], p1[1])}
}
// Bevel returns a 3D beveled object based on the provided Line.
func (s Line) Bevel(height, offset, deg, maxDegrees float64, flipNormals bool, prevNN, nextNN *vec2.T) ([]Triangle3D, poly2tri.PointArray) {
h := offset * math.Tan(deg*math.Pi/180.0)
p0 := s.At(0)
p1 := s.At(1)
n0 := s.NNormal(0)
n1 := s.NNormal(1)
if flipNormals {
n0[0], n0[1], n1[0], n1[1] = -n0[0], -n0[1], -n1[0], -n1[1]
}
angle0 := vec2.Angle(prevNN, &n0)
newLength0 := offset / math.Cos(0.5*angle0)
angle1 := vec2.Angle(&n1, nextNN)
newLength1 := offset / math.Cos(0.5*angle1)
prevNN.Add(&n0)
prevNN.Normalize()
nextNN.Add(&n1)
nextNN.Normalize()
p2 := prevNN.Scale(newLength0).Add(&p0)
p3 := nextNN.Scale(newLength1).Add(&p1)
t0 := Triangle3D{
vec3.T{p0[0], p0[1], height},
vec3.T{p3[0], p3[1], height + h},
vec3.T{p2[0], p2[1], height + h},
}
if flipNormals {
t0[1], t0[2] = t0[2], t0[1]
}
t1 := Triangle3D{
vec3.T{p0[0], p0[1], height},
vec3.T{p1[0], p1[1], height},
vec3.T{p3[0], p3[1], height + h},
}
if flipNormals {
t1[1], t1[2] = t1[2], t1[1]
}
return []Triangle3D{t0, t1}, poly2tri.PointArray{poly2tri.NewPoint(p3[0], p3[1])}
}
// IsLine is true for type Line.
func (s Line) IsLine() bool {
return true
} | line2d.go | 0.885409 | 0.714591 | line2d.go | starcoder |
package polynomial
import (
"math"
)
// Sum obtains a Polynomial representing the sum of the caller and other Polynomial
func (p Polynomial) Sum(other Polynomial) Polynomial {
m := make(map[uint]float64)
grade := max(p.grade, other.grade)
for i := uint(0); i <= grade; i++ {
sum := p.coefficients[i] + other.coefficients[i]
if checkNotZero(p.coefficients[i]) {
m[i] = sum
}
}
return Polynomial{m, getGradeFromMap(m)}
}
// Subtract obtains a Polynomial substracting other from the caller
func (p Polynomial) Subtract(other Polynomial) Polynomial {
m := make(map[uint]float64)
grade := max(p.grade, other.grade)
for i := uint(0); i <= grade; i++ {
sub := p.coefficients[i] - other.coefficients[i]
if checkNotZero(sub) {
m[i] = sub
}
}
return Polynomial{m, getGradeFromMap(m)}
}
// Multiply obtains a Polynomial as a result of multiplying the caller and other Polynomial
func (p Polynomial) Multiply(other Polynomial) Polynomial {
m := make(map[uint]float64)
grade := p.grade + other.grade
for i := uint(0); i <= p.grade; i++ {
for j := uint(0); j <= other.grade; j++ {
a := p.coefficients[i]
b := other.coefficients[j]
if checkNotZero(a * b) {
m[i+j] += a * b
}
}
}
return Polynomial{m, grade}
}
// Derive retrieves the derivative Polyinomial as a result of deriving the caller Polynomial
func (p Polynomial) Derive() Polynomial {
m := make(map[uint]float64)
for i := uint(0); i <= p.grade; i++ {
if checkNotZero(p.coefficients[i+1]) {
m[i] = p.coefficients[i+1] * (float64(i + 1))
}
}
return Polynomial{m, p.grade - 1}
}
// Integrate retrieves the Polynomial result of the integration of the caller Polynomial
// The argument will be the constant of integration
func (p Polynomial) Integrate(constant float64) Polynomial {
m := make(map[uint]float64)
m[0] = constant
for i := uint(0); i <= p.grade+1; i++ {
if checkNotZero(p.coefficients[i]) {
m[i+1] = p.coefficients[i] / float64(i+1)
}
}
return Polynomial{m, p.grade + 1}
}
// Evaluate retrieves the value of the caller Polynomial expression in a given point x
func (p Polynomial) Evaluate(x float64) float64 {
var sum float64
for i := uint(0); i <= p.grade; i++ {
if checkNotZero(p.coefficients[i]) {
sum += p.coefficients[i] * math.Pow(x, float64(i))
}
}
return sum
}
func max(a uint, b uint) uint {
if a > b {
return a
}
return b
}
func checkNotZero(a float64) bool {
return a*a > precission
} | polynomial/operations.go | 0.843348 | 0.710679 | operations.go | starcoder |
package beta
import (
"bytes"
"fmt"
"math"
)
// BetaDistribution :
// http://en.wikipedia.org/wiki/Beta_distribution
// alpha shape parameter (alpha > 0)
// beta shape parameter (beta > 0)
type BetaDistribution struct {
alpha float64
beta float64
isValid bool
firstMoment float64
secondMoment float64
thirdMoment float64
}
// NewBetaDistribution : constructor
func NewBetaDistribution(alpha, beta float64) *BetaDistribution {
b := new(BetaDistribution)
b.isValid = checkValidity(alpha, beta)
if !b.isValid {
return nil
}
b.alpha = alpha
b.beta = beta
b.computeMoments()
return b
}
// checkValidity : check validity of parameters
func checkValidity(alpha, beta float64) bool {
return alpha > 0 && beta > 0
}
// computeMoments : compute the moments of the distribution
func (b *BetaDistribution) computeMoments() bool {
if !b.isValid {
return false
}
b.firstMoment = b.alpha / (b.alpha + b.beta)
b.secondMoment = b.firstMoment * (b.alpha + 1) / (b.alpha + b.beta + 1)
b.thirdMoment = b.secondMoment * (b.alpha + 2) / (b.alpha + b.beta + 2)
return true
}
// Mean : E[X], the mean of the random variable X.
func (b *BetaDistribution) Mean() float64 {
return b.firstMoment
}
// Variance :
// V[X], the variance of the random variable X.
// V[X] = E[X^2] - (E[X])^2
func (b *BetaDistribution) Variance() float64 {
return b.secondMoment - b.firstMoment*b.firstMoment
}
// DistributionFunction :
// Probability distribution function, PDF(x) of random variable X.
// The probability that X <= x.
func (b *BetaDistribution) DistributionFunction(x float64) float64 {
return RegularizedIncomplete(x, b.alpha, b.beta)
}
// DensityFunction :
// Probability density function, pdf(x) of random variable X.
// The probability that x < X < x + dx.
func (b *BetaDistribution) DensityFunction(x float64) float64 {
var betax = math.Pow(x, b.alpha-1.) * math.Pow((1.-x), (b.beta-1.))
var betac = Complete(b.alpha, b.beta)
var pdf = betax / betac
if math.IsNaN(pdf) || pdf < 0 {
pdf = 0
}
return pdf
}
// MeanResidualLife :
// E[X | age], expected residual life of X given a job age.
// "Representing the Mean Residual Life in Terms of the Failure Rate"
// by <NAME> and <NAME>
func (b *BetaDistribution) MeanResidualLife(age float64) float64 {
var survival = 1 - b.DistributionFunction(age)
if survival == 0 {
return 0
}
var failureRate = b.DensityFunction(age) / survival
if math.IsInf(failureRate, 1) {
return failureRate
}
var m = failureRate * (age * (1 - age)) / (b.alpha + b.beta)
m += b.firstMoment - age
return m
}
// MatchMoments : Match the first two moments: m1 and m2
func (b *BetaDistribution) MatchMoments(m1, m2 float64) bool {
variance := m2 - m1*m1
if m1 < 0 || m1 > 1 || variance < 0 || variance >= m1*(1-m1) {
return false
}
temp := (m1 * (1 - m1) / variance) - 1
temp = math.Max(temp, math.SmallestNonzeroFloat64)
b.alpha = m1 * temp
b.beta = (1 - m1) * temp
return b.computeMoments()
}
// GetAlpha : the alpha parameter
func (b *BetaDistribution) GetAlpha() float64 {
return b.alpha
}
// GetBeta : the beta parameter
func (b *BetaDistribution) GetBeta() float64 {
return b.beta
}
// PrintTable : print the percentile table
func (b *BetaDistribution) PrintTable() string {
var buf bytes.Buffer
fmt.Fprintf(&buf, "x \t pdf(x) \t PDF(x) \t m(x) \n")
var nMax = 20
var delta = 1. / float64(nMax)
for n := 0; n <= nMax; n++ {
x := float64(n) * delta
x = math.Min(x, 1)
fmt.Fprintf(&buf, "%f \t %f \t %f \t %f \n", x, b.DensityFunction(x), b.DistributionFunction(x), b.MeanResidualLife(x))
}
return buf.String()
}
// Print : toString() of the distribution
func (b *BetaDistribution) Print() string {
var buf bytes.Buffer
fmt.Fprintf(&buf, "BetaDistribution: ")
fmt.Fprintf(&buf, "alpha = %f; beta = %f; ", b.alpha, b.beta)
fmt.Fprintf(&buf, "mean = %f; var = %f; ", b.Mean(), b.Variance())
fmt.Fprintf(&buf, "m1 = %f; m2 = %f; m3 = %f; ", b.firstMoment, b.secondMoment, b.thirdMoment)
fmt.Fprintf(&buf, "\n")
return buf.String()
} | beta/betaDist.go | 0.779783 | 0.576661 | betaDist.go | starcoder |
Package debug transforms Kubernetes pod-bearing resources so as to configure containers
for remote debugging as suited for a container's runtime technology. This package defines
a _container transformer_ interface. Each transformer implementation should do the following:
1. The transformer should modify the container's entrypoint, command arguments, and environment to enable debugging for the appropriate language runtime.
2. The transformer should expose the port(s) required to connect remote debuggers.
3. The transformer should identify any additional support files required to enable debugging (e.g., the `ptvsd` debugger for Python).
4. The transform should return metadata to describe the remote connection information.
Certain language runtimes require additional support files to enable remote debugging.
These support files are provided through a set of support images defined at `gcr.io/k8s-skaffold/skaffold-debug-support/`
and defined at https://github.com/GoogleContainerTools/container-debug-support.
The appropriate image ID is returned by the language transformer. These support images
are configured as initContainers on the pod and are expected to copy the debugging support
files into a support volume mounted at `/dbg`. The expected convention is that each runtime's
files are placed in `/dbg/<runtimeId>`. This same volume is then mounted into the
actual containers at `/dbg`.
As Kubernetes container objects don't actually carry metadata, we place this metadata on
the container's parent as an _annotation_; as a pod/podspec can have multiple containers, each of which may
be debuggable, we record this metadata using as a JSON object keyed by the container name.
Kubernetes requires that containers within a podspec are uniquely named.
For example, a pod with two containers named `microservice` and `adapter` may be:
debug.cloud.google.com/config: '{
"microservice":{"artifact":"node-example","runtime":"nodejs","ports":{"devtools":9229}},
"adapter":{"artifact":"java-example","runtime":"jvm","ports":{"jdwp":5005}}
}'
Each configuration is itself a JSON object of type `types.ContainerDebugConfiguration`, with an
`artifact` recording the corresponding artifact's `image` in the skaffold.yaml,
a `runtime` field identifying the language runtime, the working directory of the remote image (if known),
and a set of debugging ports.
*/
package debug
import (
"context"
"encoding/json"
"strings"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/debug/types"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/output/log"
)
// PortAllocator is a function that takes a desired port and returns an available port
// Ports are normally uint16 but Kubernetes types.ContainerPort is an integer
type PortAllocator func(int32) int32
// configurationRetriever retrieves an container image configuration
type ConfigurationRetriever func(string) (ImageConfiguration, error)
// ImageConfiguration captures information from a docker/oci image configuration.
// It also includes a "artifact", usually containing the corresponding artifact's' image name from `skaffold.yaml`.
type ImageConfiguration struct {
// Artifact is the corresponding Artifact's image name (`pkg/skaffold/build.Artifact.ImageName`)
Artifact string
Labels map[string]string
Env map[string]string
Entrypoint []string
Arguments []string
WorkingDir string
}
const (
// DebuggingSupportVolume is the name of the volume used to hold language runtime debugging support files.
DebuggingSupportFilesVolume = "debugging-support-files"
)
// entrypointLaunchers is a list of known entrypoints that effectively just launches the container image's CMD
// as a command-line. These entrypoints are ignored.
var entrypointLaunchers []string
var Protocols = []string{}
// isEntrypointLauncher checks if the given entrypoint is a known entrypoint launcher,
// meaning an entrypoint that treats the image's CMD as a command-line.
func isEntrypointLauncher(entrypoint []string) bool {
if len(entrypoint) != 1 {
return false
}
for _, knownEntrypoints := range entrypointLaunchers {
if knownEntrypoints == entrypoint[0] {
return true
}
}
return false
}
func EncodeConfigurations(configurations map[string]types.ContainerDebugConfiguration) string {
bytes, err := json.Marshal(configurations)
if err != nil {
return ""
}
return string(bytes)
}
// exposePort adds a `types.ContainerPort` instance or amends an existing entry with the same port.
func exposePort(entries []types.ContainerPort, portName string, port int32) []types.ContainerPort {
found := false
for i := 0; i < len(entries); {
switch {
case entries[i].Name == portName:
// Ports and names must be unique so rewrite an existing entry if found
log.Entry(context.TODO()).Warnf("skaffold debug needs to expose port %d with name %s. Replacing clashing port definition %d (%s)", port, portName, entries[i].ContainerPort, entries[i].Name)
entries[i].Name = portName
entries[i].ContainerPort = port
found = true
i++
case entries[i].ContainerPort == port:
// Cut any entries with a clashing port
log.Entry(context.TODO()).Warnf("skaffold debug needs to expose port %d for %s. Removing clashing port definition %d (%s)", port, portName, entries[i].ContainerPort, entries[i].Name)
entries = append(entries[:i], entries[i+1:]...)
default:
i++
}
}
if found {
return entries
}
entry := types.ContainerPort{
Name: portName,
ContainerPort: port,
}
return append(entries, entry)
}
func setEnvVar(entries types.ContainerEnv, key, value string) types.ContainerEnv {
if _, found := entries.Env[key]; !found {
entries.Order = append(entries.Order, key)
}
entries.Env[key] = value
return entries
}
// shJoin joins the arguments into a quoted form suitable to pass to `sh -c`.
// Necessary as github.com/kballard/go-shellquote's `Join` quotes `$`.
func shJoin(args []string) string {
result := ""
for i, arg := range args {
if i > 0 {
result += " "
}
if strings.ContainsAny(arg, " \t\r\n\"'()[]{}") {
arg := strings.ReplaceAll(arg, `"`, `\"`)
result += `"` + arg + `"`
} else {
result += arg
}
}
return result
} | pkg/skaffold/debug/transform.go | 0.843734 | 0.600393 | transform.go | starcoder |
package gedcom
import (
"io/ioutil"
"strconv"
"strings"
)
// Tree contains a node structure of a GEDCOM file.
type Tree struct {
Nodes []*Node
Families []*Family
Individuals []*Individual
}
// ParseFromFile loads a file into memory and parses it to a Tree.
func ParseFromFile(file string) (*Tree, error) {
bytes, err := ioutil.ReadFile(file)
if err != nil {
return nil, err
}
str := string(bytes)
str = strings.Replace(str, "\r\n", "\n", -1)
str = strings.TrimSpace(str)
return Parse(strings.Split(str, "\n"))
}
// Parse takes a slice of GEDCOM lines and converts it to a Node structure in a
// Tree.
func Parse(lines []string) (*Tree, error) {
t := &Tree{}
var nodes []*Node
// Convert every line to a node
for _, line := range lines {
parts := strings.Split(line, " ")
n := &Node{}
var err error
n.Depth, err = strconv.Atoi(parts[0])
if err != nil {
return nil, err
}
n.Attribute = strings.TrimSpace(parts[1])
n.Data = strings.TrimSpace(strings.Join(parts[2:], " "))
nodes = append(nodes, n)
}
// Temporary root node that is changed throughout loop
var root *Node
// Loop through every node and assign parent and children nodes
for index, node := range nodes {
// If index is 0 we have a new root element
if node.Depth == 0 {
t.Nodes = append(t.Nodes, node)
root = node
continue
}
// If depth is 1, the root element is the parent of this node
if node.Depth == 1 {
node.Parent = root
root.Children = append(root.Children, node)
continue
}
// If depth is > 1, the parent element of this node is a node that we
// have already processed.
if node.Depth > 1 {
for i := index - 1; i > 0; i-- {
if nodes[i].Depth == node.Depth {
continue
}
if nodes[i].Depth == node.Depth-1 {
node.Parent = nodes[i]
nodes[i].Children = append(node.Parent.Children, node)
break
}
}
continue
}
}
return t, nil
}
// TraverseFamilies loops over all nodes and creates a slice of Families and a
// slice of Individuals.
func (t *Tree) TraverseFamilies() error {
individuals := make(map[string]*Individual)
fams := make(map[string]*Node)
families := make(map[string]*Family)
for _, node := range t.Nodes {
switch node.Data {
case "INDI":
individual := &Individual{Node: node}
individuals[node.Attribute] = individual
t.Individuals = append(t.Individuals, individual)
case "FAM":
fams[node.Attribute] = node
}
}
for id, family := range fams {
f := &Family{}
for _, node := range family.Children {
individual := individuals[node.Data]
switch node.Attribute {
case "HUSB":
f.Father = individual
case "WIFE":
f.Mother = individual
case "CHIL":
f.Children = append(f.Children, individual)
}
}
families[id] = f
t.Families = append(t.Families, f)
}
for _, individual := range individuals {
fam, err := individual.Node.GetDataByAttributes("FAMC")
// If there is an error that means that the individual is not a child
// of a family and has no parents set and we should move on to the next
// individual.
if err != nil {
continue
}
if f, exists := families[fam]; exists {
if f.Father != nil {
individual.Father = f.Father
f.Father.Children = append(f.Father.Children, individual)
}
if f.Mother != nil {
individual.Mother = f.Mother
f.Mother.Children = append(f.Mother.Children, individual)
}
}
}
return nil
}
// FindIndividualByAttribute searches through the slice of Individuals on the
// Tree and looks for an Individual that's internal Node structure has the
// attribute provided with the same data provided.
func (t *Tree) FindIndividualByAttribute(attribute, data string) *Individual {
for _, individual := range t.Individuals {
if a, err := individual.Node.GetDataByAttributes(attribute); err == nil {
if a == data {
return individual
}
}
}
return nil
} | tree.go | 0.613931 | 0.410697 | tree.go | starcoder |
package intersect
import "reflect"
func Interface(x interface{}, y interface{}) reflect.Value {
xValue, yValue := reflect.Value{}, reflect.Value{}
if xValueNode, ok := x.(reflect.Value); ok {
xValue = xValueNode
} else {
xValue = reflect.ValueOf(x)
}
if yValueNode, ok := y.(reflect.Value); ok {
yValue = yValueNode
} else {
yValue = reflect.ValueOf(y)
}
if xValue.Type().Kind() == reflect.Ptr {
xValue = xValue.Elem()
}
if yValue.Type().Kind() == reflect.Ptr {
yValue = yValue.Elem()
}
set := reflect.MakeSlice(xValue.Type(), 0, 0)
hash := make(map[interface{}]bool)
for i := 0; i < xValue.Len(); i++ {
v := xValue.Index(i)
hash[v.Interface()] = true
}
for i := 0; i < yValue.Len(); i++ {
v := yValue.Index(i)
if _, ok := hash[v.Interface()]; ok {
set = reflect.Append(set, v)
}
}
return set
}
func String(x []string, y []string) []string {
value := Interface(x, y)
return value.Interface().([]string)
}
func Int(x []int, y []int) []int {
value := Interface(x, y)
return value.Interface().([]int)
}
func Int8(x []int8, y []int8) []int8 {
value := Interface(x, y)
return value.Interface().([]int8)
}
func Int16(x []int16, y []int16) []int16 {
value := Interface(x, y)
return value.Interface().([]int16)
}
func Int32(x []int32, y []int32) []int32 {
value := Interface(x, y)
return value.Interface().([]int32)
}
func Int64(x []int64, y []int64) []int64 {
value := Interface(x, y)
return value.Interface().([]int64)
}
func Uint(x []uint, y []uint) []uint {
value := Interface(x, y)
return value.Interface().([]uint)
}
func Uint8(x []uint8, y []uint8) []uint8 {
value := Interface(x, y)
return value.Interface().([]uint8)
}
func Uint16(x []uint16, y []uint16) []uint16 {
value := Interface(x, y)
return value.Interface().([]uint16)
}
func Uint32(x []uint32, y []uint32) []uint32 {
value := Interface(x, y)
return value.Interface().([]uint32)
}
func Uint64(x []uint64, y []uint64) []uint64 {
value := Interface(x, y)
return value.Interface().([]uint64)
}
func Float32(x []float32, y []float32) []float32 {
value := Interface(x, y)
return value.Interface().([]float32)
}
func Float64(x []float64, y []float64) []float64 {
value := Interface(x, y)
return value.Interface().([]float64)
} | helper/intersect/intersect.go | 0.577972 | 0.428233 | intersect.go | starcoder |
package graph
import (
"bytes"
"fmt"
"io"
)
// WeightGraph is a graph with weighted edges.
type WeightGraph struct {
adj [][]Edge
e int
}
// NewWeightGraph creates an empty graph with v vertices
func NewWeightGraph(v int) WeightGraph {
return WeightGraph{
adj: make([][]Edge, v),
e: 0,
}
}
// ReadWeightGraph constructs an undirected graph from the io.Reader expecting
// to find data formed such as:
// v
// e
// a b w0
// c d w1
// ...
// y z wN
// where `v` is the vertex count, `e` the number of edges and `a`, `b`, `c`,
// `d`, ..., `y` and `z` are edges between `a` and `b`, `c` and `d`, ..., and
// `y` and `z` respectively, and `wN` is the weight of that edge.
func ReadWeightGraph(input io.Reader) (WeightGraph, error) {
scan := newWeighGraphScanner(input)
v, err := scan.NextInt()
if err != nil {
return WeightGraph{}, fmt.Errorf("failed reading vertex count, %v", err)
}
g := NewWeightGraph(v)
e, err := scan.NextInt()
if err != nil {
return WeightGraph{}, fmt.Errorf("failed reading edge count, %v", err)
}
for i := 0; i < e; i++ {
from, to, weight, err := scan.NextEdge()
if err != nil {
return g, fmt.Errorf("failed at edge line=%d, %v", i, err)
}
g.AddEdge(NewEdge(from, to, weight))
}
return g, nil
}
// AddEdge adds weigthed edge e to this graph
func (wg *WeightGraph) AddEdge(e Edge) {
wg.adj[e.from] = append(wg.adj[e.from], e)
wg.adj[e.to] = append(wg.adj[e.to], e)
wg.e++
}
// Adj gives the edges incident to v
func (wg *WeightGraph) Adj(v int) []Edge {
return wg.adj[v]
}
// Edges gives all the edges in this graph
func (wg *WeightGraph) Edges() []Edge {
var edges []Edge
for v := 0; v < wg.V(); v++ {
for _, adj := range wg.Adj(v) {
if adj.Other(v) > v {
edges = append(edges, adj)
}
}
}
return edges
}
// V is the number of vertives
func (wg *WeightGraph) V() int {
return len(wg.adj)
}
// E is the number of edges
func (wg *WeightGraph) E() int {
return wg.e
}
// GoString represents this weighted graph
func (wg *WeightGraph) GoString() string {
var output bytes.Buffer
do := func(n int, err error) {
if err != nil {
panic(err)
}
}
for v := 0; v < wg.V(); v++ {
for _, w := range wg.Adj(v) {
do(output.WriteString(w.GoString()))
do(output.WriteRune('\n'))
}
}
return output.String()
}
// Edge is a weighted edge in a weighted graph
type Edge struct {
weight float64
from int
to int
}
// NewEdge creates a weigthed edge to be used by a WeightGraph
func NewEdge(v, w int, weight float64) Edge {
return Edge{weight: weight, from: v, to: w}
}
// Less tells if this edge is less than the other edge
func (e *Edge) Less(other Edge) bool {
return e.weight < other.weight
}
// Either returns either vertices of this edge.
func (e *Edge) Either() int {
return e.from
}
// Other tells the other end of this edge, from v's perspective.
func (e *Edge) Other(v int) int {
if e.from == v {
return e.to
}
return e.from
}
// Weight tells the weight of this edge
func (e *Edge) Weight() float64 {
return e.weight
}
// GoString represents this edge in a directed, weighted fashion
func (e *Edge) GoString() string {
return fmt.Sprintf("%d-%d %.5f", e.from, e.to, e.weight)
} | weightgraph.go | 0.837321 | 0.579757 | weightgraph.go | starcoder |
package geobuf_raw
import (
"github.com/paulmach/go.geojson"
)
// BoundingBox implementation as per https://tools.ietf.org/html/rfc7946
// BoundingBox syntax: "bbox": [west, south, east, north]
// BoundingBox defaults "bbox": [-180.0, -90.0, 180.0, 90.0]
func BoundingBox_Points(pts [][]float64) []float64 {
// setting opposite default values
west, south, east, north := 180.0, 90.0, -180.0, -90.0
for pos, pt := range pts {
if pos == 0 {
west, east = pt[0], pt[0]
south, north = pt[1], pt[1]
}
x, y := pt[0], pt[1]
// can only be one condition
// using else if reduces one comparison
if x < west {
west = x
}
if x > east {
east = x
}
if y < south {
south = y
}
if y > north {
north = y
}
}
return []float64{west, south, east, north}
}
func Push_Two_BoundingBoxs(bb1 []float64, bb2 []float64) []float64 {
// setting opposite default values
west, south, east, north := 180.0, 90.0, -180.0, -90.0
// setting bb1 and bb2
west1, south1, east1, north1 := bb1[0], bb1[1], bb1[2], bb1[3]
west2, south2, east2, north2 := bb2[0], bb2[1], bb2[2], bb2[3]
// handling west values: min
if west1 < west2 {
west = west1
} else {
west = west2
}
// handling south values: min
if south1 < south2 {
south = south1
} else {
south = south2
}
// handling east values: max
if east1 > east2 {
east = east1
} else {
east = east2
}
// handling north values: max
if north1 > north2 {
north = north1
} else {
north = north2
}
return []float64{west, south, east, north}
}
// this functions takes an array of bounding box objects and
// pushses them all out
func Expand_BoundingBoxs(bboxs [][]float64) []float64 {
bbox := bboxs[0]
for _, temp_bbox := range bboxs[1:] {
bbox = Push_Two_BoundingBoxs(bbox, temp_bbox)
}
return bbox
}
// boudning box on a normal point geometry
// relatively useless
func BoundingBox_PointGeometry(pt []float64) []float64 {
return []float64{pt[0], pt[1], pt[0], pt[1]}
}
// Returns BoundingBox for a MultiPoint
func BoundingBox_MultiPointGeometry(pts [][]float64) []float64 {
return BoundingBox_Points(pts)
}
// Returns BoundingBox for a LineString
func BoundingBox_LineStringGeometry(line [][]float64) []float64 {
return BoundingBox_Points(line)
}
// Returns BoundingBox for a MultiLineString
func BoundingBox_MultiLineStringGeometry(multiline [][][]float64) []float64 {
bboxs := [][]float64{}
for _, line := range multiline {
bboxs = append(bboxs, BoundingBox_Points(line))
}
return Expand_BoundingBoxs(bboxs)
}
// Returns BoundingBox for a Polygon
func BoundingBox_PolygonGeometry(polygon [][][]float64) []float64 {
bboxs := [][]float64{}
for _, cont := range polygon {
bboxs = append(bboxs, BoundingBox_Points(cont))
}
return Expand_BoundingBoxs(bboxs)
}
// Returns BoundingBox for a Polygon
func BoundingBox_MultiPolygonGeometry(multipolygon [][][][]float64) []float64 {
bboxs := [][]float64{}
for _, polygon := range multipolygon {
for _, cont := range polygon {
bboxs = append(bboxs, BoundingBox_Points(cont))
}
}
return Expand_BoundingBoxs(bboxs)
}
// retrieves a boundingbox for a given geometry
func Get_BoundingBox(g *geojson.Geometry) []float64 {
switch g.Type {
case "Point":
return BoundingBox_PointGeometry(g.Point)
case "MultiPoint":
return BoundingBox_MultiPointGeometry(g.MultiPoint)
case "LineString":
return BoundingBox_LineStringGeometry(g.LineString)
case "MultiLineString":
return BoundingBox_MultiLineStringGeometry(g.MultiLineString)
case "Polygon":
return BoundingBox_PolygonGeometry(g.Polygon)
case "MultiPolygon":
return BoundingBox_MultiPolygonGeometry(g.MultiPolygon)
}
return []float64{}
}
// Returns a BoundingBox for a geometry collection
func BoundingBox_GeometryCollection(gs []*geojson.Geometry) []float64 {
bboxs := [][]float64{}
for _, g := range gs {
bboxs = append(bboxs, Get_BoundingBox(g))
}
return Expand_BoundingBoxs(bboxs)
} | geobuf_raw/bb.go | 0.822011 | 0.518302 | bb.go | starcoder |
package util
import (
"container/list"
"fmt"
"strings"
)
// Tree definition
type Tree struct {
Root *Node
}
// Depth the largest depth of the node
func (t *Tree) Depth() int {
var d int
t.BFS(func(n *Node) {
dep := n.Depth()
if dep > d {
d = dep
}
})
return d
}
// Height is the length of the longest path to a leaf
func (t *Tree) Height() int {
return t.Root.Height()
}
// Degree the largest degree of the node
func (t *Tree) Degree() int {
var d int
t.BFS(func(n *Node) {
deg := n.Degree()
if deg > d {
d = deg
}
})
return d
}
// Level 1 + the number of edges between the node and the root
func (t *Tree) Level() int {
return t.Depth() + 1
}
// DFSPreOrder Depth-First Search (DFS) is an algorithm for traversing or searching tree data structure.
// One starts at the root and explores as far as possible along each branch before backtracking.
// parent comes before children; overall root first
func (t *Tree) DFSPreOrder(fn func(*Node)) {
t.Root.DFSPreOrder(fn)
}
// DFSPostOrder Depth-First Search (DFS) is an algorithm for traversing or searching tree data structure.
// One starts at the root and explores as far as possible along each branch before backtracking.
// parent comes after children; overall root last
func (t *Tree) DFSPostOrder(fn func(*Node)) {
t.Root.DFSPostOrder(fn)
}
// BFS Breadth-First Search (BFS) is an algorithm for traversing or searching tree data structure.
// It starts at the tree root and explores the neighbor nodes first, before moving to the next level neighbors.
func (t *Tree) BFS(fn func(*Node)) {
t.Root.BFS(fn)
}
// Search node by key
func (t *Tree) Search(key string, compare func(interface{}, interface{}) bool,
values ...string) (*Node, bool) {
return t.Root.Search(key, compare, values...)
}
func (t *Tree) Insert(key string, compare func(interface{}, interface{}) bool,
values ...string) *Node {
return t.Root.Insert(key, compare, values...)
}
func (t *Tree) String() string {
return t.Root.String()
}
// Node definition
type Node struct {
Parent *Node
Data map[string]interface{}
Children []*Node
Format func(*Node) string
}
func NewNode() *Node {
return &Node{
Parent: nil,
Data: make(map[string]interface{}),
Children: make([]*Node, 0),
Format: func(n *Node) string {
return fmt.Sprintf("%+v", n.Data)
},
}
}
// Depth the number of edges between the node and the root.
func (n *Node) Depth() int {
if n.Parent == nil {
return 0
}
return n.Parent.Depth() + 1
}
// Height the number of edges on the longest path between that node and a leaf.
func (n *Node) Height() int {
if len(n.Children) == 0 {
return 0
}
var max int
for _, c := range n.Children {
h := c.Height()
if max < h {
max = h
}
}
return max + 1
}
// Degree the number of children. A leaf is necessarily degree zero.
func (n *Node) Degree() int {
return len(n.Children)
}
// Level 1 + the number of edges between the Node and the root
func (n *Node) Level() int {
return n.Depth() + 1
}
// DFSPreOrder Depth-First Search (DFS) is an algorithm for traversing or searching tree data structure.
// One starts at the root and explores as far as possible along each branch before backtracking.
// parent comes before children; overall root first
func (n *Node) DFSPreOrder(fn func(*Node)) {
fn(n)
for _, c := range n.Children {
c.DFSPreOrder(fn)
}
}
// DFSPostOrder Depth-First Search (DFS) is an algorithm for traversing or searching tree data structure.
// One starts at the root and explores as far as possible along each branch before backtracking.
// parent comes after children; overall root last
func (n *Node) DFSPostOrder(fn func(*Node)) {
for i := len(n.Children); i > 0; i-- {
n.Children[i-1].DFSPostOrder(fn)
}
fn(n)
}
// BFS Breadth-First Search (BFS) is an algorithm for traversing or searching tree data structure.
// It starts at the tree root and explores the neighbor nodes first, before moving to the next level neighbors.
func (n *Node) BFS(fn func(*Node)) {
l := list.New()
l.PushBack(n)
for e := l.Front(); e != nil; e = e.Next() {
ele := e.Value.(*Node)
fn(ele)
for _, c := range ele.Children {
l.PushBack(c)
}
}
}
// AddChild -
func (n *Node) AddChild(c *Node) {
c.Parent = n
for _, cc := range c.Children {
cc.Parent = c
}
if c.Format == nil {
c.Format = n.Format
}
n.Children = append(n.Children, c)
}
func (n *Node) Put(key string, value interface{}) {
n.Data[key] = value
}
func (n *Node) Get(key string) (interface{}, bool) {
value, ok := n.Data[key]
return value, ok
}
func (n *Node) Search(key string, compare func(interface{}, interface{}) bool,
values ...string) (*Node, bool) {
if len(values) == 0 {
return nil, false
}
value := values[0]
values = values[1:]
for _, child := range n.Children {
v, ok := child.Get(key)
if !ok {
continue
}
if compare(v, value) {
if len(values) == 0 {
return child, true
} else {
return child.Search(key, compare, values...)
}
}
}
return nil, false
}
func (n *Node) Insert(key string, compare func(interface{}, interface{}) bool,
values ...string) *Node {
if len(values) == 0 {
return n
}
value := values[0]
values = values[1:]
var flag bool
var child *Node
for _, child = range n.Children {
v, ok := child.Get(key)
if !ok {
continue
}
if compare(v, value) {
flag = true
break
}
}
// node don't exist
var node *Node
if !flag {
node = NewNode()
node.Put(key, value)
n.AddChild(node)
} else {
node = child
}
if len(values) == 0 {
return node
} else {
return node.Insert(key, compare, values...)
}
}
func (n *Node) stringWithFormat(fn func(*Node) string) string {
str := strings.Repeat(" ", n.Depth()) + fn(n)
for _, child := range n.Children {
str += "\n" + child.stringWithFormat(fn)
}
return str
}
// String
func (n *Node) String() string {
return n.stringWithFormat(n.Format)
} | tree.go | 0.655115 | 0.582847 | tree.go | starcoder |
package turfgo
import (
"math"
)
// Along takes a line and returns a point at a specified distance along the line.
// Returns the last point if distance is more than the span of the line.
func Along(lineString *LineString, distance float64, unit Unit) *Point {
travelled := float64(0)
points := lineString.getPoints()
for i, point := range points {
if distance >= travelled && i == len(points)-1 {
break
} else if travelled >= distance {
overshot := distance - travelled
if overshot == 0 {
return point
}
bearing := Bearing(point, points[i-1])
direction := bearing - 180
interpolated := Destination(point, overshot, direction, unit)
return interpolated
} else {
t := Distance(points[i], points[i+1], unit)
travelled += t
}
}
return points[len(points)-1]
}
// Bearing takes two points and finds the geographic bearing between them.
func Bearing(point1, point2 *Point) float64 {
lat1, lng1 := DegreesToRads(point1.Lat, point1.Lng)
lat2, lng2 := DegreesToRads(point2.Lat, point2.Lng)
a := math.Sin(lng2-lng1) * math.Cos(lat2)
b := math.Cos(lat1)*math.Sin(lat2) - math.Sin(lat1)*math.Cos(lat2)*math.Cos(lng2-lng1)
return RadsToDegree(math.Atan2(a, b))
}
// Center takes an array of points and returns the absolute center point of all points.
func Center(shapes ...Geometry) *Point {
bBox := Extent(shapes...)
lng := (bBox.West + bBox.East) / 2
lat := (bBox.South + bBox.North) / 2
return NewPoint(lat, lng)
}
// Destination takes a Point and calculates the location of a destination point
// given a distance in degrees, radians, miles, or kilometers; and bearing in
// degrees. This uses the Haversine formula to account for global curvature.
func Destination(start *Point, distance float64, bearing float64, unit Unit) *Point {
r := DistanceToRads(distance, unit)
lat, lon := DegreesToRads(start.Lat, start.Lng)
bearingRad := DegreeToRads(bearing)
destLat := math.Asin(math.Sin(lat)*math.Cos(r) +
math.Cos(lat)*math.Sin(r)*math.Cos(bearingRad))
destLon := lon + math.Atan2(math.Sin(bearingRad)*math.Sin(r)*math.Cos(lat),
math.Cos(r)-math.Sin(lat)*math.Sin(destLat))
return &Point{RadsToDegree(destLat), RadsToDegree(destLon)}
}
// Distance calculates the distance between two points in degress, radians, miles, or
// kilometers. This uses the Haversine formula to account for global curvature.
func Distance(point1 *Point, point2 *Point, unit Unit) float64 {
dLat, dLng := DegreesToRads(point2.Lat-point1.Lat, point2.Lng-point1.Lng)
latRad1 := DegreeToRads(point1.Lat)
latRad2 := DegreeToRads(point2.Lat)
a := math.Sin(dLat/2)*math.Sin(dLat/2) +
math.Sin(dLng/2)*math.Sin(dLng/2)*math.Cos(latRad1)*math.Cos(latRad2)
c := 2 * math.Atan2(math.Sqrt(a), math.Sqrt(1-a))
return RadsToDistance(c, unit)
}
// Bbox is an alias for Extent
func Bbox(shapes ...Geometry) *BoundingBox {
return Extent(shapes...)
}
// Extent Takes a set of features, calculates the extent of all input features, and returns a bounding box.
func Extent(geometries ...Geometry) *BoundingBox {
extent := NewInfiniteBBox()
for _, shape := range geometries {
for _, point := range shape.getPoints() {
if extent.West > point.Lng {
extent.West = point.Lng
}
if extent.South > point.Lat {
extent.South = point.Lat
}
if extent.East < point.Lng {
extent.East = point.Lng
}
if extent.North < point.Lat {
extent.North = point.Lat
}
}
}
return extent
}
// BboxToCorners return the corner points SouthWest and NorthEast from bbox
func BboxToCorners(box *BoundingBox) (*Point, *Point) {
return NewPoint(box.South, box.West), NewPoint(box.North, box.East)
}
// Expand Takes a set of features, calculates a collective bounding box around the features
// and expand it by the given distance in all directions. It returns a bounding box.
func Expand(distance float64, unit Unit, geometries ...Geometry) *BoundingBox {
bbox := Bbox(geometries...)
bottomLeft, topRight := BboxToCorners(bbox)
leftEdge := Destination(bottomLeft, distance, -90, unit)
bottomEdge := Destination(bottomLeft, distance, 180, unit)
rightEge := Destination(topRight, distance, 90, unit)
topEdge := Destination(topRight, distance, 0, unit)
return Extent(leftEdge, bottomEdge, rightEge, topEdge)
} | measurement.go | 0.921565 | 0.746255 | measurement.go | starcoder |
package metrics
import (
"fmt"
"math"
"strconv"
"strings"
"time"
"github.com/codahale/hdrhistogram"
)
type HistogramOptions struct {
Name string
Buckets []float64
MaxDuration time.Duration
}
type Histogram struct {
name string
buckets []float64
// this is the max number of values to store in a window
// when this value is reached, all values in the oldest window will be discarded
// ie. if there are 2 windows, at any time there will be between countBeforeRotation
// to 2*countBeforeRotation number of values for histogram calculations
countBeforeRotation int64
histogram *hdrhistogram.WindowedHistogram
}
func NewHistogram(opts HistogramOptions) *Histogram {
// e.g., you need >= 2 data points for 50, >= 4 for 25 or 75, >= 100 for 99, >= 1000 for 99.9, etc.
// Doesn't currently work well if the number has a repeating decimal, e.g., 66.6...
var minCountNeeded int64
for _, b := range opts.Buckets {
m := int64(100)
for b != math.Trunc(b) {
m *= 10
b *= 10
}
count := m / gcd(int64(math.Trunc(b)), m)
if count > minCountNeeded {
minCountNeeded = count
}
}
// Attempt to keep enough data points to smooth over noise,
// e.g., so that the most granular non-max bucket is distinguishable from max
minCountNeeded *= 3
return &Histogram{
name: opts.Name,
buckets: opts.Buckets,
// 10% rounded up of the min number of data points needed
countBeforeRotation: int64(math.Ceil(float64(minCountNeeded) / 10)),
// set to 11 windows so that combined, the histogram windows will always contain the min number
// of data points needed for the most granular percentile, and additionally up to 10% more data
// points for rotating the histogram windows
// more histogram windows means that the oldest data will be dropped more frequently, minimizing
// the number of times the same max value will be sent, thus reducing skew in graphs of max values
// NOTE: 11 windows become suboptimal when there are less than 10 datapoints needed
histogram: hdrhistogram.NewWindowed(11, 0, durationToMilliseconds(opts.MaxDuration), 1),
}
}
func (h *Histogram) Observe(duration time.Duration) error {
if h.histogram.Current.TotalCount() >= h.countBeforeRotation {
h.histogram.Rotate()
}
return h.histogram.Current.RecordValue(durationToMilliseconds(duration))
}
func (h *Histogram) Collect() map[string]int64 {
histogram := h.histogram.Merge()
values := make(map[string]int64)
values[fmt.Sprintf("%s.max", h.name)] = histogram.Max()
for _, b := range h.buckets {
quantileLabel := strings.Replace(strconv.FormatFloat(b, 'f', -1, 64), ".", "", -1)
values[fmt.Sprintf("%s.p%s", h.name, quantileLabel)] = histogram.ValueAtQuantile(b)
}
return values
}
// CountBeforeRotation is for testing
func (h *Histogram) CountBeforeRotation() int64 {
return h.countBeforeRotation
}
func durationToMilliseconds(d time.Duration) int64 {
// division between two int64 values will round down
return int64(d / time.Millisecond)
}
func gcd(x, y int64) int64 {
for y != 0 {
x, y = y, x%y
}
return x
} | metrics/histogram.go | 0.703753 | 0.612599 | histogram.go | starcoder |
package graphics
import "github.com/inkyblackness/hacked/ui/opengl"
// BitmapTexture wraps an OpenGL handle for a downloaded image.
type BitmapTexture struct {
gl opengl.OpenGL
handle uint32
width, height float32
u, v float32
pixelData []byte
}
func powerOfTwo(value int) int {
result := 2
for (result < value) && (result < 0x1000) {
result *= 2
}
return result
}
// NewBitmapTexture downloads the provided raw data to OpenGL and returns a BitmapTexture instance.
func NewBitmapTexture(gl opengl.OpenGL, width, height int, pixelData []byte) *BitmapTexture {
textureWidth := powerOfTwo(width)
textureHeight := powerOfTwo(height)
tex := &BitmapTexture{
gl: gl,
handle: gl.GenTextures(1)[0],
width: float32(width),
height: float32(height),
pixelData: pixelData,
}
tex.u = tex.width / float32(textureWidth)
tex.v = tex.height / float32(textureHeight)
paddedData := make([]byte, textureWidth*textureHeight)
for y := 0; y < height; y++ {
inStart := y * width
outOffset := y * textureWidth
for x := 0; x < width; x++ {
value := pixelData[inStart+x]
paddedData[outOffset] = value
outOffset++
}
}
gl.BindTexture(opengl.TEXTURE_2D, tex.handle)
gl.TexImage2D(opengl.TEXTURE_2D, 0, opengl.RED, int32(textureWidth), int32(textureHeight),
0, opengl.RED, opengl.UNSIGNED_BYTE, paddedData)
gl.TexParameteri(opengl.TEXTURE_2D, opengl.TEXTURE_MAG_FILTER, opengl.NEAREST)
gl.TexParameteri(opengl.TEXTURE_2D, opengl.TEXTURE_MIN_FILTER, opengl.NEAREST)
gl.GenerateMipmap(opengl.TEXTURE_2D)
gl.BindTexture(opengl.TEXTURE_2D, 0)
return tex
}
// Dispose releases the OpenGL texture.
func (tex *BitmapTexture) Dispose() {
if tex.handle != 0 {
tex.gl.DeleteTextures([]uint32{tex.handle})
tex.handle = 0
}
}
// Handle returns the texture handle.
func (tex *BitmapTexture) Handle() uint32 {
return tex.handle
}
// PixelData returns the original paletted pixel data.
func (tex *BitmapTexture) PixelData() []byte {
return tex.pixelData
}
// Size returns the dimensions of the bitmap, in pixels.
func (tex *BitmapTexture) Size() (width, height float32) {
return tex.width, tex.height
}
// UV returns the maximum U and V values for the bitmap. The bitmap will be
// stored in a power-of-two texture, which may be larger than the bitmap.
func (tex *BitmapTexture) UV() (u, v float32) {
return tex.u, tex.v
} | editor/graphics/BitmapTexture.go | 0.867976 | 0.584775 | BitmapTexture.go | starcoder |
package dpsortint
const insertionSortThreshold = 27
func dataequal(data []int, i, k int) bool { return !(dataless(data, i, k) || dataless(data, k, i)) }
func dataless(data []int, i, k int) bool { return data[i] < data[k] }
func dataswap(data []int, i, k int) { data[i], data[k] = data[k], data[i] }
func insertionSort(data []int, lo, hi int) {
for i := lo + 1; i <= hi; i++ {
for k := i; k > lo && dataless(data, k, k-1); k-- {
dataswap(data, k, k-1)
}
}
}
func Sort(data []int) {
sortp(data, 0, len(data)-1, 3)
}
func sortp(data []int, left, right int, div int) {
n := right - left
if n == 0 {
return
} else if n < insertionSortThreshold {
insertionSort(data, left, right)
return
}
third := n / div
// "medians"
m1 := left + third
m2 := right - third
if m1 <= left {
m1 = left + 1
}
if m2 >= right {
m2 = right - 1
}
if dataless(data, m1, m2) {
dataswap(data, m1, left)
dataswap(data, m2, right)
} else {
dataswap(data, m1, right)
dataswap(data, m2, left)
}
// pointers
less := left + 1
great := right - 1
// sorting
for k := less; k <= great; k++ {
if dataless(data, k, left) {
dataswap(data, k, less)
less++
} else if dataless(data, right, k) {
for k < great && dataless(data, right, great) {
great--
}
dataswap(data, k, great)
great--
if dataless(data, k, left) {
dataswap(data, k, less)
less++
}
}
}
// swaps
dist := great - less
if dist < 13 {
div++
}
dataswap(data, less-1, left)
dataswap(data, great+1, right)
// subarrays
sortp(data, left, less-2, div)
sortp(data, great+2, right, div)
// equal elements
if dist > n-13 && !dataequal(data, left, right) {
for k := less; k <= great; k++ {
if dataequal(data, k, left) {
dataswap(data, k, less)
less++
} else if dataequal(data, k, right) {
dataswap(data, k, great)
great--
if dataequal(data, k, left) {
dataswap(data, k, less)
less++
}
}
}
}
// subarray
if dataless(data, left, right) {
sortp(data, less, great, div)
}
} | sorts/dpsortint/sort.go | 0.582016 | 0.513851 | sort.go | starcoder |
package gosql
import (
"fmt"
"strings"
)
// Builder represents SQL query builder.
type Builder interface {
// Dialect returns SQL dialect.
Dialect() Dialect
// Select creates a new select query.
Select(table string) SelectQuery
// Update creates a new update query.
Update(table string) UpdateQuery
// Delete creates a new delete query.
Delete(table string) DeleteQuery
// Insert creates a new insert query.
Insert(table string) InsertQuery
}
// Query represents SQL query.
type Query interface {
// Build generates SQL query and values.
Build() (string, []interface{})
// String returns SQL query without values.
String() string
}
// Dialect represents kind of SQL dialect.
type Dialect int
const (
// SQLiteDialect represents SQLite dialect.
SQLiteDialect Dialect = iota
// PostgresDialect represents Postgres dialect.
PostgresDialect
)
// NewBuilder creates a new instance of SQL builder.
func NewBuilder(dialect Dialect) Builder {
return &builder{dialect: dialect}
}
type builder struct {
dialect Dialect
}
func (b builder) Dialect() Dialect {
return b.dialect
}
func (b *builder) Select(table string) SelectQuery {
return selectQuery{builder: b, table: table}
}
func (b *builder) Update(table string) UpdateQuery {
return updateQuery{builder: b, table: table}
}
func (b *builder) Delete(table string) DeleteQuery {
return deleteQuery{builder: b, table: table}
}
func (b *builder) Insert(table string) InsertQuery {
return insertQuery{builder: b, table: table}
}
func (b builder) buildName(name string) string {
return fmt.Sprintf("%q", name)
}
func (b builder) buildOpt(n int) string {
return fmt.Sprintf("$%d", n)
}
// RawBuilder is used for building query string with specified values.
type RawBuilder interface {
WriteRune(rune)
WriteString(string)
WriteName(string)
WriteValue(interface{})
String() string
Values() []interface{}
}
type rawBuilder struct {
builder *builder
query strings.Builder
values []interface{}
}
func (s *rawBuilder) WriteRune(r rune) {
s.query.WriteRune(r)
}
func (s *rawBuilder) WriteString(str string) {
s.query.WriteString(str)
}
func (s *rawBuilder) WriteName(name string) {
s.query.WriteString(s.builder.buildName(name))
}
func (s *rawBuilder) WriteValue(value interface{}) {
s.values = append(s.values, value)
s.query.WriteString(s.builder.buildOpt(len(s.values)))
}
func (s rawBuilder) String() string {
return s.query.String()
}
func (s rawBuilder) Values() []interface{} {
return s.values
}
// Expression represents buildable expression.
type Expression interface {
Build(RawBuilder)
}
// BoolExpression represents boolean expression.
type BoolExpression interface {
Expression
And(BoolExpression) BoolExpression
Or(BoolExpression) BoolExpression
}
type exprKind int
const (
orExpr exprKind = iota
andExpr
)
type binaryExpr struct {
kind exprKind
lhs, rhs BoolExpression
}
func (e binaryExpr) Or(o BoolExpression) BoolExpression {
return binaryExpr{kind: orExpr, lhs: e, rhs: o}
}
func (e binaryExpr) And(o BoolExpression) BoolExpression {
return binaryExpr{kind: andExpr, lhs: e, rhs: o}
}
func (e binaryExpr) Build(builder RawBuilder) {
e.lhs.Build(builder)
switch e.kind {
case orExpr:
builder.WriteString(" OR ")
case andExpr:
builder.WriteString(" AND ")
default:
panic(fmt.Errorf("unsupported binary expression: %d", e.kind))
}
e.rhs.Build(builder)
}
// Value represents comparable value.
type Value interface {
Expression
Equal(interface{}) BoolExpression
NotEqual(interface{}) BoolExpression
Less(interface{}) BoolExpression
Greater(interface{}) BoolExpression
LessEqual(interface{}) BoolExpression
GreaterEqual(interface{}) BoolExpression
}
// Column represents comparable table column.
type Column string
// Equal build boolean expression: "column = value".
func (c Column) Equal(o interface{}) BoolExpression {
return cmp{kind: eqCmp, lhs: c, rhs: wrapValue(o)}
}
// NotEqual build boolean expression: "column <> value".
func (c Column) NotEqual(o interface{}) BoolExpression {
return cmp{kind: notEqCmp, lhs: c, rhs: wrapValue(o)}
}
// Less build boolean expression: "column < value".
func (c Column) Less(o interface{}) BoolExpression {
return cmp{kind: lessCmp, lhs: c, rhs: wrapValue(o)}
}
// Greater build boolean expression: "column > value".
func (c Column) Greater(o interface{}) BoolExpression {
return cmp{kind: greaterCmp, lhs: c, rhs: wrapValue(o)}
}
// LessEqual build boolean expression: "column <= value".
func (c Column) LessEqual(o interface{}) BoolExpression {
return cmp{kind: lessEqualCmp, lhs: c, rhs: wrapValue(o)}
}
// GreaterEqual build boolean expression: "column >= value".
func (c Column) GreaterEqual(o interface{}) BoolExpression {
return cmp{kind: greaterEqualCmp, lhs: c, rhs: wrapValue(o)}
}
func (c Column) Build(builder RawBuilder) {
builder.WriteName(string(c))
}
type value struct {
value interface{}
}
func (v value) Equal(o interface{}) BoolExpression {
return cmp{kind: eqCmp, lhs: v, rhs: wrapValue(o)}
}
func (v value) NotEqual(o interface{}) BoolExpression {
return cmp{kind: notEqCmp, lhs: v, rhs: wrapValue(o)}
}
func (v value) Less(o interface{}) BoolExpression {
return cmp{kind: lessCmp, lhs: v, rhs: wrapValue(o)}
}
func (v value) Greater(o interface{}) BoolExpression {
return cmp{kind: greaterCmp, lhs: v, rhs: wrapValue(o)}
}
func (v value) LessEqual(o interface{}) BoolExpression {
return cmp{kind: lessEqualCmp, lhs: v, rhs: wrapValue(o)}
}
func (v value) GreaterEqual(o interface{}) BoolExpression {
return cmp{kind: greaterEqualCmp, lhs: v, rhs: wrapValue(o)}
}
func (v value) Build(builder RawBuilder) {
builder.WriteValue(v.value)
}
type Order int
const (
AscendingOrder Order = iota
DescendingOrder
)
type OrderExpression interface {
Expression
Order() Order
Expression() Expression
}
type order struct {
kind Order
expr Expression
}
// Order returns order of expression.
func (e order) Order() Order {
return e.kind
}
// Expression returns wrapped expression.
func (e order) Expression() Expression {
return e.expr
}
func (e order) Build(builder RawBuilder) {
e.expr.Build(builder)
switch e.kind {
case AscendingOrder:
builder.WriteString(" ASC")
case DescendingOrder:
builder.WriteString(" DESC")
default:
panic(fmt.Errorf("unsupported order: %d", e.kind))
}
}
// Ascending represents ascending order of sorting.
func Ascending(val interface{}) OrderExpression {
switch v := val.(type) {
case OrderExpression:
return order{kind: AscendingOrder, expr: v.Expression()}
default:
return order{kind: AscendingOrder, expr: wrapExpression(v)}
}
}
// Descending represents descending order of sorting.
func Descending(val interface{}) OrderExpression {
switch v := val.(type) {
case OrderExpression:
return order{kind: DescendingOrder, expr: v.Expression()}
default:
return order{kind: DescendingOrder, expr: wrapExpression(v)}
}
}
type cmpKind int
const (
eqCmp cmpKind = iota
notEqCmp
lessCmp
greaterCmp
lessEqualCmp
greaterEqualCmp
)
type cmp struct {
kind cmpKind
lhs, rhs Value
}
func (c cmp) Or(o BoolExpression) BoolExpression {
return binaryExpr{kind: orExpr, lhs: c, rhs: o}
}
func (c cmp) And(o BoolExpression) BoolExpression {
return binaryExpr{kind: andExpr, lhs: c, rhs: o}
}
func (c cmp) Build(builder RawBuilder) {
c.lhs.Build(builder)
switch c.kind {
case eqCmp:
if isNullValue(c.rhs) {
builder.WriteString(" IS NULL")
return
}
builder.WriteString(" = ")
case notEqCmp:
if isNullValue(c.rhs) {
builder.WriteString(" IS NOT NULL")
return
}
builder.WriteString(" <> ")
case lessCmp:
builder.WriteString(" < ")
case greaterCmp:
builder.WriteString(" > ")
case lessEqualCmp:
builder.WriteString(" <= ")
case greaterEqualCmp:
builder.WriteString(" >= ")
default:
panic(fmt.Errorf("unsupported binaryExpr %q", c.kind))
}
c.rhs.Build(builder)
}
func isNullValue(val Value) bool {
v, ok := val.(value)
return ok && v.value == nil
}
func wrapValue(val interface{}) Value {
if v, ok := val.(Value); ok {
return v
}
return value{value: val}
}
func wrapExpression(val interface{}) Expression {
switch v := val.(type) {
case Expression:
return v
case string:
return Column(v)
default:
panic(fmt.Errorf("unsupported type: %T", v))
}
}
func wrapOrderExpression(val interface{}) OrderExpression {
switch v := val.(type) {
case OrderExpression:
return v
default:
return Ascending(wrapExpression(v))
}
} | builder.go | 0.837985 | 0.419232 | builder.go | starcoder |
package mongo
// Format represents the currency's currencyFormat.
type currencyFormat struct {
code string // The ISO 4217 currency code.
subunits int // The number of subunits.
thouSep string // The thousand separator.
subSep string // The subunit separator.
template string // The string format template.
}
// CurrencyFormats contain a map of all recognised currency formats.
var currencyFormats = map[string]currencyFormat{
"AED": {code: "AED", subunits: 2, thouSep: ",", subSep: ".", template: "0 د.إ"},
"AFN": {code: "AFN", subunits: 2, thouSep: ",", subSep: ".", template: "0 ؋"},
"ALL": {code: "ALL", subunits: 2, thouSep: ",", subSep: ".", template: "L0"},
"AMD": {code: "AMD", subunits: 2, thouSep: ",", subSep: ".", template: "0 ֏"},
"ANG": {code: "ANG", subunits: 2, thouSep: ".", subSep: ",", template: "ƒ0"},
"AOA": {code: "AOA", subunits: 2, thouSep: ",", subSep: ".", template: "0Kz"},
"ARS": {code: "ARS", subunits: 2, thouSep: ",", subSep: ".", template: "$0"},
"AUD": {code: "AUD", subunits: 2, thouSep: ",", subSep: ".", template: "$0"},
"AWG": {code: "AWG", subunits: 2, thouSep: ",", subSep: ".", template: "0ƒ"},
"AZN": {code: "AZN", subunits: 2, thouSep: ",", subSep: ".", template: "m0"},
"BAM": {code: "BAM", subunits: 2, thouSep: ",", subSep: ".", template: "KM0"},
"BBD": {code: "BBD", subunits: 2, thouSep: ",", subSep: ".", template: "$0"},
"BDT": {code: "BDT", subunits: 2, thouSep: ",", subSep: ".", template: "৳0"},
"BGN": {code: "BGN", subunits: 2, thouSep: ",", subSep: ".", template: "лв0"},
"BHD": {code: "BHD", subunits: 3, thouSep: ",", subSep: ".", template: "0 .د.ب "},
"BIF": {code: "BIF", subunits: 0, thouSep: ",", subSep: ".", template: "0Fr"},
"BMD": {code: "BMD", subunits: 2, thouSep: ",", subSep: ".", template: "$0"},
"BND": {code: "BND", subunits: 2, thouSep: ",", subSep: ".", template: "$0"},
"BOB": {code: "BOB", subunits: 2, thouSep: ",", subSep: ".", template: "Bs.0"},
"BRL": {code: "BRL", subunits: 2, thouSep: ".", subSep: ",", template: "R$0"},
"BSD": {code: "BSD", subunits: 2, thouSep: ",", subSep: ".", template: "$0"},
"BTN": {code: "BTN", subunits: 2, thouSep: ",", subSep: ".", template: "0Nu."},
"BWP": {code: "BWP", subunits: 2, thouSep: ",", subSep: ".", template: "P0"},
"BYN": {code: "BYN", subunits: 2, thouSep: " ", subSep: ",", template: "0 p."},
"BYR": {code: "BYR", subunits: 0, thouSep: " ", subSep: ",", template: "0 p."},
"BZD": {code: "BZD", subunits: 2, thouSep: ",", subSep: ".", template: "BZ$0"},
"CAD": {code: "CAD", subunits: 2, thouSep: ",", subSep: ".", template: "$0"},
"CDF": {code: "CDF", subunits: 2, thouSep: ",", subSep: ".", template: "0FC"},
"CHF": {code: "CHF", subunits: 2, thouSep: ",", subSep: ".", template: "0 CHF"},
"CLF": {code: "CLF", subunits: 4, thouSep: ".", subSep: ",", template: "UF0"},
"CLP": {code: "CLP", subunits: 0, thouSep: ".", subSep: ",", template: "$0"},
"CNY": {code: "CNY", subunits: 2, thouSep: ",", subSep: ".", template: "0 ¥"},
"COP": {code: "COP", subunits: 2, thouSep: ".", subSep: ",", template: "$0"},
"CRC": {code: "CRC", subunits: 2, thouSep: ",", subSep: ".", template: "₡0"},
"CUC": {code: "CUC", subunits: 2, thouSep: ",", subSep: ".", template: "0$"},
"CUP": {code: "CUP", subunits: 2, thouSep: ",", subSep: ".", template: "$MN0"},
"CVE": {code: "CVE", subunits: 2, thouSep: ",", subSep: ".", template: "0$"},
"CZK": {code: "CZK", subunits: 2, thouSep: ",", subSep: ".", template: "0 Kč"},
"DJF": {code: "DJF", subunits: 0, thouSep: ",", subSep: ".", template: "0 Fdj"},
"DKK": {code: "DKK", subunits: 2, thouSep: ".", subSep: ",", template: "kr 1"},
"DOP": {code: "DOP", subunits: 2, thouSep: ",", subSep: ".", template: "RD$0"},
"DZD": {code: "DZD", subunits: 2, thouSep: ",", subSep: ".", template: "0 دج "},
"EEK": {code: "EEK", subunits: 2, thouSep: ",", subSep: ".", template: "kr0"},
"EGP": {code: "EGP", subunits: 2, thouSep: ",", subSep: ".", template: "ج.م 0"},
"ERN": {code: "ERN", subunits: 2, thouSep: ",", subSep: ".", template: "0 Nfk"},
"ETB": {code: "ETB", subunits: 2, thouSep: ",", subSep: ".", template: "0 Br"},
"EUR": {code: "EUR", subunits: 2, thouSep: ",", subSep: ".", template: "€0"},
"FJD": {code: "FJD", subunits: 2, thouSep: ",", subSep: ".", template: "$0"},
"FKP": {code: "FKP", subunits: 2, thouSep: ",", subSep: ".", template: "£0"},
"GBP": {code: "GBP", subunits: 2, thouSep: ",", subSep: ".", template: "£0"},
"GEL": {code: "GEL", subunits: 2, thouSep: ",", subSep: ".", template: "0 ლ"},
"GGP": {code: "GGP", subunits: 2, thouSep: ",", subSep: ".", template: "£0"},
"GHC": {code: "GHC", subunits: 2, thouSep: ",", subSep: ".", template: "GH₵0"},
"GHS": {code: "GHS", subunits: 2, thouSep: ",", subSep: ".", template: "GH₵0"},
"GIP": {code: "GIP", subunits: 2, thouSep: ",", subSep: ".", template: "£0"},
"GMD": {code: "GMD", subunits: 2, thouSep: ",", subSep: ".", template: "0 D"},
"GNF": {code: "GNF", subunits: 0, thouSep: ",", subSep: ".", template: "0 FG"},
"GTQ": {code: "GTQ", subunits: 2, thouSep: ",", subSep: ".", template: "Q0"},
"GYD": {code: "GYD", subunits: 2, thouSep: ",", subSep: ".", template: "$0"},
"HKD": {code: "HKD", subunits: 2, thouSep: ",", subSep: ".", template: "$0"},
"HNL": {code: "HNL", subunits: 2, thouSep: ",", subSep: ".", template: "L0"},
"HRK": {code: "HRK", subunits: 2, thouSep: ".", subSep: ",", template: "0 Kn"},
"HTG": {code: "HTG", subunits: 2, thouSep: ".", subSep: ",", template: "0 G"},
"HUF": {code: "HUF", subunits: 0, thouSep: ",", subSep: ".", template: "Ft0"},
"IDR": {code: "IDR", subunits: 2, thouSep: ",", subSep: ".", template: "Rp0"},
"ILS": {code: "ILS", subunits: 2, thouSep: ",", subSep: ".", template: "₪0"},
"IMP": {code: "IMP", subunits: 2, thouSep: ",", subSep: ".", template: "£0"},
"INR": {code: "INR", subunits: 2, thouSep: ",", subSep: ".", template: "₹0"},
"IQD": {code: "IQD", subunits: 3, thouSep: ",", subSep: ".", template: "0 د.ع"},
"IRR": {code: "IRR", subunits: 2, thouSep: ",", subSep: ".", template: "0 ﷼"},
"ISK": {code: "ISK", subunits: 0, thouSep: ".", subSep: ",", template: "Kr0"},
"JEP": {code: "JEP", subunits: 2, thouSep: ",", subSep: ".", template: "£0"},
"JMD": {code: "JMD", subunits: 2, thouSep: ",", subSep: ".", template: "J$0"},
"JOD": {code: "JOD", subunits: 3, thouSep: ",", subSep: ".", template: "0 د.أ"},
"JPY": {code: "JPY", subunits: 0, thouSep: ",", subSep: ".", template: "¥0"},
"KES": {code: "KES", subunits: 2, thouSep: ",", subSep: ".", template: "KSh0"},
"KGS": {code: "KGS", subunits: 2, thouSep: ",", subSep: ".", template: "С̲0"},
"KHR": {code: "KHR", subunits: 2, thouSep: ",", subSep: ".", template: "៛0"},
"KMF": {code: "KMF", subunits: 0, thouSep: ",", subSep: ".", template: "CF0"},
"KPW": {code: "KPW", subunits: 0, thouSep: ",", subSep: ".", template: "₩0"},
"KRW": {code: "KRW", subunits: 0, thouSep: ",", subSep: ".", template: "₩0"},
"KWD": {code: "KWD", subunits: 3, thouSep: ",", subSep: ".", template: "0 د.ك"},
"KYD": {code: "KYD", subunits: 2, thouSep: ",", subSep: ".", template: "$0"},
"KZT": {code: "KZT", subunits: 2, thouSep: ",", subSep: ".", template: "₸0"},
"LAK": {code: "LAK", subunits: 2, thouSep: ",", subSep: ".", template: "₭0"},
"LBP": {code: "LBP", subunits: 2, thouSep: ",", subSep: ".", template: "£0"},
"LKR": {code: "LKR", subunits: 2, thouSep: ",", subSep: ".", template: "රු, ரூ0"},
"LRD": {code: "LRD", subunits: 2, thouSep: ",", subSep: ".", template: "$0"},
"LSL": {code: "LSL", subunits: 2, thouSep: ",", subSep: ".", template: "L0"},
"LTL": {code: "LTL", subunits: 2, thouSep: ",", subSep: ".", template: "Lt0"},
"LVL": {code: "LVL", subunits: 2, thouSep: ",", subSep: ".", template: "0 Ls"},
"LYD": {code: "LYD", subunits: 3, thouSep: ",", subSep: ".", template: "0 ل.د"},
"MAD": {code: "MAD", subunits: 2, thouSep: ",", subSep: ".", template: "0 DH"},
"MDL": {code: "MDL", subunits: 2, thouSep: ",", subSep: ".", template: "0 lei"},
"MKD": {code: "MKD", subunits: 2, thouSep: ",", subSep: ".", template: "ден0"},
"MMK": {code: "MMK", subunits: 2, thouSep: ",", subSep: ".", template: "K0"},
"MNT": {code: "MNT", subunits: 2, thouSep: ",", subSep: ".", template: "₮0"},
"MOP": {code: "MOP", subunits: 2, thouSep: ",", subSep: ".", template: "0 P"},
"MUR": {code: "MUR", subunits: 2, thouSep: ",", subSep: ".", template: "₨0"},
"MVR": {code: "MVR", subunits: 2, thouSep: ",", subSep: ".", template: "0 MVR"},
"MWK": {code: "MWK", subunits: 2, thouSep: ",", subSep: ".", template: "MK0"},
"MXN": {code: "MXN", subunits: 2, thouSep: ",", subSep: ".", template: "$0"},
"MYR": {code: "MYR", subunits: 2, thouSep: ",", subSep: ".", template: "RM0"},
"MZN": {code: "MZN", subunits: 2, thouSep: ",", subSep: ".", template: "MT0"},
"NAD": {code: "NAD", subunits: 2, thouSep: ",", subSep: ".", template: "$0"},
"NGN": {code: "NGN", subunits: 2, thouSep: ",", subSep: ".", template: "₦0"},
"NIO": {code: "NIO", subunits: 2, thouSep: ",", subSep: ".", template: "C$0"},
"NOK": {code: "NOK", subunits: 2, thouSep: ",", subSep: ".", template: "0 Kr"},
"NPR": {code: "NPR", subunits: 2, thouSep: ",", subSep: ".", template: "रु0"},
"NZD": {code: "NZD", subunits: 2, thouSep: ",", subSep: ".", template: "$0"},
"OMR": {code: "OMR", subunits: 3, thouSep: ",", subSep: ".", template: "0 ر.ع."},
"PAB": {code: "PAB", subunits: 2, thouSep: ",", subSep: ".", template: "B/.0"},
"PEN": {code: "PEN", subunits: 2, thouSep: ",", subSep: ".", template: "S/0"},
"PGK": {code: "PGK", subunits: 2, thouSep: ",", subSep: ".", template: "0 K"},
"PHP": {code: "PHP", subunits: 2, thouSep: ",", subSep: ".", template: "₱0"},
"PKR": {code: "PKR", subunits: 2, thouSep: ",", subSep: ".", template: "₨0"},
"PLN": {code: "PLN", subunits: 2, thouSep: ",", subSep: ".", template: "0 zł"},
"PYG": {code: "PYG", subunits: 0, thouSep: ",", subSep: ".", template: "0Gs"},
"QAR": {code: "QAR", subunits: 2, thouSep: ",", subSep: ".", template: "0 ر.ق"},
"RON": {code: "RON", subunits: 2, thouSep: ",", subSep: ".", template: "lei0"},
"RSD": {code: "RSD", subunits: 2, thouSep: ",", subSep: ".", template: "дин0"},
"RUB": {code: "RUB", subunits: 2, thouSep: ",", subSep: ".", template: "0 ₽"},
"RUR": {code: "RUR", subunits: 2, thouSep: ",", subSep: ".", template: "0 ₽"},
"RWF": {code: "RWF", subunits: 0, thouSep: ",", subSep: ".", template: "0 FRw"},
"SAR": {code: "SAR", subunits: 2, thouSep: ",", subSep: ".", template: "0 ر.س"},
"SBD": {code: "SBD", subunits: 2, thouSep: ",", subSep: ".", template: "$0"},
"SCR": {code: "SCR", subunits: 2, thouSep: ",", subSep: ".", template: "SCR0"},
"SDG": {code: "SDG", subunits: 2, thouSep: ",", subSep: ".", template: "£0"},
"SEK": {code: "SEK", subunits: 2, thouSep: ",", subSep: ".", template: "0 Kr"},
"SGD": {code: "SGD", subunits: 2, thouSep: ",", subSep: ".", template: "$0"},
"SHP": {code: "SHP", subunits: 2, thouSep: ",", subSep: ".", template: "£0"},
"SKK": {code: "SKK", subunits: 2, thouSep: ",", subSep: ".", template: "Sk0"},
"SLL": {code: "SLL", subunits: 2, thouSep: ",", subSep: ".", template: "0 Le"},
"SOS": {code: "SOS", subunits: 2, thouSep: ",", subSep: ".", template: "0 Sh"},
"SRD": {code: "SRD", subunits: 2, thouSep: ",", subSep: ".", template: "$0"},
"SSP": {code: "SSP", subunits: 2, thouSep: ",", subSep: ".", template: "0 £"},
"STD": {code: "STD", subunits: 2, thouSep: ",", subSep: ".", template: "0 Db"},
"SVC": {code: "SVC", subunits: 2, thouSep: ",", subSep: ".", template: "₡0"},
"SYP": {code: "SYP", subunits: 2, thouSep: ",", subSep: ".", template: "0 £"},
"SZL": {code: "SZL", subunits: 2, thouSep: ",", subSep: ".", template: "£0"},
"THB": {code: "THB", subunits: 2, thouSep: ",", subSep: ".", template: "฿ 20"},
"TJS": {code: "TJS", subunits: 2, thouSep: ",", subSep: ".", template: "0 SM"},
"TMT": {code: "TMT", subunits: 2, thouSep: ",", subSep: ".", template: "0 T"},
"TND": {code: "TND", subunits: 3, thouSep: ",", subSep: ".", template: "0 د.ت"},
"TOP": {code: "TOP", subunits: 2, thouSep: ",", subSep: ".", template: "T$0"},
"TRL": {code: "TRL", subunits: 2, thouSep: ",", subSep: ".", template: "₺0"},
"TRY": {code: "TRY", subunits: 2, thouSep: ",", subSep: ".", template: "₺0"},
"TTD": {code: "TTD", subunits: 2, thouSep: ",", subSep: ".", template: "TT$0"},
"TWD": {code: "TWD", subunits: 2, thouSep: ",", subSep: ".", template: "NT$0"},
"TZS": {code: "TZS", subunits: 0, thouSep: ",", subSep: ".", template: "TSh0"},
"UAH": {code: "UAH", subunits: 2, thouSep: ",", subSep: ".", template: "0 ₴"},
"UGX": {code: "UGX", subunits: 0, thouSep: ",", subSep: ".", template: "0 USh"},
"USD": {code: "USD", subunits: 2, thouSep: ",", subSep: ".", template: "$0"},
"UYU": {code: "UYU", subunits: 2, thouSep: ",", subSep: ".", template: "U$0"},
"UZS": {code: "UZS", subunits: 2, thouSep: ",", subSep: ".", template: "сум0"},
"VEF": {code: "VEF", subunits: 2, thouSep: ",", subSep: ".", template: "Bs0"},
"VND": {code: "VND", subunits: 0, thouSep: ",", subSep: ".", template: "0 ₫"},
"VUV": {code: "VUV", subunits: 0, thouSep: ",", subSep: ".", template: "Vt0"},
"WST": {code: "WST", subunits: 2, thouSep: ",", subSep: ".", template: "0 T"},
"XAF": {code: "XAF", subunits: 0, thouSep: ",", subSep: ".", template: "0 Fr"},
"XAG": {code: "XAG", subunits: 0, thouSep: ",", subSep: ".", template: "0 oz t"},
"XAU": {code: "XAU", subunits: 0, thouSep: ",", subSep: ".", template: "0 oz t"},
"XCD": {code: "XCD", subunits: 2, thouSep: ",", subSep: ".", template: "$0"},
"XDR": {code: "XDR", subunits: 0, thouSep: ",", subSep: ".", template: "0 SDR"},
"XPF": {code: "XPF", subunits: 0, thouSep: ",", subSep: ".", template: "0 ₣"},
"YER": {code: "YER", subunits: 2, thouSep: ",", subSep: ".", template: "0 ر.ي, ﷼"},
"ZAR": {code: "ZAR", subunits: 2, thouSep: ",", subSep: ".", template: "R0"},
"ZMW": {code: "ZMW", subunits: 2, thouSep: ",", subSep: ".", template: "ZK0"},
"ZWD": {code: "ZWD", subunits: 2, thouSep: ",", subSep: ".", template: "Z$0"},
} | format.go | 0.529507 | 0.59302 | format.go | starcoder |
package shape
import "github.com/mokiat/gomath/sprec"
type Intersection struct {
Depth float32
FirstContact sprec.Vec3
FirstDisplaceNormal sprec.Vec3
SecondContact sprec.Vec3
SecondDisplaceNormal sprec.Vec3
}
func (i Intersection) Flipped() Intersection {
i.FirstContact, i.SecondContact = i.SecondContact, i.FirstContact
i.FirstDisplaceNormal, i.SecondDisplaceNormal = i.SecondDisplaceNormal, i.FirstDisplaceNormal
return i
}
func NewIntersectionResultSet(capacity int) *IntersectionResultSet {
return &IntersectionResultSet{
intersections: make([]Intersection, 0, capacity),
flipped: false,
}
}
type IntersectionResultSet struct {
intersections []Intersection
flipped bool
}
func (s *IntersectionResultSet) Reset() {
s.intersections = s.intersections[:0]
}
func (s *IntersectionResultSet) AddFlipped(flipped bool) {
s.flipped = true
}
func (s *IntersectionResultSet) Add(intersection Intersection) {
if s.flipped {
s.intersections = append(s.intersections, intersection.Flipped())
} else {
s.intersections = append(s.intersections, intersection)
}
}
func (s *IntersectionResultSet) Found() bool {
return len(s.intersections) > 0
}
func (s *IntersectionResultSet) Intersections() []Intersection {
return s.intersections
}
func CheckIntersection(first, second Placement, resultSet *IntersectionResultSet) {
switch first.Shape.(type) {
case StaticSphere:
CheckIntersectionSphereUnknown(first, second, resultSet)
case StaticBox:
CheckIntersectionBoxUnknown(first, second, resultSet)
case StaticMesh:
CheckIntersectionMeshUnknown(first, second, resultSet)
}
}
func CheckIntersectionSphereUnknown(first, second Placement, resultSet *IntersectionResultSet) {
switch second.Shape.(type) {
case StaticSphere:
resultSet.AddFlipped(false)
CheckIntersectionSphereSphere(first, second, resultSet)
case StaticBox:
resultSet.AddFlipped(false)
CheckIntersectionSphereBox(first, second, resultSet)
case StaticMesh:
resultSet.AddFlipped(false)
CheckIntersectionSphereMesh(first, second, resultSet)
}
}
func CheckIntersectionBoxUnknown(first, second Placement, resultSet *IntersectionResultSet) {
switch second.Shape.(type) {
case StaticSphere:
resultSet.AddFlipped(true)
CheckIntersectionSphereBox(second, first, resultSet)
case StaticBox:
resultSet.AddFlipped(false)
CheckIntersectionBoxBox(first, second, resultSet)
case StaticMesh:
resultSet.AddFlipped(false)
CheckIntersectionBoxMesh(first, second, resultSet)
}
}
func CheckIntersectionMeshUnknown(first, second Placement, resultSet *IntersectionResultSet) {
switch second.Shape.(type) {
case StaticSphere:
resultSet.AddFlipped(true)
CheckIntersectionSphereMesh(second, first, resultSet)
case StaticBox:
resultSet.AddFlipped(true)
CheckIntersectionBoxMesh(second, first, resultSet)
case StaticMesh:
resultSet.AddFlipped(false)
CheckIntersectionMeshMesh(first, second, resultSet)
}
}
func CheckIntersectionSphereSphere(first, second Placement, resultSet *IntersectionResultSet) {
}
func CheckIntersectionSphereBox(first, second Placement, resultSet *IntersectionResultSet) {
}
func CheckIntersectionSphereMesh(spherePlacement, meshPlacement Placement, resultSet *IntersectionResultSet) {
sphere := spherePlacement.Shape.(StaticSphere)
mesh := meshPlacement.Shape.(StaticMesh)
// broad phase
deltaPosition := sprec.Vec3Diff(meshPlacement.Position, spherePlacement.Position)
if deltaPosition.Length() > sphere.Radius()+mesh.BoundingSphereRadius() {
return
}
// narrow phase
for _, triangle := range mesh.Triangles() {
triangleWS := triangle.Transformed(meshPlacement.Position, meshPlacement.Orientation)
height := sprec.Vec3Dot(triangleWS.Normal(), sprec.Vec3Diff(spherePlacement.Position, triangleWS.A()))
if height > sphere.Radius() || height < -sphere.Radius() {
continue
}
projectedPoint := sprec.Vec3Diff(spherePlacement.Position, sprec.Vec3Prod(triangle.Normal(), height))
if triangleWS.ContainsPoint(projectedPoint) {
resultSet.Add(Intersection{
Depth: sphere.Radius() - height,
FirstContact: projectedPoint, // TODO: Extrude to equal radius length
FirstDisplaceNormal: triangle.Normal(),
SecondContact: projectedPoint,
SecondDisplaceNormal: sprec.InverseVec3(triangle.Normal()),
})
}
}
}
func CheckIntersectionBoxBox(first, second Placement, resultSet *IntersectionResultSet) {
}
func CheckIntersectionBoxMesh(boxPlacement, meshPlacement Placement, resultSet *IntersectionResultSet) {
box := boxPlacement.Shape.(StaticBox)
mesh := meshPlacement.Shape.(StaticMesh)
// broad phase
deltaPosition := sprec.Vec3Diff(meshPlacement.Position, boxPlacement.Position)
boxBoundingSphereRadius := sprec.Sqrt(box.Width()*box.Width()+box.Height()*box.Height()+box.Length()*box.Length()) / 2.0
if deltaPosition.Length() > boxBoundingSphereRadius+mesh.BoundingSphereRadius() {
return
}
minX := sprec.Vec3Prod(boxPlacement.Orientation.OrientationX(), -box.Width()/2.0)
maxX := sprec.Vec3Prod(boxPlacement.Orientation.OrientationX(), box.Width()/2.0)
minY := sprec.Vec3Prod(boxPlacement.Orientation.OrientationY(), -box.Height()/2.0)
maxY := sprec.Vec3Prod(boxPlacement.Orientation.OrientationY(), box.Height()/2.0)
minZ := sprec.Vec3Prod(boxPlacement.Orientation.OrientationZ(), -box.Length()/2.0)
maxZ := sprec.Vec3Prod(boxPlacement.Orientation.OrientationZ(), box.Length()/2.0)
p1 := sprec.Vec3Sum(sprec.Vec3Sum(sprec.Vec3Sum(boxPlacement.Position, minX), minZ), maxY)
p2 := sprec.Vec3Sum(sprec.Vec3Sum(sprec.Vec3Sum(boxPlacement.Position, minX), maxZ), maxY)
p3 := sprec.Vec3Sum(sprec.Vec3Sum(sprec.Vec3Sum(boxPlacement.Position, maxX), maxZ), maxY)
p4 := sprec.Vec3Sum(sprec.Vec3Sum(sprec.Vec3Sum(boxPlacement.Position, maxX), minZ), maxY)
p5 := sprec.Vec3Sum(sprec.Vec3Sum(sprec.Vec3Sum(boxPlacement.Position, minX), minZ), minY)
p6 := sprec.Vec3Sum(sprec.Vec3Sum(sprec.Vec3Sum(boxPlacement.Position, minX), maxZ), minY)
p7 := sprec.Vec3Sum(sprec.Vec3Sum(sprec.Vec3Sum(boxPlacement.Position, maxX), maxZ), minY)
p8 := sprec.Vec3Sum(sprec.Vec3Sum(sprec.Vec3Sum(boxPlacement.Position, maxX), minZ), minY)
checkLineIntersection := func(line StaticLine, triangle StaticTriangle) {
heightA := sprec.Vec3Dot(triangle.Normal(), sprec.Vec3Diff(line.A(), triangle.A()))
heightB := sprec.Vec3Dot(triangle.Normal(), sprec.Vec3Diff(line.B(), triangle.A()))
if heightA > 0.0 && heightB > 0.0 {
return
}
if heightA < 0.0 && heightB < 0.0 {
return
}
if heightA < 0.0 {
line = NewStaticLine(line.B(), line.A())
heightA, heightB = heightB, heightA
}
projectedPoint := sprec.Vec3Sum(
sprec.Vec3Prod(line.A(), -heightB/(heightA-heightB)),
sprec.Vec3Prod(line.B(), heightA/(heightA-heightB)),
)
if triangle.ContainsPoint(projectedPoint) {
resultSet.Add(Intersection{
Depth: -heightB,
FirstContact: projectedPoint,
FirstDisplaceNormal: triangle.Normal(),
SecondContact: projectedPoint,
SecondDisplaceNormal: sprec.InverseVec3(triangle.Normal()),
})
}
}
// narrow phase
for _, triangle := range mesh.Triangles() {
triangleWS := triangle.Transformed(meshPlacement.Position, meshPlacement.Orientation)
checkLineIntersection(NewStaticLine(p1, p2), triangleWS)
checkLineIntersection(NewStaticLine(p2, p3), triangleWS)
checkLineIntersection(NewStaticLine(p3, p4), triangleWS)
checkLineIntersection(NewStaticLine(p4, p1), triangleWS)
checkLineIntersection(NewStaticLine(p5, p6), triangleWS)
checkLineIntersection(NewStaticLine(p6, p7), triangleWS)
checkLineIntersection(NewStaticLine(p7, p8), triangleWS)
checkLineIntersection(NewStaticLine(p8, p5), triangleWS)
checkLineIntersection(NewStaticLine(p1, p5), triangleWS)
checkLineIntersection(NewStaticLine(p2, p6), triangleWS)
checkLineIntersection(NewStaticLine(p3, p7), triangleWS)
checkLineIntersection(NewStaticLine(p4, p8), triangleWS)
}
}
func CheckIntersectionMeshMesh(first, second Placement, resultSet *IntersectionResultSet) {
} | shape/intersection.go | 0.566978 | 0.407157 | intersection.go | starcoder |
package sequences
import . "github.com/objecthub/containerkit"
type Sequence interface {
SequenceBase
SequenceDerived
}
type SequenceBase interface {
IndexedBase
}
type SequenceDerived interface {
IndexedDerived
Container
Subsequence(start int, maxSize int) DependentSequence
MapValues(f Mapping) DependentSequence
Reverse() DependentSequence
Join(other Sequence) DependentSequence
ReadOnly() DependentSequence
}
// SequenceClass defines the interface for embedding and
// instantiating implementations of the Sequence interface.
type SequenceClass interface {
Embed(obj Sequence) Sequence
New(elements... interface{}) Sequence
From(coll Container) Sequence
}
func EmbeddedSequence(obj Sequence) Sequence {
return &sequence{obj,
obj,
EmbeddedIndexed(obj),
EmbeddedFiniteContainer(obj)}
}
type sequence struct {
obj Sequence
SequenceBase
IndexedDerived
FiniteContainerDerived
}
func (this *sequence) Elements() Iterator {
return &sequenceIterator{this.obj, 0}
}
func (this *sequence) Reverse() DependentSequence {
return newReversedSequence(this.obj)
}
func (this *sequence) Subsequence(start int, maxSize int) DependentSequence {
return newSubsequence(this.obj, start, maxSize)
}
func (this *sequence) MapValues(f Mapping) DependentSequence {
return newMappedSequence(this.obj, f)
}
func (this *sequence) Join(other Sequence) DependentSequence {
return newAppendedSequence(this.obj, other)
}
func (this *sequence) ReadOnly() DependentSequence {
return wrappedSequence(this.obj, false)
}
func (this *sequence) String() string {
return "[" + this.FiniteContainerDerived.String() + "]"
}
type sequenceIterator struct {
data Sequence
index int
}
func (this *sequenceIterator) HasNext() bool {
return this.index < this.data.Size()
}
func (this *sequenceIterator) Next() interface{} {
if !this.HasNext() {
panic("sequenceIterator.Next: no next value")
}
res := this.data.At(this.index)
this.index++
return res
} | sequences/sequence.go | 0.879949 | 0.406626 | sequence.go | starcoder |
package testcase
import (
"bytes"
"fmt"
"path/filepath"
"reflect"
"runtime"
"sort"
"testing"
"unsafe"
)
// TestCase represents a test case.
type TestCase struct {
tc testCase
}
// Copy copies the test case and returns a clone.
func (tc *TestCase) Copy() (clone *TestCase) { return tc.tc.Copy().TestCase() }
// Exclude excludes the test case from the list to run.
func (tc *TestCase) Exclude() (self *TestCase) { return tc.tc.Exclude().TestCase() }
// ExcludeOthers excludes other test cases from the list to run.
func (tc *TestCase) ExcludeOthers() (self *TestCase) { return tc.tc.ExcludeOthers().TestCase() }
// Given annotates the test case.
func (tc *TestCase) Given(given string) (self *TestCase) { return tc.tc.Given(given).TestCase() }
// When annotates the test case.
func (tc *TestCase) When(when string) (self *TestCase) { return tc.tc.When(when).TestCase() }
// Then annotates the test case.
func (tc *TestCase) Then(then string) (self *TestCase) { return tc.tc.Then(then).TestCase() }
// Step adds a step with the given number to the test case.
// Steps will be executed in ascending order of step number.
func (tc *TestCase) Step(stepNo float64, step interface{}) (self *TestCase) {
return tc.tc.Step(stepNo, step).TestCase()
}
// New creates a new test case.
func New() *TestCase { return new(testCase).Init().TestCase() }
type testCase struct {
IsExcluded bool
OthersAreExcluded bool
locator string
given string
when string
then string
stepType reflect.Type
workspaceType reflect.Type
steps map[float64]interface{}
}
func (tc *testCase) Init() *testCase {
_, fileName, lineNumber, _ := runtime.Caller(2)
tc.setLocator(fileName, lineNumber)
return tc
}
func (tc *testCase) Copy() *testCase {
clone := testCase{
IsExcluded: tc.IsExcluded,
OthersAreExcluded: tc.OthersAreExcluded,
given: tc.given,
when: tc.when,
then: tc.then,
stepType: tc.stepType,
workspaceType: tc.workspaceType,
}
_, fileName, lineNumber, _ := runtime.Caller(2)
clone.setLocator(fileName, lineNumber)
clone.steps = tc.copySteps()
return &clone
}
func (tc *testCase) setLocator(fileName string, lineNumber int) {
shortFileName := filepath.Base(fileName)
tc.locator = fmt.Sprintf("%s:%d", shortFileName, lineNumber)
}
func (tc *testCase) copySteps() map[float64]interface{} {
stepsClone := make(map[float64]interface{}, len(tc.steps))
for stepNo, step := range tc.steps {
stepsClone[stepNo] = step
}
return stepsClone
}
func (tc *testCase) Exclude() *testCase {
tc.IsExcluded = true
return tc
}
func (tc *testCase) ExcludeOthers() *testCase {
tc.OthersAreExcluded = true
return tc
}
func (tc *testCase) Given(given string) *testCase {
tc.given = given
return tc
}
func (tc *testCase) When(when string) *testCase {
tc.when = when
return tc
}
func (tc *testCase) Then(then string) *testCase {
tc.then = then
return tc
}
func (tc *testCase) Step(stepNo float64, step interface{}) *testCase {
tc.validateStepType(step, stepNo)
tc.addStep(stepNo, step)
return tc
}
func (tc *testCase) validateStepType(step interface{}, stepNo float64) {
stepType := reflect.TypeOf(step)
if tc.stepType != nil {
if stepType != tc.stepType {
panic(fmt.Sprintf("step type mismatch; stepNo=%v stepType=%q expectedStepType=%q",
stepNo, stepType, tc.stepType))
}
return
}
if stepType.Kind() != reflect.Func {
panic(fmt.Sprintf("step should be function; stepNo=%v stepType=%q", stepNo, stepType))
}
if stepType.NumIn() != 2 {
panic(fmt.Sprintf("step should have exactly two parameters; stepNo=%v stepType=%q",
stepNo, stepType))
}
if stepType.In(0) != reflect.TypeOf((*testing.T)(nil)) {
panic(fmt.Sprintf("step parameter #1 should be pointer to testing.T; stepNo=%v stepType=%q",
stepNo, stepType))
}
workspaceType, ok := func() (reflect.Type, bool) {
workspaceTypePtr := stepType.In(1)
if workspaceTypePtr.Kind() != reflect.Ptr {
return nil, false
}
workspaceType := workspaceTypePtr.Elem()
if workspaceType.Kind() != reflect.Struct {
return nil, false
}
return workspaceType, true
}()
if !ok {
panic(fmt.Sprintf("step parameter #2 should be pointer to structure; stepNo=%v stepType=%q",
stepNo, stepType))
}
if stepType.NumOut() != 0 {
panic(fmt.Sprintf("step should not return any results; stepNo=%v stepType=%q", stepNo, stepType))
}
tc.stepType = stepType
tc.workspaceType = workspaceType
}
func (tc *testCase) addStep(stepNo float64, step interface{}) {
steps := tc.steps
if steps == nil {
steps = make(map[float64]interface{}, 1)
tc.steps = steps
} else {
if _, ok := steps[stepNo]; ok {
panic(fmt.Sprintf("duplicate step number; stepNo=%v", stepNo))
}
}
steps[stepNo] = step
}
func (tc *testCase) Run(t *testing.T, parallel bool) {
if tc.steps == nil {
panic("no step")
}
t.Run(tc.locator, func(t *testing.T) {
if parallel {
t.Parallel()
}
tc.logGWT(t)
tc.executeSteps(t)
})
}
func (tc *testCase) logGWT(t *testing.T) {
var buffer bytes.Buffer
if tc.given != "" {
buffer.WriteString("\nGIVEN " + tc.given)
}
if tc.when != "" {
buffer.WriteString("\nWHEN " + tc.when)
}
if tc.then != "" {
buffer.WriteString("\nTHEN " + tc.then)
}
if buffer.Len() == 0 {
return
}
t.Log(buffer.String())
}
func (tc *testCase) executeSteps(t *testing.T) {
steps := tc.sortSteps()
tValuePtr := reflect.ValueOf(t)
workspaceValuePtr := reflect.New(tc.workspaceType)
args := []reflect.Value{tValuePtr, workspaceValuePtr}
for _, step := range steps {
reflect.ValueOf(step).Call(args)
}
}
func (tc *testCase) sortSteps() []interface{} {
stepNos := make([]float64, len(tc.steps))
i := 0
for stepNo := range tc.steps {
stepNos[i] = stepNo
i++
}
sort.Float64s(stepNos)
steps := make([]interface{}, len(tc.steps))
i = 0
for _, stepNo := range stepNos {
steps[i] = tc.steps[stepNo]
i++
}
return steps
}
func (tc *testCase) TestCase() *TestCase { return (*TestCase)(unsafe.Pointer(tc)) }
// RunList runs the given list of test cases, steps in each test case will be
// executed in order.
// Test cases will be run with isolated workspaces and each step in a test case
// shares the same workspace.
func RunList(t *testing.T, list ...*TestCase) {
doRunList(t, list, false)
}
// RunListParallel runs the given list of test cases parallel, steps in each test case
// will be executed in order.
// Test cases will be run with isolated workspaces and each step in a test case
// shares the same workspace.
func RunListParallel(t *testing.T, list ...*TestCase) {
doRunList(t, list, true)
}
func doRunList(t *testing.T, list []*TestCase, parallel bool) {
for _, tc := range list {
tc := &tc.tc
if tc.OthersAreExcluded {
tc.Run(t, false)
return
}
}
for _, tc := range list {
tc := &tc.tc
if !tc.IsExcluded {
tc.Run(t, parallel)
}
}
} | testcase.go | 0.655667 | 0.501038 | testcase.go | starcoder |
package data
type (
// List represents a singly-linked List
List interface {
list() // marker
Sequence
Indexed
Counted
Prepend(Value) Sequence
Reverse() Sequence
}
list struct {
first Value
rest List
count int
}
)
// NewList creates a new List instance
func NewList(v ...Value) List {
var res List = EmptyList
for i, u := len(v)-1, 1; i >= 0; i, u = i-1, u+1 {
res = &list{
first: v[i],
rest: res,
count: u,
}
}
return res
}
func (l *list) list() {}
// First returns the first element of the List
func (l *list) First() Value {
return l.first
}
// Rest returns the elements of the List that follow the first
func (l *list) Rest() Sequence {
return l.rest
}
// IsEmpty returns whether this sequence is empty
func (l *list) IsEmpty() bool {
return l.count == 0
}
// Split breaks the List into its components (first, rest, ok)
func (l *list) Split() (Value, Sequence, bool) {
return l.first, l.rest, l.count != 0
}
// Car returns the first element of a Pair
func (l *list) Car() Value {
return SequenceCar(l)
}
// Cdr returns the second element of a Pair
func (l *list) Cdr() Value {
return SequenceCdr(l)
}
// Prepend inserts an element at the beginning of the List
func (l *list) Prepend(v Value) Sequence {
return &list{
first: v,
rest: l,
count: l.count + 1,
}
}
// Reverse returns a reversed copy of this List
func (l *list) Reverse() Sequence {
if l.count <= 1 {
return l
}
var res List = EmptyList
var e List = l
for d, u := e.Count(), 1; d > 0; e, d, u = e.Rest().(List), d-1, u+1 {
res = &list{
first: e.First(),
rest: res,
count: u,
}
}
return res
}
// Count returns the number of elements in the List
func (l *list) Count() int {
return l.count
}
// ElementAt returns a specific element of the List
func (l *list) ElementAt(index int) (Value, bool) {
if index > l.count-1 || index < 0 {
return Nil, false
}
var e List = l
for i := 0; i < index; i++ {
e = e.Rest().(List)
}
return e.First(), true
}
// Applicative turns List into a Caller
func (l *list) Call(args ...Value) Value {
return indexedCall(l, args)
}
// Convention returns the function's calling convention
func (l *list) Convention() Convention {
return ApplicativeCall
}
// CheckArity performs a compile-time arity check for the function
func (l *list) CheckArity(argCount int) error {
return checkRangedArity(1, 2, argCount)
}
func (l *list) Equal(v Value) bool {
if v, ok := v.(*list); ok {
if l == v {
return true
}
if l.count != v.count || !l.first.Equal(v.first) {
return false
}
return l.rest.Equal(v.rest)
}
return false
}
// String converts this List to a string
func (l *list) String() string {
return MakeSequenceStr(l)
} | data/list.go | 0.825555 | 0.495789 | list.go | starcoder |
package clac
import (
"github.com/kpmy/ypk/halt"
)
func b_(fn func(Value, Value) bool) func(Value, Value) Value {
return func(l Value, r Value) (ret Value) {
ret = Value{T: BOOLEAN}
ret.V = fn(l, r)
return
}
}
func b_i_(fn func(int64, Value) bool) func(Value, Value) bool {
return func(l Value, r Value) bool {
li := l.ToInt()
return fn(li, r)
}
}
func b_i_i_(fn func(int64, int64) bool) func(int64, Value) bool {
return func(li int64, r Value) bool {
ri := r.ToInt()
return fn(li, ri)
}
}
func b_r_(fn func(float64, Value) bool) func(Value, Value) bool {
return func(l Value, r Value) bool {
lr := l.ToFlo()
return fn(lr, r)
}
}
func b_r_r_(fn func(float64, float64) bool) func(float64, Value) bool {
return func(lr float64, r Value) bool {
rr := r.ToFlo()
return fn(lr, rr)
}
}
func b_ir_(fn func(float64, Value) bool) func(Value, Value) bool {
return func(l Value, r Value) bool {
if l.T == FLOAT {
lr := l.ToFlo()
return fn(lr, r)
} else if l.T == INTEGER {
lr := l.ToFlo()
return fn(lr, r)
} else {
halt.As(100, "cannot convert")
}
panic(0)
}
}
func b_ir_ir_(fn func(float64, float64) bool) func(float64, Value) bool {
return func(lr float64, r Value) bool {
if r.T == FLOAT {
rr := r.ToFlo()
return fn(lr, rr)
} else if r.T == INTEGER {
rr := r.ToFlo()
return fn(lr, rr)
} else {
halt.As(100, "cannot convert")
}
panic(0)
}
}
func b_c_(fn func(complex128, Value) bool) func(Value, Value) bool {
return func(l Value, r Value) bool {
lc := l.ToCmp()
return fn(lc, r)
}
}
func b_c_c_(fn func(complex128, complex128) bool) func(complex128, Value) bool {
return func(lc complex128, r Value) bool {
rc := r.ToCmp()
return fn(lc, rc)
}
}
func b_c_ir_(fn func(complex128, float64) bool) func(complex128, Value) bool {
return func(lc complex128, r Value) bool {
if r.T == FLOAT {
rr := r.ToFlo()
return fn(lc, rr)
} else if r.T == INTEGER {
rr := r.ToFlo()
return fn(lc, rr)
} else {
halt.As(100, "cannot convert")
}
panic(0)
}
}
func b_ir_c_(fn func(float64, complex128) bool) func(float64, Value) bool {
return func(lr float64, r Value) bool {
rc := r.ToCmp()
return fn(lr, rc)
}
}
func i_(fn func(Value, Value) int64) func(Value, Value) Value {
return func(l Value, r Value) (ret Value) {
ret = Value{T: INTEGER}
ret.V = thisVal(fn(l, r))
return
}
}
func i_i_(fn func(int64, Value) int64) func(Value, Value) int64 {
return func(l Value, r Value) int64 {
li := l.ToInt()
return fn(li, r)
}
}
func i_i_i_(fn func(int64, int64) int64) func(int64, Value) int64 {
return func(li int64, r Value) int64 {
ri := r.ToInt()
return fn(li, ri)
}
}
func r_(fn func(Value, Value) float64) func(Value, Value) Value {
return func(l Value, r Value) (ret Value) {
ret = Value{T: FLOAT}
ret.V = thisVal(fn(l, r))
return
}
}
func r_r_(fn func(float64, Value) float64) func(Value, Value) float64 {
return func(l Value, r Value) float64 {
lr := l.ToFlo()
return fn(lr, r)
}
}
func r_r_r_(fn func(float64, float64) float64) func(float64, Value) float64 {
return func(lr float64, r Value) float64 {
rr := r.ToFlo()
return fn(lr, rr)
}
}
func r_ir_(fn func(float64, Value) float64) func(Value, Value) float64 {
return func(l Value, r Value) float64 {
if l.T == FLOAT {
lr := l.ToFlo()
return fn(lr, r)
} else if l.T == INTEGER {
lr := l.ToFlo()
return fn(lr, r)
} else {
halt.As(100, "cannot convert")
}
panic(0)
}
}
func r_ir_ir_(fn func(float64, float64) float64) func(float64, Value) float64 {
return func(lr float64, r Value) float64 {
if r.T == FLOAT {
rr := r.ToFlo()
return fn(lr, rr)
} else if r.T == INTEGER {
rr := r.ToFlo()
return fn(lr, rr)
} else {
halt.As(100, "cannot convert")
}
panic(0)
}
}
func c_(fn func(Value, Value) complex128) func(Value, Value) Value {
return func(l Value, r Value) (ret Value) {
ret = Value{T: COMPLEX}
ret.V = thisVal(fn(l, r))
return
}
}
func c_c_(fn func(complex128, Value) complex128) func(Value, Value) complex128 {
return func(l Value, r Value) complex128 {
lc := l.ToCmp()
return fn(lc, r)
}
}
func c_c_c_(fn func(complex128, complex128) complex128) func(complex128, Value) complex128 {
return func(lc complex128, r Value) complex128 {
rc := r.ToCmp()
return fn(lc, rc)
}
}
func c_ir_(fn func(float64, Value) complex128) func(Value, Value) complex128 {
return func(l Value, r Value) complex128 {
if l.T == FLOAT {
lr := l.ToFlo()
return fn(lr, r)
} else if l.T == INTEGER {
lr := l.ToFlo()
return fn(lr, r)
} else {
halt.As(100, "cannot convert")
}
panic(0)
}
}
func c_ir_ir_(fn func(float64, float64) complex128) func(float64, Value) complex128 {
return func(lr float64, r Value) complex128 {
if r.T == FLOAT {
rr := r.ToFlo()
return fn(lr, rr)
} else if r.T == INTEGER {
rr := r.ToFlo()
return fn(lr, rr)
} else {
halt.As(100, "cannot convert")
}
panic(0)
}
}
func c_c_ir_(fn func(complex128, float64) complex128) func(complex128, Value) complex128 {
return func(lc complex128, r Value) complex128 {
if r.T == FLOAT {
rr := r.ToFlo()
return fn(lc, rr)
} else if r.T == INTEGER {
rr := r.ToFlo()
return fn(lc, rr)
} else {
halt.As(100, "cannot convert")
}
panic(0)
}
}
func c_ir_c_(fn func(float64, complex128) complex128) func(float64, Value) complex128 {
return func(lr float64, r Value) complex128 {
rc := r.ToCmp()
return fn(lr, rc)
}
} | fn.go | 0.580114 | 0.607343 | fn.go | starcoder |
package typ
// Compare checks if either value is greater or equal to the other.
// The result will be 0 if a == b, -1 if a < b, and +1 if a > b.
func Compare[T Ordered](a, b T) int {
if a > b {
return 1
}
if a < b {
return -1
}
return 0
}
// Less returns true if the first argument is less than the second.
func Less[T Ordered](a, b T) bool {
return a < b
}
// Zero returns the zero value for a given type.
func Zero[T any]() T {
var zero T
return zero
}
// IsZero returns true if the value is zero. If the type implements
// IsZero() bool
// then that method is also used.
func IsZero[T comparable](value T) bool {
var zero T
if value == zero {
return true
}
var asAny any = value
if isZeroer, ok := asAny.(interface{ IsZero() bool }); ok {
return isZeroer.IsZero()
}
return false
}
// ZeroOf returns the zero value for a given type. The first argument is unused,
// but using Go's type inference can be useful to create the zero value for an
// anonymous type without needing to declare the full type.
func ZeroOf[T any](T) T {
var zero T
return zero
}
// Coal will return the first non-zero value. Equivalent to the "null coalescing"
// operator from other languages, or the SQL "COALESCE(...)" expression.
// var result = null ?? myDefaultValue; // C#, JavaScript, PHP, etc
// var result = typ.Coal(nil, myDefaultValue) // Go
func Coal[T comparable](values ...T) T {
var zero T
for _, v := range values {
if v != zero {
return v
}
}
return zero
}
// Tern returns different values depending on the given conditional boolean.
// Equivalent to the "ternary" operator from other languages.
// var result = 1 > 2 ? "yes" : "no"; // C#, JavaScript, PHP, etc
// var result = typ.Tern(1 > 2, "yes", "no") // Go
func Tern[T any](cond bool, ifTrue, ifFalse T) T {
if cond {
return ifTrue
}
return ifFalse
}
// TernCast will cast the value if condition is true. Otherwise the last
// argument is returned.
func TernCast[T any](cond bool, value any, ifFalse T) T {
if cond {
return value.(T)
}
return ifFalse
}
// IsNil checks if the generic value is nil.
func IsNil[T any](value T) bool {
var asAny any = value
return asAny == nil
}
// Ref returns a pointer to the value. Useful when working with literals.
func Ref[T any](value T) *T {
return &value
}
// DerefZero returns the dereferenced value, or zero if it was nil.
func DerefZero[P ~*V, V any](ptr P) V {
if ptr == nil {
return Zero[V]()
}
return *ptr
} | util.go | 0.754282 | 0.620291 | util.go | starcoder |
// Package geo contains the base types for spatial data type operations.
package geo
import (
"encoding/binary"
"encoding/hex"
"strings"
"github.com/cockroachdb/cockroach/pkg/geo/geopb"
"github.com/golang/geo/s2"
"github.com/twpayne/go-geom"
"github.com/twpayne/go-geom/encoding/ewkb"
)
var ewkbEncodingFormat = binary.LittleEndian
// spatialObjectBase is the base for spatial objects.
type spatialObjectBase struct {
ewkb geopb.EWKB
}
// EWKB returns the EWKB form of the data type.
func (b *spatialObjectBase) EWKB() geopb.EWKB {
return b.ewkb
}
// SRID returns the SRID of the given spatial object.
func (b *spatialObjectBase) SRID() geopb.SRID {
// We always assume EWKB is little endian and valid.
// Mask the 5th byte and check if it has the SRID bit set.
if b.ewkb[4]&0x20 == 0 {
return 0
}
// Read the next 4 bytes as little endian.
return geopb.SRID(
int32(b.ewkb[5]) +
(int32(b.ewkb[6]) << 8) +
(int32(b.ewkb[7]) << 16) +
(int32(b.ewkb[8]) << 24),
)
}
// EWKBHex returns the EWKB-hex version of this data type
func (b *spatialObjectBase) EWKBHex() string {
return strings.ToUpper(hex.EncodeToString(b.ewkb))
}
// makeSpatialObjectBase creates a spatialObjectBase from an unvalidated EWKB.
func makeSpatialObjectBase(in geopb.UnvalidatedEWKB) (spatialObjectBase, error) {
t, err := ewkb.Unmarshal(in)
if err != nil {
return spatialObjectBase{}, err
}
ret, err := ewkb.Marshal(t, ewkbEncodingFormat)
if err != nil {
return spatialObjectBase{}, err
}
return spatialObjectBase{ewkb: geopb.EWKB(ret)}, nil
}
// Geometry is planar spatial object.
type Geometry struct {
spatialObjectBase
}
// NewGeometry returns a new Geometry. Assumes the input EWKB is validated and in little endian.
func NewGeometry(ewkb geopb.EWKB) *Geometry {
return &Geometry{spatialObjectBase{ewkb: ewkb}}
}
// NewGeometryFromUnvalidatedEWKB returns a new Geometry from an unvalidated EWKB.
func NewGeometryFromUnvalidatedEWKB(ewkb geopb.UnvalidatedEWKB) (*Geometry, error) {
base, err := makeSpatialObjectBase(ewkb)
if err != nil {
return nil, err
}
return &Geometry{base}, nil
}
// ParseGeometry parses a Geometry from a given text.
func ParseGeometry(str string) (*Geometry, error) {
ewkb, err := parseAmbiguousTextToEWKB(str, geopb.DefaultGeometrySRID)
if err != nil {
return nil, err
}
return NewGeometry(ewkb), nil
}
// MustParseGeometry behaves as ParseGeometry, but panics if there is an error.
func MustParseGeometry(str string) *Geometry {
g, err := ParseGeometry(str)
if err != nil {
panic(err)
}
return g
}
// AsGeography converts a given Geometry to it's Geography form.
func (g *Geometry) AsGeography() (*Geography, error) {
if g.SRID() != 0 {
// TODO(otan): check SRID is latlng
return NewGeography(g.ewkb), nil
}
// Set a default SRID if one is not already set.
geom, err := ewkb.Unmarshal(g.ewkb)
if err != nil {
return nil, err
}
adjustGeomSRID(geom, geopb.DefaultGeographySRID)
ret, err := ewkb.Marshal(geom, ewkbEncodingFormat)
if err != nil {
return nil, err
}
return NewGeography(geopb.EWKB(ret)), nil
}
// AsGeomT returns the geometry as a geom.T object.
func (g *Geometry) AsGeomT() (geom.T, error) {
return ewkb.Unmarshal(g.ewkb)
}
// Geography is a spherical spatial object.
type Geography struct {
spatialObjectBase
}
// NewGeography returns a new Geography. Assumes the input EWKB is validated and in little endian.
func NewGeography(ewkb geopb.EWKB) *Geography {
return &Geography{spatialObjectBase{ewkb: ewkb}}
}
// NewGeographyFromUnvalidatedEWKB returns a new Geography from an unvalidated EWKB.
func NewGeographyFromUnvalidatedEWKB(ewkb geopb.UnvalidatedEWKB) (*Geography, error) {
base, err := makeSpatialObjectBase(ewkb)
if err != nil {
return nil, err
}
return &Geography{base}, nil
}
// ParseGeography parses a Geography from a given text.
func ParseGeography(str string) (*Geography, error) {
// TODO(otan): set SRID of EWKB to 4326.
ewkb, err := parseAmbiguousTextToEWKB(str, geopb.DefaultGeographySRID)
if err != nil {
return nil, err
}
return NewGeography(ewkb), nil
}
// AsGeometry converts a given Geography to it's Geometry form.
func (g *Geography) AsGeometry() *Geometry {
return NewGeometry(g.ewkb)
}
// AsS2 converts a given Geography into it's S2 form.
func (g *Geography) AsS2() ([]s2.Region, error) {
// TODO(otan): parse EWKB ourselves.
geomRepr, err := ewkb.Unmarshal(g.ewkb)
if err != nil {
return nil, err
}
// TODO(otan): convert by reading from S2 directly.
return s2RegionsFromGeom(geomRepr), nil
}
// s2RegionsFromGeom converts an geom representation of an object
// to s2 regions.
func s2RegionsFromGeom(geomRepr geom.T) []s2.Region {
var regions []s2.Region
switch repr := geomRepr.(type) {
case *geom.Point:
regions = []s2.Region{
s2.PointFromLatLng(s2.LatLngFromDegrees(repr.Y(), repr.X())),
}
case *geom.LineString:
latLngs := make([]s2.LatLng, repr.NumCoords())
for i := 0; i < repr.NumCoords(); i++ {
p := repr.Coord(i)
latLngs[i] = s2.LatLngFromDegrees(p.Y(), p.X())
}
regions = []s2.Region{
s2.PolylineFromLatLngs(latLngs),
}
case *geom.Polygon:
loops := make([]*s2.Loop, repr.NumLinearRings())
// The first ring is a "shell", which is represented as CCW.
// Following rings are "holes", which are CW. For S2, they are CCW and automatically figured out.
for ringIdx := 0; ringIdx < repr.NumLinearRings(); ringIdx++ {
linearRing := repr.LinearRing(ringIdx)
points := make([]s2.Point, linearRing.NumCoords())
for pointIdx := 0; pointIdx < linearRing.NumCoords(); pointIdx++ {
p := linearRing.Coord(pointIdx)
pt := s2.PointFromLatLng(s2.LatLngFromDegrees(p.Y(), p.X()))
if ringIdx == 0 {
points[pointIdx] = pt
} else {
points[len(points)-pointIdx-1] = pt
}
}
loops[ringIdx] = s2.LoopFromPoints(points)
}
regions = []s2.Region{
s2.PolygonFromLoops(loops),
}
case *geom.GeometryCollection:
for _, geom := range repr.Geoms() {
regions = append(regions, s2RegionsFromGeom(geom)...)
}
case *geom.MultiPoint:
for i := 0; i < repr.NumPoints(); i++ {
regions = append(regions, s2RegionsFromGeom(repr.Point(i))...)
}
case *geom.MultiLineString:
for i := 0; i < repr.NumLineStrings(); i++ {
regions = append(regions, s2RegionsFromGeom(repr.LineString(i))...)
}
case *geom.MultiPolygon:
for i := 0; i < repr.NumPolygons(); i++ {
regions = append(regions, s2RegionsFromGeom(repr.Polygon(i))...)
}
}
return regions
} | pkg/geo/geo.go | 0.725454 | 0.474753 | geo.go | starcoder |
package projecteuler
import (
"fmt"
"math/big"
)
// BigIntMatrix struct
type BigIntMatrix struct {
m [][]*big.Int
}
// Dim returns length of the BigIntMatrix
func (a *BigIntMatrix) Dim() (x, y int) {
return len(a.m[0]), len(a.m)
}
// At returns element at (y,x)
func (a *BigIntMatrix) At(y, x int) (result *big.Int, err error) {
if x < 0 || y < 0 {
err = errNegDim
return
}
dx, dy := a.Dim()
if x > dx || y > dy {
err = errDim
return
}
result = &big.Int{}
result.Set(a.m[y][x])
return
}
// Print prints the BigIntMatrix
func (a *BigIntMatrix) Print() {
x, y := len(a.m[0]), len(a.m)
for i := 0; i < y; i++ {
for j := 0; j < x; j++ {
fmt.Print(a.m[i][j].String())
}
fmt.Println()
}
}
func bigIntMatrixConstructionHelper(x, y int) (result *BigIntMatrix, err error) {
if x <= 0 || y <= 0 {
err = errNegDim
return
}
result = &BigIntMatrix{}
result.m = make([][]*big.Int, y)
for i := 0; i < y; i++ {
result.m[i] = make([]*big.Int, x)
}
return
}
// NewUnitBigIntMatrix constructs new unit BigIntMatrix
func NewUnitBigIntMatrix(x int) (result *BigIntMatrix, err error) {
if result, err = bigIntMatrixConstructionHelper(x, x); err != nil {
return
}
for i := 0; i < x; i++ {
result.m[i][i] = big.NewInt(int64(1))
}
return
}
// NewBigIntMatrix constructs new BigIntMatrix
func NewBigIntMatrix(x, y int, m []int64) (result *BigIntMatrix, err error) {
if len(m) != x*y {
err = errDim
return
}
if result, err = bigIntMatrixConstructionHelper(x, y); err != nil {
return
}
for i := 0; i < y; i++ {
for j := 0; j < x; j++ {
result.m[i][j] = big.NewInt(m[i*x+j])
}
}
return
}
// Clone copies receiver to new BigIntMatrix
func (a *BigIntMatrix) Clone() (result *BigIntMatrix) {
x, y := a.Dim()
result, _ = bigIntMatrixConstructionHelper(x, y)
for i := 0; i < y; i++ {
for j := 0; j < x; j++ {
result.m[i][j] = &big.Int{}
result.m[i][j].Set(a.m[i][j])
}
}
return
}
// MulBigIntMatrix multiplies arguments and puts the result in the new BigIntMatrix
func MulBigIntMatrix(a, b *BigIntMatrix) (result *BigIntMatrix) {
_, ay := a.Dim()
bx, by := b.Dim()
result, _ = bigIntMatrixConstructionHelper(bx, ay)
for i := 0; i < ay; i++ {
for j := 0; j < bx; j++ {
bSlice := make([]*big.Int, by)
for k := 0; k < by; k++ {
bSlice[k] = b.m[k][j]
}
aVec, _ := NewVectorFromBigIntSlice(a.m[i])
bVec, _ := NewVectorFromBigIntSlice(bSlice)
result.m[i][j] = MulBigIntVectors(aVec, bVec)
}
}
return
} | bigIntMatrix.go | 0.737253 | 0.48987 | bigIntMatrix.go | starcoder |
package objprop
const (
// CommonPropertiesLength specifies the length a common properties structure has.
CommonPropertiesLength = uint32(27)
)
// StandardProperties returns an array of class descriptors that represent the standard
// configuration of the existing file
func StandardProperties() []ClassDescriptor {
result := []ClassDescriptor{}
{ // Weapons
subclasses := []SubclassDescriptor{
SubclassDescriptor{TypeCount: 5, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 2, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 2, SpecificDataLength: 16},
SubclassDescriptor{TypeCount: 2, SpecificDataLength: 13},
SubclassDescriptor{TypeCount: 3, SpecificDataLength: 13},
SubclassDescriptor{TypeCount: 2, SpecificDataLength: 18}}
result = append(result, ClassDescriptor{GenericDataLength: 2, Subclasses: subclasses})
}
{ // Clips
subclasses := []SubclassDescriptor{
SubclassDescriptor{TypeCount: 2, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 2, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 3, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 2, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 2, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 2, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 2, SpecificDataLength: 1}}
result = append(result, ClassDescriptor{GenericDataLength: 14, Subclasses: subclasses})
}
{ // Projectiles
subclasses := []SubclassDescriptor{
SubclassDescriptor{TypeCount: 6, SpecificDataLength: 20},
SubclassDescriptor{TypeCount: 16, SpecificDataLength: 6},
SubclassDescriptor{TypeCount: 2, SpecificDataLength: 1}}
result = append(result, ClassDescriptor{GenericDataLength: 1, Subclasses: subclasses})
}
{ // Explosives
subclasses := []SubclassDescriptor{
SubclassDescriptor{TypeCount: 5, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 3, SpecificDataLength: 3}}
result = append(result, ClassDescriptor{GenericDataLength: 15, Subclasses: subclasses})
}
{ // Patches
subclasses := []SubclassDescriptor{
SubclassDescriptor{TypeCount: 7, SpecificDataLength: 1}}
result = append(result, ClassDescriptor{GenericDataLength: 22, Subclasses: subclasses})
}
{ // Hardware
subclasses := []SubclassDescriptor{
SubclassDescriptor{TypeCount: 5, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 10, SpecificDataLength: 1}}
result = append(result, ClassDescriptor{GenericDataLength: 9, Subclasses: subclasses})
}
{ // Softs
subclasses := []SubclassDescriptor{
SubclassDescriptor{TypeCount: 7, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 3, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 4, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 5, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 3, SpecificDataLength: 1}}
result = append(result, ClassDescriptor{GenericDataLength: 5, Subclasses: subclasses})
}
{ // Fixtures
subclasses := []SubclassDescriptor{
SubclassDescriptor{TypeCount: 9, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 10, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 11, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 4, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 9, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 8, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 16, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 10, SpecificDataLength: 1}}
result = append(result, ClassDescriptor{GenericDataLength: 2, Subclasses: subclasses})
}
{ // Items
subclasses := []SubclassDescriptor{
SubclassDescriptor{TypeCount: 8, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 10, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 15, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 6, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 12, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 12, SpecificDataLength: 6},
SubclassDescriptor{TypeCount: 9, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 8, SpecificDataLength: 2}}
result = append(result, ClassDescriptor{GenericDataLength: 2, Subclasses: subclasses})
}
{ // Panels
subclasses := []SubclassDescriptor{
SubclassDescriptor{TypeCount: 9, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 7, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 3, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 11, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 2, SpecificDataLength: 0}, // skipped vending machines
SubclassDescriptor{TypeCount: 3, SpecificDataLength: 1}}
result = append(result, ClassDescriptor{GenericDataLength: 1, Subclasses: subclasses})
}
{ // Barriers
subclasses := []SubclassDescriptor{
SubclassDescriptor{TypeCount: 10, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 9, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 7, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 5, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 10, SpecificDataLength: 1}}
result = append(result, ClassDescriptor{GenericDataLength: 1, Subclasses: subclasses})
}
{ // Animated
subclasses := []SubclassDescriptor{
SubclassDescriptor{TypeCount: 9, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 11, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 14, SpecificDataLength: 1}}
result = append(result, ClassDescriptor{GenericDataLength: 2, Subclasses: subclasses})
}
{ // Marker
subclasses := []SubclassDescriptor{
SubclassDescriptor{TypeCount: 13, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 1, SpecificDataLength: 2},
SubclassDescriptor{TypeCount: 5, SpecificDataLength: 1}}
result = append(result, ClassDescriptor{GenericDataLength: 1, Subclasses: subclasses})
}
{ // Container
subclasses := []SubclassDescriptor{
SubclassDescriptor{TypeCount: 3, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 3, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 4, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 8, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 13, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 7, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 8, SpecificDataLength: 1}}
result = append(result, ClassDescriptor{GenericDataLength: 3, Subclasses: subclasses})
}
{ // Critter
subclasses := []SubclassDescriptor{
SubclassDescriptor{TypeCount: 9, SpecificDataLength: 3},
SubclassDescriptor{TypeCount: 12, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 7, SpecificDataLength: 1},
SubclassDescriptor{TypeCount: 7, SpecificDataLength: 6},
SubclassDescriptor{TypeCount: 2, SpecificDataLength: 1}}
result = append(result, ClassDescriptor{GenericDataLength: 75, Subclasses: subclasses})
}
return result
} | objprop/Constants.go | 0.68342 | 0.506652 | Constants.go | starcoder |
package logic
import (
"fmt"
"image/color"
"math"
"strings"
"time"
"janrobas/spacefetcher/constants"
graphics "janrobas/spacefetcher/graphics"
"janrobas/spacefetcher/models"
"github.com/hajimehoshi/ebiten"
)
func initialize(state *models.GameState) {
state.GameRunning = false
state.Countdown = 3
state.CountdownTs = time.Now().Unix() + 1
state.Fuel = 100
state.ShipX = constants.ScreenWidth / 2
state.ShipY = constants.ScreenHeight / 2
state.MoveXOffset = 0
state.MoveYOffset = 0
state.IndexXOffset = 0
state.IndexYOffset = 0
state.CurrentMap = models.GameMap{
Name: state.Maps[state.CurrentMapIndex].Name,
Map: make([][]rune, len(state.Maps[state.CurrentMapIndex].Map)),
}
for i, row := range state.Maps[state.CurrentMapIndex].Map {
state.CurrentMap.Map[i] = make([]rune, len(row))
for j, val := range row {
state.CurrentMap.Map[i][j] = val
if val == 'S' {
state.IndexXOffset = i - constants.HexesX/2 - 1
state.IndexYOffset = j - constants.HexesY/2 - 3
}
}
}
state.ItemsLeft = 0
for _, row := range state.CurrentMap.Map {
for _, val := range row {
if val == 'X' {
state.ItemsLeft = state.ItemsLeft + 1
}
}
}
state.GameRunning = true
}
func shipIsClose(state *models.GameState, x float32, y float32, dist float64) bool {
return math.Abs(float64(x)-float64(state.ShipX)) < dist/1.5 &&
math.Abs(float64(y)-float64(state.ShipY)) < dist/1.5
}
func drawHexAndReturnIfCollision(screen *ebiten.Image, state *models.GameState, w float32, h float32, x float32, y float32, logicalX int, logicalY int, imgs *models.GameImages) bool {
isOnMap := logicalX >= 0 && logicalY >= 0 &&
len(state.CurrentMap.Map) > logicalX &&
len(state.CurrentMap.Map[logicalX]) > logicalY
var color *color.RGBA
shipIsOnThisHex := shipIsClose(state, x, y, constants.HexSize)
if isOnMap && state.CurrentMap.Map[logicalX][logicalY] == 'X' {
color = constants.HexFuelColor
} else if isOnMap && (state.CurrentMap.Map[logicalX][logicalY] == '1' || state.CurrentMap.Map[logicalX][logicalY] == 'S') {
color = constants.HexRoadColor
} else if isOnMap && state.CurrentMap.Map[logicalX][logicalY] == '2' {
color = constants.HexRoadFastColor
} else if shipIsOnThisHex {
color = constants.HexDangerColor
} else {
color = constants.HexSpaceColor
/*if (logicalX+logicalY)%2 == 0 {
color = constants.HexDangerColor
}*/
}
graphics.DrawHex(screen, w, h, x, y, imgs.EmptyImage, color)
return shipIsOnThisHex && isOnMap
}
func UpdateGame(screen *ebiten.Image, state *models.GameState, imgs *models.GameImages) error {
if ebiten.IsDrawingSkipped() || !state.GameRunning {
return nil
}
currentCollisions := make([]models.IntCoordinates, 0)
for i := 0; i < constants.HexesX; i++ {
for j := 0; j < constants.HexesY; j++ {
offset := -4 * constants.HexSize
if j%2 == 1 {
offset = offset - constants.HexSize + constants.HexSize/2 - constants.HexMarginLeft + constants.HexMarginLeft/2
}
logicalX := i + state.IndexXOffset
logicalY := constants.HexesY - j + state.IndexYOffset
isCollision := drawHexAndReturnIfCollision(screen, state, constants.HexSize, constants.HexSize,
float32(+offset+i*(constants.HexSize+constants.HexMarginLeft))+state.MoveXOffset,
float32(-(2*constants.HexSize)+j*(constants.HexSize+constants.HexMarginTop))+state.MoveYOffset,
logicalX, logicalY, imgs)
if isCollision {
currentCollisions = append(currentCollisions, models.IntCoordinates{X: logicalX, Y: logicalY})
}
}
}
state.CurrentCollisions = currentCollisions
if state.ItemsLeft == 0 && state.CurrentMapIndex == len(state.Maps)-1 {
graphics.DarkScreen(screen)
graphics.DisplayMessage(screen, 20,
constants.ScreenHeight/2,
"Congratulations, space cadet,")
graphics.DisplayMessage(screen, 20,
constants.ScreenHeight/2+30,
"you've cleared all stages!")
graphics.DisplayMessage(screen, 20,
constants.ScreenHeight/2+70,
fmt.Sprintf("Your final score: %d", state.Score+int(math.Ceil(state.Fuel))))
graphics.DisplayMessage(screen, 20,
constants.ScreenHeight/2+110,
"Always keep searching and never get lost!")
return nil
}
graphics.DrawShip(screen, 40, 50, state.ShipX, state.ShipY, state.ShipRotation, imgs.EmptyImage, constants.ShipColor)
graphics.DrawFuel(screen, state.Fuel)
graphics.DisplayMessage(screen, 20, 22, fmt.Sprintf("Stage: %s", state.CurrentMap.Name))
if state.Countdown > 0 {
graphics.DisplayMessage(screen, 20,
constants.ScreenHeight/2,
fmt.Sprintf("Position the ship. Starting in %d sec.", state.Countdown))
}
if state.Fuel <= 0 {
graphics.DarkScreen(screen)
graphics.DisplayMessage(screen, 20,
constants.ScreenHeight/2,
"NO FUEL. Press SPACE to restart.")
}
if state.ItemsLeft == 0 {
graphics.DarkScreen(screen)
graphics.DisplayMessage(screen, 20,
constants.ScreenHeight/2,
"Stage cleared! Press SPACE to continue.")
}
graphics.DisplayMessage(screen, 20,
constants.ScreenHeight-20,
fmt.Sprintf("%d left to pick", state.ItemsLeft))
if state.Score != 0 {
graphics.DisplayMessage(screen, 20,
constants.ScreenHeight-50,
fmt.Sprintf("Score: %d", state.Score))
}
return nil
}
func processKeyboardActions(state *models.GameState, gameaudio *models.GameAudio, delta int64) {
gameFinished := state.ItemsLeft == 0 && state.CurrentMapIndex == len(state.Maps)-1
if gameFinished {
return
}
if ebiten.IsKeyPressed(ebiten.KeyRight) {
state.ShipRotation = state.ShipRotation + float32(delta)/599
}
if ebiten.IsKeyPressed(ebiten.KeyLeft) {
state.ShipRotation = state.ShipRotation - float32(delta)/599
}
if ebiten.IsKeyPressed(ebiten.KeySpace) &&
(state.ItemsLeft == 0 && state.Countdown == 0 || state.Fuel <= 0) {
if state.ItemsLeft == 0 && state.Countdown == 0 {
state.CurrentMapIndex = state.CurrentMapIndex + 1
state.Score += int(math.Ceil(float64(state.Fuel)))
}
initialize(state)
}
if ebiten.IsKeyPressed(ebiten.KeyBackspace) && state.Countdown == 0 {
// restart
initialize(state)
}
if ebiten.IsKeyPressed(ebiten.KeyM) {
// this is checked on every tick in game loop
// we want to wait a little before changing state, so we don't do mute-unmute-mute-unmute loop
tMuteChange := time.NewTimer(time.Millisecond * 500)
if gameaudio.Muted {
gameaudio.Theme.SetVolume(constants.MusicVolume)
gameaudio.Pick.SetVolume(constants.FxVolume)
go func() {
<-tMuteChange.C
gameaudio.Muted = false
}()
} else {
gameaudio.Theme.SetVolume(0)
gameaudio.Pick.SetVolume(0)
go func() {
<-tMuteChange.C
gameaudio.Muted = true
}()
}
}
if state.ShipRotation > math.Pi*2 {
state.ShipRotation = 0
}
}
func moveTerrain(state *models.GameState, delta int64) {
var terrainSpeedMultiply float32 = 1
if ebiten.IsKeyPressed(ebiten.KeyUp) {
for _, collision := range state.CurrentCollisions {
collisionChar := state.CurrentMap.Map[collision.X][collision.Y]
if collisionChar == '2' {
terrainSpeedMultiply = 2
break
}
}
}
state.MoveXOffset -= float32(math.Sin(float64(state.ShipRotation))) * (float32(delta) / 7.5) * terrainSpeedMultiply
state.MoveYOffset += float32(math.Cos(float64(state.ShipRotation))) * (float32(delta) / 7.5) * terrainSpeedMultiply
if math.Abs(float64(state.MoveXOffset)) > 3*constants.HexSize+3*constants.HexMarginLeft {
if state.MoveXOffset < 0 {
state.IndexXOffset = state.IndexXOffset + 3
} else {
state.IndexXOffset = state.IndexXOffset - 3
}
state.MoveXOffset = 0
}
if math.Abs(float64(state.MoveYOffset)) > 2*constants.HexSize+2*constants.HexMarginTop {
if state.MoveYOffset < 0 {
state.IndexYOffset = state.IndexYOffset - 2
} else {
state.IndexYOffset = state.IndexYOffset + 2
}
state.MoveYOffset = 0
}
}
func updateFuel(state *models.GameState, gameaudio *models.GameAudio, delta int64) {
if len(state.CurrentCollisions) == 0 {
state.Fuel -= float64(delta) / 166
}
for _, collision := range state.CurrentCollisions {
collisionChar := state.CurrentMap.Map[collision.X][collision.Y]
if collisionChar == 'X' {
state.CurrentMap.Map[collision.X][collision.Y] = '0'
state.ItemsLeft = state.ItemsLeft - 1
state.Fuel += 10
gameaudio.Pick.Rewind()
gameaudio.Pick.Play()
}
if collisionChar == '0' {
state.Fuel -= 0.09
}
}
state.Fuel -= float64(delta) / 1444
}
func RunGame(state *models.GameState, gameaudio *models.GameAudio) *GameLoop {
initialize(state)
state.Score = 0
gameaudio.Pick.SetVolume(constants.FxVolume)
gameaudio.Theme.SetVolume(constants.MusicVolume)
gameLoop := PrepareGameLoop(func(delta int64, gl *GameLoop) {
if !gameaudio.Theme.IsPlaying() {
gameaudio.Theme.Play()
}
if !state.GameRunning {
return
}
processKeyboardActions(state, gameaudio, delta)
if state.Countdown != 0 {
if time.Now().Unix()-state.CountdownTs >= 1 {
state.Countdown = state.Countdown - 1
state.CountdownTs = time.Now().Unix()
}
return
}
if state.Fuel <= 0 {
return
}
if state.ItemsLeft == 0 {
return
}
moveTerrain(state, delta)
updateFuel(state, gameaudio, delta)
}, func() {
gameaudio.Theme.Close()
})
go StartGameLoop(gameLoop)
return gameLoop
}
func StringToGameMap(minimized string, name string) models.GameMap {
result := make([][]rune, 0, 0)
for _, row := range strings.Split(minimized, "\n") {
rowRes := make([][]rune, 4)
for n := 0; n < 4; n++ {
rowRes[n] = make([]rune, len(row)*4)
for i, char := range row {
if char == 'X' {
if n%4 != 2 {
char = '0'
}
rowRes[n][4*i] = '0'
rowRes[n][4*i+1] = '0'
rowRes[n][4*i+2] = char
rowRes[n][4*i+3] = '0'
} else {
rowRes[n][4*i] = char
rowRes[n][4*i+1] = char
rowRes[n][4*i+2] = char
rowRes[n][4*i+3] = char
}
}
}
result = append(result, rowRes...)
}
return models.GameMap{Map: result, Name: name}
} | logic/gamelogic.go | 0.663778 | 0.425546 | gamelogic.go | starcoder |
package main
// Only the plain math package is needed for the formulas.
import (
"fmt"
"math"
)
// The lengths of the two segments of the robot’s arm. Using the same length for both segments allows the robot to reach the (0,0) coordinate.
const (
len1 = 100.0
len2 = 100.0
)
// The law of cosines, transfomred so that C is the unknown. The names of the sides and angles correspond to the standard names in mathematical writing. Later, we have to map the sides and angles from our scenario to a, b, c, and C, respectively.
func lawOfCosines(a, b, c float64) (C float64) {
// fmt.Printf("Calculating acos %v, a %v, b %v, c %v", (a*a + b*b - c*c) / (2 * a * b), a, b, c)
return math.Acos((a*a + b*b - c*c) / (2 * a * b))
}
// The distance from (0,0) to (x,y). HT to Pythagoras.
func distance(x, y float64) float64 {
return math.Sqrt(x*x + y*y)
}
// Calculating the two joint angles for given x and y.
func angles(x, y float64) (A1, A2 float64) {
//First, get the length of line dist.
dist := distance(x, y)
// Calculating angle D1 is trivial. Atan2 is a modified arctan() function that returns unambiguous results.
D1 := math.Atan2(y, x)
// D2 can be calculated using the law of cosines where a = dist, b = len1, and c = len2.
D2 := lawOfCosines(dist, len1, len2)
// Then A1 is simply the sum of D1 and D2.
A1 = D1 + D2
// A2 can also be calculated with the law of cosine, but this time with a = len1, b = len2, and c = dist.
A2 = lawOfCosines(len1, len2, dist)
fmt.Printf("dist %v, D1 %v, D2 %v, A1 %v, A2 %v", dist, D1, D2, A1, A2)
return A1, A2
}
// Convert radians into degrees.
func deg(rad float64) float64 {
return rad * 180 / math.Pi
}
func convAngles(A1, A2 float64) (alpha, beta float64) {
alpha = math.Mod(math.Pi * 2.5 - A1, math.Pi * 2)
beta = math.Mod(math.Pi * 3 - (A2 - alpha + 2 * math.Pi), 2 * math.Pi)
return alpha, beta
}
func show(x, y, a1, a2, alpha, beta float64) {
fmt.Printf("x=%v, y=%v: A1=%v (%v°), A2=%v (%v°), alpha=%v (%v°), beta=%v (%v°)\n\n",
x, y, a1, deg(a1), a2, deg(a2), alpha, deg(alpha), beta, deg(beta))
}
func main() {
fmt.Println("Lets do some tests. First move to (5,5):")
x, y := 5.0, 5.0
a1, a2 := angles(x, y)
alpha, beta := convAngles(a1, a2)
show (x,y,a1,a2,alpha, beta)
fmt.Println("If y is 0 and x = Sqrt(len1^2 + len2^2), then alpha should become 45 degrees and beta should become 90 degrees.")
x, y = math.Sqrt(len1*len1+len2*len2), 0
a1, a2 = angles(x, y)
alpha, beta = convAngles(a1, a2)
show (x,y,a1,a2,alpha, beta)
fmt.Println("Now let's try moving to (1, 190).")
x, y = 1, 190
a1, a2 = angles(x, y)
alpha, beta = convAngles(a1, a2)
show (x,y,a1,a2,alpha, beta)
fmt.Println("n extreme case: (200,0). The arm needs to stretch along the y axis.")
x, y = 200, 0
a1, a2 = angles(x, y)
alpha, beta = convAngles(a1, a2)
show (x,y,a1,a2,alpha, beta)
fmt.Println("And (0,200).")
x, y = 0, 200
a1, a2 = angles(x, y)
alpha, beta = convAngles(a1, a2)
show (x,y,a1,a2,alpha, beta)
fmt.Println("Moving to (0,0) technically works if the arm segments have the same length, and if the arm does not block itself. Still the result looks a bit weird!?")
x, y = 0, 0
a1, a2 = angles(x, y)
alpha, beta = convAngles(a1, a2)
show (x,y,a1,a2,alpha, beta)
fmt.Println("What happens if the target point is outside the reach? Like (200,200).")
x, y = 200, 200
a1, a2 = angles(x, y)
alpha, beta = convAngles(a1, a2)
show (x,y,a1,a2,alpha, beta)
} | Tests/ScaraSingleArmCalcs/ScaraSingleArmCalcs.go | 0.817502 | 0.762667 | ScaraSingleArmCalcs.go | starcoder |
package sdkv2provider
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourcePingAccessPingFederateRuntimeMetadata() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourcePingAccessPingFederateRuntimeMetadataRead,
Schema: dataSourcePingAccessPingFederateRuntimeMetadataSchema(),
Description: "Use this data source to get the PingFederate Runtime metadata.",
}
}
func dataSourcePingAccessPingFederateRuntimeMetadataSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"authorization_endpoint": {
Type: schema.TypeString,
Computed: true,
Description: "URL of the OpenID Connect provider's authorization endpoint.",
},
"backchannel_authentication_endpoint": {
Type: schema.TypeString,
Computed: true,
Description: "The endpoint used to initiate an out-of-band authentication.",
},
"claim_types_supported": {
Type: schema.TypeList,
Computed: true,
Description: "JSON array containing a list of the claim types that the OpenID Connect provider supports.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"claims_parameter_supported": {
Type: schema.TypeBool,
Computed: true,
Description: "Boolean value specifying whether the OpenID Connect provider supports use of the claims parameter, with true indicating support.",
},
"claims_supported": {
Type: schema.TypeList,
Computed: true,
Description: "JSON array containing a list of the claim names of the claims that the OpenID Connect provider MAY be able to supply values for.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"code_challenge_methods_supported": {
Type: schema.TypeList,
Computed: true,
Description: "Proof Key for Code Exchange (PKCE) code challenge methods supported by this OpenID Connect provider.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"end_session_endpoint": {
Type: schema.TypeString,
Computed: true,
Description: "URL at the OpenID Connect provider to which a relying party can perform a redirect to request that the end-user be logged out at the OpenID Connect provider.",
},
"grant_types_supported": {
Type: schema.TypeList,
Computed: true,
Description: "JSON array containing a list of the OAuth 2.0 grant type values that this OpenID Connect provider supports.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"id_token_signing_alg_values_supported": {
Type: schema.TypeList,
Computed: true,
Description: "JSON array containing a list of the JWS signing algorithms supported by the OpenID Connect provider for the id token to encode the claims in a JWT.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"introspection_endpoint": {
Type: schema.TypeString,
Computed: true,
Description: "URL of the OpenID Connect provider's OAuth 2.0 introspection endpoint.",
},
"issuer": {
Type: schema.TypeString,
Computed: true,
Description: "OpenID Connect provider's issuer identifier URL.",
},
"jwks_uri": {
Type: schema.TypeString,
Computed: true,
Description: "URL of the OpenID Connect provider's JWK Set document.",
},
"ping_end_session_endpoint": {
Type: schema.TypeString,
Computed: true,
Description: "PingFederate logout endpoint. (Not applicable if PingFederate is not the OpenID Connect provider)",
},
"ping_revoked_sris_endpoint": {
Type: schema.TypeString,
Computed: true,
Description: "PingFederate session revocation endpoint. (Not applicable if PingFederate is not the OpenID Connect provider)",
},
"request_object_signing_alg_values_supported": {
Type: schema.TypeList,
Computed: true,
Description: "JSON array containing a list of the JWS signing algorithms supported by the OpenID Connect provider for request objects.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"request_parameter_supported": {
Type: schema.TypeBool,
Computed: true,
Description: "Boolean value specifying whether the OpenID Connect provider supports use of the request parameter, with true indicating support.",
},
"request_uri_parameter_supported": {
Type: schema.TypeBool,
Computed: true,
Description: "Boolean value specifying whether the OpenID Connect provider supports use of the request_uri parameter, with true indicating support.",
},
"response_modes_supported": {
Type: schema.TypeList,
Computed: true,
Description: "JSON array containing a list of the OAuth 2.0 \"response_mode\" values that this OpenID Connect provider supports.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"response_types_supported": {
Type: schema.TypeList,
Computed: true,
Description: "JSON array containing a list of the OAuth 2.0 \"response_type\" values that this OpenID Connect provider supports.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"revocation_endpoint": {
Type: schema.TypeString,
Computed: true,
Description: "URL of the OpenID Connect provider's OAuth 2.0 revocation endpoint.",
},
"scopes_supported": {
Type: schema.TypeList,
Computed: true,
Description: "JSON array containing a list of the OAuth 2.0 \"scope\" values that this OpenID Connect provider supports.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"subject_types_supported": {
Type: schema.TypeList,
Computed: true,
Description: "JSON array containing a list of the Subject Identifier types that this OpenID Connect provider supports.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"token_endpoint": {
Type: schema.TypeString,
Computed: true,
Description: "URL of the OpenID Connect provider's token endpoint.",
},
"token_endpoint_auth_methods_supported": {
Type: schema.TypeList,
Computed: true,
Description: "JSON array containing a list of client authentication methods supported by this token endpoint.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"userinfo_endpoint": {
Type: schema.TypeString,
Computed: true,
Description: "URL of the OpenID Connect provider's userInfo endpoint.",
},
"userinfo_signing_alg_values_supported": {
Type: schema.TypeList,
Computed: true,
Description: "JSON array containing a list of the JWS signing algorithms supported by the userInfo endpoint to encode the claims in a JWT.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
}
}
func dataSourcePingAccessPingFederateRuntimeMetadataRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
svc := m.(paClient).Pingfederate
result, resp, err := svc.GetPingFederateRuntimeMetadataCommand()
if err != nil {
return diag.Errorf("unable to read PingFederate Runtime Metadata: %s\n%v", err, resp)
}
var diags diag.Diagnostics
d.SetId("pingfederate_runtime_metadata")
setResourceDataStringWithDiagnostic(d, "authorization_endpoint", result.AuthorizationEndpoint, &diags)
setResourceDataStringWithDiagnostic(d, "backchannel_authentication_endpoint", result.BackchannelAuthenticationEndpoint, &diags)
if err := d.Set("claim_types_supported", result.ClaimTypesSupported); err != nil {
diags = append(diags, diag.FromErr(err)...)
}
if err := d.Set("claims_parameter_supported", result.ClaimsParameterSupported); err != nil {
diags = append(diags, diag.FromErr(err)...)
}
if err := d.Set("claims_supported", result.ClaimsSupported); err != nil {
diags = append(diags, diag.FromErr(err)...)
}
if err := d.Set("code_challenge_methods_supported", result.CodeChallengeMethodsSupported); err != nil {
diags = append(diags, diag.FromErr(err)...)
}
setResourceDataStringWithDiagnostic(d, "end_session_endpoint", result.EndSessionEndpoint, &diags)
if err := d.Set("grant_types_supported", result.GrantTypesSupported); err != nil {
diags = append(diags, diag.FromErr(err)...)
}
if err := d.Set("id_token_signing_alg_values_supported", result.IdTokenSigningAlgValuesSupported); err != nil {
diags = append(diags, diag.FromErr(err)...)
}
setResourceDataStringWithDiagnostic(d, "introspection_endpoint", result.IntrospectionEndpoint, &diags)
setResourceDataStringWithDiagnostic(d, "issuer", result.Issuer, &diags)
setResourceDataStringWithDiagnostic(d, "jwks_uri", result.JwksUri, &diags)
setResourceDataStringWithDiagnostic(d, "ping_end_session_endpoint", result.PingEndSessionEndpoint, &diags)
setResourceDataStringWithDiagnostic(d, "ping_revoked_sris_endpoint", result.PingRevokedSrisEndpoint, &diags)
if err := d.Set("request_object_signing_alg_values_supported", result.RequestObjectSigningAlgValuesSupported); err != nil {
diags = append(diags, diag.FromErr(err)...)
}
setResourceDataBoolWithDiagnostic(d, "request_parameter_supported", result.RequestParameterSupported, &diags)
setResourceDataBoolWithDiagnostic(d, "request_uri_parameter_supported", result.RequestUriParameterSupported, &diags)
if err := d.Set("response_modes_supported", result.ResponseModesSupported); err != nil {
diags = append(diags, diag.FromErr(err)...)
}
if err := d.Set("response_types_supported", result.ResponseTypesSupported); err != nil {
diags = append(diags, diag.FromErr(err)...)
}
setResourceDataStringWithDiagnostic(d, "revocation_endpoint", result.RevocationEndpoint, &diags)
if err := d.Set("scopes_supported", result.ScopesSupported); err != nil {
diags = append(diags, diag.FromErr(err)...)
}
if err := d.Set("subject_types_supported", result.SubjectTypesSupported); err != nil {
diags = append(diags, diag.FromErr(err)...)
}
setResourceDataStringWithDiagnostic(d, "token_endpoint", result.TokenEndpoint, &diags)
if err := d.Set("token_endpoint_auth_methods_supported", result.TokenEndpointAuthMethodsSupported); err != nil {
diags = append(diags, diag.FromErr(err)...)
}
setResourceDataStringWithDiagnostic(d, "userinfo_endpoint", result.UserinfoEndpoint, &diags)
if err := d.Set("userinfo_signing_alg_values_supported", result.UserinfoSigningAlgValuesSupported); err != nil {
diags = append(diags, diag.FromErr(err)...)
}
return diags
} | internal/sdkv2provider/data_source_pingaccess_pingfederate_runtime_metadata.go | 0.67854 | 0.440951 | data_source_pingaccess_pingfederate_runtime_metadata.go | starcoder |
package engine
import "math"
// DefaultEvaluableFunctors is a EvaluableFunctors with builtin functions.
var DefaultEvaluableFunctors = EvaluableFunctors{
Constant: map[Atom]Number{
`pi`: Float(math.Pi),
},
Unary: map[Atom]func(Number) (Number, error){
`-`: Neg,
`abs`: Abs,
`sign`: Sign,
`float_integer_part`: FloatIntegerPart,
`float_fractional_part`: FloatFractionalPart,
`float`: AsFloat,
`floor`: Floor,
`truncate`: Truncate,
`round`: Round,
`ceiling`: Ceiling,
`sin`: Sin,
`cos`: Cos,
`atan`: Atan,
`exp`: Exp,
`log`: Log,
`sqrt`: Sqrt,
`\`: BitwiseComplement,
`+`: Pos,
`asin`: Asin,
`acos`: Acos,
`tan`: Tan,
},
Binary: map[Atom]func(Number, Number) (Number, error){
`+`: Add,
`-`: Sub,
`*`: Mul,
`//`: IntDiv,
`/`: Div,
`rem`: Rem,
`mod`: Mod,
`**`: Power,
`>>`: BitwiseRightShift,
`<<`: BitwiseLeftShift,
`/\`: BitwiseAnd,
`\/`: BitwiseOr,
`div`: IntFloorDiv,
`max`: Max,
`min`: Min,
`^`: IntegerPower,
`atan2`: Atan2,
`xor`: Xor,
},
}
// Number is a prolog number, either Integer or Float.
type Number interface {
Term
number()
}
// EvaluableFunctors is a set of unary/binary functions.
type EvaluableFunctors struct {
// Constant is a set of constants.
Constant map[Atom]Number
// Unary is a set of functions of arity 1.
Unary map[Atom]func(x Number) (Number, error)
// Binary is a set of functions of arity 2.
Binary map[Atom]func(x, y Number) (Number, error)
}
// Is evaluates expression and unifies the result with result.
func (e EvaluableFunctors) Is(result, expression Term, k func(*Env) *Promise, env *Env) *Promise {
v, err := e.eval(expression, env)
if err != nil {
return Error(err)
}
return Unify(result, v, k, env)
}
// Equal succeeds iff e1 equals to e2.
func (e EvaluableFunctors) Equal(e1, e2 Term, k func(*Env) *Promise, env *Env) *Promise {
ev1, err := e.eval(e1, env)
if err != nil {
return Error(err)
}
ev2, err := e.eval(e2, env)
if err != nil {
return Error(err)
}
var ok bool
switch ev1 := ev1.(type) {
case Integer:
switch ev2 := ev2.(type) {
case Integer:
ok = eqI(ev1, ev2)
case Float:
ok = eqIF(ev1, ev2)
}
case Float:
switch ev2 := ev2.(type) {
case Integer:
ok = eqFI(ev1, ev2)
case Float:
ok = eqF(ev1, ev2)
}
}
if !ok {
return Bool(false)
}
return k(env)
}
// NotEqual succeeds iff e1 doesn't equal to e2.
func (e EvaluableFunctors) NotEqual(e1, e2 Term, k func(*Env) *Promise, env *Env) *Promise {
ev1, err := e.eval(e1, env)
if err != nil {
return Error(err)
}
ev2, err := e.eval(e2, env)
if err != nil {
return Error(err)
}
var ok bool
switch ev1 := ev1.(type) {
case Integer:
switch ev2 := ev2.(type) {
case Integer:
ok = neqI(ev1, ev2)
case Float:
ok = neqIF(ev1, ev2)
}
case Float:
switch ev2 := ev2.(type) {
case Integer:
ok = neqFI(ev1, ev2)
case Float:
ok = neqF(ev1, ev2)
}
}
if !ok {
return Bool(false)
}
return k(env)
}
// LessThan succeeds iff e1 is less than e2.
func (e EvaluableFunctors) LessThan(e1, e2 Term, k func(*Env) *Promise, env *Env) *Promise {
ev1, err := e.eval(e1, env)
if err != nil {
return Error(err)
}
ev2, err := e.eval(e2, env)
if err != nil {
return Error(err)
}
var ok bool
switch ev1 := ev1.(type) {
case Integer:
switch ev2 := ev2.(type) {
case Integer:
ok = lssI(ev1, ev2)
case Float:
ok = lssIF(ev1, ev2)
}
case Float:
switch ev2 := ev2.(type) {
case Integer:
ok = lssFI(ev1, ev2)
case Float:
ok = lssF(ev1, ev2)
}
}
if !ok {
return Bool(false)
}
return k(env)
}
// GreaterThan succeeds iff e1 is greater than e2.
func (e EvaluableFunctors) GreaterThan(e1, e2 Term, k func(*Env) *Promise, env *Env) *Promise {
ev1, err := e.eval(e1, env)
if err != nil {
return Error(err)
}
ev2, err := e.eval(e2, env)
if err != nil {
return Error(err)
}
var ok bool
switch ev1 := ev1.(type) {
case Integer:
switch ev2 := ev2.(type) {
case Integer:
ok = gtrI(ev1, ev2)
case Float:
ok = gtrIF(ev1, ev2)
}
case Float:
switch ev2 := ev2.(type) {
case Integer:
ok = gtrFI(ev1, ev2)
case Float:
ok = gtrF(ev1, ev2)
}
}
if !ok {
return Bool(false)
}
return k(env)
}
// LessThanOrEqual succeeds iff e1 is less than or equal to e2.
func (e EvaluableFunctors) LessThanOrEqual(e1, e2 Term, k func(*Env) *Promise, env *Env) *Promise {
ev1, err := e.eval(e1, env)
if err != nil {
return Error(err)
}
ev2, err := e.eval(e2, env)
if err != nil {
return Error(err)
}
var ok bool
switch ev1 := ev1.(type) {
case Integer:
switch ev2 := ev2.(type) {
case Integer:
ok = leqI(ev1, ev2)
case Float:
ok = leqIF(ev1, ev2)
}
case Float:
switch ev2 := ev2.(type) {
case Integer:
ok = leqFI(ev1, ev2)
case Float:
ok = leqF(ev1, ev2)
}
}
if !ok {
return Bool(false)
}
return k(env)
}
// GreaterThanOrEqual succeeds iff e1 is greater than or equal to e2.
func (e EvaluableFunctors) GreaterThanOrEqual(e1, e2 Term, k func(*Env) *Promise, env *Env) *Promise {
ev1, err := e.eval(e1, env)
if err != nil {
return Error(err)
}
ev2, err := e.eval(e2, env)
if err != nil {
return Error(err)
}
var ok bool
switch ev1 := ev1.(type) {
case Integer:
switch ev2 := ev2.(type) {
case Integer:
ok = geqI(ev1, ev2)
case Float:
ok = geqIF(ev1, ev2)
}
case Float:
switch ev2 := ev2.(type) {
case Integer:
ok = geqFI(ev1, ev2)
case Float:
ok = geqF(ev1, ev2)
}
}
if !ok {
return Bool(false)
}
return k(env)
}
func (e EvaluableFunctors) eval(expression Term, env *Env) (Number, error) {
switch t := env.Resolve(expression).(type) {
case Variable:
return nil, ErrInstantiation
case Atom:
c, ok := e.Constant[t]
if !ok {
return nil, TypeErrorEvaluable(&Compound{
Functor: "/",
Args: []Term{t, Integer(0)},
})
}
return c, nil
case Number:
return t, nil
case *Compound:
switch arity := len(t.Args); arity {
case 1:
f, ok := e.Unary[t.Functor]
if !ok {
return nil, TypeErrorEvaluable(&Compound{
Functor: "/",
Args: []Term{
t.Functor,
Integer(1),
},
})
}
x, err := e.eval(t.Args[0], env)
if err != nil {
return nil, err
}
return f(x)
case 2:
f, ok := e.Binary[t.Functor]
if !ok {
return nil, TypeErrorEvaluable(&Compound{
Functor: "/",
Args: []Term{
t.Functor,
Integer(2),
},
})
}
x, err := e.eval(t.Args[0], env)
if err != nil {
return nil, err
}
y, err := e.eval(t.Args[1], env)
if err != nil {
return nil, err
}
return f(x, y)
default:
return nil, TypeErrorEvaluable(&Compound{
Functor: "/",
Args: []Term{t.Functor, Integer(arity)},
})
}
default:
return nil, TypeErrorEvaluable(&Compound{
Functor: "/",
Args: []Term{t, Integer(0)},
})
}
}
// Add returns sum of 2 numbers.
func Add(x, y Number) (Number, error) {
switch x := x.(type) {
case Integer:
switch y := y.(type) {
case Integer:
return addI(x, y)
case Float:
return addIF(x, y)
}
case Float:
switch y := y.(type) {
case Integer:
return addFI(x, y)
case Float:
return addF(x, y)
}
}
return nil, ErrUndefined
}
// Sub returns subtraction of 2 numbers.
func Sub(x, y Number) (Number, error) {
switch x := x.(type) {
case Integer:
switch y := y.(type) {
case Integer:
return subI(x, y)
case Float:
return subIF(x, y)
}
case Float:
switch y := y.(type) {
case Integer:
return subFI(x, y)
case Float:
return subF(x, y)
}
}
return nil, ErrUndefined
}
// Mul returns multiplication of 2 numbers.
func Mul(x, y Number) (Number, error) {
switch x := x.(type) {
case Integer:
switch y := y.(type) {
case Integer:
return mulI(x, y)
case Float:
return mulIF(x, y)
}
case Float:
switch y := y.(type) {
case Integer:
return mulFI(x, y)
case Float:
return mulF(x, y)
}
}
return nil, ErrUndefined
}
// IntDiv returns integer division of 2 numbers.
func IntDiv(x, y Number) (Number, error) {
switch x := x.(type) {
case Integer:
switch y := y.(type) {
case Integer:
return intDivI(x, y)
default:
return nil, TypeErrorInteger(y)
}
default:
return nil, TypeErrorInteger(x)
}
}
// Div returns division of 2 numbers
func Div(x, y Number) (Number, error) {
switch x := x.(type) {
case Integer:
switch y := y.(type) {
case Integer:
return divII(x, y)
case Float:
return divIF(x, y)
}
case Float:
switch y := y.(type) {
case Integer:
return divFI(x, y)
case Float:
return divF(x, y)
}
}
return nil, ErrUndefined
}
// Rem returns remainder of 2 numbers.
func Rem(x, y Number) (Number, error) {
switch x := x.(type) {
case Integer:
switch y := y.(type) {
case Integer:
return remI(x, y)
default:
return nil, TypeErrorInteger(y)
}
default:
return nil, TypeErrorInteger(x)
}
}
// Mod returns modulo of 2 numbers.
func Mod(x, y Number) (Number, error) {
switch x := x.(type) {
case Integer:
switch y := y.(type) {
case Integer:
return modI(x, y)
default:
return nil, TypeErrorInteger(y)
}
default:
return nil, TypeErrorInteger(x)
}
}
// Neg returns the negation of a number.
func Neg(x Number) (Number, error) {
switch x := x.(type) {
case Integer:
return negI(x)
case Float:
return negF(x), nil
default:
return nil, ErrUndefined
}
}
// Abs returns the absolute value of x.
func Abs(x Number) (Number, error) {
switch x := x.(type) {
case Integer:
return absI(x)
case Float:
return absF(x), nil
default:
return nil, ErrUndefined
}
}
// Sign returns +1, 0, or -1 depending on the sign of x.
func Sign(x Number) (Number, error) {
switch x := x.(type) {
case Integer:
return signI(x), nil
case Float:
return signF(x), nil
default:
return nil, ErrUndefined
}
}
// FloatIntegerPart returns the integer part of x.
func FloatIntegerPart(x Number) (Number, error) {
switch x := x.(type) {
case Float:
return intPartF(x), nil
default:
return nil, TypeErrorFloat(x)
}
}
// FloatFractionalPart returns the fractional part of x.
func FloatFractionalPart(x Number) (Number, error) {
switch x := x.(type) {
case Float:
return fractPartF(x), nil
default:
return nil, TypeErrorFloat(x)
}
}
// AsFloat returns x as engine.Float.
func AsFloat(x Number) (Number, error) {
switch x := x.(type) {
case Integer:
return floatItoF(x), nil
case Float:
return floatFtoF(x), nil
default:
return nil, ErrUndefined
}
}
// Floor returns the greatest integer value less than or equal to x.
func Floor(x Number) (Number, error) {
switch x := x.(type) {
case Float:
return floorFtoI(x)
default:
return nil, TypeErrorFloat(x)
}
}
// Truncate returns the integer value of x.
func Truncate(x Number) (Number, error) {
switch x := x.(type) {
case Float:
return truncateFtoI(x)
default:
return nil, TypeErrorFloat(x)
}
}
// Round returns the nearest integer of x.
func Round(x Number) (Number, error) {
switch x := x.(type) {
case Float:
return roundFtoI(x)
default:
return nil, TypeErrorFloat(x)
}
}
// Ceiling returns the least integer value greater than or equal to x.
func Ceiling(x Number) (Number, error) {
switch x := x.(type) {
case Float:
return ceilingFtoI(x)
default:
return nil, TypeErrorFloat(x)
}
}
// Power returns the base-x exponential of y.
func Power(x, y Number) (Number, error) {
var vx float64
switch x := x.(type) {
case Integer:
vx = float64(x)
case Float:
vx = float64(x)
default:
return nil, ErrUndefined
}
var vy float64
switch y := y.(type) {
case Integer:
vy = float64(y)
case Float:
vy = float64(y)
default:
return nil, ErrUndefined
}
// 9.3.1.3 d) special case
if vx == 0 && vy < 0 {
return nil, ErrUndefined
}
r := Float(math.Pow(vx, vy))
switch {
case math.IsInf(float64(r), 0):
return nil, ErrFloatOverflow
case r == 0 && vx != 0: // Underflow: r can be 0 iff x = 0.
return nil, ErrUnderflow
case math.IsNaN(float64(r)):
return nil, ErrUndefined
default:
return r, nil
}
}
// Sin returns the sine of x.
func Sin(x Number) (Number, error) {
switch x := x.(type) {
case Integer:
return Float(math.Sin(float64(x))), nil
case Float:
return Float(math.Sin(float64(x))), nil
default:
return nil, ErrUndefined
}
}
// Cos returns the cosine of x.
func Cos(x Number) (Number, error) {
switch x := x.(type) {
case Integer:
return Float(math.Cos(float64(x))), nil
case Float:
return Float(math.Cos(float64(x))), nil
default:
return nil, ErrUndefined
}
}
// Atan returns the arctangent of x.
func Atan(x Number) (Number, error) {
switch x := x.(type) {
case Integer:
return Float(math.Atan(float64(x))), nil
case Float:
return Float(math.Atan(float64(x))), nil
default:
return nil, ErrUndefined
}
}
// Exp returns the base-e exponential of x.
func Exp(x Number) (Number, error) {
var vx float64
switch x := x.(type) {
case Integer:
vx = float64(x)
case Float:
vx = float64(x)
default:
return nil, ErrUndefined
}
// Positive overflow:
// e^x > max
// log(e^x) > log(max)
// x * log(e) > log(max)
// x > log(max)
if vx > math.Log(math.MaxFloat64) {
return nil, ErrFloatOverflow
}
r := Float(math.Exp(vx))
if r == 0 { // e^x != 0.
return nil, ErrUnderflow
}
return r, nil
}
// Log returns the natural logarithm of x.
func Log(x Number) (Number, error) {
var vx float64
switch x := x.(type) {
case Integer:
vx = float64(x)
case Float:
vx = float64(x)
default:
return nil, ErrUndefined
}
if vx <= 0 {
return nil, ErrUndefined
}
return Float(math.Log(vx)), nil
}
// Sqrt returns the square root of x.
func Sqrt(x Number) (Number, error) {
var vx float64
switch x := x.(type) {
case Integer:
vx = float64(x)
case Float:
vx = float64(x)
default:
return nil, ErrUndefined
}
if vx < 0 {
return nil, ErrUndefined
}
return Float(math.Sqrt(vx)), nil
}
// BitwiseRightShift returns n bit-shifted by s to the right.
func BitwiseRightShift(n, s Number) (Number, error) {
switch n := n.(type) {
case Integer:
switch s := s.(type) {
case Integer:
return Integer(n >> s), nil
default:
return nil, TypeErrorInteger(s)
}
default:
return nil, TypeErrorInteger(n)
}
}
// BitwiseLeftShift returns n bit-shifted by s to the left.
func BitwiseLeftShift(n, s Number) (Number, error) {
switch n := n.(type) {
case Integer:
switch s := s.(type) {
case Integer:
return Integer(n << s), nil
default:
return nil, TypeErrorInteger(s)
}
default:
return nil, TypeErrorInteger(n)
}
}
// BitwiseAnd returns the logical AND on each bit.
func BitwiseAnd(b1, b2 Number) (Number, error) {
switch b1 := b1.(type) {
case Integer:
switch b2 := b2.(type) {
case Integer:
return b1 & b2, nil
default:
return nil, TypeErrorInteger(b2)
}
default:
return nil, TypeErrorInteger(b1)
}
}
// BitwiseOr returns the logical OR on each bit.
func BitwiseOr(b1, b2 Number) (Number, error) {
switch b1 := b1.(type) {
case Integer:
switch b2 := b2.(type) {
case Integer:
return b1 | b2, nil
default:
return nil, TypeErrorInteger(b2)
}
default:
return nil, TypeErrorInteger(b1)
}
}
// BitwiseComplement returns the logical negation on each bit.
func BitwiseComplement(b1 Number) (Number, error) {
switch b1 := b1.(type) {
case Integer:
return ^b1, nil
default:
return nil, TypeErrorInteger(b1)
}
}
// Pos returns x as is.
func Pos(x Number) (Number, error) {
switch x := x.(type) {
case Integer:
return posI(x)
case Float:
return posF(x)
default:
return nil, ErrUndefined
}
}
// IntFloorDiv returns the integer floor division.
func IntFloorDiv(x, y Number) (Number, error) {
switch x := x.(type) {
case Integer:
switch y := y.(type) {
case Integer:
return intFloorDivI(x, y)
default:
return nil, TypeErrorInteger(y)
}
default:
return nil, TypeErrorInteger(x)
}
}
// Max returns the maximum of x or y.
func Max(x, y Number) (Number, error) {
switch x := x.(type) {
case Integer:
switch y := y.(type) {
case Integer:
if x < y {
return y, nil
}
return x, nil
case Float:
if floatItoF(x) < y {
return y, nil
}
return x, nil
default:
return nil, ErrUndefined
}
case Float:
switch y := y.(type) {
case Integer:
if x < floatItoF(y) {
return y, nil
}
return x, nil
case Float:
if x < y {
return y, nil
}
return x, nil
default:
return nil, ErrUndefined
}
default:
return nil, ErrUndefined
}
}
// Min returns the minimum of x or y.
func Min(x, y Number) (Number, error) {
switch x := x.(type) {
case Integer:
switch y := y.(type) {
case Integer:
if x > y {
return y, nil
}
return x, nil
case Float:
if floatItoF(x) > y {
return y, nil
}
return x, nil
default:
return nil, ErrUndefined
}
case Float:
switch y := y.(type) {
case Integer:
if x > floatItoF(y) {
return y, nil
}
return x, nil
case Float:
if x > y {
return y, nil
}
return x, nil
default:
return nil, ErrUndefined
}
default:
return nil, ErrUndefined
}
}
// IntegerPower returns x raised to the power of y.
func IntegerPower(x, y Number) (Number, error) {
if x, ok := x.(Integer); ok {
if y, ok := y.(Integer); ok {
if x != 1 && y < -1 {
return nil, TypeErrorFloat(x)
}
r, err := Power(x, y)
if err != nil {
return nil, err
}
return truncateFtoI(r.(Float))
}
}
return Power(x, y)
}
// Asin returns the arc sine of x.
func Asin(x Number) (Number, error) {
var vx float64
switch x := x.(type) {
case Integer:
vx = float64(x)
case Float:
vx = float64(x)
default:
return nil, ErrUndefined
}
if vx > 1 || vx < -1 {
return nil, ErrUndefined
}
return Float(math.Asin(vx)), nil
}
// Acos returns the arc cosine of x.
func Acos(x Number) (Number, error) {
var vx float64
switch x := x.(type) {
case Integer:
vx = float64(x)
case Float:
vx = float64(x)
default:
return nil, ErrUndefined
}
if vx > 1 || vx < -1 {
return nil, ErrUndefined
}
return Float(math.Acos(vx)), nil
}
// Atan2 returns the arc tangent of y/x.
func Atan2(y, x Number) (Number, error) {
var vy float64
switch y := y.(type) {
case Integer:
vy = float64(y)
case Float:
vy = float64(y)
default:
return nil, ErrUndefined
}
var vx float64
switch x := x.(type) {
case Integer:
vx = float64(x)
case Float:
vx = float64(x)
default:
return nil, ErrUndefined
}
if vx == 0 && vy == 0 {
return nil, ErrUndefined
}
return Float(math.Atan2(vy, vx)), nil
}
// Tan returns the tangent of x.
func Tan(x Number) (Number, error) {
var vx float64
switch x := x.(type) {
case Integer:
vx = float64(x)
case Float:
vx = float64(x)
default:
return nil, ErrUndefined
}
return Float(math.Tan(vx)), nil
}
func Xor(x, y Number) (Number, error) {
vx, ok := x.(Integer)
if !ok {
return nil, TypeErrorInteger(x)
}
vy, ok := y.(Integer)
if !ok {
return nil, TypeErrorInteger(y)
}
return vx ^ vy, nil
}
// Comparison
func eqF(x, y Float) bool {
return x == y
}
func eqI(m, n Integer) bool {
return m == n
}
func eqFI(x Float, n Integer) bool {
y := floatItoF(n)
return eqF(x, y)
}
func eqIF(n Integer, y Float) bool {
return eqFI(y, n)
}
func neqF(x, y Float) bool {
return x != y
}
func neqI(m, n Integer) bool {
return m != n
}
func neqFI(x Float, n Integer) bool {
y := floatItoF(n)
return neqF(x, y)
}
func neqIF(n Integer, y Float) bool {
return neqFI(y, n)
}
func lssF(x, y Float) bool {
return x < y
}
func lssI(m, n Integer) bool {
return m < n
}
func lssFI(x Float, n Integer) bool {
y := floatItoF(n)
return lssF(x, y)
}
func lssIF(n Integer, y Float) bool {
return gtrFI(y, n)
}
func leqF(x, y Float) bool {
return x <= y
}
func leqI(m, n Integer) bool {
return m <= n
}
func leqFI(x Float, n Integer) bool {
y := floatItoF(n)
return leqF(x, y)
}
func leqIF(n Integer, y Float) bool {
return geqFI(y, n)
}
func gtrF(x, y Float) bool {
return x > y
}
func gtrI(m, n Integer) bool {
return m > n
}
func gtrFI(x Float, n Integer) bool {
y := floatItoF(n)
return gtrF(x, y)
}
func gtrIF(n Integer, y Float) bool {
return lssFI(y, n)
}
func geqF(x, y Float) bool {
return x >= y
}
func geqI(m, n Integer) bool {
return m >= n
}
func geqFI(x Float, n Integer) bool {
y := floatItoF(n)
return geqF(x, y)
}
func geqIF(n Integer, y Float) bool {
return leqFI(y, n)
}
// Type conversion operations
func floatItoF(n Integer) Float {
return Float(n)
}
func floatFtoF(x Float) Float {
return x
}
func floorFtoI(x Float) (Integer, error) {
f := math.Floor(float64(x))
if f > math.MaxInt64 || f < math.MinInt64 {
return 0, ErrIntOverflow
}
return Integer(f), nil
}
func truncateFtoI(x Float) (Integer, error) {
t := math.Trunc(float64(x))
if t > math.MaxInt64 || t < math.MinInt64 {
return 0, ErrIntOverflow
}
return Integer(t), nil
}
func roundFtoI(x Float) (Integer, error) {
r := math.Round(float64(x))
if r > math.MaxInt64 || r < math.MinInt64 {
return 0, ErrIntOverflow
}
return Integer(r), nil
}
func ceilingFtoI(x Float) (Integer, error) {
c := math.Ceil(float64(x))
if c > math.MaxInt64 || c < math.MinInt64 {
return 0, ErrIntOverflow
}
return Integer(c), nil
}
// Integer operations
func addI(x, y Integer) (Integer, error) {
switch {
case y > 0 && x > math.MaxInt64-y:
return 0, ErrIntOverflow
case y < 0 && x < math.MinInt64-y:
return 0, ErrIntOverflow
default:
return x + y, nil
}
}
func subI(x, y Integer) (Integer, error) {
switch {
case y < 0 && x > math.MaxInt64+y:
return 0, ErrIntOverflow
case y > 0 && x < math.MinInt64+y:
return 0, ErrIntOverflow
default:
return x - y, nil
}
}
func mulI(x, y Integer) (Integer, error) {
switch {
case x == -1 && y == math.MinInt64:
return 0, ErrIntOverflow
case x == math.MinInt64 && y == -1:
return 0, ErrIntOverflow
case y == 0:
return 0, nil
case x > math.MaxInt64/y:
return 0, ErrIntOverflow
case x < math.MinInt64/y:
return 0, ErrIntOverflow
default:
return x * y, nil
}
}
func intDivI(x, y Integer) (Integer, error) {
switch {
case y == 0:
return 0, ErrZeroDivisor
case x == math.MinInt64 && y == -1:
// Two's complement special case
return 0, ErrIntOverflow
default:
return x / y, nil
}
}
func remI(x, y Integer) (Integer, error) {
if y == 0 {
return 0, ErrZeroDivisor
}
return x - ((x / y) * y), nil
}
func modI(x, y Integer) (Integer, error) {
if y == 0 {
return 0, ErrZeroDivisor
}
return x - (Integer(math.Floor(float64(x)/float64(y))) * y), nil
}
func negI(x Integer) (Integer, error) {
// Two's complement special case
if x == math.MinInt64 {
return 0, ErrIntOverflow
}
return -x, nil
}
func absI(x Integer) (Integer, error) {
switch {
case x == math.MinInt64:
return 0, ErrIntOverflow
case x < 0:
return -x, nil
default:
return x, nil
}
}
func signI(x Integer) Integer {
switch {
case x > 0:
return 1
case x < 0:
return -1
default:
return 0
}
}
func posI(x Integer) (Integer, error) {
return x, nil
}
func intFloorDivI(x, y Integer) (Integer, error) {
switch {
case x == math.MinInt64 && y == -1:
return 0, ErrIntOverflow
case y == 0:
return 0, ErrZeroDivisor
default:
return Integer(math.Floor(float64(x) / float64(y))), nil
}
}
// Float operations
func addF(x, y Float) (Float, error) {
switch {
case y > 0 && x > math.MaxFloat64-y:
return 0, ErrFloatOverflow
case y < 0 && x < -math.MaxFloat64-y:
return 0, ErrFloatOverflow
}
return x + y, nil
}
func subF(x, y Float) (Float, error) {
return addF(x, -y)
}
func mulF(x, y Float) (Float, error) {
switch {
case y != 0 && x > math.MaxFloat64/y:
return 0, ErrFloatOverflow
case y != 0 && x < -math.MaxFloat64/y:
return 0, ErrFloatOverflow
}
r := x * y
// Underflow: x*y = 0 iff x = 0 or y = 0.
if r == 0 && x != 0 && y != 0 {
return 0, ErrUnderflow
}
return r, nil
}
func divF(x, y Float) (Float, error) {
switch {
case y == 0:
return 0, ErrZeroDivisor
case x > math.MaxFloat64*y:
return 0, ErrFloatOverflow
case x < -math.MaxFloat64*y:
return 0, ErrFloatOverflow
}
r := x / y
// Underflow: x/y = 0 iff x = 0 and y != 0.
if r == 0 && x != 0 {
return 0, ErrUnderflow
}
return r, nil
}
func negF(x Float) Float {
return -x
}
func absF(x Float) Float {
return Float(math.Abs(float64(x)))
}
func signF(x Float) Float {
switch {
case x > 0:
return 1
case x < 0:
return -1
default:
return 0
}
}
func intPartF(x Float) Float {
s := signF(x)
return s * Float(math.Floor(math.Abs(float64(x))))
}
func fractPartF(x Float) Float {
i := intPartF(x)
return x - i
}
func posF(x Float) (Float, error) {
return x, nil
}
// Mixed mode operations
func addFI(x Float, n Integer) (Float, error) {
return addF(x, Float(n))
}
func addIF(n Integer, x Float) (Float, error) {
return addF(Float(n), x)
}
func subFI(x Float, n Integer) (Float, error) {
return subF(x, Float(n))
}
func subIF(n Integer, x Float) (Float, error) {
return subF(Float(n), x)
}
func mulFI(x Float, n Integer) (Float, error) {
return mulF(x, Float(n))
}
func mulIF(n Integer, x Float) (Float, error) {
return mulF(Float(n), x)
}
func divFI(x Float, n Integer) (Float, error) {
return divF(x, Float(n))
}
func divIF(n Integer, x Float) (Float, error) {
return divF(Float(n), x)
}
func divII(n, m Integer) (Float, error) {
return divF(Float(n), Float(m))
} | engine/number.go | 0.636805 | 0.671471 | number.go | starcoder |
package qwak
import (
"encoding/json"
"errors"
"fmt"
"github.com/qwak-ai/go-sdk/qwak/http"
)
// PredictionRequest represents a fluent API to build a prediction request on your model
type PredictionRequest struct {
modelId string
featuresVector []*FeatureVector
}
// NewPredictionRequest is a constructor of PredictionRequest fluent API
func NewPredictionRequest(modelId string) *PredictionRequest {
return &PredictionRequest{modelId: modelId}
}
// AddFeatureVector adding a new feature vector to your prediction request using fluent API
func (ir *PredictionRequest) AddFeatureVector(featureVector *FeatureVector) *PredictionRequest {
ir.featuresVector = append(ir.featuresVector, featureVector)
return ir
}
// AddFeatureVectors adding many new feature vectors to your prediction request using fluent API
func (ir *PredictionRequest) AddFeatureVectors(featuresVector ...*FeatureVector) *PredictionRequest {
ir.featuresVector = append(ir.featuresVector, featuresVector...)
return ir
}
func (ir *PredictionRequest) asPandaOrientedDf() http.PandaOrientedDf {
index := make([]int, len(ir.featuresVector))
columnNextIdx := 0
columnsIdxByName := map[string]int{}
columnsData := make([][]interface{}, len(ir.featuresVector))
// collect columns names and indeces
for idx, vector := range ir.featuresVector {
index[idx] = idx
for _, feature := range vector.features {
if _, ok := columnsIdxByName[feature.name]; !ok {
columnsIdxByName[feature.name] = columnNextIdx
columnNextIdx++
}
}
}
// collect values
for idx, vector := range ir.featuresVector {
columnsData[idx] = make([]interface{}, len(columnsIdxByName))
for _, feature := range vector.features {
columnsData[idx][columnsIdxByName[feature.name]] = feature.value
}
}
columnsNames := make([]string, len(columnsIdxByName))
for columnName, columnIdx := range columnsIdxByName {
columnsNames[columnIdx] = columnName
}
return http.NewPandaOrientedDf(columnsNames, index, columnsData)
}
// PredictionResponse represents a response from your model to a prediction request
type PredictionResponse struct {
predictions []*PredictionResult
}
// GetPredictions is getting a results array from response
func (pr *PredictionResponse) GetPredictions() []*PredictionResult {
return pr.predictions
}
// GetSinglePrediction return a single result from a prediction response
func (pr *PredictionResponse) GetSinglePrediction() *PredictionResult {
if len(pr.predictions) > 0 {
return pr.predictions[0]
}
return nil
}
func responseFromRaw(results []byte) (*PredictionResponse, error) {
var response []map[string]interface{}
err := json.Unmarshal(results, &response)
if err != nil {
return nil, fmt.Errorf("qwak client failed to predict: %s", err.Error())
}
predictionResponse := &PredictionResponse{}
for _, result := range response {
predictionResponse.predictions = append(predictionResponse.predictions, &PredictionResult{
valuesMap: result,
})
}
return predictionResponse, nil
}
// PredictionResult represents one result in a response for prediction request
type PredictionResult struct {
valuesMap map[string]interface{}
}
// GetValueAsInt returning the value of column in a result converted to int.
// If conversion failed or if the column dose not exists, an error returned
func (pr *PredictionResult) GetValueAsInt(columnName string) (int, error) {
value, ok := pr.valuesMap[columnName]
if !ok {
return 0, errors.New("column is not exists")
}
parsedValue, ok := value.(float64)
if !ok {
return 0, errors.New("column value is not a number")
}
return int(parsedValue), nil
}
// GetValueAsFloat returning the value of column in a result converted to float.
// If conversion failed or if the column dose not exists, an error returned
func (pr *PredictionResult) GetValueAsFloat(columnName string) (float64, error) {
value, ok := pr.valuesMap[columnName]
if !ok {
return 0, errors.New("column is not exists")
}
parsedValue, ok := value.(float64)
if !ok {
return 0, errors.New("column value is not a float")
}
return parsedValue, nil
}
// GetValueAsString returning the value of column in a result converted to string.
// If conversion failed or if the column dose not exists, an error returned
func (pr *PredictionResult) GetValueAsString(columnName string) (string, error) {
value, ok := pr.valuesMap[columnName]
if !ok {
return "", errors.New("column is not exists")
}
parsedValue, ok := value.(string)
if !ok {
return "", errors.New("column value is not a float")
}
return parsedValue, nil
}
// FeatureVector represents a vector of features with their name and value
type FeatureVector struct {
features []*feature
}
// NewFeatureVector is a constructor for FeatureVector with fluent API
func NewFeatureVector() *FeatureVector {
return &FeatureVector{}
}
// WithFeature set a feature on a FeatureVector
func (fr *FeatureVector) WithFeature(name string, value interface{}) *FeatureVector {
fr.features = append(fr.features, &feature{
name: name,
value: value,
})
return fr
}
type feature struct {
name string
value interface{}
} | qwak/request.go | 0.765769 | 0.524943 | request.go | starcoder |
package logf
import (
"strconv"
)
// PageSize is the recommended buffer size.
const (
PageSize = 4 * 1024
)
// NewBuffer creates the new instance of Buffer with default capacity.
func NewBuffer() *Buffer {
return NewBufferWithCapacity(PageSize)
}
// NewBufferWithCapacity creates the new instance of Buffer with the given
// capacity.
func NewBufferWithCapacity(capacity int) *Buffer {
return &Buffer{make([]byte, 0, capacity)}
}
// Buffer is a helping wrapper for byte slice.
type Buffer struct {
Data []byte
}
// Write implements io.Writer.
func (b *Buffer) Write(p []byte) (n int, err error) {
b.Data = append(b.Data, p...)
return len(p), nil
}
// String implements fmt.Stringer.
func (b *Buffer) String() string {
return string(b.Bytes())
}
// EnsureSize ensures that the Buffer is able to append 's' bytes without
// a further realloc.
func (b *Buffer) EnsureSize(s int) []byte {
if cap(b.Data)-len(b.Data) < s {
tmpLen := len(b.Data)
tmp := make([]byte, tmpLen, tmpLen+s+(tmpLen>>1))
copy(tmp, b.Data)
b.Data = tmp
}
return b.Data
}
// ExtendBytes extends the Buffer with the given size and returns a slice
// tp extended part of the Buffer.
func (b *Buffer) ExtendBytes(s int) []byte {
b.Data = append(b.Data, make([]byte, s)...)
return b.Data[len(b.Data)-s:]
}
// AppendString appends a string to the Buffer.
func (b *Buffer) AppendString(data string) {
b.Data = append(b.Data, data...)
}
// AppendBytes appends a byte slice to the Buffer.
func (b *Buffer) AppendBytes(data []byte) {
b.Data = append(b.Data, data...)
}
// AppendByte appends a single byte to the Buffer.
func (b *Buffer) AppendByte(data byte) {
b.Data = append(b.Data, data)
}
// Reset resets the underlying byte slice.
func (b *Buffer) Reset() {
b.Data = b.Data[:0]
}
// Back returns the last byte of the underlying byte slice. A caller is in
// charge of checking that the Buffer is not empty.
func (b *Buffer) Back() byte {
return b.Data[len(b.Data)-1]
}
// Bytes returns the underlying byte slice as is.
func (b *Buffer) Bytes() []byte {
return b.Data
}
// Len returns the length of the underlying byte slice.
func (b *Buffer) Len() int {
return len(b.Data)
}
// Cap returns the capacity of the underlying byte slice.
func (b *Buffer) Cap() int {
return cap(b.Data)
}
// AppendUint appends the string form in the base 10 of the given unsigned
// integer to the given Buffer.
func AppendUint(b *Buffer, n uint64) {
b.Data = strconv.AppendUint(b.Data, n, 10)
}
// AppendInt appends the string form in the base 10 of the given integer
// to the given Buffer.
func AppendInt(b *Buffer, n int64) {
b.Data = strconv.AppendInt(b.Data, n, 10)
}
// AppendFloat32 appends the string form of the given float32 to the given
// Buffer.
func AppendFloat32(b *Buffer, n float32) {
b.Data = strconv.AppendFloat(b.Data, float64(n), 'g', -1, 32)
}
// AppendFloat64 appends the string form of the given float32 to the given
// Buffer.
func AppendFloat64(b *Buffer, n float64) {
b.Data = strconv.AppendFloat(b.Data, n, 'g', -1, 64)
}
// AppendBool appends "true" or "false", according to the given bool to the
// given Buffer.
func AppendBool(b *Buffer, n bool) {
b.Data = strconv.AppendBool(b.Data, n)
} | buffer.go | 0.814643 | 0.42662 | buffer.go | starcoder |
package schema
import (
"errors"
"fmt"
"unicode"
)
type DataType string
const (
// DataTypeCRef The data type is a cross-reference, it is starting with a capital letter
DataTypeCRef DataType = "cref"
// DataTypeString The data type is a value of type string
DataTypeString DataType = "string"
// DataTypeInt The data type is a value of type int
DataTypeInt DataType = "int"
// DataTypeNumber The data type is a value of type number/float
DataTypeNumber DataType = "number"
// DataTypeBoolean The data type is a value of type boolean
DataTypeBoolean DataType = "boolean"
// DataTypeDate The data type is a value of type date
DataTypeDate DataType = "date"
)
var PrimitiveDataTypes []DataType = []DataType{DataTypeString, DataTypeInt, DataTypeNumber, DataTypeBoolean, DataTypeDate}
type PropertyKind int
const PropertyKindPrimitive PropertyKind = 1
const PropertyKindRef PropertyKind = 2
type PropertyDataType interface {
Kind() PropertyKind
IsPrimitive() bool
AsPrimitive() DataType
IsReference() bool
Classes() []ClassName
ContainsClass(name ClassName) bool
}
type propertyDataType struct {
kind PropertyKind
primitiveType DataType
classes []ClassName
}
func (p *propertyDataType) Kind() PropertyKind {
return p.kind
}
func (p *propertyDataType) IsPrimitive() bool {
return p.kind == PropertyKindPrimitive
}
func (p *propertyDataType) AsPrimitive() DataType {
if p.kind != PropertyKindPrimitive {
panic("not primitive type")
}
return p.primitiveType
}
func (p *propertyDataType) IsReference() bool {
return p.kind == PropertyKindRef
}
func (p *propertyDataType) Classes() []ClassName {
if p.kind != PropertyKindRef {
panic("not MultipleRef type")
}
return p.classes
}
func (p *propertyDataType) ContainsClass(needle ClassName) bool {
if p.kind != PropertyKindRef {
panic("not MultipleRef type")
}
for _, class := range p.classes {
if class == needle {
return true
}
}
return false
}
// Based on the schema, return a valid description of the defined datatype
func (s *Schema) FindPropertyDataType(dataType []string) (PropertyDataType, error) {
if len(dataType) < 1 {
return nil, errors.New("Empty datatype is invalid")
} else if len(dataType) == 1 {
someDataType := dataType[0]
firstLetter := rune(someDataType[0])
if unicode.IsLower(firstLetter) {
switch someDataType {
case string(DataTypeString), string(DataTypeInt), string(DataTypeNumber), string(DataTypeBoolean), string(DataTypeDate):
return &propertyDataType{
kind: PropertyKindPrimitive,
primitiveType: DataType(someDataType),
}, nil
default:
return nil, fmt.Errorf("Unknown primitive data type '%s'", someDataType)
}
}
}
/* implies len(dataType) > 1, or first element is a class already */
var classes []ClassName
for _, someDataType := range dataType {
className := AssertValidClassName(someDataType)
if s.FindClassByName(className) == nil {
return nil, fmt.Errorf("SingleRef class name '%s' does not exist", className)
}
classes = append(classes, className)
}
return &propertyDataType{
kind: PropertyKindRef,
classes: classes,
}, nil
} | database/schema/data_types.go | 0.638385 | 0.620219 | data_types.go | starcoder |
package main
import (
"math"
"sort"
)
/**
A block is defined by 6 planes. Each plane is defined by a normal to the plane with an origin
at the center of the coordinate system (0, 0, 0) and a scalar k along that normal where the
plane exists.
So, for a single plane if we have a normal (xn, yn, zn) and a value k, then every point on that plane
is defined by the equation
x*xn + y*yn + z*zn = k
As an example, if we have a plane at z=4 then this would be expressed as the normal
(0, 0, 1) and k=4. Using our equation about that means that
x*0 + y*0 + z*1 = 4
in other words, it doesn't mater the x and y as long as z=4, so a plane hovering at z=4
Ray (x,y,z) = (sx,sy,sz) + m (dx,dy,dz)
where (sx,sy,sz) = source
(dx,dy,dz) = direction
m = magnitude
which breaks down to
x = sx + m * dx
y = sy + m * dy
z = sz + m * dz
substituting that into the normal we get
(sx + m * dx) * xn + (sy + m * dy) * yn + (sz + m * dz) * zn = k
sx * xn + m * dx * xn + sy * yn + m * dy * yn + sz * zn + m * dz * zn = k
m (dx * xn + dy * yn + dz * zn) + (sx * xn + sy * yn + sz * zn) + k = 0
m = (k - (sx * xn + sy * yn + sz * zn)) / (dx * xn + dy * yn + dz * zn)
m = - (sx * xn + sy * yn + sz * zn + k) / (dx * xn + dy * yn + dz * zn)
So for a given ray we can compute at what scalar(m) it intersects with the plane
The one issue here is that if the dot product of the ray direction and
the plane normal is zero it means that the ray is parallel or contained
within the plane. For this case we need to determine the distance from
the center to the line and from the center to the plane and determine
which is closer.
For the distance between the point and the plane, lets use the normal
x*xn + y*yn + z*zn = k
There exists some point on the plane such that some magnitude of
the normal plus this point intersects the origin.
(x, y, z) + m * N = (0, 0, 0)
x + m * xn = 0 => x = - m * xn
y + m * yn = 0 => y = - m * yn
z + m * zn = 0 => z = - m * zn
Substituting
(-m * xn * xn) + (-m * yn * yn) + (-z * zn * zn) = k
Solve for m
- m (xn*xn + yn*yn + zn*zn) = k
m = - k / (xn*xn + yn*yn + zn*zn)
Since we really just care about distance we can take the absolute value and drop the negative
Interestingly, as long as K is guaranteed to be positive we can drop the absolute all together
m = k / (xn*xn + yn*yn + zn*zn)
For the distance between a point (the origin) and a line we know that x, y, z is on the line so
rx + m * dx = x
ry + m * dy = y
rz + m * dz = z
We also know that a the dot product between a vector from that point and the origin and
the original line must be zero as they are perpendicular
(x, y, z) dot ( dx, dy, dz) = 0
x * dx + y * dy + z * dz = 0
Substituting in the line info
(rx + m * dx) * dx + (ry + m * dy) * dy + (rz + m * dz) * dz = 0
rx * dx + m * dx^2 + ry * dy + m * dy^2 + rz * dz + m * dz^2 = 0
m ( dx^2 + dy^2 + dz^2 ) = - (rx * dx + ry * dy + rz * dz)
m = - (rx * dx + ry * dy + rz * dz) / ( dx^2 + dy^2 + dz^2 )
Since ray.direction is a unit vector ( dx^2 + dy^2 + dz^2 ) == 1
m = - (rx * dx + ry * dy + rz * dz)
From here we can calculate the point and then the distance to the origin
*/
var Black = NewLambertian(NewVec3(0.0, 0.0, 0.0))
// A plane is a normal vector and a multiplier along that vector
type Plane struct {
Normal Vec3
K float64
}
func NewPlane(normal Vec3, k float64) Plane {
return Plane{
Normal: normal,
K: k,
}
}
type Block struct {
Center Vec3
Planes [6]Plane
Material Material
Outline bool
}
func NewBlock(center Vec3, xSize, ySize, zSize float64, material Material, outline bool) *Block {
bottom := NewPlane(NewVec3(0, -1, 0), zSize/2.0)
top := NewPlane(NewVec3(0, 1, 0), zSize/2.0)
left := NewPlane(NewVec3(-1, 0, 0), xSize/2.0)
right := NewPlane(NewVec3(1, 0, 0), xSize/2.0)
front := NewPlane(NewVec3(0, 0, -1), ySize/2.0)
back := NewPlane(NewVec3(0, 0, 1), ySize/2.0)
return &Block{
Center: center,
Planes: [6]Plane{bottom, top, left, right, front, back},
Material: material,
Outline: outline,
}
}
func (b *Block) RotateX(degrees float64) *Block {
// degree = rad × 180/π
// rad = degree * PI / 180
rad := degrees * math.Pi / 180.0
// https://en.wikipedia.org/wiki/Rotation_matrix
matrix := Matrix{[3]Row{
{1, 0, 0},
{0, math.Cos(rad), -math.Sin(rad)},
{0, math.Sin(rad), math.Cos(rad)},
}}
var planes [6]Plane
for i, plane := range b.Planes {
planes[i] = NewPlane(matrix.multiplyPoint(plane.Normal), plane.K)
}
return &Block{
Center: b.Center,
Planes: planes,
Material: b.Material,
Outline: b.Outline,
}
}
func (b *Block) RotateY(degrees float64) *Block {
// degree = rad × 180/π
// rad = degree * PI / 180
rad := degrees * math.Pi / 180.0
// https://en.wikipedia.org/wiki/Rotation_matrix
matrix := Matrix{[3]Row{
{math.Cos(rad), 0, math.Sin(rad)},
{0, 1, 0},
{-math.Sin(rad), 0, math.Cos(rad)},
}}
var planes [6]Plane
for i, plane := range b.Planes {
planes[i] = NewPlane(matrix.multiplyPoint(plane.Normal), plane.K)
}
return &Block{
Center: b.Center,
Planes: planes,
Material: b.Material,
Outline: b.Outline,
}
}
func (b *Block) Hit(ray Ray, tMin, tMax float64) (*Hit, Material) {
// We need to move the cube to the origin so we can rotate it. The easiest way
// is simply to ignore its center. But then we also need to move the ray
// the same distance so create a copy ray which is translated
rayCopy := ray.SubtractVec3(b.Center)
// Compute the intersection with each plane
var hits []*Hit
for _, plane := range b.Planes {
// Determine where our ray intersects the plane
dot := rayCopy.Direction.Dot(plane.Normal)
if dot == 0.0 {
// Okay, so this ray is either above, below, or contained in the plane.
// Figure out the distance from the center to the plane
// m = - k / (xn*xn + yn*yn + zn*zn)
planeDistance := plane.K / (square(plane.Normal.X()) + square(plane.Normal.Y()) + square(plane.Normal.Z()))
// Now determine the distance from the line to the center.
m := -(rayCopy.Origin.X()*rayCopy.Direction.X() + rayCopy.Origin.Y()*rayCopy.Direction.Y() + rayCopy.Origin.Z()*rayCopy.Direction.Z())
closestPoint := ray.PointAt(m)
lineDistance := math.Sqrt(square(closestPoint.X()) + square(closestPoint.Y()) + square(closestPoint.Z()))
if lineDistance >= planeDistance {
return nil, nil
}
// Otherwise, just skip this as we will intersect some other plane.
continue
}
n := plane.K - (rayCopy.Origin.X()*plane.Normal.X() +
rayCopy.Origin.Y()*plane.Normal.Y() +
rayCopy.Origin.Z()*plane.Normal.Z())
m := n / dot
// For calculating the hit, use the actual ray
hits = append(hits, &Hit{Scalar: m, Point: ray.PointAt(m), Normal: plane.Normal})
}
sort.Slice(hits, func(i, j int) bool {
return hits[i].Scalar < hits[j].Scalar
})
edge := false
// Assume the first hit is going in
in := true
var lastHit *Hit
for _, hit := range hits {
dot := rayCopy.Direction.Dot(hit.Normal)
if dot < 0 {
// Normal is pointing in opposite direction of ray so this is an IN
if in {
// The last one was also going in so this is our new last_m
if lastHit != nil && math.Abs(lastHit.Scalar - hit.Scalar) < 0.005 {
// I _think_ this is an edge
edge = true
} else {
edge = false
}
lastHit = hit
} else {
// The last one was going out and this is an IN so we missed
return nil, nil
}
} else {
// Normal and ray are pointing in the same direction so this is an OUT
in = false
}
}
if lastHit != nil && lastHit.Scalar < tMax && lastHit.Scalar > tMin {
if b.Outline && edge {
return lastHit, Black
}
return lastHit, b.Material
}
return nil, nil
}
func square(x float64) float64 {
return x * x
}
type Row struct {
X float64
Y float64
Z float64
}
type Matrix struct {
Rows [3]Row
}
func (r *Row) multiplyPoint(point Vec3) float64 {
return r.X*point.X() + r.Y*point.Y() + r.Z*point.Z()
}
func (m *Matrix) multiplyPoint(point Vec3) Vec3 {
x1 := m.Rows[0].multiplyPoint(point)
y1 := m.Rows[1].multiplyPoint(point)
z1 := m.Rows[2].multiplyPoint(point)
return NewVec3(x1, y1, z1)
} | cmd/weekend/block.go | 0.84556 | 0.666918 | block.go | starcoder |
package data
import (
"fmt"
)
// treeMap is a map whose key is a data id and the value is the list of data id.
// This map is used to map the children data to their parents (the key is a
// parent data id and the value is the list of ID of its children)
type treeMap map[TaskID]TaskIDArray
// addChild adds a child in the list of children of the data of ID parentID
func (tree *treeMap) addChild(parentID TaskID, childID TaskID) error {
if parentID == childID {
return fmt.Errorf("ERR: a child can not be parent of itself (ID=%v)", childID)
}
_, exists := (*tree)[parentID]
if !exists {
(*tree)[parentID] = make(TaskIDArray, 0)
}
(*tree)[parentID] = append((*tree)[parentID], childID)
return nil
}
// initialize initializes the tree structure from the data array
func (tree *treeMap) initialize(tasks TaskArray) error {
for i := 0; i < len(tasks); i++ {
task := tasks[i]
err := tree.addChild(TaskID(task.ParentID), TaskID(task.UIndex))
if err != nil {
return err
}
}
return nil
}
// TreeString returns a tree representation of the dataArray
func TreeString(tasks TaskArray) string {
// Create the children tree
tree := make(treeMap, 0)
tree.initialize(tasks)
// The principle is to iterate on dataArray root elements (element with no
// parent) and then create a string reresentation of the children tree using
// a recurcive function nodeString
const groupsep = "\n" // group separator (a group is a task that has no parent and has children)
const tabindent = " "
const tabchild = " └─"
//const tabchild = " └" + core.PrettyArrowRight
const tabstart = ""
startIndent := func(size int) string {
s := ""
for i := 0; i < size; i++ {
s += " "
}
return s
}(len(tabstart))
// nodeString is the recursive function
var nodeString func(taskID TaskID, tab string) string
nodeString = func(taskID TaskID, tab string) string {
idx := tasks.indexFromUID(taskID)
s := fmt.Sprintf("%s%s\n", tab, tasks[idx].String())
_, exists := tree[taskID]
if !exists {
// This task has no child
return s
}
children := tree[taskID]
if len(children) == 0 {
return s
}
if tab == tabstart {
// It is a project task (task with no parent AND with children
// tasks), then (1) the tabulation of children is starting with a
// startIndent and (2) we add a groupsep to the main task.
tab = startIndent + tabchild
s = groupsep + s
} else {
tab = tabindent + tab
}
for i := 0; i < len(children); i++ {
s += nodeString(children[i], tab)
}
return s
}
stree := ""
noParentTaskIDs := tree[NoUID]
for k := 0; k < len(noParentTaskIDs); k++ {
stree += nodeString(noParentTaskIDs[k], tabstart)
}
return stree
} | src/todogo/data/tree.go | 0.573559 | 0.54256 | tree.go | starcoder |
package light
import (
"unsafe"
"github.com/leapar/engine/core"
"github.com/leapar/engine/gls"
"github.com/leapar/engine/math32"
)
// Spot represents a spotlight
type Spot struct {
core.Node // Embedded node
color math32.Color // Light color
intensity float32 // Light intensity
uni gls.Uniform // Uniform location cache
udata struct { // Combined uniform data in 5 vec3:
color math32.Color // Light color
position math32.Vector3 // Light position
direction math32.Vector3 // Light direction
angularDecay float32 // Angular decay factor
cutoffAngle float32 // Cut off angle
linearDecay float32 // Distance linear decay
quadraticDecay float32 // Distance quadratic decay
dummy1 float32 // Completes 5*vec3
dummy2 float32 // Completes 5*vec3
}
}
// NewSpot creates and returns a spot light with the specified color and intensity
func NewSpot(color *math32.Color, intensity float32) *Spot {
l := new(Spot)
l.Node.Init()
l.color = *color
l.intensity = intensity
l.uni.Init("SpotLight")
l.SetColor(color)
l.SetAngularDecay(15.0)
l.SetCutoffAngle(45.0)
l.SetLinearDecay(1.0)
l.SetQuadraticDecay(1.0)
return l
}
// SetColor sets the color of this light
func (l *Spot) SetColor(color *math32.Color) {
l.color = *color
l.udata.color = l.color
l.udata.color.MultiplyScalar(l.intensity)
}
// Color returns the current color of this light
func (l *Spot) Color() math32.Color {
return l.color
}
// SetIntensity sets the intensity of this light
func (l *Spot) SetIntensity(intensity float32) {
l.intensity = intensity
l.udata.color = l.color
l.udata.color.MultiplyScalar(l.intensity)
}
// Intensity returns the current intensity of this light
func (l *Spot) Intensity() float32 {
return l.intensity
}
// SetCutoffAngle sets the cutoff angle in degrees from 0 to 90
func (l *Spot) SetCutoffAngle(angle float32) {
l.udata.cutoffAngle = angle
}
// CutoffAngle returns the current cutoff angle in degrees from 0 to 90
func (l *Spot) CutoffAngle() float32 {
return l.udata.cutoffAngle
}
// SetAngularDecay sets the angular decay exponent
func (l *Spot) SetAngularDecay(decay float32) {
l.udata.angularDecay = decay
}
// AngularDecay returns the current angular decay exponent
func (l *Spot) AngularDecay() float32 {
return l.udata.angularDecay
}
// SetLinearDecay sets the linear decay factor as a function of the distance
func (l *Spot) SetLinearDecay(decay float32) {
l.udata.linearDecay = decay
}
// LinearDecay returns the current linear decay factor
func (l *Spot) LinearDecay() float32 {
return l.udata.linearDecay
}
// SetQuadraticDecay sets the quadratic decay factor as a function of the distance
func (l *Spot) SetQuadraticDecay(decay float32) {
l.udata.quadraticDecay = decay
}
// QuadraticDecay returns the current quadratic decay factor
func (l *Spot) QuadraticDecay() float32 {
return l.udata.quadraticDecay
}
// RenderSetup is called by the engine before rendering the scene
func (l *Spot) RenderSetup(gs *gls.GLS, rinfo *core.RenderInfo, idx int) {
// Calculates and updates light position uniform in camera coordinates
var pos math32.Vector3
l.WorldPosition(&pos)
var pos4 math32.Vector4
pos4.SetVector3(&pos, 1.0)
pos4.ApplyMatrix4(&rinfo.ViewMatrix)
l.udata.position.X = pos4.X
l.udata.position.Y = pos4.Y
l.udata.position.Z = pos4.Z
// Calculates and updates light direction uniform in camera coordinates
var dir math32.Vector3
l.WorldDirection(&dir)
pos4.SetVector3(&dir, 0.0)
pos4.ApplyMatrix4(&rinfo.ViewMatrix)
l.udata.direction.X = pos4.X
l.udata.direction.Y = pos4.Y
l.udata.direction.Z = pos4.Z
// Transfer uniform data
const vec3count = 5
location := l.uni.LocationIdx(gs, vec3count*int32(idx))
gs.Uniform3fvUP(location, vec3count, unsafe.Pointer(&l.udata))
} | light/spot.go | 0.853333 | 0.481576 | spot.go | starcoder |
package orb
// Geometry is an interface that represents the shared attributes
// of a geometry.
type Geometry interface {
GeoJSONType() string
Dimensions() int // e.g. 0d, 1d, 2d
Bound() Bound
GCJ02ToWGS84()
BD09ToWGS84()
WGS84ToGCJ02()
WGS84ToBD09()
// requiring because sub package type switch over all possible types.
private()
}
// compile time checks
var (
_ Geometry = Point{}
_ Geometry = MultiPoint{}
_ Geometry = LineString{}
_ Geometry = MultiLineString{}
_ Geometry = Ring{}
_ Geometry = Polygon{}
_ Geometry = MultiPolygon{}
_ Geometry = Bound{}
_ Geometry = Collection{}
)
func (p Point) private() {}
func (mp MultiPoint) private() {}
func (ls LineString) private() {}
func (mls MultiLineString) private() {}
func (r Ring) private() {}
func (p Polygon) private() {}
func (mp MultiPolygon) private() {}
func (b Bound) private() {}
func (c Collection) private() {}
// AllGeometries lists all possible types and values that a geometry
// interface can be. It should be used only for testing to verify
// functions that accept a Geometry will work in all cases.
var AllGeometries = []Geometry{
nil,
Point{},
MultiPoint{},
LineString{},
MultiLineString{},
Ring{},
Polygon{},
MultiPolygon{},
Bound{},
Collection{},
// nil values
MultiPoint(nil),
LineString(nil),
MultiLineString(nil),
Ring(nil),
Polygon(nil),
MultiPolygon(nil),
Collection(nil),
// Collection of Collection
Collection{Collection{Point{}}},
}
// A Collection is a collection of geometries that is also a Geometry.
type Collection []Geometry
// GeoJSONType returns the geometry collection type.
func (c Collection) GeoJSONType() string {
return "GeometryCollection"
}
// Dimensions returns the max of the dimensions of the collection.
func (c Collection) Dimensions() int {
max := -1
for _, g := range c {
if d := g.Dimensions(); d > max {
max = d
}
}
return max
}
// Bound returns the bounding box of all the Geometries combined.
func (c Collection) Bound() Bound {
if len(c) == 0 {
return emptyBound
}
var b Bound
start := -1
for i, g := range c {
if g != nil {
start = i
b = g.Bound()
break
}
}
if start == -1 {
return emptyBound
}
for i := start + 1; i < len(c); i++ {
if c[i] == nil {
continue
}
b = b.Union(c[i].Bound())
}
return b
}
// Equal compares two collections. Returns true if lengths are the same
// and all the sub geometries are the same and in the same order.
func (c Collection) Equal(collection Collection) bool {
if len(c) != len(collection) {
return false
}
for i, g := range c {
if !Equal(g, collection[i]) {
return false
}
}
return true
}
// Clone returns a deep copy of the collection.
func (c Collection) Clone() Collection {
if c == nil {
return nil
}
nc := make(Collection, len(c))
for i, g := range c {
nc[i] = Clone(g)
}
return nc
}
// GCJ02ToWGS84 GCJ02 to WGS84.
func (c Collection) GCJ02ToWGS84() {
}
// WGS84ToGCJ02 WGS84 to GCJ02.
func (c Collection) WGS84ToGCJ02() {
}
// BD09ToWGS84 BD09 to WGS84.
func (c Collection) BD09ToWGS84() {
}
// WGS84ToBD09 WGS84 to BD09.
func (c Collection) WGS84ToBD09() {
} | geometry.go | 0.868367 | 0.435001 | geometry.go | starcoder |
package filters
import (
"math"
"github.com/bspaans/bleep/audio"
)
// Cutoff frequency = Alpha / ((1 - Alpha) * 2 * Pi * dt
// Alpha = 2Pi * dt * Cutoff / (2Pi * dt * Cutoff + 1)
type LowPassFilter struct {
Cutoff float64
PreviousLeft float64
PreviousRight float64
}
func NewLowPassFilter(cutoff float64) *LowPassFilter {
return &LowPassFilter{
Cutoff: cutoff,
PreviousLeft: 0.0,
PreviousRight: 0.0,
}
}
func (f *LowPassFilter) Filter(cfg *audio.AudioConfig, samples []float64) []float64 {
n := len(samples)
if cfg.Stereo {
n = n / 2
}
waveLength := float64(n) / float64(cfg.SampleRate)
rc := 1.0 / (2 * math.Pi * f.Cutoff)
alpha := waveLength / (rc + waveLength)
for i := 0; i < n; i++ {
if cfg.Stereo {
samples[i*2] = f.PreviousLeft + alpha*(samples[i*2]-f.PreviousLeft)
samples[i*2+1] = f.PreviousRight + alpha*(samples[i*2+1]-f.PreviousRight)
f.PreviousLeft = samples[i*2]
f.PreviousRight = samples[i*2+1]
} else {
samples[i] = f.PreviousLeft + alpha*(samples[i]-f.PreviousLeft)
f.PreviousLeft = samples[i]
}
}
return samples
}
type LowPassConvolutionFilter struct {
Cutoff float64
// The order of the filter. Should be odd.
// The order can't be changed once set without resetting the convolution
// filter.
Order int
// The underlying SimpleConvolutionFilter used.
ConvolutionFilter *SimpleConvolutionFilter
}
func NewLowPassConvolutionFilter(cutoff float64, order int) *LowPassConvolutionFilter {
return &LowPassConvolutionFilter{
Cutoff: cutoff,
Order: order,
}
}
func (f *LowPassConvolutionFilter) Filter(cfg *audio.AudioConfig, samples []float64) []float64 {
coefficients := LowPassConvolution(float64(cfg.SampleRate), f.Cutoff, f.Order)
if f.ConvolutionFilter == nil {
f.ConvolutionFilter = NewSimpleConvolutionFilter(coefficients)
} else {
f.ConvolutionFilter.Coefficients = coefficients
}
return f.ConvolutionFilter.Filter(cfg, samples)
}
// Order should be odd.
func LowPassConvolution(sampleRate, cutoff float64, order int) []float64 {
result := make([]float64, order)
fc := cutoff / sampleRate
phase := 2 * math.Pi * fc
middle := order / 2
for i := -middle; i < middle; i++ {
if i == 0 {
result[middle] = 2 * fc
} else {
result[i+middle] = math.Sin(phase*float64(i)) / (math.Pi * float64(i))
}
}
return result
} | filters/lpf.go | 0.72027 | 0.426142 | lpf.go | starcoder |
package xrand
var (
letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
digits = []rune("0123456789")
)
// Meet randomly calculate whether the given probability <num>/<total> is met.
func Meet(num, total int) bool {
return Intn(total) < num
}
// MeetProb randomly calculate whether the given probability is met.
func MeetProb(prob float32) bool {
return Intn(1e7) < int(prob*1e7)
}
// N returns a random int between min and max - [min, max].
func N(min, max int) int {
if min >= max {
return min
}
if min >= 0 {
// Because Intn dose not support negative number,
// so we should first shift the value to left,
// then call Intn to produce the random number,
// and finally shift the result to right.
return Intn(max-(min-0)+1) + (min - 0)
}
if min < 0 {
// Because Intn dose not support negative number,
// so we should first shift the value to right,
// then call Intn to produce the random number,
// and finally shift the result to left.
return Intn(max+(0-min)+1) - (0 - min)
}
return 0
}
// Deprecated.
// Alias of N.
func Rand(min, max int) int {
return N(min, max)
}
// Str returns a random string which contains digits and letters, and its length is <n>.
func Str(n int) string {
b := make([]rune, n)
for i := range b {
if Intn(2) == 1 {
b[i] = digits[Intn(10)]
} else {
b[i] = letters[Intn(52)]
}
}
return string(b)
}
// Deprecated.
// Alias of Str.
func RandStr(n int) string {
return Str(n)
}
// Digits returns a random string which contains only digits, and its length is <n>.
func Digits(n int) string {
b := make([]rune, n)
for i := range b {
b[i] = digits[Intn(10)]
}
return string(b)
}
// Deprecated.
// Alias of Digits.
func RandDigits(n int) string {
return Digits(n)
}
// Letters returns a random string which contains only letters, and its length is <n>.
func Letters(n int) string {
b := make([]rune, n)
for i := range b {
b[i] = letters[Intn(52)]
}
return string(b)
}
// Deprecated.
// Alias of Letters.
func RandLetters(n int) string {
return Letters(n)
}
// Perm returns, as a slice of n ints, a pseudo-random permutation of the integers [0,n).
func Perm(n int) []int {
m := make([]int, n)
for i := 0; i < n; i++ {
j := Intn(i + 1)
m[i] = m[j]
m[j] = i
}
return m
} | utils/xrand/xrand.go | 0.733165 | 0.426322 | xrand.go | starcoder |
package yqlib
import (
"bytes"
"container/list"
"fmt"
"strconv"
"strings"
logging "gopkg.in/op/go-logging.v1"
yaml "gopkg.in/yaml.v3"
)
type xmlPreferences struct {
AttributePrefix string
ContentName string
}
var log = logging.MustGetLogger("yq-lib")
// GetLogger returns the yq logger instance.
func GetLogger() *logging.Logger {
return log
}
type operationType struct {
Type string
NumArgs uint // number of arguments to the op
Precedence uint
Handler operatorHandler
}
var orOpType = &operationType{Type: "OR", NumArgs: 2, Precedence: 20, Handler: orOperator}
var andOpType = &operationType{Type: "AND", NumArgs: 2, Precedence: 20, Handler: andOperator}
var reduceOpType = &operationType{Type: "REDUCE", NumArgs: 2, Precedence: 35, Handler: reduceOperator}
var blockOpType = &operationType{Type: "BLOCK", Precedence: 10, NumArgs: 2, Handler: emptyOperator}
var unionOpType = &operationType{Type: "UNION", NumArgs: 2, Precedence: 10, Handler: unionOperator}
var pipeOpType = &operationType{Type: "PIPE", NumArgs: 2, Precedence: 30, Handler: pipeOperator}
var assignOpType = &operationType{Type: "ASSIGN", NumArgs: 2, Precedence: 40, Handler: assignUpdateOperator}
var addAssignOpType = &operationType{Type: "ADD_ASSIGN", NumArgs: 2, Precedence: 40, Handler: addAssignOperator}
var subtractAssignOpType = &operationType{Type: "SUBTRACT_ASSIGN", NumArgs: 2, Precedence: 40, Handler: subtractAssignOperator}
var assignAttributesOpType = &operationType{Type: "ASSIGN_ATTRIBUTES", NumArgs: 2, Precedence: 40, Handler: assignAttributesOperator}
var assignStyleOpType = &operationType{Type: "ASSIGN_STYLE", NumArgs: 2, Precedence: 40, Handler: assignStyleOperator}
var assignVariableOpType = &operationType{Type: "ASSIGN_VARIABLE", NumArgs: 2, Precedence: 40, Handler: assignVariableOperator}
var assignTagOpType = &operationType{Type: "ASSIGN_TAG", NumArgs: 2, Precedence: 40, Handler: assignTagOperator}
var assignCommentOpType = &operationType{Type: "ASSIGN_COMMENT", NumArgs: 2, Precedence: 40, Handler: assignCommentsOperator}
var assignAnchorOpType = &operationType{Type: "ASSIGN_ANCHOR", NumArgs: 2, Precedence: 40, Handler: assignAnchorOperator}
var assignAliasOpType = &operationType{Type: "ASSIGN_ALIAS", NumArgs: 2, Precedence: 40, Handler: assignAliasOperator}
var multiplyOpType = &operationType{Type: "MULTIPLY", NumArgs: 2, Precedence: 42, Handler: multiplyOperator}
var addOpType = &operationType{Type: "ADD", NumArgs: 2, Precedence: 42, Handler: addOperator}
var subtractOpType = &operationType{Type: "SUBTRACT", NumArgs: 2, Precedence: 42, Handler: subtractOperator}
var alternativeOpType = &operationType{Type: "ALTERNATIVE", NumArgs: 2, Precedence: 42, Handler: alternativeOperator}
var equalsOpType = &operationType{Type: "EQUALS", NumArgs: 2, Precedence: 40, Handler: equalsOperator}
var notEqualsOpType = &operationType{Type: "EQUALS", NumArgs: 2, Precedence: 40, Handler: notEqualsOperator}
//createmap needs to be above union, as we use union to build the components of the objects
var createMapOpType = &operationType{Type: "CREATE_MAP", NumArgs: 2, Precedence: 15, Handler: createMapOperator}
var shortPipeOpType = &operationType{Type: "SHORT_PIPE", NumArgs: 2, Precedence: 45, Handler: pipeOperator}
var lengthOpType = &operationType{Type: "LENGTH", NumArgs: 0, Precedence: 50, Handler: lengthOperator}
var collectOpType = &operationType{Type: "COLLECT", NumArgs: 1, Precedence: 50, Handler: collectOperator}
var mapOpType = &operationType{Type: "MAP", NumArgs: 1, Precedence: 50, Handler: mapOperator}
var mapValuesOpType = &operationType{Type: "MAP_VALUES", NumArgs: 1, Precedence: 50, Handler: mapValuesOperator}
var encodeOpType = &operationType{Type: "ENCODE", NumArgs: 0, Precedence: 50, Handler: encodeOperator}
var decodeOpType = &operationType{Type: "DECODE", NumArgs: 0, Precedence: 50, Handler: decodeOperator}
var anyOpType = &operationType{Type: "ANY", NumArgs: 0, Precedence: 50, Handler: anyOperator}
var allOpType = &operationType{Type: "ALL", NumArgs: 0, Precedence: 50, Handler: allOperator}
var containsOpType = &operationType{Type: "CONTAINS", NumArgs: 1, Precedence: 50, Handler: containsOperator}
var anyConditionOpType = &operationType{Type: "ANY_CONDITION", NumArgs: 1, Precedence: 50, Handler: anyOperator}
var allConditionOpType = &operationType{Type: "ALL_CONDITION", NumArgs: 1, Precedence: 50, Handler: allOperator}
var toEntriesOpType = &operationType{Type: "TO_ENTRIES", NumArgs: 0, Precedence: 50, Handler: toEntriesOperator}
var fromEntriesOpType = &operationType{Type: "FROM_ENTRIES", NumArgs: 0, Precedence: 50, Handler: fromEntriesOperator}
var withEntriesOpType = &operationType{Type: "WITH_ENTRIES", NumArgs: 1, Precedence: 50, Handler: withEntriesOperator}
var withOpType = &operationType{Type: "WITH", NumArgs: 1, Precedence: 50, Handler: withOperator}
var splitDocumentOpType = &operationType{Type: "SPLIT_DOC", NumArgs: 0, Precedence: 50, Handler: splitDocumentOperator}
var getVariableOpType = &operationType{Type: "GET_VARIABLE", NumArgs: 0, Precedence: 55, Handler: getVariableOperator}
var getStyleOpType = &operationType{Type: "GET_STYLE", NumArgs: 0, Precedence: 50, Handler: getStyleOperator}
var getTagOpType = &operationType{Type: "GET_TAG", NumArgs: 0, Precedence: 50, Handler: getTagOperator}
var getKeyOpType = &operationType{Type: "GET_KEY", NumArgs: 0, Precedence: 50, Handler: getKeyOperator}
var getParentOpType = &operationType{Type: "GET_PARENT", NumArgs: 0, Precedence: 50, Handler: getParentOperator}
var getCommentOpType = &operationType{Type: "GET_COMMENT", NumArgs: 0, Precedence: 50, Handler: getCommentsOperator}
var getAnchorOpType = &operationType{Type: "GET_ANCHOR", NumArgs: 0, Precedence: 50, Handler: getAnchorOperator}
var getAliasOptype = &operationType{Type: "GET_ALIAS", NumArgs: 0, Precedence: 50, Handler: getAliasOperator}
var getDocumentIndexOpType = &operationType{Type: "GET_DOCUMENT_INDEX", NumArgs: 0, Precedence: 50, Handler: getDocumentIndexOperator}
var getFilenameOpType = &operationType{Type: "GET_FILENAME", NumArgs: 0, Precedence: 50, Handler: getFilenameOperator}
var getFileIndexOpType = &operationType{Type: "GET_FILE_INDEX", NumArgs: 0, Precedence: 50, Handler: getFileIndexOperator}
var getPathOpType = &operationType{Type: "GET_PATH", NumArgs: 0, Precedence: 50, Handler: getPathOperator}
var explodeOpType = &operationType{Type: "EXPLODE", NumArgs: 1, Precedence: 50, Handler: explodeOperator}
var sortByOpType = &operationType{Type: "SORT_BY", NumArgs: 1, Precedence: 50, Handler: sortByOperator}
var sortOpType = &operationType{Type: "SORT", NumArgs: 0, Precedence: 50, Handler: sortOperator}
var sortKeysOpType = &operationType{Type: "SORT_KEYS", NumArgs: 1, Precedence: 50, Handler: sortKeysOperator}
var joinStringOpType = &operationType{Type: "JOIN", NumArgs: 1, Precedence: 50, Handler: joinStringOperator}
var subStringOpType = &operationType{Type: "SUBSTR", NumArgs: 1, Precedence: 50, Handler: substituteStringOperator}
var matchOpType = &operationType{Type: "MATCH", NumArgs: 1, Precedence: 50, Handler: matchOperator}
var captureOpType = &operationType{Type: "CAPTURE", NumArgs: 1, Precedence: 50, Handler: captureOperator}
var testOpType = &operationType{Type: "TEST", NumArgs: 1, Precedence: 50, Handler: testOperator}
var splitStringOpType = &operationType{Type: "SPLIT", NumArgs: 1, Precedence: 50, Handler: splitStringOperator}
var loadOpType = &operationType{Type: "LOAD", NumArgs: 1, Precedence: 50, Handler: loadYamlOperator}
var keysOpType = &operationType{Type: "KEYS", NumArgs: 0, Precedence: 50, Handler: keysOperator}
var collectObjectOpType = &operationType{Type: "COLLECT_OBJECT", NumArgs: 0, Precedence: 50, Handler: collectObjectOperator}
var traversePathOpType = &operationType{Type: "TRAVERSE_PATH", NumArgs: 0, Precedence: 55, Handler: traversePathOperator}
var traverseArrayOpType = &operationType{Type: "TRAVERSE_ARRAY", NumArgs: 2, Precedence: 50, Handler: traverseArrayOperator}
var selfReferenceOpType = &operationType{Type: "SELF", NumArgs: 0, Precedence: 55, Handler: selfOperator}
var valueOpType = &operationType{Type: "VALUE", NumArgs: 0, Precedence: 50, Handler: valueOperator}
var envOpType = &operationType{Type: "ENV", NumArgs: 0, Precedence: 50, Handler: envOperator}
var notOpType = &operationType{Type: "NOT", NumArgs: 0, Precedence: 50, Handler: notOperator}
var emptyOpType = &operationType{Type: "EMPTY", Precedence: 50, Handler: emptyOperator}
var recursiveDescentOpType = &operationType{Type: "RECURSIVE_DESCENT", NumArgs: 0, Precedence: 50, Handler: recursiveDescentOperator}
var selectOpType = &operationType{Type: "SELECT", NumArgs: 1, Precedence: 50, Handler: selectOperator}
var hasOpType = &operationType{Type: "HAS", NumArgs: 1, Precedence: 50, Handler: hasOperator}
var uniqueOpType = &operationType{Type: "UNIQUE", NumArgs: 0, Precedence: 50, Handler: unique}
var uniqueByOpType = &operationType{Type: "UNIQUE_BY", NumArgs: 1, Precedence: 50, Handler: uniqueBy}
var groupByOpType = &operationType{Type: "GROUP_BY", NumArgs: 1, Precedence: 50, Handler: groupBy}
var flattenOpType = &operationType{Type: "FLATTEN_BY", NumArgs: 0, Precedence: 50, Handler: flattenOp}
var deleteChildOpType = &operationType{Type: "DELETE", NumArgs: 1, Precedence: 40, Handler: deleteChildOperator}
type Operation struct {
OperationType *operationType
Value interface{}
StringValue string
CandidateNode *CandidateNode // used for Value Path elements
Preferences interface{}
UpdateAssign bool // used for assign ops, when true it means we evaluate the rhs given the lhs
}
func recurseNodeArrayEqual(lhs *yaml.Node, rhs *yaml.Node) bool {
if len(lhs.Content) != len(rhs.Content) {
return false
}
for index := 0; index < len(lhs.Content); index = index + 1 {
if !recursiveNodeEqual(lhs.Content[index], rhs.Content[index]) {
return false
}
}
return true
}
func findInArray(array *yaml.Node, item *yaml.Node) int {
for index := 0; index < len(array.Content); index = index + 1 {
if recursiveNodeEqual(array.Content[index], item) {
return index
}
}
return -1
}
func recurseNodeObjectEqual(lhs *yaml.Node, rhs *yaml.Node) bool {
if len(lhs.Content) != len(rhs.Content) {
return false
}
for index := 0; index < len(lhs.Content); index = index + 2 {
key := lhs.Content[index]
value := lhs.Content[index+1]
indexInRhs := findInArray(rhs, key)
if indexInRhs == -1 || !recursiveNodeEqual(value, rhs.Content[indexInRhs+1]) {
return false
}
}
return true
}
func recursiveNodeEqual(lhs *yaml.Node, rhs *yaml.Node) bool {
if lhs.Kind != rhs.Kind || lhs.Tag != rhs.Tag {
return false
} else if lhs.Tag == "!!null" {
return true
} else if lhs.Kind == yaml.ScalarNode {
return lhs.Value == rhs.Value
} else if lhs.Kind == yaml.SequenceNode {
return recurseNodeArrayEqual(lhs, rhs)
} else if lhs.Kind == yaml.MappingNode {
return recurseNodeObjectEqual(lhs, rhs)
}
return false
}
// yaml numbers can be hex encoded...
func parseInt(numberString string) (string, int64, error) {
if strings.HasPrefix(numberString, "0x") ||
strings.HasPrefix(numberString, "0X") {
num, err := strconv.ParseInt(numberString[2:], 16, 64)
return "0x%X", num, err
}
num, err := strconv.ParseInt(numberString, 10, 64)
return "%v", num, err
}
func createScalarNode(value interface{}, stringValue string) *yaml.Node {
var node = &yaml.Node{Kind: yaml.ScalarNode}
node.Value = stringValue
switch value.(type) {
case float32, float64:
node.Tag = "!!float"
case int, int64, int32:
node.Tag = "!!int"
case bool:
node.Tag = "!!bool"
case string:
node.Tag = "!!str"
case nil:
node.Tag = "!!null"
}
return node
}
func headAndLineComment(node *yaml.Node) string {
return headComment(node) + lineComment(node)
}
func headComment(node *yaml.Node) string {
return strings.Replace(node.HeadComment, "#", "", 1)
}
func lineComment(node *yaml.Node) string {
return strings.Replace(node.LineComment, "#", "", 1)
}
func footComment(node *yaml.Node) string {
return strings.Replace(node.FootComment, "#", "", 1)
}
func createValueOperation(value interface{}, stringValue string) *Operation {
var node *yaml.Node = createScalarNode(value, stringValue)
return &Operation{
OperationType: valueOpType,
Value: value,
StringValue: stringValue,
CandidateNode: &CandidateNode{Node: node},
}
}
// debugging purposes only
func (p *Operation) toString() string {
if p == nil {
return "OP IS NIL"
}
if p.OperationType == traversePathOpType {
return fmt.Sprintf("%v", p.Value)
} else if p.OperationType == selfReferenceOpType {
return "SELF"
} else if p.OperationType == valueOpType {
return fmt.Sprintf("%v (%T)", p.Value, p.Value)
} else {
return fmt.Sprintf("%v", p.OperationType.Type)
}
}
//use for debugging only
func NodesToString(collection *list.List) string {
if !log.IsEnabledFor(logging.DEBUG) {
return ""
}
result := fmt.Sprintf("%v results\n", collection.Len())
for el := collection.Front(); el != nil; el = el.Next() {
result = result + "\n" + NodeToString(el.Value.(*CandidateNode))
}
return result
}
func NodeToString(node *CandidateNode) string {
if !log.IsEnabledFor(logging.DEBUG) {
return ""
}
value := node.Node
if value == nil {
return "-- nil --"
}
buf := new(bytes.Buffer)
encoder := yaml.NewEncoder(buf)
errorEncoding := encoder.Encode(value)
if errorEncoding != nil {
log.Error("Error debugging node, %v", errorEncoding.Error())
}
errorClosingEncoder := encoder.Close()
if errorClosingEncoder != nil {
log.Error("Error closing encoder: ", errorClosingEncoder.Error())
}
tag := value.Tag
if value.Kind == yaml.DocumentNode {
tag = "doc"
} else if value.Kind == yaml.AliasNode {
tag = "alias"
}
return fmt.Sprintf(`D%v, P%v, (%v)::%v`, node.Document, node.Path, tag, buf.String())
}
func KindString(kind yaml.Kind) string {
switch kind {
case yaml.ScalarNode:
return "ScalarNode"
case yaml.SequenceNode:
return "SequenceNode"
case yaml.MappingNode:
return "MappingNode"
case yaml.DocumentNode:
return "DocumentNode"
case yaml.AliasNode:
return "AliasNode"
default:
return "unknown!"
}
} | pkg/yqlib/lib.go | 0.50293 | 0.52902 | lib.go | starcoder |
package plan
import (
"github.com/dolthub/go-mysql-server/sql"
)
// Visitor visits nodes in the plan.
type Visitor interface {
// Visit method is invoked for each node encountered by Walk.
// If the result Visitor is not nil, Walk visits each of the children
// of the node with that visitor, followed by a call of Visit(nil)
// to the returned visitor.
Visit(node sql.Node) Visitor
}
// Walk traverses the plan tree in depth-first order. It starts by calling v.Visit(node); node must not be nil. If the
// visitor returned by v.Visit(node) is not nil, Walk is invoked recursively with the returned visitor for each
// children of the node, followed by a call of v.Visit(nil) to the returned visitor. If v.Visit(node) returns non-nil,
// then all children are walked, even if one of them returns nil for v.Visit().
func Walk(v Visitor, node sql.Node) {
if v = v.Visit(node); v == nil {
return
}
for _, child := range node.Children() {
Walk(v, child)
}
v.Visit(nil)
}
type inspector func(sql.Node) bool
func (f inspector) Visit(node sql.Node) Visitor {
if f(node) {
return f
}
return nil
}
// Inspect traverses the plan in depth-first order: It starts by calling
// f(node); node must not be nil. If f returns true, Inspect invokes f
// recursively for each of the children of node, followed by a call of
// f(nil).
func Inspect(node sql.Node, f func(sql.Node) bool) {
Walk(inspector(f), node)
}
// WalkExpressions traverses the plan and calls sql.Walk on any expression it finds.
func WalkExpressions(v sql.Visitor, node sql.Node) {
Inspect(node, func(node sql.Node) bool {
if n, ok := node.(sql.Expressioner); ok {
for _, e := range n.Expressions() {
sql.Walk(v, e)
}
}
return true
})
}
// WalkExpressionsWithNode traverses the plan and calls sql.WalkWithNode on any expression it finds.
func WalkExpressionsWithNode(v sql.NodeVisitor, n sql.Node) {
Inspect(n, func(n sql.Node) bool {
if expressioner, ok := n.(sql.Expressioner); ok {
for _, e := range expressioner.Expressions() {
sql.WalkWithNode(v, n, e)
}
}
return true
})
}
// InspectExpressions traverses the plan and calls sql.Inspect on any
// expression it finds.
func InspectExpressions(node sql.Node, f func(sql.Expression) bool) {
WalkExpressions(exprInspector(f), node)
}
type exprInspector func(sql.Expression) bool
func (f exprInspector) Visit(e sql.Expression) sql.Visitor {
if f(e) {
return f
}
return nil
}
// InspectExpressionsWithNode traverses the plan and calls sql.Inspect on any expression it finds.
func InspectExpressionsWithNode(node sql.Node, f func(sql.Node, sql.Expression) bool) {
WalkExpressionsWithNode(exprWithNodeInspector(f), node)
}
type exprWithNodeInspector func(sql.Node, sql.Expression) bool
func (f exprWithNodeInspector) Visit(n sql.Node, e sql.Expression) sql.NodeVisitor {
if f(n, e) {
return f
}
return nil
} | sql/plan/walk.go | 0.694095 | 0.532729 | walk.go | starcoder |
package shape
import (
"fmt"
"math"
"strings"
"github.com/fogleman/gg"
"github.com/golang/freetype/raster"
)
const LineMutate = 4 // 5 for line width
type Line struct {
X1, Y1 float64
X2, Y2 float64
Width float64
MaxLineWidth float64
}
func NewLine() *Line {
l := &Line{}
l.MaxLineWidth = 1.0 / 2
return l
}
func (q *Line) Init(plane *Plane) {
q.X1 = randomW(plane)
q.Y1 = randomH(plane)
q.X2 = randomW(plane)
q.Y2 = randomH(plane)
q.Width = 1.0 / 2
q.mutateImpl(plane, 1.0, 1, ActionAny)
}
func (q *Line) Draw(dc *gg.Context, scale float64) {
dc.MoveTo(q.X1, q.Y1)
dc.LineTo(q.X2, q.Y2)
dc.SetLineWidth(q.Width * scale)
dc.Stroke()
}
func (q *Line) SVG(attrs string) string {
// TODO: this is a little silly
attrs = strings.Replace(attrs, "fill", "stroke", -1)
return fmt.Sprintf(
"<path %s fill=\"none\" d=\"M %f %f L %f %f\" stroke-width=\"%f\" />",
attrs, q.X1, q.Y1, q.X2, q.Y2, q.Width)
}
func (q *Line) Copy() Shape {
a := *q
return &a
}
func (q *Line) Mutate(plane *Plane, temp float64) {
q.mutateImpl(plane, temp, 10, ActionAny)
}
func (q *Line) mutateImpl(plane *Plane, temp float64, rollback int, actions ActionType) {
if actions == ActionNone {
return
}
const R = math.Pi / 4.0
const m = 16
w := plane.W
h := plane.H
rnd := plane.Rnd
scale := 16 * temp
save := *q
for {
switch rnd.Intn(LineMutate) {
case 0: // Move
if (actions & ActionMutate) == 0 {
continue
}
a := rnd.NormFloat64() * scale
b := rnd.NormFloat64() * scale
q.X1 = clamp(q.X1+a, -m, float64(w-1+m))
q.Y1 = clamp(q.Y1+b, -m, float64(h-1+m))
case 1:
if (actions & ActionMutate) == 0 {
continue
}
a := rnd.NormFloat64() * scale
b := rnd.NormFloat64() * scale
q.X2 = clamp(q.X2+a, -m, float64(w-1+m))
q.Y2 = clamp(q.Y2+b, -m, float64(h-1+m))
case 2: // Translate
if (actions & ActionTranslate) == 0 {
continue
}
a := rnd.NormFloat64() * scale
b := rnd.NormFloat64() * scale
q.X1 = clamp(q.X1+a, -m, float64(w-1+m))
q.Y1 = clamp(q.Y1+b, -m, float64(h-1+m))
q.X2 = clamp(q.X2+a, -m, float64(w-1+m))
q.Y2 = clamp(q.Y2+b, -m, float64(h-1+m))
case 3: // Rotate
if (actions & ActionRotate) == 0 {
continue
}
cx := (q.X1 + q.X2) / 2
cy := (q.Y1 + q.Y2) / 2
theta := rnd.NormFloat64() * temp * R
cos := math.Cos(theta)
sin := math.Sin(theta)
var a, b float64
a, b = rotateAbout(q.X1, q.Y1, cx, cy, cos, sin)
q.X1 = clamp(a, -m, float64(w-1+m))
q.Y1 = clamp(b, -m, float64(h-1+m))
a, b = rotateAbout(q.X2, q.Y2, cx, cy, cos, sin)
q.X2 = clamp(a, -m, float64(w-1+m))
q.Y2 = clamp(b, -m, float64(h-1+m))
case 4: // Width
if q.Width != q.MaxLineWidth {
q.Width = clamp(q.Width+rnd.NormFloat64(), 0.1, q.MaxLineWidth)
}
}
if q.Valid() {
break
}
if rollback > 0 {
*q = save
rollback -= 1
}
}
}
func (q *Line) Valid() bool {
x1, x2 := q.X1, q.X2
if x1 > x2 {
x1, x2 = x2, x1
}
y1, y2 := q.Y1, q.Y2
if y1 > y2 {
y1, y2 = y2, y1
}
return (y2-y1) > 1 || (x2-x1) > 1
}
func (q *Line) Rasterize(rc *RasterContext) []Scanline {
var path raster.Path
p1 := fixp(q.X1, q.Y1)
p2 := fixp(q.X2, q.Y2)
path.Start(p1)
path.Add1(p2)
width := fix(q.Width)
return strokePath(rc, path, width, raster.RoundCapper, raster.RoundJoiner)
}
type RadialLine struct {
CX, CY float64
Line Line
}
func NewRadialLine(cx, cy float64) *RadialLine {
l := &RadialLine{}
l.CX = cx
l.CY = cy
l.Line.MaxLineWidth = 1.0 / 2
return l
}
func (l *RadialLine) Init(plane *Plane) {
rnd := plane.Rnd
l.Line.X1 = l.CX * float64(plane.W)
l.Line.Y1 = l.CY * float64(plane.H)
l.Line.X2 = rnd.Float64() * float64(plane.W)
l.Line.Y2 = rnd.Float64() * float64(plane.H)
l.Line.Width = 1.0 / 2
l.mutateImpl(plane, 1.0, 1, ActionAny)
}
func (l *RadialLine) Draw(dc *gg.Context, scale float64) {
l.Line.Draw(dc, scale)
}
func (l *RadialLine) SVG(attrs string) string {
return l.Line.SVG(attrs)
}
func (l *RadialLine) Copy() Shape {
a := *l
return &a
}
func (l *RadialLine) Mutate(plane *Plane, temp float64) {
l.mutateImpl(plane, temp, 10, ActionAny)
}
func (l *RadialLine) mutateImpl(plane *Plane, temp float64, rollback int, actions ActionType) {
if actions == ActionNone {
return
}
const MaxLineWidth = 4
const m = 16
w := plane.W
h := plane.H
rnd := plane.Rnd
scale := 16 * temp
save := *l
for {
switch rnd.Intn(LineMutate) {
case 0:
if (actions & ActionMutate) == 0 {
continue
}
// New radial line
l.Line.X1 = l.CX * float64(w)
l.Line.Y1 = l.CY * float64(h)
l.Line.X2 = clamp(l.Line.X2+rnd.NormFloat64()*scale, -m, float64(w-1+m))
l.Line.Y2 = clamp(l.Line.Y2+rnd.NormFloat64()*scale, -m, float64(h-1+m))
case 1:
if (actions & ActionMutate) == 0 {
continue
}
// Move along radial point
xd := l.Line.X2 - l.Line.X1
yd := l.Line.Y2 - l.Line.Y1
v := rnd.NormFloat64() * temp
l.Line.X1 = l.Line.X1 + v*xd
l.Line.Y1 = l.Line.Y1 + v*yd
case 2:
l.Line.Width = clamp(l.Line.Width+rnd.NormFloat64(), 1, MaxLineWidth)
}
if l.Valid() {
break
}
if rollback > 0 {
*l = save
rollback -= 1
}
}
}
func (l *RadialLine) Valid() bool {
return l.Line.Valid()
}
func (l *RadialLine) Rasterize(rc *RasterContext) []Scanline {
return l.Line.Rasterize(rc)
} | primitive/shape/line.go | 0.564819 | 0.424472 | line.go | starcoder |
package goglbackend
import (
"github.com/gsvigruha/canvas/backend/backendbase"
"github.com/gsvigruha/canvas/backend/goglbackend/gl"
)
// LinearGradient is a gradient with any number of
// stops and any number of colors. The gradient will
// be drawn such that each point on the gradient
// will correspond to a straight line
type LinearGradient struct {
gradient
}
// RadialGradient is a gradient with any number of
// stops and any number of colors. The gradient will
// be drawn such that each point on the gradient
// will correspond to a circle
type RadialGradient struct {
gradient
}
type gradient struct {
b *GoGLBackend
tex uint32
}
func (b *GoGLBackend) LoadLinearGradient(data backendbase.Gradient) backendbase.LinearGradient {
b.activate()
lg := &LinearGradient{
gradient: gradient{b: b},
}
gl.GenTextures(1, &lg.tex)
gl.ActiveTexture(gl.TEXTURE0)
gl.BindTexture(gl.TEXTURE_2D, lg.tex)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)
lg.load(data)
return lg
}
func (b *GoGLBackend) LoadRadialGradient(data backendbase.Gradient) backendbase.RadialGradient {
b.activate()
rg := &RadialGradient{
gradient: gradient{b: b},
}
gl.GenTextures(1, &rg.tex)
gl.ActiveTexture(gl.TEXTURE0)
gl.BindTexture(gl.TEXTURE_2D, rg.tex)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)
rg.load(data)
return rg
}
// Delete explicitly deletes the gradient
func (g *gradient) Delete() {
g.b.activate()
gl.DeleteTextures(1, &g.tex)
}
func (lg *LinearGradient) Replace(data backendbase.Gradient) { lg.load(data) }
func (rg *RadialGradient) Replace(data backendbase.Gradient) { rg.load(data) }
func (g *gradient) load(stops backendbase.Gradient) {
g.b.activate()
gl.ActiveTexture(gl.TEXTURE0)
gl.BindTexture(gl.TEXTURE_2D, g.tex)
var pixels [2048 * 4]byte
pp := 0
for i := 0; i < 2048; i++ {
c := stops.ColorAt(float64(i) / 2047)
pixels[pp] = c.R
pixels[pp+1] = c.G
pixels[pp+2] = c.B
pixels[pp+3] = c.A
pp += 4
}
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 2048, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, gl.Ptr(&pixels[0]))
} | backend/goglbackend/gradients.go | 0.761716 | 0.421492 | gradients.go | starcoder |
package knapsack
import (
"crypto/rand"
"crypto/sha256"
"errors"
"math/big"
)
// Knapsack contains the private data used to generate the public key and decrypt messages
type Knapsack struct {
PublicKey []*big.Int
PrivateKey []*big.Int
M *big.Int // modulus
W *big.Int // random mutating constant
WI *big.Int // inverse of w
}
// NewKnapsack auto generates private knapsack params
func NewKnapsack(keyLength int64) (*Knapsack, error) {
if keyLength < 1 {
return nil, errors.New("key length must be > 0")
}
// start by generating a random superincreasing sequence
one := big.NewInt(1)
privateKey, err := randomSuperincreasingSequence(keyLength)
if err != nil {
return nil, err
}
// the modulus should be in [ 2^(length * 2 + 1) + 1, 2^(length * 2 + 2) - 1 ]
min := new(big.Int).Exp(big.NewInt(2), big.NewInt(keyLength*2+1), nil) // 2^(length * 2 + 1)
max := new(big.Int).Exp(big.NewInt(2), big.NewInt(keyLength*2+2), nil) // 2^(length * 2 + 2)
min.Add(min, one) // 2^(length * 2 + 1) + 1
max.Sub(max, one) // 2^(length * 2 + 2) - 1
m, err := randomUniform(min, max)
if err != nil {
return nil, err
}
// w' should be in [ 2, m - 2 ]
min.SetInt64(2)
max = new(big.Int).Sub(m, min)
// goal of this loop: get a good `w` that has an inverse mod m
var w, wi *big.Int
for w == nil || wi == nil {
wPrime, err := randomUniform(min, max)
if err != nil {
return nil, err
}
// w = wPrime/gcd(wPrime, m); wi = inverse of w
w = new(big.Int).Div(wPrime, new(big.Int).GCD(nil, nil, wPrime, m))
wi = new(big.Int).ModInverse(w, m)
}
// calculate public key (for now, not doing index mangling)
publicKey := make([]*big.Int, len(privateKey))
for idx, n := range privateKey {
nw := new(big.Int).Mul(n, w)
publicKey[idx] = nw.Mod(nw, m)
}
return &Knapsack{
PublicKey: publicKey,
PrivateKey: privateKey,
M: m,
W: w,
WI: wi,
}, nil
}
// GetKeyID returns first 10 bytes of sha256(key)
func GetKeyID(key []*big.Int) []byte {
h := sha256.New()
for _, n := range key {
h.Write(n.Bytes())
}
return h.Sum(nil)[:10]
}
// EncryptString encrypts `message` using `publicKey`.
func EncryptString(publicKey []*big.Int, message string) ([]byte, error) {
return EncryptBytes(publicKey, []byte(message))
}
// EncryptBytes encrypts `messageBytes` using `publicKey`.
func EncryptBytes(publicKey []*big.Int, messageBytes []byte) ([]byte, error) {
ct, err := encrypt(publicKey, bytesToBits(messageBytes))
if err != nil {
return nil, err
}
return ct.Bytes(), nil
}
func encrypt(publicKey []*big.Int, messageBits []byte) (*big.Int, error) {
if len(publicKey) < len(messageBits) {
return nil, errors.New("public key must be longer than messageBits")
}
ct := big.NewInt(0)
for idx, bit := range messageBits {
if bit == 1 {
ct.Add(ct, publicKey[idx])
}
}
return ct, nil
}
// Decrypt uses the private key to solve the knapsack problem and returns
// the message reconstructed into bytes from the slice of bits.
func (k *Knapsack) Decrypt(ct *big.Int) []byte {
// undo the mutation of `w`
c := new(big.Int).Mul(ct, k.WI)
c.Mod(c, k.M)
// solve the knapsack problem with weights=privateKey, target=c
msg := solveKnapsack(k.PrivateKey, c)
return bitsToBytes(msg)
}
// DecryptBytes constructs the ciphertext int from the bytes
// and uses the private key to solve the knapsack problem.
// The message is reconstructed into bytes from the slice of bits.
func (k *Knapsack) DecryptBytes(ct []byte) []byte {
return k.Decrypt(new(big.Int).SetBytes(ct))
}
// returns a slice of [x0, x1, ..] where xi is 0 or 1.
// the slice itself is the bits of the binary representation of the bytes
// of the string -- not the runes.
func stringToBits(s string) []byte {
return bytesToBits([]byte(s))
}
func bytesToBits(bs []byte) []byte {
bitLen := 8 * len(bs)
bitsOfBytes := make([]byte, bitLen)
for i, b := range bs {
bitIdx := 0
for b > 0 {
bitsOfBytes[(i*8)+bitIdx] = ((b & 0x80) >> 7) & 1 // just the top bit of the byte
b <<= 1
bitIdx++
}
}
return bitsOfBytes
}
func bitsToBytes(bs []byte) []byte {
byteLen := len(bs) / 8
bytesOfBits := make([]byte, byteLen)
var currentByte byte
for i, b := range bs {
currentByte |= b
if i%8 == 7 {
bytesOfBits[i/8] = currentByte
currentByte = 0
} else {
currentByte <<= 1
}
}
return bytesOfBits
}
// returns the mask (e.g. [0, 1, 1, 0]) of the weights to choose to reach target
// this function assumes:
// a) the private key is a superincreasing sequence
// b) a solution exists (at least for now...may add failure cases later)
func solveKnapsack(weights []*big.Int, s *big.Int) []byte {
zero := big.NewInt(0)
solution := make([]byte, len(weights))
solutionIdx := len(weights) - 1
var solve func([]*big.Int, *big.Int, *big.Int)
solve = func(remainingWeights []*big.Int, sumOfRemainingWeights *big.Int, target *big.Int) {
if len(remainingWeights) == 0 || target.Cmp(zero) == 0 {
return
}
last := remainingWeights[len(remainingWeights)-1]
weightsWithoutLast := remainingWeights[:len(remainingWeights)-1]
sumWithoutLast := new(big.Int).Sub(sumOfRemainingWeights, last)
if target.Cmp(sumWithoutLast) > 0 {
solution[solutionIdx] = 1
solutionIdx--
solve(weightsWithoutLast, sumWithoutLast, target.Sub(target, last))
} else {
solution[solutionIdx] = 0
solutionIdx--
solve(weightsWithoutLast, sumWithoutLast, target)
}
}
solve(weights, sum(weights), s)
return solution
}
// reduces the array with summation fn
func sum(arr []*big.Int) *big.Int {
sum := new(big.Int)
for _, n := range arr {
sum.Add(sum, n)
}
return sum
}
func randomUniform(min, max *big.Int) (*big.Int, error) {
n, err := rand.Int(rand.Reader, new(big.Int).Sub(max, min))
if err != nil {
return nil, err
}
return n.Add(n, min), nil
}
func randomSuperincreasingSequence(length int64) ([]*big.Int, error) {
// choose random numbers in the range:
// [ (2^(i-1) - 1) * 2^length + 1, 2^(i-1) * 2^length ]
// the above assumes 1-indexed arrays; our arrays are 0-indexed,
// so s/i-1/i/. rand.Int is exclusive, so we need add 1 to the max:
// [ (2^i - 1) * 2^length + 1, 2^i * 2^length + 1 ]
one := big.NewInt(1)
twoLen := new(big.Int).Exp(big.NewInt(2), big.NewInt(length), nil) // 2^length
multiplier := new(big.Int).Add(twoLen, one) // 2^length + 1
out := make([]*big.Int, length)
for i := range out {
max := new(big.Int).Exp(big.NewInt(2), big.NewInt(int64(i)), nil) // 2^i
min := new(big.Int).Sub(max, one) // 2^i - 1
min.Mul(min, multiplier) // 2^i - 1 * 2^length
max.Mul(max, multiplier) // 2^i * 2^length
n, err := randomUniform(min, max)
if err != nil {
return nil, err
}
out[i] = n
}
return out, nil
} | crypto.go | 0.762513 | 0.420719 | crypto.go | starcoder |
package types
// Reference: https://www.ietf.org/rfc/rfc4120.txt
// Section: 5.2.7
import (
"fmt"
"time"
"github.com/jcmturner/gofork/encoding/asn1"
"github.com/wangzhengzh/gokrb5/v8/iana/patype"
)
// PAData implements RFC 4120 types: https://tools.ietf.org/html/rfc4120#section-5.2.7
type PAData struct {
PADataType int32 `asn1:"explicit,tag:1"`
PADataValue []byte `asn1:"explicit,tag:2"`
}
// PADataSequence implements RFC 4120 types: https://tools.ietf.org/html/rfc4120#section-5.2.7
type PADataSequence []PAData
// MethodData implements RFC 4120 types: https://tools.ietf.org/html/rfc4120#section-5.9.1
type MethodData []PAData
// PAEncTimestamp implements RFC 4120 types: https://tools.ietf.org/html/rfc4120#section-5.2.7.2
type PAEncTimestamp EncryptedData
// PAEncTSEnc implements RFC 4120 types: https://tools.ietf.org/html/rfc4120#section-5.2.7.2
type PAEncTSEnc struct {
PATimestamp time.Time `asn1:"generalized,explicit,tag:0"`
PAUSec int `asn1:"explicit,optional,tag:1"`
}
// Contains tests if a PADataSequence contains PA Data of a certain type.
func (pas *PADataSequence) Contains(patype int32) bool {
for _, pa := range *pas {
if pa.PADataType == patype {
return true
}
}
return false
}
// GetPAEncTSEncAsnMarshalled returns the bytes of a PAEncTSEnc.
func GetPAEncTSEncAsnMarshalled() ([]byte, error) {
t := time.Now().UTC()
p := PAEncTSEnc{
PATimestamp: t,
PAUSec: int((t.UnixNano() / int64(time.Microsecond)) - (t.Unix() * 1e6)),
}
b, err := asn1.Marshal(p)
if err != nil {
return b, fmt.Errorf("error mashaling PAEncTSEnc: %v", err)
}
return b, nil
}
// ETypeInfoEntry implements RFC 4120 types: https://tools.ietf.org/html/rfc4120#section-5.2.7.4
type ETypeInfoEntry struct {
EType int32 `asn1:"explicit,tag:0"`
Salt []byte `asn1:"explicit,optional,tag:1"`
}
// ETypeInfo implements RFC 4120 types: https://tools.ietf.org/html/rfc4120#section-5.2.7.4
type ETypeInfo []ETypeInfoEntry
// ETypeInfo2Entry implements RFC 4120 types: https://tools.ietf.org/html/rfc4120#section-5.2.7.5
type ETypeInfo2Entry struct {
EType int32 `asn1:"explicit,tag:0"`
Salt string `asn1:"explicit,optional,generalstring,tag:1"`
S2KParams []byte `asn1:"explicit,optional,tag:2"`
}
// ETypeInfo2 implements RFC 4120 types: https://tools.ietf.org/html/rfc4120#section-5.2.7.5
type ETypeInfo2 []ETypeInfo2Entry
// PAReqEncPARep PA Data Type
type PAReqEncPARep struct {
ChksumType int32 `asn1:"explicit,tag:0"`
Chksum []byte `asn1:"explicit,tag:1"`
}
// Unmarshal bytes into the PAData
func (pa *PAData) Unmarshal(b []byte) error {
_, err := asn1.Unmarshal(b, pa)
return err
}
// Unmarshal bytes into the PADataSequence
func (pas *PADataSequence) Unmarshal(b []byte) error {
_, err := asn1.Unmarshal(b, pas)
return err
}
// Unmarshal bytes into the PAReqEncPARep
func (pa *PAReqEncPARep) Unmarshal(b []byte) error {
_, err := asn1.Unmarshal(b, pa)
return err
}
// Unmarshal bytes into the PAEncTimestamp
func (pa *PAEncTimestamp) Unmarshal(b []byte) error {
_, err := asn1.Unmarshal(b, pa)
return err
}
// Unmarshal bytes into the PAEncTSEnc
func (pa *PAEncTSEnc) Unmarshal(b []byte) error {
_, err := asn1.Unmarshal(b, pa)
return err
}
// Unmarshal bytes into the ETypeInfo
func (a *ETypeInfo) Unmarshal(b []byte) error {
_, err := asn1.Unmarshal(b, a)
return err
}
// Unmarshal bytes into the ETypeInfoEntry
func (a *ETypeInfoEntry) Unmarshal(b []byte) error {
_, err := asn1.Unmarshal(b, a)
return err
}
// Unmarshal bytes into the ETypeInfo2
func (a *ETypeInfo2) Unmarshal(b []byte) error {
_, err := asn1.Unmarshal(b, a)
return err
}
// Unmarshal bytes into the ETypeInfo2Entry
func (a *ETypeInfo2Entry) Unmarshal(b []byte) error {
_, err := asn1.Unmarshal(b, a)
return err
}
// GetETypeInfo returns an ETypeInfo from the PAData.
func (pa *PAData) GetETypeInfo() (d ETypeInfo, err error) {
if pa.PADataType != patype.PA_ETYPE_INFO {
err = fmt.Errorf("PAData does not contain PA EType Info data. TypeID Expected: %v; Actual: %v", patype.PA_ETYPE_INFO, pa.PADataType)
return
}
_, err = asn1.Unmarshal(pa.PADataValue, &d)
return
}
// GetETypeInfo2 returns an ETypeInfo2 from the PAData.
func (pa *PAData) GetETypeInfo2() (d ETypeInfo2, err error) {
if pa.PADataType != patype.PA_ETYPE_INFO2 {
err = fmt.Errorf("PAData does not contain PA EType Info 2 data. TypeID Expected: %v; Actual: %v", patype.PA_ETYPE_INFO2, pa.PADataType)
return
}
_, err = asn1.Unmarshal(pa.PADataValue, &d)
return
} | v8/types/PAData.go | 0.774583 | 0.437103 | PAData.go | starcoder |
package graphic
import (
"github.com/lquesada/cavernal/lib/g3n/engine/core"
"github.com/lquesada/cavernal/lib/g3n/engine/geometry"
"github.com/lquesada/cavernal/lib/g3n/engine/gls"
"github.com/lquesada/cavernal/lib/g3n/engine/material"
"github.com/lquesada/cavernal/lib/g3n/engine/math32"
)
// Sprite is a potentially animated image positioned in space that always faces the camera.
type Sprite struct {
Graphic // Embedded graphic
uniMVPM gls.Uniform // Model view projection matrix uniform location cache
}
// NewSprite creates and returns a pointer to a sprite with the specified dimensions and material
func NewSprite(width, height float32, imat material.IMaterial) *Sprite {
s := new(Sprite)
// Creates geometry
geom := geometry.NewGeometry()
w := width / 2
h := height / 2
// Builds array with vertex positions and texture coordinates
positions := math32.NewArrayF32(0, 12)
positions.Append(
-w, -h, 0, 0, 0,
w, -h, 0, 1, 0,
w, h, 0, 1, 1,
-w, h, 0, 0, 1,
)
// Builds array of indices
indices := math32.NewArrayU32(0, 6)
indices.Append(0, 1, 2, 0, 2, 3)
// Set geometry buffers
geom.SetIndices(indices)
geom.AddVBO(
gls.NewVBO(positions).
AddAttrib(gls.VertexPosition).
AddAttrib(gls.VertexTexcoord),
)
s.Graphic.Init(geom, gls.TRIANGLES)
s.AddMaterial(s, imat, 0, 0)
s.uniMVPM.Init("MVP")
return s
}
// RenderSetup sets up the rendering of the sprite.
func (s *Sprite) RenderSetup(gs *gls.GLS, rinfo *core.RenderInfo) {
// Calculates model view matrix
mw := s.MatrixWorld()
var mvm math32.Matrix4
mvm.MultiplyMatrices(&rinfo.ViewMatrix, &mw)
// Decomposes model view matrix
var position math32.Vector3
var quaternion math32.Quaternion
var scale math32.Vector3
mvm.Decompose(&position, &quaternion, &scale)
// Removes any rotation in X and Y axes and compose new model view matrix
rotation := s.Rotation()
rotation.X = 0
rotation.Y = 0
quaternion.SetFromEuler(&rotation)
var mvmNew math32.Matrix4
mvmNew.Compose(&position, &quaternion, &scale)
// Calculates final MVP and updates uniform
var mvpm math32.Matrix4
mvpm.MultiplyMatrices(&rinfo.ProjMatrix, &mvmNew)
location := s.uniMVPM.Location(gs)
gs.UniformMatrix4fv(location, 1, false, &mvpm[0])
}
// Raycast checks intersections between this geometry and the specified raycaster
// and if any found appends it to the specified intersects array.
func (s *Sprite) Raycast(rc *core.Raycaster, intersects *[]core.Intersect) {
// Copy and convert ray to camera coordinates
var ray math32.Ray
ray.Copy(&rc.Ray).ApplyMatrix4(&rc.ViewMatrix)
// Calculates ViewMatrix * MatrixWorld
var mv math32.Matrix4
matrixWorld := s.MatrixWorld()
mv.MultiplyMatrices(&rc.ViewMatrix, &matrixWorld)
// Decompose transformation matrix in its components
var position math32.Vector3
var quaternion math32.Quaternion
var scale math32.Vector3
mv.Decompose(&position, &quaternion, &scale)
// Remove any rotation in X and Y axis and
// compose new transformation matrix
rotation := s.Rotation()
rotation.X = 0
rotation.Y = 0
quaternion.SetFromEuler(&rotation)
mv.Compose(&position, &quaternion, &scale)
// Get buffer with vertices and uvs
geom := s.GetGeometry()
vboPos := geom.VBO(gls.VertexPosition)
if vboPos == nil {
panic("sprite.Raycast(): VertexPosition VBO not found")
}
// Get vertex positions, transform to camera coordinates and
// checks intersection with ray
buffer := vboPos.Buffer()
indices := geom.Indices()
var v1 math32.Vector3
var v2 math32.Vector3
var v3 math32.Vector3
var point math32.Vector3
intersect := false
for i := 0; i < indices.Size(); i += 3 {
pos := indices[i]
buffer.GetVector3(int(pos*5), &v1)
v1.ApplyMatrix4(&mv)
pos = indices[i+1]
buffer.GetVector3(int(pos*5), &v2)
v2.ApplyMatrix4(&mv)
pos = indices[i+2]
buffer.GetVector3(int(pos*5), &v3)
v3.ApplyMatrix4(&mv)
if ray.IntersectTriangle(&v1, &v2, &v3, false, &point) {
intersect = true
break
}
}
if !intersect {
return
}
// Get distance from intersection point
origin := ray.Origin()
distance := origin.DistanceTo(&point)
// Checks if distance is between the bounds of the raycaster
if distance < rc.Near || distance > rc.Far {
return
}
// Appends intersection to received parameter.
*intersects = append(*intersects, core.Intersect{
Distance: distance,
Point: point,
Object: s,
})
} | lib/g3n/engine/graphic/sprite.go | 0.774157 | 0.506103 | sprite.go | starcoder |
package gohome
type RenderType uint16
// The different render types.
// Determines which projection, back buffer, camera etc. will be used for the RenderObject
const (
TYPE_3D_NORMAL RenderType = (1 << 1)
TYPE_2D_NORMAL RenderType = (1 << 2)
TYPE_3D_INSTANCED RenderType = (1 << 3)
TYPE_2D_INSTANCED RenderType = (1 << 4)
TYPE_CASTS_SHADOWS RenderType = (1 << 5)
TYPE_2D RenderType = TYPE_2D_NORMAL | TYPE_2D_INSTANCED
TYPE_3D RenderType = TYPE_3D_NORMAL | TYPE_3D_INSTANCED
TYPE_EVERYTHING RenderType = (1 << 16) - 1
)
// Returns if a RenderType can be drawn using a render type
func (this RenderType) Compatible(rtype RenderType) bool {
if this == TYPE_2D || this == TYPE_3D || this == TYPE_EVERYTHING {
return (this & rtype) != 0
} else {
return (this & rtype) == this
}
}
// An interface used for handling the transformation matrices
type TransformableObject interface {
// Calculates the transformation matrix
CalculateTransformMatrix(rmgr *RenderManager, notRelativeToCamera int)
// Sets the current transformation matrix
SetTransformMatrix(rmgr *RenderManager)
}
// An object that can be rendered
type RenderObject interface {
// Calls the draw method of the data in the GPU
Render()
// Sets the shader used for rendering
SetShader(s Shader)
// Returns the shader used for rendering
GetShader() Shader
// Set the render type of the object
SetType(rtype RenderType)
// Returns the render type of the object
GetType() RenderType
// Returns wether this object should be rendered
IsVisible() bool
// Returns to which camera this object is not relative to
NotRelativeCamera() int
// Sets the transformable object of the RenderObject
SetTransformableObject(tobj TransformableObject)
// Returns the transformable object of the RenderObject
GetTransformableObject() TransformableObject
// Returns wether this object will be rendered after everything else
RendersLast() bool
// Returns wether depth testing is enabled for this object
HasDepthTesting() bool
}
// An implementation of RenderObject that does nothing
type NilRenderObject struct {
}
func (*NilRenderObject) Render() {
}
func (*NilRenderObject) SetShader(s Shader) {
}
func (*NilRenderObject) GetShader() Shader {
return nil
}
func (*NilRenderObject) SetType(rtype RenderType) {
}
func (*NilRenderObject) GetType() RenderType {
return TYPE_EVERYTHING
}
func (*NilRenderObject) IsVisible() bool {
return true
}
func (*NilRenderObject) NotRelativeCamera() int {
return -1
}
func (*NilRenderObject) SetTransformableObject(tobj TransformableObject) {
}
func (*NilRenderObject) GetTransformableObject() TransformableObject {
return nil
}
func (*NilRenderObject) RendersLast() bool {
return false
}
func (*NilRenderObject) HasDepthTesting() bool {
return true
} | src/gohome/renderobject.go | 0.75985 | 0.425784 | renderobject.go | starcoder |
// Design your implementation of the linked list. You can choose to use the singly linked list or the doubly linked list. A node in a singly linked list should have two attributes: val and next. val is the value of the current node, and next is a pointer/reference to the next node. If you want to use the doubly linked list, you will need one more attribute prev to indicate the previous node in the linked list. Assume all nodes in the linked list are 0-indexed.
// Implement these functions in your linked list class:
// - get(index) : Get the value of the index-th node in the linked list. If the index is invalid, return -1.
// - addAtHead(val) : Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list.
// - addAtTail(val) : Append a node of value val to the last element of the linked list.
// - addAtIndex(index, val) : Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted.
// - deleteAtIndex(index) : Delete the index-th node in the linked list, if the index is valid.
// Example:
// MyLinkedList linkedList = new MyLinkedList();
// linkedList.addAtHead(1);
// linkedList.addAtTail(3);
// linkedList.addAtIndex(1, 2); // linked list becomes 1->2->3
// linkedList.get(1); // returns 2
// linkedList.deleteAtIndex(1); // now the linked list is 1->3
// linkedList.get(1); // returns 3
// Note:
// - All values will be in the range of [1, 1000].
// - The number of operations will be in the range of [1, 1000].
// - Please do not use the built-in LinkedList library.
package leetcode
type listNode struct {
val int
next *listNode
}
// MyLinkedList is my implementation of the linked list.
type MyLinkedList struct {
head *listNode
tail *listNode
length int
}
// Constructor initialize your data structure here.
func Constructor() MyLinkedList {
return MyLinkedList{}
}
// Get get the value of the index-th node in the linked list. If the index is invalid, return -1.
func (l *MyLinkedList) Get(index int) int {
if index < 0 || index >= l.length {
return -1
}
if index == l.length-1 {
return l.tail.val
}
node := l.head
for i := 0; i < index; i++ {
node = node.next
}
return node.val
}
// AddAtHead add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list.
func (l *MyLinkedList) AddAtHead(val int) {
head := &listNode{val: val}
head.next = l.head
l.head = head
if l.tail == nil {
l.tail = head
}
l.length++
}
// AddAtTail append a node of value val to the last element of the linked list.
func (l *MyLinkedList) AddAtTail(val int) {
tail := &listNode{val: val}
if l.tail != nil {
l.tail.next = tail
} else {
l.head = tail
}
l.tail = tail
l.length++
}
// AddAtIndex add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted.
func (l *MyLinkedList) AddAtIndex(index int, val int) {
if index == 0 {
l.AddAtHead(val)
return
}
if index == l.length {
l.AddAtTail(val)
return
}
if index < 0 || index > l.length {
return
}
var prev, node *listNode
node = l.head
for i := 0; i < index; i++ {
prev = node
node = node.next
}
prev.next = &listNode{val: val, next: node}
l.length++
}
// DeleteAtIndex delete the index-th node in the linked list, if the index is valid.
func (l *MyLinkedList) DeleteAtIndex(index int) {
if index < 0 || index >= l.length {
return
}
var prev, node *listNode
node = l.head
for i := 0; i < index; i++ {
prev = node
node = node.next
}
if prev != nil {
prev.next = node.next
} else {
l.head = node.next
}
if node.next != nil {
node.next = nil
} else {
l.tail = prev
}
l.length--
} | 0707/code.go | 0.697609 | 0.618032 | code.go | starcoder |
package filter
import "github.com/nerdynick/ccloud-go-sdk/telemetry/labels"
const (
//OpAnd is a static def for AND Operand
OpAnd string = "AND"
//OpOr is a static def for OR Operand
OpOr string = "OR"
)
// CompoundFilter to use for a query
type CompoundFilter struct {
Op string `json:"op"`
Filters []Filter `json:"filters"`
}
func (fil CompoundFilter) Not() UnaryFilter {
return Not(fil)
}
func (fil CompoundFilter) Add(filters ...Filter) CompoundFilter {
fil.Filters = append(fil.Filters, filters...)
return fil
}
func (fil CompoundFilter) And(filters ...Filter) CompoundFilter {
if fil.Op == OpAnd {
return fil.Add(filters...)
} else {
return And(fil).Add(filters...)
}
}
func (fil CompoundFilter) AndEqualTo(field labels.Label, value string) CompoundFilter {
return fil.And(EqualTo(field, value))
}
func (fil CompoundFilter) AndNotEqualTo(field labels.Label, value string) CompoundFilter {
return fil.And(NotEqualTo(field, value))
}
func (fil CompoundFilter) AndGreaterThan(field labels.Label, value string) CompoundFilter {
return fil.And(GreaterThan(field, value))
}
func (fil CompoundFilter) AndNotGreaterThan(field labels.Label, value string) CompoundFilter {
return fil.And(NotGreaterThan(field, value))
}
func (fil CompoundFilter) AndGreaterThanOrEqualTo(field labels.Label, value string) CompoundFilter {
return fil.And(GreaterThanOrEqualTo(field, value))
}
func (fil CompoundFilter) AndNotGreaterThanOrEqualTo(field labels.Label, value string) CompoundFilter {
return fil.And(NotGreaterThanOrEqualTo(field, value))
}
func (fil CompoundFilter) Or(filters ...Filter) CompoundFilter {
if fil.Op == OpOr {
return fil.Add(filters...)
} else {
return Or(fil).Add(filters...)
}
}
func (fil CompoundFilter) OrEqualTo(field labels.Label, value string) CompoundFilter {
return fil.Or(EqualTo(field, value))
}
func (fil CompoundFilter) OrNotEqualTo(field labels.Label, value string) CompoundFilter {
return fil.Or(NotEqualTo(field, value))
}
func (fil CompoundFilter) OrGreaterThan(field labels.Label, value string) CompoundFilter {
return fil.Or(GreaterThan(field, value))
}
func (fil CompoundFilter) OrNotGreaterThan(field labels.Label, value string) CompoundFilter {
return fil.Or(NotGreaterThan(field, value))
}
func (fil CompoundFilter) OrGreaterThanOrEqualTo(field labels.Label, value string) CompoundFilter {
return fil.Or(GreaterThanOrEqualTo(field, value))
}
func (fil CompoundFilter) OrNotGreaterThanOrEqualTo(field labels.Label, value string) CompoundFilter {
return fil.Or(NotGreaterThanOrEqualTo(field, value))
} | telemetry/query/filter/compound.go | 0.790166 | 0.451931 | compound.go | starcoder |
package main
import (
"fmt"
. "github.com/jakecoffman/cp"
"github.com/jakecoffman/cp/examples"
)
var scaleStaticBody, ballBody *Body
func main() {
space := NewSpace()
space.Iterations = 30
space.SetGravity(Vector{0, -300})
space.SetCollisionSlop(0.5)
space.SleepTimeThreshold = 1
var body *Body
var shape *Shape
walls := []Vector{
{-320, -240}, {-320, 240},
{320, -240}, {320, 240},
{-320, -240}, {320, -240},
}
for i := 0; i < len(walls)-1; i += 2 {
shape = space.AddShape(NewSegment(space.StaticBody, walls[i], walls[i+1], 0))
shape.SetElasticity(1)
shape.SetFriction(1)
shape.SetFilter(examples.NotGrabbableFilter)
}
scaleStaticBody = NewStaticBody()
shape = space.AddShape(NewSegment(scaleStaticBody, Vector{-240, -180}, Vector{-140, -180}, 4))
shape.SetElasticity(1)
shape.SetFriction(1)
shape.SetFilter(examples.NotGrabbableFilter)
for i := 0; i < 5; i++ {
body = space.AddBody(NewBody(1, MomentForBox(1, 30, 30)))
body.SetPosition(Vector{0, float64(i*32 - 220)})
shape = space.AddShape(NewBox(body, 30, 30, 0))
shape.SetElasticity(0)
shape.SetFriction(0.8)
}
radius := 15.0
ballBody = space.AddBody(NewBody(10, MomentForCircle(10, 0, radius, Vector{})))
ballBody.SetPosition(Vector{120, -240 + radius + 5})
shape = space.AddShape(NewCircle(ballBody, radius, Vector{}))
shape.SetElasticity(0)
shape.SetFriction(0.9)
examples.Main(space, 1.0/60.0, update, examples.DefaultDraw)
}
func update(space *Space, dt float64) {
space.Step(dt)
// Sum the total impulse applied to the scale from all collision pairs in the contact graph.
var impulseSum Vector
scaleStaticBody.EachArbiter(func(arbiter *Arbiter) {
impulseSum = impulseSum.Add(arbiter.TotalImpulse())
})
// Force is the impulse divided by the timestep.
force := impulseSum.Length() / dt
// Weight can be found similarly from the gravity vector.
g := space.Gravity()
weight := g.Dot(impulseSum) / (g.LengthSq() * dt)
// Highlight and count the number of shapes the ball is touching.
var count int
ballBody.EachArbiter(func(arb *Arbiter) {
_, other := arb.Shapes()
examples.DrawBB(other.BB(), FColor{1, 0, 0, 1})
count++
})
var magnitudeSum float64
var vectorSum Vector
ballBody.EachArbiter(func(arb *Arbiter) {
j := arb.TotalImpulse()
magnitudeSum += j.Length()
vectorSum = vectorSum.Add(j)
})
crushForce := (magnitudeSum - vectorSum.Length()) * dt
var crush string
if crushForce > 10 {
crush = "The ball is being crushed. (f: %.2f)"
} else {
crush = "The ball is not being crushed. (f %.2f)"
}
str := `Place objects on the scale to weigh them. The ball marks the shapes it's sitting on.
Total force: %5.2f, Total weight: %5.2f. The ball is touching %d shapes
` + crush
examples.DrawString(Vector{-300, -200}, fmt.Sprintf(str, force, weight, count, crushForce))
} | examples/contactgraph/contactgraph.go | 0.70069 | 0.519704 | contactgraph.go | starcoder |
package utm
import (
"fmt"
"strconv"
"unicode"
)
// Zone specifies the zone number and hemisphere
type Zone struct {
Number int // Zone number 1 to 60
Letter rune // Zone letter C to X (omitting O, I)
North bool // Zone hemisphere
}
// String returns a text representation of the zone
func (z Zone) String() string {
if z.Letter == 0 {
z.Letter = '?'
}
if z.North {
return fmt.Sprintf("%d%c (north)", z.Number, z.Letter)
}
return fmt.Sprintf("%d%c (south)", z.Number, z.Letter)
}
// Valid checks if the zone is valid
func (z Zone) Valid() bool {
switch z.Letter {
case 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X':
if !z.North {
return false
}
case 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M':
if z.North {
return false
}
case 0:
default:
return false
}
return 1 <= z.Number && z.Number <= 60
}
// SRID returns the zone EPSG/SRID code
func (z Zone) SRID() int {
if z.North {
return z.Number + 32600
}
return z.Number + 32700
}
// LookupSRID returns a Zone by its EPSG/SRID code.
// Since the srid code only specifies the longitude zone
// number, the zone letter is left unset.
func LookupSRID(srid int) (Zone, bool) {
if 32601 <= srid && srid <= 32660 {
return Zone{
Number: srid - 32600,
North: true,
}, true
}
if 32701 <= srid && srid <= 32760 {
return Zone{
Number: srid - 32700,
}, true
}
return Zone{}, false
}
// CentralMeridian returns the zone's center longitude
func (z Zone) CentralMeridian() float64 {
return float64((z.Number-1)*6 - 180 + 3)
}
// LatLonZone returns the Zone for the provided coordinates
func LatLonZone(latitude, longitude float64) Zone {
const letters = "CDEFGHJKLMNPQRSTUVWXX"
var letter rune
if -80 <= latitude && latitude <= 84 {
letter = rune(letters[int(latitude+80)>>3])
}
north := latitude >= 0
if 56 <= latitude && latitude <= 64 && 3 <= longitude && longitude <= 12 {
return Zone{Number: 32, Letter: letter, North: north}
}
if 72 <= latitude && latitude <= 84 && longitude >= 0 {
if longitude <= 9 {
return Zone{Number: 31, Letter: letter, North: north}
} else if longitude <= 21 {
return Zone{Number: 33, Letter: letter, North: north}
} else if longitude <= 33 {
return Zone{Number: 35, Letter: letter, North: north}
} else if longitude <= 42 {
return Zone{Number: 37, Letter: letter, North: north}
}
}
return Zone{
Number: int((longitude+180)/6) + 1,
Letter: letter,
North: north,
}
}
// ParseZone parses a zone number followed by a zone letter
func ParseZone(s string) (Zone, bool) {
if len(s) < 2 {
return Zone{}, false
}
last := len(s) - 1
n, err := strconv.Atoi(s[:last])
if err != nil || n < 1 || n > 60 {
return Zone{}, false
}
var north bool
switch unicode.ToUpper(rune(s[last])) {
case 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X':
north = true
case 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M':
default:
return Zone{}, false
}
return Zone{Number: n, Letter: rune(s[last]), North: north}, true
} | zone.go | 0.782372 | 0.415551 | zone.go | starcoder |
package output
import (
"github.com/Jeffail/benthos/v3/lib/log"
"github.com/Jeffail/benthos/v3/lib/metrics"
"github.com/Jeffail/benthos/v3/lib/output/writer"
"github.com/Jeffail/benthos/v3/lib/types"
"github.com/Jeffail/benthos/v3/lib/x/docs"
)
//------------------------------------------------------------------------------
func init() {
Constructors[TypeRedisHash] = TypeSpec{
constructor: NewRedisHash,
Summary: `
Sets Redis hash objects using the HMSET command.`,
Description: `
The field ` + "`key`" + ` supports
[interpolation functions](/docs/configuration/interpolation#bloblang-queries), allowing
you to create a unique key for each message.
The field ` + "`fields`" + ` allows you to specify an explicit map of field
names to interpolated values, also evaluated per message of a batch:
` + "```yaml" + `
redis_hash:
url: tcp://localhost:6379
key: ${!json("id")}
fields:
topic: ${!meta("kafka_topic")}
partition: ${!meta("kafka_partition")}
content: ${!json("document.text")}
` + "```" + `
If the field ` + "`walk_metadata`" + ` is set to ` + "`true`" + ` then Benthos
will walk all metadata fields of messages and add them to the list of hash
fields to set.
If the field ` + "`walk_json_object`" + ` is set to ` + "`true`" + ` then
Benthos will walk each message as a JSON object, extracting keys and the string
representation of their value and adds them to the list of hash fields to set.
The order of hash field extraction is as follows:
1. Metadata (if enabled)
2. JSON object (if enabled)
3. Explicit fields
Where latter stages will overwrite matching field names of a former stage.`,
Async: true,
FieldSpecs: docs.FieldSpecs{
docs.FieldCommon("url", "The URL of a Redis server to connect to.", "tcp://localhost:6379"),
docs.FieldCommon(
"key", "The key for each message, function interpolations should be used to create a unique key per message.",
"${!meta(\"kafka_key\")}", "${!json(\"doc.id\")}", "${!count(\"msgs\")}",
).SupportsInterpolation(false),
docs.FieldCommon("walk_metadata", "Whether all metadata fields of messages should be walked and added to the list of hash fields to set."),
docs.FieldCommon("walk_json_object", "Whether to walk each message as a JSON object and add each key/value pair to the list of hash fields to set."),
docs.FieldCommon("fields", "A map of key/value pairs to set as hash fields.").SupportsInterpolation(false),
docs.FieldCommon("max_in_flight", "The maximum number of messages to have in flight at a given time. Increase this to improve throughput."),
},
}
}
//------------------------------------------------------------------------------
// NewRedisHash creates a new RedisHash output type.
func NewRedisHash(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error) {
rhash, err := writer.NewRedisHash(conf.RedisHash, log, stats)
if err != nil {
return nil, err
}
if conf.RedisHash.MaxInFlight == 1 {
return NewWriter(
TypeRedisHash, rhash, log, stats,
)
}
return NewAsyncWriter(
TypeRedisHash, conf.RedisHash.MaxInFlight, rhash, log, stats,
)
}
//------------------------------------------------------------------------------ | lib/output/redis_hash.go | 0.749912 | 0.762159 | redis_hash.go | starcoder |
package util
import (
"bytes"
"crypto/rand"
"errors"
"math/big"
"strings"
)
// OptionalBool a boolean that can be "null"
type OptionalBool byte
const (
// OptionalBoolNone a "null" boolean value
OptionalBoolNone = iota
// OptionalBoolTrue a "true" boolean value
OptionalBoolTrue
// OptionalBoolFalse a "false" boolean value
OptionalBoolFalse
)
// IsTrue return true if equal to OptionalBoolTrue
func (o OptionalBool) IsTrue() bool {
return o == OptionalBoolTrue
}
// IsFalse return true if equal to OptionalBoolFalse
func (o OptionalBool) IsFalse() bool {
return o == OptionalBoolFalse
}
// IsNone return true if equal to OptionalBoolNone
func (o OptionalBool) IsNone() bool {
return o == OptionalBoolNone
}
// OptionalBoolOf get the corresponding OptionalBool of a bool
func OptionalBoolOf(b bool) OptionalBool {
if b {
return OptionalBoolTrue
}
return OptionalBoolFalse
}
// Max max of two ints
func Max(a, b int) int {
if a < b {
return b
}
return a
}
// Min min of two ints
func Min(a, b int) int {
if a > b {
return b
}
return a
}
// IsEmptyString checks if the provided string is empty
func IsEmptyString(s string) bool {
return len(strings.TrimSpace(s)) == 0
}
// NormalizeEOL will convert Windows (CRLF) and Mac (CR) EOLs to UNIX (LF)
func NormalizeEOL(input []byte) []byte {
var right, left, pos int
if right = bytes.IndexByte(input, '\r'); right == -1 {
return input
}
length := len(input)
tmp := make([]byte, length)
// We know that left < length because otherwise right would be -1 from IndexByte.
copy(tmp[pos:pos+right], input[left:left+right])
pos += right
tmp[pos] = '\n'
left += right + 1
pos++
for left < length {
if input[left] == '\n' {
left++
}
right = bytes.IndexByte(input[left:], '\r')
if right == -1 {
copy(tmp[pos:], input[left:])
pos += length - left
break
}
copy(tmp[pos:pos+right], input[left:left+right])
pos += right
tmp[pos] = '\n'
left += right + 1
pos++
}
return tmp[:pos]
}
// MergeInto merges pairs of values into a "dict"
func MergeInto(dict map[string]interface{}, values ...interface{}) (map[string]interface{}, error) {
for i := 0; i < len(values); i++ {
switch key := values[i].(type) {
case string:
i++
if i == len(values) {
return nil, errors.New("specify the key for non array values")
}
dict[key] = values[i]
case map[string]interface{}:
m := values[i].(map[string]interface{})
for i, v := range m {
dict[i] = v
}
default:
return nil, errors.New("dict values must be maps")
}
}
return dict, nil
}
// RandomInt returns a random integer between 0 and limit, inclusive
func RandomInt(limit int64) (int64, error) {
int, err := rand.Int(rand.Reader, big.NewInt(limit))
if err != nil {
return 0, err
}
return int.Int64(), nil
}
const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
// RandomString generates a random alphanumerical string
func RandomString(length int64) (string, error) {
bytes := make([]byte, length)
limit := int64(len(letters))
for i := range bytes {
num, err := RandomInt(limit)
if err != nil {
return "", err
}
bytes[i] = letters[num]
}
return string(bytes), nil
} | modules/util/util.go | 0.767429 | 0.4831 | util.go | starcoder |
package radius
import (
"github.com/dayaftereh/stargen/stargen/constants"
"github.com/dayaftereh/stargen/types"
)
func gasRadius4point5Gyr1960K0coreMass(planet *types.Planet) float64 {
totalEarthMasses := planet.Mass * constants.SunMassInEarthMasses
var jupiterRadii float64
if totalEarthMasses < 28.0 {
//jupiterRadii = quad_trend(-0.00117641848, 0.0813324707, 0, totalEarthMasses);
jupiterRadii = PlanetRadiusHelper(totalEarthMasses, 0.0, 0.0, 28.0, 1.355, 46.0, 1.252)
} else if totalEarthMasses < 46.0 {
//jupiterRadii = quad_trend(7.1355424E-5, -0.0110025236, 1.607128008, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 0.0, 0.0, 28.0, 1.355, 46.0, 1.252)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 28.0, 1.355, 46.0, 1.252, 77.0, 1.183)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 28.0, 46.0)
} else if totalEarthMasses < 77.0 {
//jupiterRadii = quad_trend(2.8438817E-5, -0.005723781, 1.455117388, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 28.0, 1.355, 46.0, 1.252, 77.0, 1.183)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 46.0, 1.252, 77.0, 1.183, 129.0, 1.19)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 46.0, 77.0)
} else if totalEarthMasses < 129.0 {
//jupiterRadii = quad_trend(-1.059734E-6, 3.5292059E-4, 1.162108278, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 46.0, 1.252, 77.0, 1.183, 129.0, 1.19)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 77.0, 1.183, 129.0, 1.19, 215.0, 1.189)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 77.0, 129.0)
} else if totalEarthMasses < 215.0 {
//jupiterRadii = quad_trend(-4.521665E-7, 1.4391737E-4, 1.178959162, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 77.0, 1.183, 129.0, 1.19, 215.0, 1.189)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 129.0, 1.19, 215.0, 1.189, 318.0, 1.179)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 129.0, 215.0)
} else if totalEarthMasses < 318.0 {
//jupiterRadii = quad_trend(2.523727E-7, -2.31602E-4, 1.227128508, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 129.0, 1.19, 215.0, 1.189, 318.0, 1.179)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 215.0, 1.189, 318.0, 1.179, 464.0, 1.174)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 215.0, 318.0)
} else if totalEarthMasses < 464.0 {
//jupiterRadii = quad_trend(4.6805591E-8, -7.084855E-5, 1.19679668, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 215.0, 1.189, 318.0, 1.179, 464.0, 1.174)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 318.0, 1.179, 464.0, 1.174, 774.0, 1.17)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 318.0, 464.0)
} else if totalEarthMasses < 774.0 {
//jupiterRadii = quad_trend(3.4235799E-8, -5.528714E-5, 1.192282405, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 318.0, 1.179, 464.0, 1.174, 774.0, 1.17)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.174, 774.0, 1.17, 1292.0, 1.178)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 464.0, 774.0)
} else if totalEarthMasses < 1292.0 {
//jupiterRadii = quad_trend(-2.296037E-8, 6.2880146E-5, 1.135085775, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.174, 774.0, 1.17, 1292.0, 1.178)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.17, 1292.0, 1.178, 2154.0, 1.164)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 774.0, 1292.0)
} else if totalEarthMasses < 2154.0 {
//jupiterRadii = quad_trend(-6.821523E-9, 7.2656677E-6, 1.179999679, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.17, 1292.0, 1.178, 2154.0, 1.164)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.178, 2154.0, 1.164, 3594.0, 1.118)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 1292.0, 2154.0)
} else if totalEarthMasses < 3594.0 {
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.178, 2154.0, 1.164, 3594.0, 1.118)
jupiterRadii2 := PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.164, 3594.0, 1.118)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 2154.0, 3594.0)
} else {
//jupiterRadii = ln_trend(1.853640017, -0.0898544185, totalEarthMasses);
jupiterRadii = PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.164, 3594.0, 1.118)
}
return jupiterRadii
}
func gasRadius4point5Gyr1960K10coreMass(planet *types.Planet) float64 {
totalEarthMasses := planet.Mass * constants.SunMassInEarthMasses
massRadii10 := RadiusImproved(10.0/constants.SunMassInEarthMasses, planet)
var jupiterRadii float64
if totalEarthMasses < 10.0 {
//jupiterRadii = radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone(), the_planet) / KM_JUPITER_RADIUS;
jupiterRadii = massRadii10
} else if totalEarthMasses < 17.0 {
/*double x[] = {10, 17, 28};
double y[] = {radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone()) / KM_JUPITER_RADIUS, 0.726, 0.934};
double coeff[3];
polynomialfit(3, 3, x, y, coeff);
jupiterRadii = quad_trend(coeff[2], coeff[1], coeff[0], totalEarthMasses);*/
jupiterRadii = PlanetRadiusHelper(totalEarthMasses, 10.0, massRadii10, 17.0, 0.726, 28.0, 0.934)
} else if totalEarthMasses < 28.0 {
//jupiterRadii = quad_trend(-4.892024E-4, 0.0409231975, 0.1716851271, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 10.0, massRadii10, 17.0, 0.726, 28.0, 0.934)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 17.0, 0.726, 28.0, 0.934, 46.0, 1.019)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 17.0, 28.0)
} else if totalEarthMasses < 46.0 {
//jupiterRadii = quad_trend(-6.148051E-5, 0.0092717797, 0.7225908858, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 17.0, 0.726, 28.0, 0.934, 46.0, 1.019)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 28.0, 0.934, 46.0, 1.019, 77.0, 1.072)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 28.0, 46.0)
} else if totalEarthMasses < 77.0 {
//jupiterRadii = quad_trend(-8.782026E-6, 0.0027898667, 0.9092489013, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 28.0, 0.934, 46.0, 1.019, 77.0, 1.072)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 46.0, 1.019, 77.0, 1.072, 129.0, 1.123)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 46.0, 77.0)
} else if totalEarthMasses < 129.0 {
//jupiterRadii = quad_trend(-5.000519E-6, 0.002010876, 0.9468106187, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 46.0, 1.019, 77.0, 1.072, 129.0, 1.123)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 77.0, 1.072, 129.0, 1.123, 215.0, 1.148)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 77.0, 129.0)
} else if totalEarthMasses < 215.0 {
//jupiterRadii = quad_trend(-1.281238E-6, 7.3144355E-4, 1.049964864, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 77.0, 1.072, 129.0, 1.123, 215.0, 1.148)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 129.0, 1.123, 215.0, 1.148, 318.0, 1.153)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 129.0, 215.0)
} else if totalEarthMasses < 318.0 {
//jupiterRadii = quad_trend(-8.492542E-8, 9.3808937E-5, 1.131756756, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 129.0, 1.123, 215.0, 1.148, 318.0, 1.153)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 215.0, 1.148, 318.0, 1.153, 464.0, 1.157)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 215.0, 318.0)
} else if totalEarthMasses < 464.0 {
//jupiterRadii = quad_trend(-3.88593E-8, 5.7785233E-5, 1.138553904, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 215.0, 1.148, 318.0, 1.153, 464.0, 1.157)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 318.0, 1.153, 464.0, 1.157, 774.0, 1.16)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 318.0, 464.0)
} else if totalEarthMasses < 774.0 {
//jupiterRadii = quad_trend(1.6290584E-8, -1.049032E-5, 1.158360213, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 318.0, 1.153, 464.0, 1.157, 774.0, 1.16)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.157, 774.0, 1.16, 1292.0, 1.172)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 464.0, 774.0)
} else if totalEarthMasses < 1292.0 {
//jupiterRadii = quad_trend(-2.687474E-8, 7.868923E-5, 1.115194546, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.157, 774.0, 1.16, 1292.0, 1.172)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.16, 1292.0, 1.172, 2154.0, 1.16)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 774.0, 1292.0)
} else if totalEarthMasses < 2154.0 {
//jupiterRadii = quad_trend(-7.226082E-9, 1.0979967E-5, 1.169876123, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.16, 1292.0, 1.172, 2154.0, 1.16)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.172, 2154.0, 1.16, 3594.0, 1.116)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 1292.0, 2154.0)
} else if totalEarthMasses < 3594.0 {
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.172, 2154.0, 1.16, 3594.0, 1.116)
jupiterRadii2 := PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.16, 3594.0, 1.116)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 2154.0, 3594.0)
} else {
//jupiterRadii = ln_trend(1.819655669, -0.0859477047, totalEarthMasses);
jupiterRadii = PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.16, 3594.0, 1.116)
}
return jupiterRadii
}
func gasRadius4point5Gyr1960K25coreMass(planet *types.Planet) float64 {
totalEarthMasses := planet.Mass * constants.SunMassInEarthMasses
massRadii25 := RadiusImproved(25.0/constants.SunMassInEarthMasses, planet)
var jupiterRadii float64
if totalEarthMasses < 25.0 {
//jupiterRadii = radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone(), the_planet) / KM_JUPITER_RADIUS;
jupiterRadii = massRadii25
} else if totalEarthMasses < 28.0 {
/*double x[] = {25, 28, 46};
double y[] = {radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone()) / KM_JUPITER_RADIUS, 0.430, 0.756};
double coeff[3];
polynomialfit(3, 3, x, y, coeff);
jupiterRadii = quad_trend(coeff[2], coeff[1], coeff[0], totalEarthMasses);*/
jupiterRadii = PlanetRadiusHelper(totalEarthMasses, 25.0, massRadii25, 28.0, 0.43, 46.0, 0.756)
} else if totalEarthMasses < 46.0 {
//jupiterRadii = quad_trend(-2.563821E-4, 0.0370833882, -0.4073312852, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 25.0, massRadii25, 28.0, 0.43, 46.0, 0.756)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 28.0, 0.43, 46.0, 0.756, 77.0, 0.928)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 28.0, 46.0)
} else if totalEarthMasses < 77.0 {
//jupiterRadii = quad_trend(-4.275165E-5, 0.0108068403, 0.349347843, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 28.0, 0.43, 46.0, 0.756, 77.0, 0.928)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 46.0, 0.756, 77.0, 0.928, 129.0, 1.032)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 46.0, 77.0)
} else if totalEarthMasses < 129.0 {
//jupiterRadii = quad_trend(-9.521402E-6, 0.0039614088, 0.679423913, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 46.0, 0.756, 77.0, 0.928, 129.0, 1.032)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 77.0, 0.928, 129.0, 1.032, 215.0, 1.091)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 77.0, 129.0)
} else if totalEarthMasses < 215.0 {
//jupiterRadii = quad_trend(-2.345651E-6, 0.0014929505, 0.8784433657, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 77.0, 0.928, 129.0, 1.032, 215.0, 1.091)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 129.0, 1.032, 215.0, 1.091, 318.0, 1.116)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 129.0, 215.0)
} else if totalEarthMasses < 318.0 {
//jupiterRadii = quad_trend(-5.621635E-7, 5.4325161E-4, 1.000380413, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 129.0, 1.032, 215.0, 1.091, 318.0, 1.116)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 215.0, 1.091, 318.0, 1.116, 464.0, 1.131)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 215.0, 318.0)
} else if totalEarthMasses < 464.0 {
//jupiterRadii = quad_trend(-1.262685E-7, 2.0148169E-4, 1.064697598, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 215.0, 1.091, 318.0, 1.116, 464.0, 1.131)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 318.0, 1.116, 464.0, 1.131, 774.0, 1.145)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 318.0, 464.0)
} else if totalEarthMasses < 774.0 {
//jupiterRadii = quad_trend(-1.257519E-8, 6.0729373E-5, 1.105528959, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 318.0, 1.116, 464.0, 1.131, 774.0, 1.145)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.131, 774.0, 1.145, 1292.0, 1.163)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 464.0, 774.0)
} else if totalEarthMasses < 1292.0 {
//jupiterRadii = quad_trend(-3.190564E-8, 1.0066608E-4, 1.086198356, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.131, 774.0, 1.145, 1292.0, 1.163)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.145, 1292.0, 1.163, 2154.0, 1.155)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 774.0, 1292.0)
} else if totalEarthMasses < 2154.0 {
//jupiterRadii = quad_trend(-8.940212E-9, 2.1527229E-5, 1.150110395, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.145, 1292.0, 1.163, 2154.0, 1.155)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.163, 2154.0, 1.155, 3594.0, 1.112)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 1292.0, 2154.0)
} else if totalEarthMasses < 3594.0 {
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.163, 2154.0, 1.155, 3594.0, 1.112)
jupiterRadii2 := PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.155, 3594.0, 1.112)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 2154.0, 3594.0)
} else {
//jupiterRadii = ln_trend(1.799663495, -0.0839943477, totalEarthMasses);
jupiterRadii = PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.155, 3594.0, 1.112)
}
return jupiterRadii
}
func gasRadius4point5Gyr1960K50coreMass(planet *types.Planet) float64 {
totalEarthMasses := planet.Mass * constants.SunMassInEarthMasses
massRadii50 := RadiusImproved(50.0/constants.SunMassInEarthMasses, planet)
var jupiterRadii float64
if totalEarthMasses < 50.0 {
//jupiterRadii = radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone(), the_planet) / KM_JUPITER_RADIUS;
jupiterRadii = massRadii50
} else if totalEarthMasses < 77.0 {
/*double x[] = {50, 77, 129};
double y[] = {radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone()) / KM_JUPITER_RADIUS, 0.695, 0.891};
double coeff[3];
polynomialfit(3, 3, x, y, coeff);
jupiterRadii = quad_trend(coeff[2], coeff[1], coeff[0], totalEarthMasses);*/
jupiterRadii = PlanetRadiusHelper(totalEarthMasses, 50.0, massRadii50, 77.0, 0.695, 129.0, 0.891)
} else if totalEarthMasses < 129.0 {
//jupiterRadii = quad_trend(-1.779186E-5, 0.0074343548, 0.2280426421, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 50.0, massRadii50, 77.0, 0.695, 129.0, 0.891)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 77.0, 0.695, 129.0, 0.891, 215.0, 1.004)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 77.0, 129.0)
} else if totalEarthMasses < 215.0 {
//jupiterRadii = quad_trend(-4.280948E-6, 0.0027865995, 0.6027679149, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 77.0, 0.695, 129.0, 0.891, 215.0, 1.004)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 129.0, 0.891, 215.0, 1.004, 318.0, 1.056)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 129.0, 215.0)
} else if totalEarthMasses < 318.0 {
//jupiterRadii = quad_trend(-1.064772E-6, 0.0010723781, 0.8226578179, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 129.0, 0.891, 215.0, 1.004, 318.0, 1.056)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 215.0, 1.004, 318.0, 1.056, 464.0, 1.091)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 215.0, 318.0)
} else if totalEarthMasses < 464.0 {
//jupiterRadii = quad_trend(-3.134909E-7, 4.8487588E-4, 0.9335109194, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 215.0, 1.004, 318.0, 1.056, 464.0, 1.091)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 318.0, 1.056, 464.0, 1.091, 774.0, 1.121)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 318.0, 464.0)
} else if totalEarthMasses < 774.0 {
//jupiterRadii = quad_trend(-5.39259E-8, 1.6353445E-4, 1.026730044, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 318.0, 1.056, 464.0, 1.091, 774.0, 1.121)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.091, 774.0, 1.121, 1292.0, 1.148)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 464.0, 774.0)
} else if totalEarthMasses < 1292.0 {
//jupiterRadii = quad_trend(-4.113328E-8, 1.371049E-4, 1.039522764, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.091, 774.0, 1.121, 1292.0, 1.148)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.121, 1292.0, 1.148, 2154.0, 1.144)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 774.0, 1292.0)
} else if totalEarthMasses < 2154.0 {
//jupiterRadii = quad_trend(-9.447662E-9, 2.7916272E-5, 1.127702819, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.121, 1292.0, 1.148, 2154.0, 1.144)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.148, 2154.0, 1.144, 3594.0, 1.106)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 1292.0, 2154.0)
} else if totalEarthMasses < 3594.0 {
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.148, 2154.0, 1.144, 3594.0, 1.106)
jupiterRadii2 := PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.144, 3594.0, 1.106)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 2154.0, 3594.0)
} else {
//jupiterRadii = ln_trend(1.713702623, -0.0742275631, totalEarthMasses);
jupiterRadii = PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.144, 3594.0, 1.106)
}
return jupiterRadii
}
func gasRadius4point5Gyr1960K100coreMass(planet *types.Planet) float64 {
totalEarthMasses := planet.Mass * constants.SunMassInEarthMasses
massRadii100 := RadiusImproved(100.0/constants.SunMassInEarthMasses, planet)
var jupiterRadii float64
if totalEarthMasses < 100.0 {
//jupiterRadii = radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone(), the_planet) / KM_JUPITER_RADIUS;
jupiterRadii = massRadii100
} else if totalEarthMasses < 129.0 {
/*double x[] = {100, 129, 215};
double y[] = {radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone()) / KM_JUPITER_RADIUS, 0.613, 0.841};
double coeff[3];
polynomialfit(3, 3, x, y, coeff);
jupiterRadii = quad_trend(coeff[2], coeff[1], coeff[0], totalEarthMasses);*/
jupiterRadii = PlanetRadiusHelper(totalEarthMasses, 100.0, massRadii100, 129.0, 0.613, 215.0, 0.841)
} else if totalEarthMasses < 215.0 {
//jupiterRadii = quad_trend(-8.736311E-6, 0.0056564538, 0.0286984127, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 100.0, massRadii100, 129.0, 0.613, 215.0, 0.841)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 129.0, 0.613, 215.0, 0.841, 318.0, 0.944)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 129.0, 215.0)
} else if totalEarthMasses < 318.0 {
//jupiterRadii = quad_trend(-2.173076E-6, 0.0021582494, 0.4774268031, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 129.0, 0.613, 215.0, 0.841, 318.0, 0.944)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 215.0, 0.841, 318.0, 0.944, 464.0, 1.011)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 215.0, 318.0)
} else if totalEarthMasses < 464.0 {
//jupiterRadii = quad_trend(-5.465498E-7, 8.8630602E-4, 0.7174239831, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 215.0, 0.841, 318.0, 0.944, 464.0, 1.011)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 318.0, 0.944, 464.0, 1.011, 774.0, 1.076)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 318.0, 464.0)
} else if totalEarthMasses < 774.0 {
//jupiterRadii = quad_trend(-1.553096E-7, 4.0195069E-4, 0.8579324135, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 318.0, 0.944, 464.0, 1.011, 774.0, 1.076)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.011, 774.0, 1.076, 1292.0, 1.118)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 464.0, 774.0)
} else if totalEarthMasses < 1292.0 {
//jupiterRadii = quad_trend(-5.286988E-8, 1.9031025E-4, 0.9603729424, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.011, 774.0, 1.076, 1292.0, 1.118)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.076, 1292.0, 1.118, 2154.0, 1.125)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 774.0, 1292.0)
} else if totalEarthMasses < 2154.0 {
//jupiterRadii = quad_trend(-1.257775E-8, 5.146358E-5, 1.072504642, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.076, 1292.0, 1.118, 2154.0, 1.125)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.118, 2154.0, 1.125, 3594.0, 1.095)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 1292.0, 2154.0)
} else if totalEarthMasses < 3594.0 {
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.118, 2154.0, 1.125, 3594.0, 1.095)
jupiterRadii2 := PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.125, 3594.0, 1.095)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 2154.0, 3594.0)
} else {
//jupiterRadii = ln_trend(1.574765229, -0.0586007077, totalEarthMasses);
jupiterRadii = PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.125, 3594.0, 1.095)
}
return jupiterRadii
}
func gasRadius4point5Gyr1960K(planet *types.Planet) float64 {
coreMassRadii0 := gasRadius4point5Gyr1960K0coreMass(planet)
coreMassRadii10 := gasRadius4point5Gyr1960K10coreMass(planet)
coreMassRadii25 := gasRadius4point5Gyr1960K25coreMass(planet)
coreMassRadii50 := gasRadius4point5Gyr1960K50coreMass(planet)
coreMassRadii100 := gasRadius4point5Gyr1960K100coreMass(planet)
coreEarthMasses := planet.DustMass * constants.SunMassInEarthMasses
var jupiterRadii float64
if coreEarthMasses <= 10.0 {
jupiterRadii = PlanetRadiusHelper(coreEarthMasses, 0.0, coreMassRadii0, 10.0, coreMassRadii10, 25.0, coreMassRadii25)
} else if coreEarthMasses <= 25.0 {
jupiterRadii1 := PlanetRadiusHelper(coreEarthMasses, 0.0, coreMassRadii0, 10.0, coreMassRadii10, 25.0, coreMassRadii25)
jupiterRadii2 := PlanetRadiusHelper(coreEarthMasses, 10.0, coreMassRadii10, 25.0, coreMassRadii25, 50.0, coreMassRadii50)
jupiterRadii = RangeAdjust(coreEarthMasses, jupiterRadii1, jupiterRadii2, 10.0, 25.0)
} else if coreEarthMasses <= 50.0 {
jupiterRadii1 := PlanetRadiusHelper(coreEarthMasses, 10.0, coreMassRadii10, 25.0, coreMassRadii25, 50.0, coreMassRadii50)
jupiterRadii2 := PlanetRadiusHelper(coreEarthMasses, 25.0, coreMassRadii25, 50.0, coreMassRadii50, 100.0, coreMassRadii100)
jupiterRadii = RangeAdjust(coreEarthMasses, jupiterRadii1, jupiterRadii2, 25.0, 50.0)
} else if coreEarthMasses <= 100.0 {
jupiterRadii1 := PlanetRadiusHelper(coreEarthMasses, 25.0, coreMassRadii25, 50.0, coreMassRadii50, 100.0, coreMassRadii100)
jupiterRadii2 := PlanetRadiusHelper2(coreEarthMasses, 50.0, coreMassRadii50, 100.0, coreMassRadii100)
jupiterRadii = RangeAdjust(coreEarthMasses, jupiterRadii1, jupiterRadii2, 50.0, 100.0)
} else {
jupiterRadii = PlanetRadiusHelper2(coreEarthMasses, 50.0, coreMassRadii50, 100.0, coreMassRadii100)
}
return jupiterRadii
}
func gasRadius4point5Gyr1300K0coreMass(planet *types.Planet) float64 {
totalEarthMasses := planet.Mass * constants.SunMassInEarthMasses
var jupiterRadii float64
if totalEarthMasses < 17.0 {
//jupiterRadii = quad_trend(-0.0024406035, 0.1063726127, 0, totalEarthMasses);
jupiterRadii = PlanetRadiusHelper(totalEarthMasses, 0.0, 0.0, 17.0, 1.103, 28.0, 1.065)
} else if totalEarthMasses < 28.0 {
//jupiterRadii = quad_trend(6.7398119E-5, -0.0064874608, 1.193808777, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 0.0, 0.0, 17.0, 1.103, 28.0, 1.065)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 17.0, 1.103, 28.0, 1.065, 46.0, 1.038)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 17.0, 28.0)
} else if totalEarthMasses < 46.0 {
//jupiterRadii = quad_trend(3.7853851E-5, -0.004301185, 1.15575576, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 17.0, 1.103, 28.0, 1.065, 46.0, 1.038)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 28.0, 1.065, 46.0, 1.038, 77.0, 1.049)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 28.0, 46.0)
} else if totalEarthMasses < 77.0 {
//jupiterRadii = quad_trend(4.2975874E-6, -1.737645E-4, 1.036899474, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 28.0, 1.065, 46.0, 1.038, 77.0, 1.049)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 46.0, 1.038, 77.0, 1.049, 129.0, 1.086)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 46.0, 77.0)
} else if totalEarthMasses < 129.0 {
//jupiterRadii = quad_trend(-3.555132E-6, 0.0024438957, 0.9588984114, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 46.0, 1.038, 77.0, 1.049, 129.0, 1.086)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 77.0, 1.049, 129.0, 1.086, 215.0, 1.105)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 77.0, 129.0)
} else if totalEarthMasses < 215.0 {
//jupiterRadii = quad_trend(-1.066205E-6, 5.8770477E-4, 1.027928803, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 77.0, 1.049, 129.0, 1.086, 215.0, 1.105)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 129.0, 1.086, 215.0, 1.105, 318.0, 1.107)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 129.0, 215.0)
} else if totalEarthMasses < 318.0 {
//jupiterRadii = quad_trend(-5.047454E-8, 4.6320406E-5, 1.097374298, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 129.0, 1.086, 215.0, 1.105, 318.0, 1.107)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 215.0, 1.105, 318.0, 1.107, 464.0, 1.108)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 215.0, 318.0)
} else if totalEarthMasses < 464.0 {
//jupiterRadii = quad_trend(2.0350257E-8, -9.064586E-6, 1.107824639, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 215.0, 1.105, 318.0, 1.107, 464.0, 1.108)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 318.0, 1.107, 464.0, 1.108, 774.0, 1.113)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 318.0, 464.0)
} else if totalEarthMasses < 774.0 {
//jupiterRadii = quad_trend(-7.821887E-9, 2.5812529E-5, 1.097707008, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 318.0, 1.107, 464.0, 1.108, 774.0, 1.113)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.108, 774.0, 1.113, 1292.0, 1.118)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 464.0, 774.0)
} else if totalEarthMasses < 1292.0 {
//jupiterRadii = quad_trend(-2.296686E-8, 5.7102052E-5, 1.082561909, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.108, 774.0, 1.113, 1292.0, 1.118)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.113, 1292.0, 1.118, 2154.0, 1.099)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 774.0, 1292.0)
} else if totalEarthMasses < 2154.0 {
//jupiterRadii = quad_trend(-4.301773E-9, -7.217854E-6, 1.134506262, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.113, 1292.0, 1.118, 2154.0, 1.099)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.118, 2154.0, 1.099, 3594.0, 1.053)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 1292.0, 2154.0)
} else if totalEarthMasses < 3594.0 {
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.118, 2154.0, 1.099, 3594.0, 1.053)
jupiterRadii2 := PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.099, 3594.0, 1.053)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 2154.0, 3594.0)
} else {
//jupiterRadii = ln_trend(1.788640017, -0.0898544185, totalEarthMasses);
jupiterRadii = PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.099, 3594.0, 1.053)
}
return jupiterRadii
}
func gasRadius4point5Gyr1300K10coreMass(planet *types.Planet) float64 {
totalEarthMasses := planet.Mass * constants.SunMassInEarthMasses
massRadii10 := RadiusImproved(10.0/constants.SunMassInEarthMasses, planet)
var jupiterRadii float64
if totalEarthMasses < 10.0 {
//jupiterRadii = radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone(), the_planet) / KM_JUPITER_RADIUS;
jupiterRadii = massRadii10
} else if totalEarthMasses < 17.0 {
/*double x[] = {10, 17, 28};
double y[] = {radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone()) / KM_JUPITER_RADIUS, 0.599, 0.775};
double coeff[3];
polynomialfit(3, 3, x, y, coeff);
jupiterRadii = quad_trend(coeff[2], coeff[1], coeff[0], totalEarthMasses);*/
jupiterRadii = PlanetRadiusHelper(totalEarthMasses, 10.0, massRadii10, 17.0, 0.599, 28.0, 0.775)
} else if totalEarthMasses < 28.0 {
//jupiterRadii = quad_trend(-3.544061E-4, 0.0319482759, 0.158302682, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 10.0, massRadii10, 17.0, 0.599, 28.0, 0.775)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 17.0, 0.599, 28.0, 0.775, 46.0, 0.878)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 17.0, 28.0)
} else if totalEarthMasses < 46.0 {
//jupiterRadii = quad_trend(-6.016385E-5, 0.0101743472, 0.5372867384, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 17.0, 0.599, 28.0, 0.775, 46.0, 0.878)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 28.0, 0.775, 46.0, 0.878, 77.0, 0.964)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 28.0, 46.0)
} else if totalEarthMasses < 77.0 {
//jupiterRadii = quad_trend(-1.836378E-5, 0.0050329382, 0.6853425962, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 28.0, 0.775, 46.0, 0.878, 77.0, 0.964)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 46.0, 0.878, 77.0, 0.964, 129.0, 1.029)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 46.0, 77.0)
} else if totalEarthMasses < 129.0 {
//jupiterRadii = quad_trend(-5.687563E-5, 0.002421638, 0.8112554348, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 46.0, 0.878, 77.0, 0.964, 129.0, 1.029)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 77.0, 0.964, 129.0, 1.029, 215.0, 1.069)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 77.0, 129.0)
} else if totalEarthMasses < 215.0 {
//jupiterRadii = quad_trend(-1.741767E-6, 0.0010642841, 0.9206920943, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 77.0, 0.964, 129.0, 1.029, 215.0, 1.069)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 129.0, 1.029, 215.0, 1.069, 318.0, 1.083)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 129.0, 215.0)
} else if totalEarthMasses < 318.0 {
//jupiterRadii = quad_trend(-2.983072E-7, 2.9492007E-4, 1.019381435, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 129.0, 1.029, 215.0, 1.069, 318.0, 1.083)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 215.0, 1.069, 318.0, 1.083, 464.0, 1.092)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 215.0, 318.0)
} else if totalEarthMasses < 464.0 {
//jupiterRadii = quad_trend(-5.029421E-8, 1.0097391E-4, 1.05597625, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 215.0, 1.069, 318.0, 1.083, 464.0, 1.092)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 318.0, 1.083, 464.0, 1.092, 774.0, 1.104)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 318.0, 464.0)
} else if totalEarthMasses < 774.0 {
//jupiterRadii = quad_trend(-2.809863E-8, 7.3495776E-5, 1.063947482, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 318.0, 1.083, 464.0, 1.092, 774.0, 1.104)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.092, 774.0, 1.104, 1292.0, 1.112)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 464.0, 774.0)
} else if totalEarthMasses < 1292.0 {
//jupiterRadii = quad_trend(-2.548231E-8, 6.8090476E-5, 1.066563814, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.092, 774.0, 1.104, 1292.0, 1.112)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.104, 1292.0, 1.112, 2154.0, 1.095)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 774.0, 1292.0)
} else if totalEarthMasses < 2154.0 {
//jupiterRadii = quad_trend(-5.008003E-9, -2.464E-6, 1.123543167, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.104, 1292.0, 1.112, 2154.0, 1.095)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.112, 2154.0, 1.095, 3594.0, 1.05)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 1292.0, 2154.0)
} else if totalEarthMasses < 3594.0 {
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.112, 2154.0, 1.095, 3594.0, 1.05)
jupiterRadii2 := PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.095, 3594.0, 1.05)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 2154.0, 3594.0)
} else {
//jupiterRadii = ln_trend(1.769647843, -0.0879010616, totalEarthMasses);
jupiterRadii = PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.095, 3594.0, 1.05)
}
return jupiterRadii
}
func gasRadius4point5Gyr1300K25coreMass(planet *types.Planet) float64 {
totalEarthMasses := planet.Mass * constants.SunMassInEarthMasses
massRadii25 := RadiusImproved(25.0/constants.SunMassInEarthMasses, planet)
var jupiterRadii float64
if totalEarthMasses < 25.0 {
//jupiterRadii = radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone(), the_planet) / KM_JUPITER_RADIUS;
jupiterRadii = massRadii25
} else if totalEarthMasses < 28.0 {
/*double x[] = {25, 28, 46};
double y[] = {radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone()) / KM_JUPITER_RADIUS, 0.403, 0.686};
double coeff[3];
polynomialfit(3, 3, x, y, coeff);
jupiterRadii = quad_trend(coeff[2], coeff[1], coeff[0], totalEarthMasses);*/
jupiterRadii = PlanetRadiusHelper(totalEarthMasses, 25.0, massRadii25, 28.0, 0.403, 46.0, 0.686)
} else if totalEarthMasses < 46.0 {
//jupiterRadii = quad_trend(-2.155292E-4, 0.0316713847, -0.3148238607, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 25.0, massRadii25, 28.0, 0.403, 46.0, 0.686)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 28.0, 0.403, 46.0, 0.686, 77.0, 0.846)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 28.0, 46.0)
} else if totalEarthMasses < 77.0 {
//jupiterRadii = quad_trend(-3.762444E-5, 0.0097890968, 0.3153148674, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 28.0, 0.403, 46.0, 0.686, 77.0, 0.846)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 46.0, 0.686, 77.0, 0.846, 129.0, 0.952)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 46.0, 77.0)
} else if totalEarthMasses < 129.0 {
//jupiterRadii = quad_trend(-9.126027E-6, 0.0039184232, 0.5983896321, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 46.0, 0.686, 77.0, 0.846, 129.0, 0.952)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 77.0, 0.846, 129.0, 0.952, 215.0, 1.019)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 77.0, 129.0)
} else if totalEarthMasses < 215.0 {
//jupiterRadii = quad_trend(-2.529624E-6, 0.0016492603, 0.7813408846, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 77.0, 0.846, 129.0, 0.952, 215.0, 1.019)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 129.0, 0.952, 215.0, 1.019, 318.0, 1.05)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 129.0, 215.0)
} else if totalEarthMasses < 318.0 {
//jupiterRadii = quad_trend(-6.860799E-7, 6.6665144E-4, 0.9073839815, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 129.0, 0.952, 215.0, 1.019, 318.0, 1.05)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 215.0, 1.019, 318.0, 1.05, 464.0, 1.069)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 215.0, 318.0)
} else if totalEarthMasses < 464.0 {
//jupiterRadii = quad_trend(-1.368313E-7, 2.3713903E-4, 0.9884267135, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 215.0, 1.019, 318.0, 1.05, 464.0, 1.069)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 318.0, 1.05, 464.0, 1.069, 774.0, 1.09)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 318.0, 464.0)
} else if totalEarthMasses < 774.0 {
//jupiterRadii = quad_trend(-4.917259E-8, 1.2861761E-4, 1.019908093, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 318.0, 1.05, 464.0, 1.069, 774.0, 1.09)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.069, 774.0, 1.09, 1292.0, 1.104)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 464.0, 774.0)
} else if totalEarthMasses < 1292.0 {
//jupiterRadii = quad_trend(-3.135386E-8, 9.1804101E-5, 1.037726971, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.069, 774.0, 1.09, 1292.0, 1.104)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.09, 1292.0, 1.104, 2154.0, 1.09)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 774.0, 1292.0)
} else if totalEarthMasses < 2154.0 {
//jupiterRadii = quad_trend(-5.916513E-9, 4.1470028E-6, 1.108518294, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.09, 1292.0, 1.104, 2154.0, 1.09)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.104, 2154.0, 1.09, 3594.0, 1.047)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 1292.0, 2154.0)
} else if totalEarthMasses < 3594.0 {
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.104, 2154.0, 1.09, 3594.0, 1.047)
jupiterRadii2 := PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.09, 3594.0, 1.047)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 2154.0, 3594.0)
} else {
///jupiterRadii = ln_trend(1.734663495, -0.0839943477, totalEarthMasses);
jupiterRadii = PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.09, 3594.0, 1.047)
}
return jupiterRadii
}
func gasRadius4point5Gyr1300K50coreMass(planet *types.Planet) float64 {
totalEarthMasses := planet.Mass * constants.SunMassInEarthMasses
massRadii50 := RadiusImproved(50.0/constants.SunMassInEarthMasses, planet)
var jupiterRadii float64
if totalEarthMasses < 50.0 {
//jupiterRadii = radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone(), the_planet) / KM_JUPITER_RADIUS;
jupiterRadii = massRadii50
} else if totalEarthMasses < 77.0 {
/*double x[] = {50, 77, 129};
double y[] = {radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone()) / KM_JUPITER_RADIUS, 0.648, 0.831};
double coeff[3];
polynomialfit(3, 3, x, y, coeff);
jupiterRadii = quad_trend(coeff[2], coeff[1], coeff[0], totalEarthMasses);*/
jupiterRadii = PlanetRadiusHelper(totalEarthMasses, 50.0, massRadii50, 77.0, 0.648, 129.0, 0.831)
} else if totalEarthMasses < 129.0 {
//jupiterRadii = quad_trend(-1.614879E-5, 0.0068458816, 0.2166132943, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 50.0, massRadii50, 77.0, 0.648, 129.0, 0.831)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 77.0, 0.648, 129.0, 0.831, 215.0, 0.942)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 77.0, 129.0)
} else if totalEarthMasses < 215.0 {
//jupiterRadii = quad_trend(-4.055163E-6, 0.0026856738, 0.5520300509, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 77.0, 0.648, 129.0, 0.831, 215.0, 0.942)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 129.0, 0.831, 215.0, 0.942, 318.0, 0.996)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 129.0, 215.0)
} else if totalEarthMasses < 318.0 {
//jupiterRadii = quad_trend(-1.08774E-6, 0.0011040371, 0.7549127896, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 129.0, 0.831, 215.0, 0.942, 318.0, 0.996)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 215.0, 0.942, 318.0, 0.996, 464.0, 1.033)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 215.0, 318.0)
} else if totalEarthMasses < 464.0 {
//jupiterRadii = quad_trend(-3.08161E-7, 4.9440659E-4, 0.8699411819, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 215.0, 0.942, 318.0, 0.996, 464.0, 1.033)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 318.0, 0.996, 464.0, 1.033, 774.0, 1.068)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 318.0, 464.0)
} else if totalEarthMasses < 774.0 {
//jupiterRadii = quad_trend(-8.506302E-8, 2.1821125E-4, 0.9500637093, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 318.0, 0.996, 464.0, 1.033, 774.0, 1.068)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.033, 774.0, 1.068, 1292.0, 1.09)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 464.0, 774.0)
} else if totalEarthMasses < 1292.0 {
//jupiterRadii = quad_trend(-3.845194E-8, 1.2168549E-4, 0.996785166, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.033, 774.0, 1.068, 1292.0, 1.09)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.068, 1292.0, 1.09, 2154.0, 1.081)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 774.0, 1292.0)
} else if totalEarthMasses < 2154.0 {
//jupiterRadii = quad_trend(-7.229582E-9, 1.4472305E-5, 1.083369863, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.068, 1292.0, 1.09, 2154.0, 1.081)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.09, 2154.0, 1.081, 3594.0, 1.042)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 1292.0, 2154.0)
} else if totalEarthMasses < 3594.0 {
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.09, 2154.0, 1.081, 3594.0, 1.042)
jupiterRadii2 := PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.081, 3594.0, 1.042)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 2154.0, 3594.0)
} else {
//jupiterRadii = ln_trend(1.665694797, -0.0761809201, totalEarthMasses);
jupiterRadii = PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.081, 3594.0, 1.042)
}
return jupiterRadii
}
func gasRadius4point5Gyr1300K100coreMass(planet *types.Planet) float64 {
totalEarthMasses := planet.Mass * constants.SunMassInEarthMasses
massRadii100 := RadiusImproved(100.0/constants.SunMassInEarthMasses, planet)
var jupiterRadii float64
if totalEarthMasses < 100.0 {
//jupiterRadii = radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone(), the_planet) / KM_JUPITER_RADIUS;
jupiterRadii = massRadii100
} else if totalEarthMasses < 129.0 {
/*double x[] = {100, 129, 215};
double y[] = {radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone()) / KM_JUPITER_RADIUS, 0.587, 0.798};
double coeff[3];
polynomialfit(3, 3, x, y, coeff);
jupiterRadii = quad_trend(coeff[2], coeff[1], coeff[0], totalEarthMasses);*/
jupiterRadii = PlanetRadiusHelper(totalEarthMasses, 100.0, massRadii100, 129.0, 0.587, 215.0, 0.798)
} else if totalEarthMasses < 215.0 {
//jupiterRadii = quad_trend(-7.94726E-6, 0.0051873457, 0.0500827554, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 100.0, massRadii100, 129.0, 0.587, 215.0, 0.798)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 129.0, 0.587, 215.0, 0.798, 318.0, 0.896)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 129.0, 215.0)
} else if totalEarthMasses < 318.0 {
//jupiterRadii = quad_trend(-2.033136E-6, 0.0020351177, 0.4544313939, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 129.0, 0.587, 215.0, 0.798, 318.0, 0.896)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 215.0, 0.798, 318.0, 0.896, 464.0, 0.961)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 215.0, 318.0)
} else if totalEarthMasses < 464.0 {
//jupiterRadii = quad_trend(-5.165089E-7, 8.4911544E-4, 0.6782127358, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 215.0, 0.798, 318.0, 0.896, 464.0, 0.961)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 318.0, 0.896, 464.0, 0.961, 774.0, 1.026)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 318.0, 464.0)
} else if totalEarthMasses < 774.0 {
//jupiterRadii = quad_trend(-1.692987E-7, 4.1926925E-4, 0.8029084081, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 318.0, 0.896, 464.0, 0.961, 774.0, 1.026)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 464.0, 0.961, 774.0, 1.026, 1292.0, 1.062)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 464.0, 774.0)
} else if totalEarthMasses < 1292.0 {
//jupiterRadii = quad_trend(-4.952027E-8, 1.7180685E-4, 0.9226878251, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 464.0, 0.961, 774.0, 1.026, 1292.0, 1.062)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.026, 1292.0, 1.062, 2154.0, 1.063)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 774.0, 1292.0)
} else if totalEarthMasses < 2154.0 {
//jupiterRadii = quad_trend(-9.855721E-9, 3.5122909E-5, 1.033073003, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.026, 1292.0, 1.062, 2154.0, 1.063)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.062, 2154.0, 1.063, 3594.0, 1.032)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 1292.0, 2154.0)
} else if totalEarthMasses < 3594.0 {
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.062, 2154.0, 1.063, 3594.0, 1.032)
jupiterRadii2 := PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.063, 3594.0, 1.032)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 2154.0, 3594.0)
} else {
//jupiterRadii = ln_trend(1.527757403, -0.0605540647, totalEarthMasses);
jupiterRadii = PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.063, 3594.0, 1.032)
}
return jupiterRadii
}
func gasRadius4point5Gyr1300K(planet *types.Planet) float64 {
coreMassRadii0 := gasRadius4point5Gyr1300K0coreMass(planet)
coreMassRadii10 := gasRadius4point5Gyr1300K10coreMass(planet)
coreMassRadii25 := gasRadius4point5Gyr1300K25coreMass(planet)
coreMassRadii50 := gasRadius4point5Gyr1300K50coreMass(planet)
coreMassRadii100 := gasRadius4point5Gyr1300K100coreMass(planet)
coreEarthMasses := planet.DustMass * constants.SunMassInEarthMasses
var jupiterRadii float64
if coreEarthMasses <= 10.0 {
jupiterRadii = PlanetRadiusHelper(coreEarthMasses, 0.0, coreMassRadii0, 10.0, coreMassRadii10, 25.0, coreMassRadii25)
} else if coreEarthMasses <= 25.0 {
jupiterRadii1 := PlanetRadiusHelper(coreEarthMasses, 0.0, coreMassRadii0, 10.0, coreMassRadii10, 25.0, coreMassRadii25)
jupiterRadii2 := PlanetRadiusHelper(coreEarthMasses, 10.0, coreMassRadii10, 25.0, coreMassRadii25, 50.0, coreMassRadii50)
jupiterRadii = RangeAdjust(coreEarthMasses, jupiterRadii1, jupiterRadii2, 10.0, 25.0)
} else if coreEarthMasses <= 50.0 {
jupiterRadii1 := PlanetRadiusHelper(coreEarthMasses, 10.0, coreMassRadii10, 25.0, coreMassRadii25, 50.0, coreMassRadii50)
jupiterRadii2 := PlanetRadiusHelper(coreEarthMasses, 25.0, coreMassRadii25, 50.0, coreMassRadii50, 100.0, coreMassRadii100)
jupiterRadii = RangeAdjust(coreEarthMasses, jupiterRadii1, jupiterRadii2, 25.0, 50.0)
} else if coreEarthMasses <= 100.0 {
jupiterRadii1 := PlanetRadiusHelper(coreEarthMasses, 25.0, coreMassRadii25, 50.0, coreMassRadii50, 100.0, coreMassRadii100)
jupiterRadii2 := PlanetRadiusHelper2(coreEarthMasses, 50.0, coreMassRadii50, 100.0, coreMassRadii100)
jupiterRadii = RangeAdjust(coreEarthMasses, jupiterRadii1, jupiterRadii2, 50.0, 100.0)
} else {
jupiterRadii = PlanetRadiusHelper2(coreEarthMasses, 50.0, coreMassRadii50, 100.0, coreMassRadii100)
}
return jupiterRadii
}
func gasRadius4point5Gyr875K0coreMass(planet *types.Planet) float64 {
totalEarthMasses := planet.Mass * constants.SunMassInEarthMasses
var jupiterRadii float64
if totalEarthMasses < 17.0 {
//jupiterRadii = quad_trend(-0.0023768144, 0.1032293736, 0, totalEarthMasses);
jupiterRadii = PlanetRadiusHelper(totalEarthMasses, 0.0, 0.0, 17.0, 1.068, 28.0, 1.027)
} else if totalEarthMasses < 28.0 {
//jupiterRadii = quad_trend(8.6381052E-5, -0.0076144201, 1.172481017, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 0.0, 0.0, 17.0, 1.068, 28.0, 1.027)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 17.0, 1.068, 28.0, 1.027, 46.0, 1.005)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 17.0, 28.0)
} else if totalEarthMasses < 46.0 {
//jupiterRadii = quad_trend(3.745154E-5, -0.0039936362, 1.109459805, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 17.0, 1.068, 28.0, 1.027, 46.0, 1.005)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 28.0, 1.027, 46.0, 1.005, 77.0, 1.024)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 28.0, 46.0)
} else if totalEarthMasses < 77.0 {
//jupiterRadii = quad_trend(1.4200723E-6, 4.3823433E-4, 0.9818363479, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 28.0, 1.027, 46.0, 1.005, 77.0, 1.024)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 46.0, 1.005, 77.0, 1.024, 129.0, 1.062)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 46.0, 77.0)
} else if totalEarthMasses < 129.0 {
//jupiterRadii = quad_trend(-3.357445E-6, 0.0014224028, 0.9343812709, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 46.0, 1.005, 77.0, 1.024, 129.0, 1.062)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 77.0, 1.024, 129.0, 1.062, 215.0, 1.085)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 77.0, 129.0)
} else if totalEarthMasses < 215.0 {
//jupiterRadii = quad_trend(-1.158191E-6, 6.658597E-4, 0.995377562, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 77.0, 1.024, 129.0, 1.062, 215.0, 1.085)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 129.0, 1.062, 215.0, 1.085, 318.0, 1.09)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 129.0, 215.0)
} else if totalEarthMasses < 318.0 {
//jupiterRadii = quad_trend(-1.3994E-7, 1.2313171E-4, 1.064995409, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 129.0, 1.062, 215.0, 1.085, 318.0, 1.09)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 215.0, 1.085, 318.0, 1.09, 464.0, 1.092)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 215.0, 318.0)
} else if totalEarthMasses < 464.0 {
//jupiterRadii = quad_trend(1.9478103E-8, -1.533247E-6, 1.088517869, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 215.0, 1.085, 318.0, 1.09, 464.0, 1.092)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 318.0, 1.09, 464.0, 1.092, 774.0, 1.099)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 318.0, 464.0)
} else if totalEarthMasses < 774.0 {
//jupiterRadii = quad_trend(-1.561369E-8, 4.1910394E-5, 1.075915142, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 318.0, 1.09, 464.0, 1.092, 774.0, 1.099)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.092, 774.0, 1.099, 1292.0, 1.104)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 464.0, 774.0)
} else if totalEarthMasses < 1292.0 {
//jupiterRadii = quad_trend(-2.380751E-8, 5.8838828E-5, 1.067721256, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.092, 774.0, 1.099, 1292.0, 1.104)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.099, 1292.0, 1.104, 2154.0, 1.084)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 774.0, 1292.0)
} else if totalEarthMasses < 2154.0 {
//jupiterRadii = quad_trend(-3.797823E-9, -1.011456E-5, 1.123407579, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.099, 1292.0, 1.104, 2154.0, 1.084)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.104, 2154.0, 1.084, 3594.0, 1.038)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 1292.0, 2154.0)
} else if totalEarthMasses < 3594.0 {
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.104, 2154.0, 1.084, 3594.0, 1.038)
jupiterRadii2 := PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.084, 3594.0, 1.038)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 2154.0, 3594.0)
} else {
//jupiterRadii = ln_trend(1.773640017, -0.0898544185, totalEarthMasses);
jupiterRadii = PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.084, 3594.0, 1.038)
}
return jupiterRadii
}
func gasRadius4point5Gyr875K10coreMass(planet *types.Planet) float64 {
totalEarthMasses := planet.Mass * constants.SunMassInEarthMasses
massRadii10 := RadiusImproved(10.0/constants.SunMassInEarthMasses, planet)
var jupiterRadii float64
if totalEarthMasses < 10.0 {
//jupiterRadii = radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone(), the_planet) / KM_JUPITER_RADIUS;
jupiterRadii = massRadii10
} else if totalEarthMasses < 17.0 {
/*double x[] = {10, 17, 28};
double y[] = {radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone()) / KM_JUPITER_RADIUS, 0.592, 0.755};
double coeff[3];
polynomialfit(3, 3, x, y, coeff);
jupiterRadii = quad_trend(coeff[2], coeff[1], coeff[0], totalEarthMasses);*/
jupiterRadii = PlanetRadiusHelper(totalEarthMasses, 10.0, massRadii10, 17.0, 0.592, 28.0, 0.755)
} else if totalEarthMasses < 28.0 {
//jupiterRadii = quad_trend(-3.136538E-4, 0.0289326019, 0.1907917102, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 10.0, massRadii10, 17.0, 0.592, 28.0, 0.755)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 17.0, 0.592, 28.0, 0.755, 46.0, 0.858)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 17.0, 28.0)
} else if totalEarthMasses < 46.0 {
//jupiterRadii = quad_trend(-6.148051E-5, 0.0102717797, 0.5155908858, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 17.0, 0.592, 28.0, 0.755, 46.0, 0.858)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 28.0, 0.755, 46.0, 0.858, 77.0, 0.942)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 28.0, 46.0)
} else if totalEarthMasses < 77.0 {
//jupiterRadii = quad_trend(-1.735478E-5, 0.0048443152, 0.6718842118, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 28.0, 0.755, 46.0, 0.858, 77.0, 0.942)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 46.0, 0.858, 77.0, 0.942, 129.0, 1.008)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 28.0, 46.0)
} else if totalEarthMasses < 129.0 {
//jupiterRadii = quad_trend(-5.574136E-6, 0.0024175028, 0.7889013378, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 46.0, 0.858, 77.0, 0.942, 129.0, 1.008)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 77.0, 0.942, 129.0, 1.008, 215.0, 1.051)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 77.0, 129.0)
} else if totalEarthMasses < 215.0 {
//jupiterRadii = quad_trend(-1.823599E-6, 0.001127318, 0.8929224842, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 77.0, 0.942, 129.0, 1.008, 215.0, 1.051)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 129.0, 1.008, 215.0, 1.051, 318.0, 1.067)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 129.0, 215.0)
} else if totalEarthMasses < 318.0 {
//jupiterRadii = quad_trend(-3.487817E-7, 3.4124048E-4, 0.9937557337, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 129.0, 1.008, 215.0, 1.051, 318.0, 1.067)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 215.0, 1.051, 318.0, 1.067, 464.0, 1.077)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 129.0, 318.0)
} else if totalEarthMasses < 464.0 {
//jupiterRadii = quad_trend(-5.82405E-8, 1.1403722E-4, 1.036625676, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 215.0, 1.051, 318.0, 1.067, 464.0, 1.077)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 318.0, 1.067, 464.0, 1.077, 774.0, 1.09)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 318.0, 464.0)
} else if totalEarthMasses < 774.0 {
//jupiterRadii = quad_trend(-3.199453E-8, 8.1544708E-5, 1.046051549, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 318.0, 1.067, 464.0, 1.077, 774.0, 1.09)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.077, 774.0, 1.09, 1292.0, 1.098)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 464.0, 774.0)
} else if totalEarthMasses < 1292.0 {
//jupiterRadii = quad_trend(-2.632296E-8, 6.9827253E-5, 1.051723161, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.077, 774.0, 1.09, 1292.0, 1.098)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.09, 1292.0, 1.098, 2154.0, 1.08)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 774.0, 1292.0)
} else if totalEarthMasses < 2154.0 {
//jupiterRadii = quad_trend(-4.202383E-9, -6.40026E-6, 1.113284022, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.09, 1292.0, 1.098, 2154.0, 1.08)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.098, 2154.0, 1.08, 3594.0, 1.036)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 1292.0, 2154.0)
} else if totalEarthMasses < 3594.0 {
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.098, 2154.0, 1.08, 3594.0, 1.036)
jupiterRadii2 := PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.08, 3594.0, 1.036)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 2154.0, 3594.0)
} else {
//jupiterRadii = ln_trend(1.739655669, -0.0859477047, totalEarthMasses);
jupiterRadii = PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.08, 3594.0, 1.036)
}
return jupiterRadii
}
func gasRadius4point5Gyr875K25coreMass(planet *types.Planet) float64 {
totalEarthMasses := planet.Mass * constants.SunMassInEarthMasses
massRadii25 := RadiusImproved(25.0/constants.SunMassInEarthMasses, planet)
var jupiterRadii float64
if totalEarthMasses < 25.0 {
//jupiterRadii = radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone(), the_planet) / KM_JUPITER_RADIUS;
jupiterRadii = massRadii25
} else if totalEarthMasses < 28.0 {
/*double x[] = {25, 28, 46};
double y[] = {radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone()) / KM_JUPITER_RADIUS, 0.404, 0.675};
double coeff[3];
polynomialfit(3, 3, x, y, coeff);
jupiterRadii = quad_trend(coeff[2], coeff[1], coeff[0], totalEarthMasses);*/
jupiterRadii = PlanetRadiusHelper(totalEarthMasses, 25.0, massRadii25, 28.0, 0.404, 46.0, 0.675)
} else if totalEarthMasses < 46.0 {
//jupiterRadii = quad_trend(-2.058737E-4, 0.0302902129, -0.2827209421, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 25.0, massRadii25, 28.0, 0.404, 46.0, 0.675)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 28.0, 0.404, 46.0, 0.675, 77.0, 0.829)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 28.0, 46.0)
} else if totalEarthMasses < 77.0 {
//jupiterRadii = quad_trend(-3.552423E-5, 0.0093372223, 0.3206570451, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 28.0, 0.404, 46.0, 0.675, 77.0, 0.829)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 46.0, 0.675, 77.0, 0.829, 129.0, 0.934)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 46.0, 77.0)
} else if totalEarthMasses < 129.0 {
//jupiterRadii = quad_trend(-8.902414E-6, 0.003853128, 0.5850915552, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 46.0, 0.675, 77.0, 0.829, 129.0, 0.934)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 77.0, 0.829, 129.0, 0.934, 215.0, 1.002)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 77.0, 129.0)
} else if totalEarthMasses < 215.0 {
//jupiterRadii = quad_trend(-2.539778E-6, 0.0016643813, 0.7615592541, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 77.0, 0.829, 129.0, 0.934, 215.0, 1.002)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 129.0, 0.934, 215.0, 1.002, 318.0, 1.034)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 129.0, 215.0)
} else if totalEarthMasses < 318.0 {
//jupiterRadii = quad_trend(-6.975635E-7, 6.8248095E-4, 0.8875114673, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 129.0, 0.934, 215.0, 1.002, 318.0, 1.034)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 215.0, 1.002, 318.0, 1.034, 464.0, 1.054)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 215.0, 318.0)
} else if totalEarthMasses < 464.0 {
//jupiterRadii = quad_trend(-1.377034E-7, 2.4467036E-4, 0.9701199433, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 215.0, 1.002, 318.0, 1.034, 464.0, 1.054)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 318.0, 1.034, 464.0, 1.054, 774.0, 1.077)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 318.0, 464.0)
} else if totalEarthMasses < 774.0 {
//jupiterRadii = quad_trend(-5.929592E-8, 1.476019E-4, 0.9982788934, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 318.0, 1.034, 464.0, 1.054, 774.0, 1.077)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.054, 774.0, 1.077, 1292.0, 1.09)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 464.0, 774.0)
} else if totalEarthMasses < 1292.0 {
//jupiterRadii = quad_trend(-3.079559E-8, 8.8720219E-5, 1.026779451, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.054, 774.0, 1.077, 1292.0, 1.09)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.077, 1292.0, 1.09, 2154.0, 1.075)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 774.0, 1292.0)
} else if totalEarthMasses < 2154.0 {
//jupiterRadii = quad_trend(-5.110893E-9, 2.1074347E-7, 1.098259148, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.077, 1292.0, 1.09, 2154.0, 1.075)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.09, 2154.0, 1.075, 3594.0, 1.033)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 1292.0, 2154.0)
} else if totalEarthMasses < 3594.0 {
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.09, 2154.0, 1.075, 3594.0, 1.033)
jupiterRadii2 := PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.075, 3594.0, 1.033)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 2154.0, 3594.0)
} else {
//jupiterRadii = ln_trend(1.70467132, -0.0820409908, totalEarthMasses);
jupiterRadii = PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.075, 3594.0, 1.033)
}
return jupiterRadii
}
func gasRadius4point5Gyr875K50coreMass(planet *types.Planet) float64 {
totalEarthMasses := planet.Mass * constants.SunMassInEarthMasses
massRadii50 := RadiusImproved(50.0/constants.SunMassInEarthMasses, planet)
var jupiterRadii float64
if totalEarthMasses < 50.0 {
//jupiterRadii = radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone(), the_planet) / KM_JUPITER_RADIUS;
jupiterRadii = massRadii50
} else if totalEarthMasses < 77.0 {
/*double x[] = {50, 77, 129};
double y[] = {radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone()) / KM_JUPITER_RADIUS, 0.639, 0.817};
double coeff[3];
polynomialfit(3, 3, x, y, coeff);
jupiterRadii = quad_trend(coeff[2], coeff[1], coeff[0], totalEarthMasses);*/
jupiterRadii = PlanetRadiusHelper(totalEarthMasses, 50.0, massRadii50, 77.0, 0.639, 129.0, 0.817)
} else if totalEarthMasses < 129.0 {
//jupiterRadii = quad_trend(-1.545202E-5, 0.0066061938, 0.2219381271, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 50.0, massRadii50, 77.0, 0.639, 129.0, 0.817)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 77.0, 0.639, 129.0, 0.817, 215.0, 0.928)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 77.0, 129.0)
} else if totalEarthMasses < 215.0 {
//jupiterRadii = quad_trend(-4.055163E-6, 0.0026856738, 0.5380300509, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 77.0, 0.639, 129.0, 0.817, 215.0, 0.928)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 129.0, 0.817, 215.0, 0.928, 318.0, 0.982)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 129.0, 215.0)
} else if totalEarthMasses < 318.0 {
//jupiterRadii = quad_trend(-1.08774E-6, 0.0011040371, 0.7409127896, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 129.0, 0.817, 215.0, 0.928, 318.0, 0.982)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 215.0, 0.928, 318.0, 0.982, 464.0, 1.019)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 215.0, 318.0)
} else if totalEarthMasses < 464.0 {
//jupiterRadii = quad_trend(-3.010869E-7, 4.8887461E-4, 0.856984985, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 215.0, 0.928, 318.0, 0.982, 464.0, 1.019)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 318.0, 0.982, 464.0, 1.019, 774.0, 1.055)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 318.0, 464.0)
} else if totalEarthMasses < 774.0 {
//jupiterRadii = quad_trend(-9.129045E-8, 2.2914661E-4, 0.9323304424, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 318.0, 0.982, 464.0, 1.019, 774.0, 1.055)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.019, 774.0, 1.055, 1292.0, 1.076)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 464.0, 774.0)
} else if totalEarthMasses < 1292.0 {
//jupiterRadii = quad_trend(-3.778367E-8, 1.1860161E-4, 0.9858376464, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.019, 774.0, 1.055, 1292.0, 1.076)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.055, 1292.0, 1.076, 2154.0, 1.066)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 774.0, 1292.0)
} else if totalEarthMasses < 2154.0 {
//jupiterRadii = quad_trend(-6.725632E-9, 1.15756E-5, 1.07227118, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.055, 1292.0, 1.076, 2154.0, 1.066)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.076, 2154.0, 1.066, 3594.0, 1.027)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 1292.0, 2154.0)
} else if totalEarthMasses < 3594.0 {
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.076, 2154.0, 1.066, 3594.0, 1.027)
jupiterRadii2 := PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.066, 3594.0, 1.027)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 2154.0, 3594.0)
} else {
//jupiterRadii = ln_trend(1.650694797, -0.0761809201, totalEarthMasses);
jupiterRadii = PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.066, 3594.0, 1.027)
}
return jupiterRadii
}
func gasRadius4point5Gyr875K100coreMass(planet *types.Planet) float64 {
totalEarthMasses := planet.Mass * constants.SunMassInEarthMasses
massRadii100 := RadiusImproved(100.0/constants.SunMassInEarthMasses, planet)
var jupiterRadii float64
if totalEarthMasses < 100.0 {
//jupiterRadii = radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone(), the_planet) / KM_JUPITER_RADIUS;
jupiterRadii = massRadii100
} else if totalEarthMasses < 129.0 {
/*double x[] = {100, 129, 215};
double y[] = {radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone()) / KM_JUPITER_RADIUS, 0.582, 0.788};
double coeff[3];
polynomialfit(3, 3, x, y, coeff);
jupiterRadii = quad_trend(coeff[2], coeff[1], coeff[0], totalEarthMasses);*/
jupiterRadii = PlanetRadiusHelper(totalEarthMasses, 100.0, massRadii100, 129.0, 0.582, 215.0, 0.788)
} else if totalEarthMasses < 215.0 {
//jupiterRadii = quad_trend(-7.742381E-6, 0.0050587279, 0.058265064, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 100.0, massRadii100, 129.0, 0.582, 215.0, 0.788)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 129.0, 0.582, 215.0, 0.788, 318.0, 0.884)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 129.0, 215.0)
} else if totalEarthMasses < 318.0 {
//jupiterRadii = quad_trend(-1.955154E-6, 0.0019741359, 0.4539377689, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 129.0, 0.582, 215.0, 0.788, 318.0, 0.884)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 215.0, 0.788, 318.0, 0.884, 464.0, 0.949)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 215.0, 318.0)
} else if totalEarthMasses < 464.0 {
//jupiterRadii = quad_trend(-5.165089E-7, 8.4911544E-4, 0.6662127358, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 215.0, 0.788, 318.0, 0.884, 464.0, 0.949)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 318.0, 0.884, 464.0, 0.949, 774.0, 1.014)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 318.0, 464.0)
} else if totalEarthMasses < 774.0 {
//jupiterRadii = quad_trend(-1.716303E-7, 4.2215568E-4, 0.7900710739, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 318.0, 0.884, 464.0, 0.949, 774.0, 1.014)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 464.0, 0.949, 774.0, 1.014, 1292.0, 1.049)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 464.0, 774.0)
} else if totalEarthMasses < 1292.0 {
//jupiterRadii = quad_trend(-4.896201E-8, 1.6872307E-4, 0.9127403055, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 464.0, 0.949, 774.0, 1.014, 1292.0, 1.049)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.014, 1292.0, 1.049, 2154.0, 1.049)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 774.0, 1292.0)
} else if totalEarthMasses < 2154.0 {
//jupiterRadii = quad_trend(-9.351771E-9, 3.2226204E-5, 1.022974319, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.014, 1292.0, 1.049, 2154.0, 1.049)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.049, 2154.0, 1.049, 3594.0, 1.018)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 1292.0, 2154.0)
} else if totalEarthMasses < 3594.0 {
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.049, 2154.0, 1.049, 3594.0, 1.018)
jupiterRadii2 := PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.049, 3594.0, 1.018)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 2154.0, 3594.0)
} else {
//jupiterRadii = ln_trend(1.513757404, -0.0605540647, totalEarthMasses);
jupiterRadii = PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.049, 3594.0, 1.018)
}
return jupiterRadii
}
func gasRadius4point5Gyr875K(planet *types.Planet) float64 {
coreMassRadii0 := gasRadius4point5Gyr875K0coreMass(planet)
coreMassRadii10 := gasRadius4point5Gyr875K10coreMass(planet)
coreMassRadii25 := gasRadius4point5Gyr875K25coreMass(planet)
coreMassRadii50 := gasRadius4point5Gyr875K50coreMass(planet)
coreMassRadii100 := gasRadius4point5Gyr875K100coreMass(planet)
coreEarthMasses := planet.DustMass * constants.SunMassInEarthMasses
var jupiterRadii float64
if coreEarthMasses <= 10.0 {
jupiterRadii = PlanetRadiusHelper(coreEarthMasses, 0.0, coreMassRadii0, 10.0, coreMassRadii10, 25.0, coreMassRadii25)
} else if coreEarthMasses <= 25.0 {
jupiterRadii1 := PlanetRadiusHelper(coreEarthMasses, 0.0, coreMassRadii0, 10.0, coreMassRadii10, 25.0, coreMassRadii25)
jupiterRadii2 := PlanetRadiusHelper(coreEarthMasses, 10.0, coreMassRadii10, 25.0, coreMassRadii25, 50.0, coreMassRadii50)
jupiterRadii = RangeAdjust(coreEarthMasses, jupiterRadii1, jupiterRadii2, 10.0, 25.0)
} else if coreEarthMasses <= 50.0 {
jupiterRadii1 := PlanetRadiusHelper(coreEarthMasses, 10.0, coreMassRadii10, 25.0, coreMassRadii25, 50.0, coreMassRadii50)
jupiterRadii2 := PlanetRadiusHelper(coreEarthMasses, 25.0, coreMassRadii25, 50.0, coreMassRadii50, 100.0, coreMassRadii100)
jupiterRadii = RangeAdjust(coreEarthMasses, jupiterRadii1, jupiterRadii2, 25.0, 50.0)
} else if coreEarthMasses <= 100.0 {
jupiterRadii1 := PlanetRadiusHelper(coreEarthMasses, 25.0, coreMassRadii25, 50.0, coreMassRadii50, 100.0, coreMassRadii100)
jupiterRadii2 := PlanetRadiusHelper2(coreEarthMasses, 50.0, coreMassRadii50, 100.0, coreMassRadii100)
jupiterRadii = RangeAdjust(coreEarthMasses, jupiterRadii1, jupiterRadii2, 50.0, 100.0)
} else {
jupiterRadii = PlanetRadiusHelper2(coreEarthMasses, 50.0, coreMassRadii50, 100.0, coreMassRadii100)
}
return jupiterRadii
}
func gasRadius4point5Gyr260K0coreMass(planet *types.Planet) float64 {
totalEarthMasses := planet.Mass * constants.SunMassInEarthMasses
var jupiterRadii float64
if totalEarthMasses < 17.0 {
//jupiterRadii = quad_trend(-0.0021984339, 0.0970204354, 0, totalEarthMasses);
jupiterRadii = PlanetRadiusHelper(totalEarthMasses, 0.0, 0.0, 17.0, 1.014, 28.0, 0.993)
} else if totalEarthMasses < 28.0 {
//jupiterRadii = quad_trend(4.6673633E-5, -0.0040094044, 1.068671195, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 0.0, 0.0, 17.0, 1.014, 28.0, 0.993)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 17.0, 1.014, 28.0, 0.993, 46.0, 0.983)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 17.0, 28.0)
} else if totalEarthMasses < 46.0 {
//jupiterRadii = quad_trend(2.9771048E-5, -0.0027586131, 1.0469900666, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 17.0, 1.014, 28.0, 0.993, 46.0, 0.983)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 28.0, 0.993, 46.0, 0.983, 77.0, 1.011)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 28.0, 46.0)
} else if totalEarthMasses < 77.0 {
//jupiterRadii = quad_trend(-1.846094E-6, 0.0011302954, 0.9349127478, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 28.0, 0.993, 46.0, 0.983, 77.0, 1.011)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 46.0, 0.983, 77.0, 1.011, 129.0, 1.05)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 46.0, 77.0)
} else if totalEarthMasses < 129.0 {
//jupiterRadii = quad_trend(-3.412538E-6, 0.0014529828, 0.9193532609, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 46.0, 0.983, 77.0, 1.011, 129.0, 1.05)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 77.0, 1.011, 129.0, 1.05, 215.0, 1.074)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 77.0, 129.0)
} else if totalEarthMasses < 215.0 {
//jupiterRadii = quad_trend(-1.116977E-6, 6.6330976E-4, 0.9830206503, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 77.0, 1.011, 129.0, 1.05, 215.0, 1.074)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 129.0, 1.05, 215.0, 1.074, 318.0, 1.081)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 129.0, 215.0)
} else if totalEarthMasses < 318.0 {
//jupiterRadii = quad_trend(-1.904145E-7, 1.6945211E-4, 1.046369708, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 129.0, 1.05, 215.0, 1.074, 318.0, 1.081)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 215.0, 1.074, 318.0, 1.081, 464.0, 1.084)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 215.0, 318.0)
} else if totalEarthMasses < 464.0 {
//jupiterRadii = quad_trend(4.4576753E-9, 1.7062043E-5, 1.075123492, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 215.0, 1.074, 318.0, 1.081, 464.0, 1.084)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 318.0, 1.081, 464.0, 1.084, 774.0, 1.091)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 318.0, 464.0)
} else if totalEarthMasses < 774.0 {
//jupiterRadii = quad_trend(-1.561369E-8, 4.1910394E-5, 1.067915142, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 318.0, 1.081, 464.0, 1.084, 774.0, 1.091)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.084, 774.0, 1.091, 1292.0, 1.096)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 464.0, 774.0)
} else if totalEarthMasses < 1292.0 {
//jupiterRadii = quad_trend(-2.464816E-8, 6.0575605E-5, 1.058880602, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.084, 774.0, 1.091, 1292.0, 1.096)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.091, 1292.0, 1.096, 2154.0, 1.075)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 774.0, 1292.0)
} else if totalEarthMasses < 2154.0 {
//jupiterRadii = quad_trend(-2.992203E-9, -1.405082E-5, 1.119148433, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.091, 1292.0, 1.096, 2154.0, 1.075)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.096, 2154.0, 1.075, 3594.0, 1.03)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 1292.0, 2154.0)
} else if totalEarthMasses < 3594.0 {
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.096, 2154.0, 1.075, 3594.0, 1.03)
jupiterRadii2 := PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.075, 3594.0, 1.03)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 2154.0, 3594.0)
} else {
//jupiterRadii = ln_trend(1.749647843, -0.0879010616, totalEarthMasses);
jupiterRadii = PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.075, 3594.0, 1.03)
}
return jupiterRadii
}
func gasRadius4point5Gyr260K10coreMass(planet *types.Planet) float64 {
totalEarthMasses := planet.Mass * constants.SunMassInEarthMasses
massRadii10 := RadiusImproved(10.0/constants.SunMassInEarthMasses, planet)
var jupiterRadii float64
if totalEarthMasses < 10.0 {
//jupiterRadii = radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone(), the_planet) / KM_JUPITER_RADIUS;
jupiterRadii = massRadii10
} else if totalEarthMasses < 17.0 {
/*double x[] = {10, 17, 28};
double y[] = {radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone()) / KM_JUPITER_RADIUS, 0.576, 0.738};
double coeff[3];
polynomialfit(3, 3, x, y, coeff);
jupiterRadii = quad_trend(coeff[2], coeff[1], coeff[0], totalEarthMasses);*/
jupiterRadii = PlanetRadiusHelper(totalEarthMasses, 10.0, massRadii10, 17.0, 0.576, 28.0, 0.738)
} else if totalEarthMasses < 28.0 {
//jupiterRadii = quad_trend(-3.028561E-4, 0.0283557994, 0.1814768373, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 10.0, massRadii10, 17.0, 0.576, 28.0, 0.738)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 17.0, 0.576, 28.0, 0.738, 46.0, 0.845)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 17.0, 28.0)
} else if totalEarthMasses < 46.0 {
//jupiterRadii = quad_trend(-6.4699E-5, 0.0107321703, 0.4882232463, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 17.0, 0.576, 28.0, 0.738, 46.0, 0.845)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 28.0, 0.738, 46.0, 0.845, 77.0, 0.931)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 28.0, 46.0)
} else if totalEarthMasses < 77.0 {
//jupiterRadii = quad_trend(-1.813208E-5, 0.0050044396, 0.6531632635, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 28.0, 0.738, 46.0, 0.845, 77.0, 0.931)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 46.0, 0.845, 77.0, 0.931, 129.0, 0.997)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 46.0, 77.0)
} else if totalEarthMasses < 129.0 {
//jupiterRadii = quad_trend(-5.489876E-6, 0.0024001452, 0.7787382943, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 46.0, 0.845, 77.0, 0.931, 129.0, 0.997)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 77.0, 0.931, 129.0, 0.997, 215.0, 1.041)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 77.0, 129.0)
} else if totalEarthMasses < 215.0 {
//jupiterRadii = quad_trend(-1.833753E-6, 0.001142439, 0.8801408538, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 77.0, 0.931, 129.0, 0.997, 215.0, 1.041)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 129.0, 0.997, 215.0, 1.041, 318.0, 1.058)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 129.0, 215.0)
} else if totalEarthMasses < 318.0 {
//jupiterRadii = quad_trend(-3.877727E-7, 3.7173137E-4, 0.9790025462, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 129.0, 0.997, 215.0, 1.041, 318.0, 1.058)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 215.0, 1.041, 318.0, 1.058, 464.0, 1.068)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 215.0, 318.0)
} else if totalEarthMasses < 464.0 {
//jupiterRadii = quad_trend(-5.116636E-8, 1.0850524E-4, 1.028669479, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 215.0, 1.041, 318.0, 1.058, 464.0, 1.068)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 318.0, 1.058, 464.0, 1.068, 774.0, 1.082)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 318.0, 464.0)
} else if totalEarthMasses < 774.0 {
//jupiterRadii = quad_trend(-3.589043E-8, 8.9593641E-5, 1.034155616, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 318.0, 1.058, 464.0, 1.068, 774.0, 1.082)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.068, 774.0, 1.082, 1292.0, 1.09)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 464.0, 774.0)
} else if totalEarthMasses < 1292.0 {
//jupiterRadii = quad_trend(-2.632296E-8, 6.9827253E-5, 1.043723161, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.068, 774.0, 1.082, 1292.0, 1.09)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.082, 1292.0, 1.09, 2154.0, 1.072)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 774.0, 1292.0)
} else if totalEarthMasses < 2154.0 {
//jupiterRadii = quad_trend(-4.202383E-9, -6.40026E-6, 1.105284022, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.082, 1292.0, 1.09, 2154.0, 1.072)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.09, 2154.0, 1.072, 3594.0, 1.028)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 1292.0, 2154.0)
} else if totalEarthMasses < 3594.0 {
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.09, 2154.0, 1.072, 3594.0, 1.028)
jupiterRadii2 := PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.072, 3594.0, 1.028)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 2154.0, 3594.0)
} else {
//jupiterRadii = ln_trend(1.731655669, -0.0859477047, totalEarthMasses);
jupiterRadii = PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.072, 3594.0, 1.028)
}
return jupiterRadii
}
func gasRadius4point5Gyr260K25coreMass(planet *types.Planet) float64 {
totalEarthMasses := planet.Mass * constants.SunMassInEarthMasses
massRadii25 := RadiusImproved(25.0/constants.SunMassInEarthMasses, planet)
var jupiterRadii float64
if totalEarthMasses < 25.0 {
//jupiterRadii = radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone(), the_planet) / KM_JUPITER_RADIUS;
jupiterRadii = massRadii25
} else if totalEarthMasses < 28.0 {
/*double x[] = {25, 28, 46};
double y[] = {radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone()) / KM_JUPITER_RADIUS, 0.400, 0.666};
double coeff[3];
polynomialfit(3, 3, x, y, coeff);
jupiterRadii = quad_trend(coeff[2], coeff[1], coeff[0], totalEarthMasses);*/
jupiterRadii = PlanetRadiusHelper(totalEarthMasses, 25.0, massRadii25, 28.0, 0.4, 46.0, 0.666)
} else if totalEarthMasses < 46.0 {
//jupiterRadii = quad_trend(-2.002048E-4, 0.0295929339, -0.2716415771, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 25.0, massRadii25, 28.0, 0.4, 46.0, 0.666)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 28.0, 0.4, 46.0, 0.666, 77.0, 0.82)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 28.0, 46.0)
} else if totalEarthMasses < 77.0 {
//jupiterRadii = quad_trend(-3.575593E-5, 0.0093657209, 0.3108363778, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 28.0, 0.4, 46.0, 0.666, 77.0, 0.82)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 46.0, 0.666, 77.0, 0.82, 129.0, 0.924)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 46.0, 77.0)
} else if totalEarthMasses < 129.0 {
//jupiterRadii = quad_trend(-8.6788E-6, 0.0037878328, 0.5797934783, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 46.0, 0.666, 77.0, 0.82, 129.0, 0.924)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 77.0, 0.82, 129.0, 0.924, 215.0, 0.993)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 77.0, 129.0)
} else if totalEarthMasses < 215.0 {
//jupiterRadii = quad_trend(-2.549932E-6, 0.0016795023, 0.7497776237, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 77.0, 0.82, 129.0, 0.924, 215.0, 0.993)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 129.0, 0.924, 215.0, 0.993, 318.0, 1.026)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 129.0, 215.0)
} else if totalEarthMasses < 318.0 {
//jupiterRadii = quad_trend(-7.365544E-7, 7.1297185E-4, 0.8737582798, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 129.0, 0.924, 215.0, 0.993, 318.0, 1.026)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 215.0, 0.993, 318.0, 1.026, 464.0, 1.046)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 215.0, 318.0)
} else if totalEarthMasses < 464.0 {
//jupiterRadii = quad_trend(-1.377034E-7, 2.4467036E-4, 0.9621199433, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 215.0, 0.993, 318.0, 1.026, 464.0, 1.046)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 318.0, 1.026, 464.0, 1.046, 774.0, 1.069)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 318.0, 464.0)
} else if totalEarthMasses < 774.0 {
//jupiterRadii = quad_trend(-5.929592E-8, 1.476019E-4, 0.9902788934, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 318.0, 1.026, 464.0, 1.046, 774.0, 1.069)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.046, 774.0, 1.069, 1292.0, 1.082)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 464.0, 774.0)
} else if totalEarthMasses < 1292.0 {
//jupiterRadii = quad_trend(-3.079559E-8, 8.8720219E-5, 1.018779451, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.046, 774.0, 1.069, 1292.0, 1.082)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.069, 1292.0, 1.082, 2154.0, 1.067)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 774.0, 1292.0)
} else if totalEarthMasses < 2154.0 {
//jupiterRadii = quad_trend(-5.110893E-9, 2.1074347E-7, 1.090259148, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.069, 1292.0, 1.082, 2154.0, 1.067)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.082, 2154.0, 1.067, 3594.0, 1.025)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 1292.0, 2154.0)
} else if totalEarthMasses < 3594.0 {
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.082, 2154.0, 1.067, 3594.0, 1.025)
jupiterRadii2 := PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.067, 3594.0, 1.025)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 2154.0, 3594.0)
} else {
//jupiterRadii = ln_trend(1.69667132, -0.0820409908, totalEarthMasses);
jupiterRadii = PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.067, 3594.0, 1.025)
}
return jupiterRadii
}
func gasRadius4point5Gyr260K50coreMass(planet *types.Planet) float64 {
totalEarthMasses := planet.Mass * constants.SunMassInEarthMasses
massRadii50 := RadiusImproved(50.0/constants.SunMassInEarthMasses, planet)
var jupiterRadii float64
if totalEarthMasses < 50.0 {
//jupiterRadii = radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone(), the_planet) / KM_JUPITER_RADIUS;
jupiterRadii = massRadii50
} else if totalEarthMasses < 77 {
/*double x[] = {50, 77, 129};
double y[] = {radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone()) / KM_JUPITER_RADIUS, 0.633, 0.810};
double coeff[3];
polynomialfit(3, 3, x, y, coeff);
jupiterRadii = quad_trend(coeff[2], coeff[1], coeff[0], totalEarthMasses);*/
jupiterRadii = PlanetRadiusHelper(totalEarthMasses, 50.0, massRadii50, 77.0, 0.633, 129.0, 0.81)
} else if totalEarthMasses < 129.0 {
//jupiterRadii = quad_trend(-1.539693E-5, 0.0065756138, 0.2179661371, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 50.0, massRadii50, 77.0, 0.633, 129.0, 0.81)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 77.0, 0.633, 129.0, 0.81, 215.0, 0.92)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 77.0, 129.0)
} else if totalEarthMasses < 215.0 {
//jupiterRadii = quad_trend(-3.99364E-6, 0.0026528819, 0.5342364001, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 77.0, 0.633, 129.0, 0.81, 215.0, 0.92)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 129.0, 0.81, 215.0, 0.92, 318.0, 0.974)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 129.0, 215.0)
} else if totalEarthMasses < 318.0 {
//jupiterRadii = quad_trend(-1.08774E-6, 0.0011040371, 0.7329127896, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 129.0, 0.81, 215.0, 0.92, 318.0, 0.974)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 215.0, 0.92, 318.0, 0.974, 464.0, 1.011)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 215.0, 318.0)
} else if totalEarthMasses < 464.0 {
//jupiterRadii = quad_trend(-2.940128E-7, 4.8334264E-4, 0.8500287881, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 215.0, 0.92, 318.0, 0.974, 464.0, 1.011)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 318.0, 0.974, 464.0, 1.011, 774.0, 1.048)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 318.0, 464.0)
} else if totalEarthMasses < 774.0 {
//jupiterRadii = quad_trend(-9.751787E-8, 2.4008197E-4, 0.9205971755, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 318.0, 0.974, 464.0, 1.011, 774.0, 1.048)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.011, 774.0, 1.048, 1292.0, 1.068)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 464.0, 774.0)
} else if totalEarthMasses < 1292.0 {
//jupiterRadii = quad_trend(-3.638476E-8, 1.1378095E-4, 0.9817307806, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.011, 774.0, 1.048, 1292.0, 1.068)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.048, 1292.0, 1.068, 2154.0, 1.058)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 774.0, 1292.0)
} else if totalEarthMasses < 2154.0 {
//jupiterRadii = quad_trend(-6.423962E-9, 1.0536045E-5, 1.065110718, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.048, 1292.0, 1.068, 2154.0, 1.058)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.068, 2154.0, 1.058, 3594.0, 1.02)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 1292.0, 2154.0)
} else if totalEarthMasses < 3594.0 {
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.068, 2154.0, 1.058, 3594.0, 1.02)
jupiterRadii2 := PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.058, 3594.0, 1.02)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 2154.0, 3594.0)
} else {
//jupiterRadii = ln_trend(1.627702623, -0.0742275631, totalEarthMasses);
jupiterRadii = PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.058, 3594.0, 1.02)
}
return jupiterRadii
}
func gasRadius4point5Gyr260K100coreMass(planet *types.Planet) float64 {
totalEarthMasses := planet.Mass * constants.SunMassInEarthMasses
massRadii100 := RadiusImproved(100.0/constants.SunMassInEarthMasses, planet)
var jupiterRadii float64
if totalEarthMasses < 100.0 {
//jupiterRadii = radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone(), the_planet) / KM_JUPITER_RADIUS;
jupiterRadii = massRadii100
} else if totalEarthMasses < 129.0 {
/*double x[] = {100, 129, 215};
double y[] = {radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone()) / KM_JUPITER_RADIUS, 0.578, 0.782};
double coeff[3];
polynomialfit(3, 3, x, y, coeff);
jupiterRadii = quad_trend(coeff[2], coeff[1], coeff[0], totalEarthMasses);*/
jupiterRadii = PlanetRadiusHelper(totalEarthMasses, 100.0, massRadii100, 129.0, 0.578, 215.0, 0.782)
} else if totalEarthMasses < 215.0 {
//jupiterRadii = quad_trend(-7.619334E-6, 0.004993144, 0.0606777624, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 100.0, massRadii100, 129.0, 0.578, 215.0, 0.782)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 129.0, 0.578, 215.0, 0.782, 318.0, 0.878)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 129.0, 215.0)
} else if totalEarthMasses < 318.0 {
//jupiterRadii = quad_trend(-1.982661E-6, 0.0019887973, 0.4460570955, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 129.0, 0.578, 215.0, 0.782, 318.0, 0.878)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 215.0, 0.782, 318.0, 0.878, 464.0, 0.942)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 215.0, 318.0)
} else if totalEarthMasses < 464.0 {
//jupiterRadii = quad_trend(-5.014885E-7, 8.3052015E-4, 0.6646071121, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 215.0, 0.782, 318.0, 0.878, 464.0, 0.942)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 318.0, 0.878, 464.0, 0.942, 774.0, 1.007)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 318.0, 464.0)
} else if totalEarthMasses < 774.0 {
//jupiterRadii = quad_trend(-1.739619E-7, 4.250421E-4, 0.7822337397, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 318.0, 0.878, 464.0, 0.942, 774.0, 1.007)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 464.0, 0.942, 774.0, 1.007, 1292.0, 1.041)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 464.0, 774.0)
} else if totalEarthMasses < 1292.0 {
//jupiterRadii = quad_trend(-4.756309E-8, 1.6390241E-4, 0.9086334397, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 464.0, 0.942, 774.0, 1.007, 1292.0, 1.041)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.007, 1292.0, 1.041, 2154.0, 1.041)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 774.0, 1292.0)
} else if totalEarthMasses < 2154.0 {
//jupiterRadii = quad_trend(-9.351771E-9, 3.2226204E-5, 1.014974319, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.007, 1292.0, 1.041, 2154.0, 1.041)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.041, 2154.0, 1.041, 3594.0, 1.01)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 1292.0, 2154.0)
} else if totalEarthMasses < 3594.0 {
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.041, 2154.0, 1.041, 3594.0, 1.01)
jupiterRadii2 := PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.041, 3594.0, 1.01)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 2154.0, 3594.0)
} else {
//jupiterRadii = ln_trend(1.505757403, -0.0605540647, totalEarthMasses);
jupiterRadii = PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.041, 3594.0, 1.01)
}
return jupiterRadii
}
func gasRadius4point5Gyr260K(planet *types.Planet) float64 {
coreMassRadii0 := gasRadius4point5Gyr260K0coreMass(planet)
coreMassRadii10 := gasRadius4point5Gyr260K10coreMass(planet)
coreMassRadii25 := gasRadius4point5Gyr260K25coreMass(planet)
coreMassRadii50 := gasRadius4point5Gyr260K50coreMass(planet)
coreMassRadii100 := gasRadius4point5Gyr260K100coreMass(planet)
coreEarthMasses := planet.DustMass * constants.SunMassInEarthMasses
var jupiterRadii float64
if coreEarthMasses <= 10.0 {
jupiterRadii = PlanetRadiusHelper(coreEarthMasses, 0.0, coreMassRadii0, 10.0, coreMassRadii10, 25.0, coreMassRadii25)
} else if coreEarthMasses <= 25.0 {
jupiterRadii1 := PlanetRadiusHelper(coreEarthMasses, 0.0, coreMassRadii0, 10.0, coreMassRadii10, 25.0, coreMassRadii25)
jupiterRadii2 := PlanetRadiusHelper(coreEarthMasses, 10.0, coreMassRadii10, 25.0, coreMassRadii25, 50.0, coreMassRadii50)
jupiterRadii = RangeAdjust(coreEarthMasses, jupiterRadii1, jupiterRadii2, 10.0, 25.0)
} else if coreEarthMasses <= 50.0 {
jupiterRadii1 := PlanetRadiusHelper(coreEarthMasses, 10.0, coreMassRadii10, 25.0, coreMassRadii25, 50.0, coreMassRadii50)
jupiterRadii2 := PlanetRadiusHelper(coreEarthMasses, 25.0, coreMassRadii25, 50.0, coreMassRadii50, 100.0, coreMassRadii100)
jupiterRadii = RangeAdjust(coreEarthMasses, jupiterRadii1, jupiterRadii2, 25.0, 50.0)
} else if coreEarthMasses <= 100.0 {
jupiterRadii1 := PlanetRadiusHelper(coreEarthMasses, 25.0, coreMassRadii25, 50.0, coreMassRadii50, 100.0, coreMassRadii100)
jupiterRadii2 := PlanetRadiusHelper2(coreEarthMasses, 50.0, coreMassRadii50, 100.0, coreMassRadii100)
jupiterRadii = RangeAdjust(coreEarthMasses, jupiterRadii1, jupiterRadii2, 50.0, 100.0)
} else {
jupiterRadii = PlanetRadiusHelper2(coreEarthMasses, 50.0, coreMassRadii50, 100.0, coreMassRadii100)
}
return jupiterRadii
}
func gasRadius4point5Gyr78K0coreMass(planet *types.Planet) float64 {
totalEarthMasses := planet.Mass * constants.SunMassInEarthMasses
var jupiterRadii float64
if totalEarthMasses < 17.0 {
//jupiterRadii = quad_trend(-0.0015823147, 0.0738405271, 0, totalEarthMasses);
jupiterRadii = PlanetRadiusHelper(totalEarthMasses, 0.0, 0.0, 17.0, 0.798, 28.0, 0.827)
} else if totalEarthMasses < 28.0 {
//jupiterRadii = quad_trend(-1.619645E-5, 0.0033652038, 0.7454723093, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 0.0, 0.0, 17.0, 0.798, 28.0, 0.827)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 17.0, 0.798, 28.0, 0.827, 46.0, 0.866)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 17.0, 28.0)
} else if totalEarthMasses < 46.0 {
//jupiterRadii = quad_trend(-1.327628E-5, 0.0031491113, 0.7492334869, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 17.0, 0.798, 28.0, 0.827, 46.0, 0.866)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 28.0, 0.827, 46.0, 0.866, 77.0, 0.913)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 28.0, 46.0)
} else if totalEarthMasses < 77.0 {
//jupiterRadii = quad_trend(-8.07199E-6, 0.0025089838, 0.7676670752, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 28.0, 0.827, 46.0, 0.866, 77.0, 0.913)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 46.0, 0.866, 77.0, 0.913, 129.0, 0.957)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 46.0, 77.0)
} else if totalEarthMasses < 129.0 {
//jupiterRadii = quad_trend(-3.013922E-6, 0.0014670219, 0.8179088629, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 46.0, 0.866, 77.0, 0.913, 129.0, 0.957)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 77.0, 0.913, 129.0, 0.957, 215.0, 0.994)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 77.0, 129.0)
} else if totalEarthMasses < 215.0 {
//jupiterRadii = quad_trend(-9.921382E-7, 7.7152808E-4, 0.8739830482, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 77.0, 0.913, 129.0, 0.957, 215.0, 0.994)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 129.0, 0.957, 215.0, 0.994, 318.0, 1.019)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 129.0, 215.0)
} else if totalEarthMasses < 318.0 {
//jupiterRadii = quad_trend(-4.796417E-7, 4.9836746E-4, 0.9090224331, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 129.0, 0.957, 215.0, 0.994, 318.0, 1.019)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 215.0, 0.994, 318.0, 1.019, 464.0, 1.037)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 215.0, 318.0)
} else if totalEarthMasses < 464.0 {
//jupiterRadii = quad_trend(-1.359591E-7, 2.2960769E-4, 0.9597334837, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 215.0, 0.994, 318.0, 1.019, 464.0, 1.037)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 318.0, 1.019, 464.0, 1.037, 774.0, 1.056)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 318.0, 464.0)
} else if totalEarthMasses < 774.0 {
//jupiterRadii = quad_trend(-6.003298E-8, 1.3561116E-4, 0.9870012845, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 318.0, 1.019, 464.0, 1.037, 774.0, 1.056)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.037, 774.0, 1.056, 1292.0, 1.062)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 464.0, 774.0)
} else if totalEarthMasses < 1292.0 {
//jupiterRadii = quad_trend(-1.427802E-8, 4.1081391E-5, 1.032756619, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.037, 774.0, 1.056, 1292.0, 1.062)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.056, 1292.0, 1.062, 2154.0, 1.055)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 774.0, 1292.0)
} else if totalEarthMasses < 2154.0 {
//jupiterRadii = quad_trend(-6.125792E-9, 1.2988829E-5, 1.055443997, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.056, 1292.0, 1.062, 2154.0, 1.055)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.062, 2154.0, 1.055, 3594.0, 1.023)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 1292.0, 2154.0)
} else if totalEarthMasses < 3594.0 {
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.062, 2154.0, 1.055, 3594.0, 1.023)
jupiterRadii2 := PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.055, 3594.0, 1.023)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 2154.0, 3594.0)
} else {
//jupiterRadii = ln_trend(1.534749577, -0.0625074216, totalEarthMasses);
jupiterRadii = PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.055, 3594.0, 1.023)
}
return jupiterRadii
}
func gasRadius4point5Gyr78K10coreMass(planet *types.Planet) float64 {
totalEarthMasses := planet.Mass * constants.SunMassInEarthMasses
massRadii10 := RadiusImproved(10.0/constants.SunMassInEarthMasses, planet)
var jupiterRadii float64
if totalEarthMasses < 10.0 {
//jupiterRadii = radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone(), the_planet) / KM_JUPITER_RADIUS;
jupiterRadii = massRadii10
} else if totalEarthMasses < 17.0 {
/*double x[] = {10, 17, 28};
double y[] = {radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone()) / KM_JUPITER_RADIUS, 0.508, 0.653};
double coeff[3];
polynomialfit(3, 3, x, y, coeff);
jupiterRadii = quad_trend(coeff[2], coeff[1], coeff[0], totalEarthMasses);*/
jupiterRadii = PlanetRadiusHelper(totalEarthMasses, 10.0, massRadii10, 17.0, 0.508, 28.0, 0.653)
} else if totalEarthMasses < 28.0 {
//jupiterRadii = quad_trend(-2.514803E-4, 0.0244984326, 0.1642044584, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 10.0, massRadii10, 17.0, 0.508, 28.0, 0.653)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 17.0, 0.508, 28.0, 0.653, 46.0, 0.759)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 17.0, 28.0)
} else if totalEarthMasses < 46.0 {
//jupiterRadii = quad_trend(-6.422354E-5, 0.0106414308, 0.405391193, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 17.0, 0.508, 28.0, 0.653, 46.0, 0.759)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 28.0, 0.653, 46.0, 0.759, 77.0, 0.844)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 28.0, 46.0)
} else if totalEarthMasses < 77.0 {
//jupiterRadii = quad_trend(-1.751173E-5, 0.0048958788, 0.5708444049, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 28.0, 0.653, 46.0, 0.759, 77.0, 0.844)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 46.0, 0.759, 77.0, 0.844, 129.0, 0.911)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 46.0, 77.0)
} else if totalEarthMasses < 129.0 {
//jupiterRadii = quad_trend(-4.702367E-6, 0.0022571492, 0.6980798495, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 46.0, 0.759, 77.0, 0.844, 129.0, 0.911)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 77.0, 0.844, 129.0, 0.911, 215.0, 0.966)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 77.0, 129.0)
} else if totalEarthMasses < 215.0 {
//jupiterRadii = quad_trend(-1.688606E-6, 0.0012204153, 0.7816665126, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 77.0, 0.844, 129.0, 0.911, 215.0, 0.966)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 129.0, 0.911, 215.0, 0.966, 318.0, 0.999)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 129.0, 215.0)
} else if totalEarthMasses < 318.0 {
//jupiterRadii = quad_trend(-5.99018E-7, 6.3966492E-4, 0.8561616467, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 129.0, 0.911, 215.0, 0.966, 318.0, 0.999)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 215.0, 0.966, 318.0, 0.999, 464.0, 1.024)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 215.0, 318.0)
} else if totalEarthMasses < 464.0 {
//jupiterRadii = quad_trend(-2.057314E-7, 3.3211484E-4, 0.9141918645, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 215.0, 0.966, 318.0, 0.999, 464.0, 1.024)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 318.0, 0.999, 464.0, 1.024, 774.0, 1.048)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 318.0, 464.0)
} else if totalEarthMasses < 774.0 {
//jupiterRadii = quad_trend(-7.251792E-8, 1.6719654E-4, 0.9620336238, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 318.0, 0.999, 464.0, 1.024, 774.0, 1.048)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.024, 774.0, 1.048, 1292.0, 1.057)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 464.0, 774.0)
} else if totalEarthMasses < 1292.0 {
//jupiterRadii = quad_trend(-1.679346E-8, 5.2069816E-5, 1.017758524, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.024, 774.0, 1.048, 1292.0, 1.057)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.048, 1292.0, 1.057, 2154.0, 1.052)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 774.0, 1292.0)
} else if totalEarthMasses < 2154.0 {
//jupiterRadii = quad_trend(-6.832022E-9, 1.7742682E-5, 1.045480902, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.048, 1292.0, 1.057, 2154.0, 1.052)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.057, 2154.0, 1.052, 3594.0, 1.021)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 1292.0, 2154.0)
} else if totalEarthMasses < 3594.0 {
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.057, 2154.0, 1.052, 3594.0, 1.021)
jupiterRadii2 := PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.052, 3594.0, 1.021)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 2154.0, 3594.0)
} else {
//jupiterRadii = ln_trend(1.516757403, -0.0605540647, totalEarthMasses);
jupiterRadii = PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.052, 3594.0, 1.021)
}
return jupiterRadii
}
func gasRadius4point5Gyr78K25coreMass(planet *types.Planet) float64 {
totalEarthMasses := planet.Mass * constants.SunMassInEarthMasses
massRadii25 := RadiusImproved(25.0/constants.SunMassInEarthMasses, planet)
var jupiterRadii float64
if totalEarthMasses < 25.0 {
//jupiterRadii = radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone(), the_planet) / KM_JUPITER_RADIUS;
jupiterRadii = massRadii25
} else if totalEarthMasses < 28.0 {
/*double x[] = {25, 28, 46};
double y[] = {radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone()) / KM_JUPITER_RADIUS, 0.378, 0.611};
double coeff[3];
polynomialfit(3, 3, x, y, coeff);
jupiterRadii = quad_trend(coeff[2], coeff[1], coeff[0], totalEarthMasses);*/
jupiterRadii = PlanetRadiusHelper(totalEarthMasses, 25.0, massRadii25, 28.0, 0.378, 46.0, 0.611)
} else if totalEarthMasses < 46.0 {
//jupiterRadii = quad_trend(-1.726648E-4, 0.025721637, -0.2068366615, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 25.0, massRadii25, 28.0, 0.378, 46.0, 0.611)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 28.0, 0.378, 46.0, 0.611, 77.0, 0.75)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 28.0, 46.0)
} else if totalEarthMasses < 77.0 {
//jupiterRadii = quad_trend(-3.108464E-5, 0.0083072812, 0.2946401537, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 28.0, 0.378, 46.0, 0.611, 77.0, 0.75)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 46.0, 0.611, 77.0, 0.75, 129.0, 0.849)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 46.0, 77.0)
} else if totalEarthMasses < 129.0 {
//jupiterRadii = quad_trend(-7.307952E-6, 0.0034092842, 0.5308139632, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 46.0, 0.611, 77.0, 0.75, 129.0, 0.849)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 77.0, 0.75, 129.0, 0.849, 215.0, 0.926)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 77.0, 129.0)
} else if totalEarthMasses < 215.0 {
//jupiterRadii = quad_trend(-2.374322E-6, 0.0017121157, 0.6676481738, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 77.0, 0.75, 129.0, 0.849, 215.0, 0.926)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 129.0, 0.849, 215.0, 0.926, 318.0, 0.972)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 129.0, 215.0)
} else if totalEarthMasses < 318.0 {
//jupiterRadii = quad_trend(-5.608282E-9, 4.4959116E-4, 0.8295971443, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 129.0, 0.849, 215.0, 0.926, 318.0, 0.972)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 215.0, 0.926, 318.0, 0.972, 464.0, 1.037)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 215.0, 318.0)
} else if totalEarthMasses < 464.0 {
//jupiterRadii = quad_trend(-9.904761E-7, 0.0012197578, 0.684277931, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 215.0, 0.926, 318.0, 0.972, 464.0, 1.037)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 318.0, 0.972, 464.0, 1.037, 774.0, 1.035)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 318.0, 464.0)
} else if totalEarthMasses < 774.0 {
//jupiterRadii = quad_trend(4.2764664E-8, -5.939427E-5, 1.055351879, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 318.0, 0.972, 464.0, 1.037, 774.0, 1.035)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.037, 774.0, 1.035, 1292.0, 1.05)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 464.0, 774.0)
} else if totalEarthMasses < 1292.0 {
//jupiterRadii = quad_trend(-2.350566E-8, 7.7520217E-5, 0.989081027, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 464.0, 1.037, 774.0, 1.035, 1292.0, 1.05)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.035, 1292.0, 1.05, 2154.0, 1.047)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 774.0, 1292.0)
} else if totalEarthMasses < 2154.0 {
//jupiterRadii = quad_trend(-7.236581E-9, 2.1456981E-5, 1.034357345, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.035, 1292.0, 1.05, 2154.0, 1.047)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.05, 2154.0, 1.047, 3594.0, 1.018)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 1292.0, 2154.0)
} else if totalEarthMasses < 3594.0 {
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.05, 2154.0, 1.047, 3594.0, 1.018)
jupiterRadii2 := PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.047, 3594.0, 1.018)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 2154.0, 3594.0)
} else {
//jupiterRadii = ln_trend(1.481773054, -0.0566473508, totalEarthMasses);
jupiterRadii = PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.047, 3594.0, 1.018)
}
return jupiterRadii
}
func gasRadius4point5Gyr78K50coreMass(planet *types.Planet) float64 {
totalEarthMasses := planet.Mass * constants.SunMassInEarthMasses
massRadii50 := RadiusImproved(50.0/constants.SunMassInEarthMasses, planet)
var jupiterRadii float64
if totalEarthMasses < 50.0 {
//jupiterRadii = radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone(), the_planet) / KM_JUPITER_RADIUS;
jupiterRadii = massRadii50
} else if totalEarthMasses < 77.0 {
/*double x[] = {50, 77, 129};
double y[] = {radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone()) / KM_JUPITER_RADIUS, 0.594, 0.754};
double coeff[3];
polynomialfit(3, 3, x, y, coeff);
jupiterRadii = quad_trend(coeff[2], coeff[1], coeff[0], totalEarthMasses);*/
jupiterRadii = PlanetRadiusHelper(totalEarthMasses, 50.0, massRadii50, 77.0, 0.594, 129.0, 0.754)
} else if totalEarthMasses < 129.0 {
//jupiterRadii = quad_trend(-1.294366E-5, 0.0057433175, 0.2285075251, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 50.0, massRadii50, 77.0, 0.594, 129.0, 0.754)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 77.0, 0.594, 129.0, 0.754, 215.0, 0.865)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 77.0, 129.0)
} else if totalEarthMasses < 215.0 {
//jupiterRadii = quad_trend(-3.69558E-6, 0.0025619773, 0.4850030821, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 77.0, 0.594, 129.0, 0.754, 215.0, 0.865)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 129.0, 0.754, 215.0, 0.865, 318.0, 0.926)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 129.0, 215.0)
} else if totalEarthMasses < 318.0 {
//jupiterRadii = quad_trend(-1.085603E-6, 0.0011708593, 0.6634472108, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 129.0, 0.754, 215.0, 0.865, 318.0, 0.926)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 215.0, 0.865, 318.0, 0.926, 464.0, 0.973)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 215.0, 318.0)
} else if totalEarthMasses < 464.0 {
//jupiterRadii = quad_trend(-4.088464E-7, 6.4163566E-4, 0.7633040398, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 215.0, 0.865, 318.0, 0.926, 464.0, 0.973)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 318.0, 0.926, 464.0, 0.973, 774.0, 1.015)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 318.0, 464.0)
} else if totalEarthMasses < 774.0 {
//jupiterRadii = quad_trend(-1.123343E-7, 2.7455378E-4, 0.8697921805, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 318.0, 0.926, 464.0, 0.973, 774.0, 1.015)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 464.0, 0.973, 774.0, 1.015, 1292.0, 1.037)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 464.0, 774.0)
} else if totalEarthMasses < 1292.0 {
//jupiterRadii = quad_trend(-2.909482E-8, 1.0258095E-4, 0.9530323566, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 464.0, 0.973, 774.0, 1.015, 1292.0, 1.037)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.015, 1292.0, 1.037, 2154.0, 1.039)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 774.0, 1292.0)
} else if totalEarthMasses < 2154.0 {
//jupiterRadii = quad_trend(-8.851321E-9, 3.2821838E-5, 1.009369377, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 774.0, 1.015, 1292.0, 1.037, 2154.0, 1.039)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.037, 2154.0, 1.039, 3594.0, 1.013)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 1292.0, 2154.0)
} else if totalEarthMasses < 3594.0 {
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.037, 2154.0, 1.039, 3594.0, 1.013)
jupiterRadii2 := PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.039, 3594.0, 1.013)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 2154.0, 3594.0)
} else {
//jupiterRadii = ln_trend(1.428796532, -0.05078728, totalEarthMasses);
jupiterRadii = PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.039, 3594.0, 1.013)
}
return jupiterRadii
}
func gasRadius4point5Gyr78K100coreMass(planet *types.Planet) float64 {
totalEarthMasses := planet.Mass * constants.SunMassInEarthMasses
massRadii100 := RadiusImproved(100.0/constants.SunMassInEarthMasses, planet)
var jupiterRadii float64
if totalEarthMasses < 100.0 {
//jupiterRadii = radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone(), the_planet) / KM_JUPITER_RADIUS;
jupiterRadii = massRadii100
} else if totalEarthMasses < 129.0 {
/*double x[] = {100, 129, 215};
double y[] = {radius_improved(the_planet->getMass(), the_planet->getImf(), the_planet->getRmf(), the_planet->getCmf(), the_planet->getGasGiant(), the_planet->getOrbitZone()) / KM_JUPITER_RADIUS, 0.558, 0.746};
double coeff[3];
polynomialfit(3, 3, x, y, coeff);
jupiterRadii = quad_trend(coeff[2], coeff[1], coeff[0], totalEarthMasses);*/
jupiterRadii = PlanetRadiusHelper(totalEarthMasses, 100.0, massRadii100, 129.0, 0.558, 215.0, 0.746)
} else if totalEarthMasses < 215.0 {
//jupiterRadii = quad_trend(-6.634961E-6, 0.0044684732, 0.0919793497, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 100.0, massRadii100, 129.0, 0.558, 215.0, 0.746)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 129.0, 0.558, 215.0, 0.746, 318.0, 0.842)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 129.0, 215.0)
} else if totalEarthMasses < 318.0 {
//jupiterRadii = quad_trend(-1.845125E-6, 0.0019154904, 0.4194604624, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 129.0, 0.558, 215.0, 0.746, 318.0, 0.842)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 215.0, 0.746, 318.0, 0.842, 464.0, 0.911)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 215.0, 318.0)
} else if totalEarthMasses < 464.0 {
//jupiterRadii = quad_trend(-5.765906E-7, 9.234966E-4, 0.6066352304, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 215.0, 0.746, 318.0, 0.842, 464.0, 0.911)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 318.0, 0.842, 464.0, 0.911, 774.0, 0.976)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 318.0, 464.0)
} else if totalEarthMasses < 774.0 {
//jupiterRadii = quad_trend(-1.692987E-7, 4.1926925E-4, 0.7529084081, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 318.0, 0.842, 464.0, 0.911, 774.0, 0.976)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 464.0, 0.911, 774.0, 0.976, 1292.0, 1.012)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 464.0, 774.0)
} else if totalEarthMasses < 1292.0 {
//jupiterRadii = quad_trend(-4.11138E-8, 1.5443919E-4, 0.881094362, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 464.0, 0.911, 774.0, 0.976, 1292.0, 1.012)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 774.0, 0.976, 1292.0, 1.012, 2154.0, 1.023)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 774.0, 1292.0)
} else if totalEarthMasses < 2154.0 {
//jupiterRadii = quad_trend(-1.127518E-8, 5.1615293E-5, 0.9641342947, totalEarthMasses);
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 774.0, 0.976, 1292.0, 1.012, 2154.0, 1.023)
jupiterRadii2 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.012, 2154.0, 1.023, 3594.0, 1.004)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 1292.0, 2154.0)
} else if totalEarthMasses < 3594.0 {
jupiterRadii1 := PlanetRadiusHelper(totalEarthMasses, 1292.0, 1.012, 2154.0, 1.023, 3594.0, 1.004)
jupiterRadii2 := PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.023, 3594.0, 1.004)
jupiterRadii = RangeAdjust(totalEarthMasses, jupiterRadii1, jupiterRadii2, 2154.0, 3594.0)
} else {
//jupiterRadii = ln_trend(1.307851312, -0.0371137816, totalEarthMasses);
jupiterRadii = PlanetRadiusHelper2(totalEarthMasses, 2154.0, 1.023, 3594.0, 1.004)
}
return jupiterRadii
}
func gasRadius4point5Gyr78K(planet *types.Planet) float64 {
coreMassRadii0 := gasRadius4point5Gyr78K0coreMass(planet)
coreMassRadii10 := gasRadius4point5Gyr78K10coreMass(planet)
coreMassRadii25 := gasRadius4point5Gyr78K25coreMass(planet)
coreMassRadii50 := gasRadius4point5Gyr78K50coreMass(planet)
coreMassRadii100 := gasRadius4point5Gyr78K100coreMass(planet)
coreEarthMasses := planet.DustMass * constants.SunMassInEarthMasses
var jupiterRadii float64
if coreEarthMasses <= 10.0 {
jupiterRadii = PlanetRadiusHelper(coreEarthMasses, 0.0, coreMassRadii0, 10.0, coreMassRadii10, 25.0, coreMassRadii25)
} else if coreEarthMasses <= 25.0 {
jupiterRadii1 := PlanetRadiusHelper(coreEarthMasses, 0.0, coreMassRadii0, 10.0, coreMassRadii10, 25.0, coreMassRadii25)
jupiterRadii2 := PlanetRadiusHelper(coreEarthMasses, 10.0, coreMassRadii10, 25.0, coreMassRadii25, 50.0, coreMassRadii50)
jupiterRadii = RangeAdjust(coreEarthMasses, jupiterRadii1, jupiterRadii2, 10.0, 25.0)
} else if coreEarthMasses <= 50.0 {
jupiterRadii1 := PlanetRadiusHelper(coreEarthMasses, 10.0, coreMassRadii10, 25.0, coreMassRadii25, 50.0, coreMassRadii50)
jupiterRadii2 := PlanetRadiusHelper(coreEarthMasses, 25.0, coreMassRadii25, 50.0, coreMassRadii50, 100.0, coreMassRadii100)
jupiterRadii = RangeAdjust(coreEarthMasses, jupiterRadii1, jupiterRadii2, 25.0, 50.0)
} else if coreEarthMasses <= 100.0 {
jupiterRadii1 := PlanetRadiusHelper(coreEarthMasses, 25.0, coreMassRadii25, 50.0, coreMassRadii50, 100.0, coreMassRadii100)
jupiterRadii2 := PlanetRadiusHelper2(coreEarthMasses, 50.0, coreMassRadii50, 100.0, coreMassRadii100)
jupiterRadii = RangeAdjust(coreEarthMasses, jupiterRadii1, jupiterRadii2, 50.0, 100.0)
} else {
jupiterRadii = PlanetRadiusHelper2(coreEarthMasses, 50.0, coreMassRadii50, 100.0, coreMassRadii100)
}
return jupiterRadii
}
func gasRadius4point5Gyr(planet *types.Planet) float64 {
temperatureRadii1960 := gasRadius4point5Gyr1960K(planet)
temperatureRadii1300 := gasRadius4point5Gyr1300K(planet)
temperatureRadii875 := gasRadius4point5Gyr875K(planet)
temperatureRadii260 := gasRadius4point5Gyr260K(planet)
temperatureRadii78 := gasRadius4point5Gyr78K(planet)
temperatureRadii0 := 0.0
temperature := planet.EstimatedTemperature
var jupiterRadii float64
if temperature <= 78.0 {
jupiterRadii1 := PlanetRadiusHelper(temperature, 0.0, temperatureRadii0, 78.0, temperatureRadii78, 260.0, temperatureRadii260)
jupiterRadii2 := PlanetRadiusHelper2(temperature, 78.0, temperatureRadii78, 260.0, temperatureRadii260)
jupiterRadii = RangeAdjust(temperature, jupiterRadii1, jupiterRadii2, 78.0, 260.0)
} else if temperature <= 260.0 {
//jupiterRadii1 := PlanetRadiusHelper(temperature, 0.0, temperatureRadii0, 78.0, temperatureRadii78, 260.0, temperatureRadii260, false);
jupiterRadii1 := PlanetRadiusHelper2(temperature, 78.0, temperatureRadii78, 260.0, temperatureRadii260)
jupiterRadii2 := PlanetRadiusHelper(temperature, 78.0, temperatureRadii78, 260.0, temperatureRadii260, 875.0, temperatureRadii875)
jupiterRadii = RangeAdjust(temperature, jupiterRadii1, jupiterRadii2, 78.0, 260.0)
} else if temperature <= 875.0 {
jupiterRadii1 := PlanetRadiusHelper(temperature, 78.0, temperatureRadii78, 260.0, temperatureRadii260, 875.0, temperatureRadii875)
jupiterRadii2 := PlanetRadiusHelper(temperature, 260.0, temperatureRadii260, 875.0, temperatureRadii875, 1300.0, temperatureRadii1300)
jupiterRadii = RangeAdjust(temperature, jupiterRadii1, jupiterRadii2, 260.0, 875.0)
} else if temperature <= 1300.0 {
jupiterRadii1 := PlanetRadiusHelper(temperature, 260.0, temperatureRadii260, 875.0, temperatureRadii875, 1300.0, temperatureRadii1300)
jupiterRadii2 := PlanetRadiusHelper(temperature, 875.0, temperatureRadii875, 1300.0, temperatureRadii1300, 1960.0, temperatureRadii1960)
jupiterRadii = RangeAdjust(temperature, jupiterRadii1, jupiterRadii2, 875.0, 1300.0)
} else if temperature <= 1960.0 {
jupiterRadii1 := PlanetRadiusHelper(temperature, 875.0, temperatureRadii875, 1300.0, temperatureRadii1300, 1960.0, temperatureRadii1960)
jupiterRadii2 := PlanetRadiusHelper3(temperature, 1300.0, temperatureRadii1300, 1960.0, temperatureRadii1960)
jupiterRadii = RangeAdjust(temperature, jupiterRadii1, jupiterRadii2, 1300.0, 1960.0)
} else {
jupiterRadii = PlanetRadiusHelper3(temperature, 1300.0, temperatureRadii1300, 1960.0, temperatureRadii1960)
}
return jupiterRadii
} | stargen/radius/gas-5-gyr-radius.go.go | 0.630912 | 0.563558 | gas-5-gyr-radius.go.go | starcoder |
package geometry
// Rect ...
type Rect struct {
Min, Max Point
}
// Move ...
func (rect Rect) Move(deltaX, deltaY float64) Rect {
return Rect{
Min: Point{X: rect.Min.X + deltaX, Y: rect.Min.Y + deltaY},
Max: Point{X: rect.Max.X + deltaX, Y: rect.Max.Y + deltaY},
}
}
// Index ...
func (rect Rect) Index() interface{} {
return nil
}
// Clockwise ...
func (rect Rect) Clockwise() bool {
return false
}
// Center ...
func (rect Rect) Center() Point {
return Point{(rect.Max.X + rect.Min.X) / 2, (rect.Max.Y + rect.Min.Y) / 2}
}
// Area ...
func (rect Rect) Area() float64 {
return (rect.Max.X - rect.Min.X) * (rect.Max.Y - rect.Min.Y)
}
// NumPoints ...
func (rect Rect) NumPoints() int {
return 5
}
// NumSegments ...
func (rect Rect) NumSegments() int {
return 4
}
// PointAt ...
func (rect Rect) PointAt(index int) Point {
switch index {
default:
return []Point{}[0]
case 0:
return Point{rect.Min.X, rect.Min.Y}
case 1:
return Point{rect.Max.X, rect.Min.Y}
case 2:
return Point{rect.Max.X, rect.Max.Y}
case 3:
return Point{rect.Min.X, rect.Max.Y}
case 4:
return Point{rect.Min.X, rect.Min.Y}
}
}
// SegmentAt ...
func (rect Rect) SegmentAt(index int) Segment {
switch index {
default:
return []Segment{}[0]
case 0:
return Segment{
Point{rect.Min.X, rect.Min.Y},
Point{rect.Max.X, rect.Min.Y},
}
case 1:
return Segment{
Point{rect.Max.X, rect.Min.Y},
Point{rect.Max.X, rect.Max.Y},
}
case 2:
return Segment{
Point{rect.Max.X, rect.Max.Y},
Point{rect.Min.X, rect.Max.Y},
}
case 3:
return Segment{
Point{rect.Min.X, rect.Max.Y},
Point{rect.Min.X, rect.Min.Y},
}
}
}
// Search ...
func (rect Rect) Search(target Rect, iter func(seg Segment, idx int) bool) {
var idx int
rectNumSegments := rect.NumSegments()
for i := 0; i < rectNumSegments; i++ {
seg := rect.SegmentAt(i)
if seg.Rect().IntersectsRect(target) {
if !iter(seg, idx) {
break
}
}
idx++
}
}
// Empty ...
func (rect Rect) Empty() bool {
return false
}
// Valid ...
func (rect Rect) Valid() bool {
return rect.Min.Valid() && rect.Max.Valid()
}
// Rect ...
func (rect Rect) Rect() Rect {
return rect
}
// Convex ...
func (rect Rect) Convex() bool {
return true
}
// ContainsPoint ...
func (rect Rect) ContainsPoint(point Point) bool {
return point.X >= rect.Min.X && point.X <= rect.Max.X &&
point.Y >= rect.Min.Y && point.Y <= rect.Max.Y
}
// IntersectsPoint ...
func (rect Rect) IntersectsPoint(point Point) bool {
return rect.ContainsPoint(point)
}
// ContainsRect ...
func (rect Rect) ContainsRect(other Rect) bool {
if other.Min.X < rect.Min.X || other.Max.X > rect.Max.X {
return false
}
if other.Min.Y < rect.Min.Y || other.Max.Y > rect.Max.Y {
return false
}
return true
}
// IntersectsRect ...
func (rect Rect) IntersectsRect(other Rect) bool {
if rect.Min.Y > other.Max.Y || rect.Max.Y < other.Min.Y {
return false
}
if rect.Min.X > other.Max.X || rect.Max.X < other.Min.X {
return false
}
return true
}
// ContainsLine ...
func (rect Rect) ContainsLine(line *Line) bool {
if line == nil {
return false
}
return !line.Empty() && rect.ContainsRect(line.Rect())
}
// IntersectsLine ...
func (rect Rect) IntersectsLine(line *Line) bool {
if line == nil {
return false
}
return ringIntersectsLine(rect, line, true)
}
// ContainsPoly ...
func (rect Rect) ContainsPoly(poly *Poly) bool {
if poly == nil {
return false
}
return !poly.Empty() && rect.ContainsRect(poly.Rect())
}
// IntersectsPoly ...
func (rect Rect) IntersectsPoly(poly *Poly) bool {
if poly == nil {
return false
}
return poly.IntersectsRect(rect)
} | vendor/github.com/tidwall/geojson/geometry/rect.go | 0.835383 | 0.617599 | rect.go | starcoder |
package types
import (
"io"
"github.com/lyraproj/pcore/px"
)
type (
IteratorType struct {
typ px.Type
}
)
var iteratorTypeDefault = &IteratorType{typ: DefaultAnyType()}
var IteratorMetaType px.ObjectType
func init() {
IteratorMetaType = newObjectType(`Pcore::IteratorType`,
`Pcore::AnyType {
attributes => {
type => {
type => Optional[Type],
value => Any
},
}
}`, func(ctx px.Context, args []px.Value) px.Value {
return newIteratorType2(args...)
})
}
func DefaultIteratorType() *IteratorType {
return iteratorTypeDefault
}
func NewIteratorType(elementType px.Type) *IteratorType {
if elementType == nil || elementType == anyTypeDefault {
return DefaultIteratorType()
}
return &IteratorType{elementType}
}
func newIteratorType2(args ...px.Value) *IteratorType {
switch len(args) {
case 0:
return DefaultIteratorType()
case 1:
containedType, ok := args[0].(px.Type)
if !ok {
panic(illegalArgumentType(`Iterator[]`, 0, `Type`, args[0]))
}
return NewIteratorType(containedType)
default:
panic(illegalArgumentCount(`Iterator[]`, `0 - 1`, len(args)))
}
}
func (t *IteratorType) Accept(v px.Visitor, g px.Guard) {
v(t)
t.typ.Accept(v, g)
}
func (t *IteratorType) Default() px.Type {
return iteratorTypeDefault
}
func (t *IteratorType) Equals(o interface{}, g px.Guard) bool {
if ot, ok := o.(*IteratorType); ok {
return t.typ.Equals(ot.typ, g)
}
return false
}
func (t *IteratorType) Generic() px.Type {
return NewIteratorType(px.GenericType(t.typ))
}
func (t *IteratorType) Get(key string) (value px.Value, ok bool) {
switch key {
case `type`:
return t.typ, true
}
return nil, false
}
func (t *IteratorType) IsAssignable(o px.Type, g px.Guard) bool {
if it, ok := o.(*IteratorType); ok {
return GuardedIsAssignable(t.typ, it.typ, g)
}
return false
}
func (t *IteratorType) IsInstance(o px.Value, g px.Guard) bool {
if it, ok := o.(px.IteratorValue); ok {
return GuardedIsInstance(t.typ, it.ElementType(), g)
}
return false
}
func (t *IteratorType) MetaType() px.ObjectType {
return IteratorMetaType
}
func (t *IteratorType) Name() string {
return `Iterator`
}
func (t *IteratorType) Parameters() []px.Value {
if t.typ == DefaultAnyType() {
return px.EmptyValues
}
return []px.Value{t.typ}
}
func (t *IteratorType) CanSerializeAsString() bool {
return canSerializeAsString(t.typ)
}
func (t *IteratorType) SerializationString() string {
return t.String()
}
func (t *IteratorType) String() string {
return px.ToString2(t, None)
}
func (t *IteratorType) ElementType() px.Type {
return t.typ
}
func (t *IteratorType) Resolve(c px.Context) px.Type {
t.typ = resolve(c, t.typ)
return t
}
func (t *IteratorType) ToString(b io.Writer, s px.FormatContext, g px.RDetect) {
TypeToString(t, b, s, g)
}
func (t *IteratorType) PType() px.Type {
return &TypeType{t}
} | types/iteratortype.go | 0.734786 | 0.433622 | iteratortype.go | starcoder |
package postscript
import ()
//int array array -> Create array of length int
func array(interpreter *Interpreter) {
interpreter.Push(make([]Value, interpreter.PopInt()))
}
//array length int -> Return number of elements in array
func lengtharray(interpreter *Interpreter) {
interpreter.Push(float64(len(interpreter.Pop().([]Value))))
}
//array index get any -> Return array element indexed by index
func getarray(interpreter *Interpreter) {
index := interpreter.PopInt()
array := interpreter.Pop().([]Value)
interpreter.Push(array[index])
}
//array index any put – -> Put any into array at index
func putarray(interpreter *Interpreter) {
value := interpreter.Pop()
index := interpreter.PopInt()
array := interpreter.Pop().([]Value)
array[index] = value
}
//array index count getinterval subarray -> Return subarray of array starting at index for count elements
func getinterval(interpreter *Interpreter) {
count := interpreter.PopInt()
index := interpreter.PopInt()
array := interpreter.Pop().([]Value)
subarray := make([]Value, count)
copy(subarray, array[index:index+count])
interpreter.Push(subarray)
}
//array1 index array2 putinterval – Replace subarray of array1 starting at index by array2|packedarray2
func putinterval(interpreter *Interpreter) {
array2 := interpreter.Pop().([]Value)
index := interpreter.PopInt()
array1 := interpreter.Pop().([]Value)
for i, v := range array2 {
array1[i+index] = v
}
}
// any0 … anyn−1 array astore array
// stores the objects any0 to anyn−1 from the operand stack into array, where n is the length of array
func astore(interpreter *Interpreter) {
array := interpreter.Pop().([]Value)
n := len(array)
for i := 0; i < n; i++ {
array[i] = interpreter.Pop()
}
}
//array aload any0 … any-1 array
//Push all elements of array on stack
func aload(interpreter *Interpreter) {
array := interpreter.Pop().([]Value)
for _, v := range array {
interpreter.Push(v)
}
interpreter.Push(array)
}
//array proc forall – Execute proc for each element of array
func forallarray(interpreter *Interpreter) {
proc := NewProcedure(interpreter.PopProcedureDefinition())
array := interpreter.Pop().([]Value)
for _, v := range array {
interpreter.Push(v)
proc.Execute(interpreter)
}
}
var packing bool = false
func currentpacking(interpreter *Interpreter) {
interpreter.Push(packing)
}
func setpacking(interpreter *Interpreter) {
packing = interpreter.PopBoolean()
}
func initArrayOperators(interpreter *Interpreter) {
interpreter.SystemDefine("array", NewOperator(array))
interpreter.SystemDefine("getinterval", NewOperator(getinterval))
interpreter.SystemDefine("putinterval", NewOperator(putinterval))
interpreter.SystemDefine("astore", NewOperator(astore))
interpreter.SystemDefine("aload", NewOperator(aload))
interpreter.SystemDefine("currentpacking", NewOperator(currentpacking))
interpreter.SystemDefine("setpacking", NewOperator(setpacking))
} | postscript/operators_array.go | 0.54819 | 0.400105 | operators_array.go | starcoder |
package jubjub
import (
"math/big"
"math/bits"
)
// FieldElement is an element of an arbitrary integer field.
type FieldElement struct {
n *big.Int
fieldOrder *big.Int
}
// newFieldElement returns a new element of the curve's base field initialized to the value of `n`.
func (curve *Jubjub) newFieldElement(n *big.Int) *FieldElement {
return newFieldElement(n, curve.fieldOrder)
}
// FeFromBytes reads a field element from little-endian bytes and returns it.
// If the value is larger than the size of the field, FeFromBytes will return a reduced value.
func (curve *Jubjub) FeFromBytes(in []byte) *FieldElement {
fe := newFieldElement(nil, curve.fieldOrder)
return fe.fromBytes(in)
}
// newFieldElement returns a new element of the field defined by `order` initialized to the value of `n`.
func newFieldElement(n, order *big.Int) *FieldElement {
if n == nil {
n = new(big.Int)
}
if n.Cmp(order) == 1 {
// XXX timing
n.Mod(n, order)
}
return &FieldElement{n, order}
}
// Set sets z to x and returns z.
func (z *FieldElement) Set(x *FieldElement) *FieldElement {
z.n.Set(x.n)
return z
}
// Equals compares two field elements and returns true if they are equal.
func (z *FieldElement) Equals(x *FieldElement) bool {
return z.n.Cmp(x.n) == 0
}
// Exp sets z = x**y mod |m| (i.e. the sign of m is ignored), and returns z.
// If m == nil or m == 0, z = x**y unless y <= 0 then z = 1. If m > 0, y < 0,
// and x and n are not relatively prime, z is unchanged and nil is returned.
// m is always the order of the field.
func (z *FieldElement) Exp(x, y *FieldElement) *FieldElement {
z.n.Exp(x.n, y.n, z.fieldOrder)
return z
}
// Mul sets z to the product x*y, reducing the result by the field order, and returns z.
func (z *FieldElement) Mul(x, y *FieldElement) *FieldElement {
z.n.Mul(x.n, y.n).Mod(z.n, z.fieldOrder)
return z
}
// Sub sets z to the difference x-y, reducing the result by the field order, and returns z.
func (z *FieldElement) Sub(x, y *FieldElement) *FieldElement {
z.n.Sub(x.n, y.n).Mod(z.n, z.fieldOrder)
return z
}
// Add sets z to the sum x+y, reducing the result by the field order, and returns z.
func (z *FieldElement) Add(x, y *FieldElement) *FieldElement {
z.n.Add(x.n, y.n).Mod(z.n, z.fieldOrder)
return z
}
// Cmp compares x and y and returns
// -1 if x < y
// 0 if x == y
// +1 if x > y
func (z *FieldElement) Cmp(x *FieldElement) int {
return z.n.Cmp(x.n)
}
// Neg sets z to -x and returns z.
func (z *FieldElement) Neg(x *FieldElement) *FieldElement {
z.n.Neg(x.n).Mod(z.n, z.fieldOrder)
return z
}
// ModInverse sets z to the multiplicative inverse of x in the field and returns z.
func (z *FieldElement) ModInverse(x *FieldElement) *FieldElement {
z.n.ModInverse(x.n, z.fieldOrder)
return z
}
// ModSqrt sets z to a square root of x in the field if such a square root exists,
// and returns z. If x is not a square in the field, ModSqrt leaves z unchanged
// and returns nil.
func (z *FieldElement) ModSqrt(x *FieldElement) *FieldElement {
exists := z.n.ModSqrt(x.n, z.fieldOrder)
if exists == nil {
return nil
}
return z
}
// FromBytes decodes a little endian bytestring as a field element, sets z to that value, and returns z.
// It is unexported because it requires knowledge of the represented field and should be used from a concrete parameter set.
func (z *FieldElement) fromBytes(ser []byte) *FieldElement {
in := ser[:]
words := make([]big.Word, (z.fieldOrder.BitLen()+7)/bits.UintSize)
for n := range words {
for i := 0; i < bits.UintSize; i += 8 {
if len(in) == 0 {
break
}
words[n] |= big.Word(in[0]) << big.Word(i)
in = in[1:]
}
}
z.n.SetBits(words)
z.n.Mod(z.n, z.fieldOrder)
return z
}
// ToBytes converts z to a little-endian bytestring and returns the bytes.
func (z *FieldElement) ToBytes() []byte {
z.n.Mod(z.n, z.fieldOrder)
buf := make([]byte, 0, (z.fieldOrder.BitLen()+7)/8)
for _, word := range z.n.Bits() {
for i := 0; i < bits.UintSize; i += 8 {
if len(buf) >= cap(buf) {
break
}
buf = append(buf, byte(word))
word >>= 8
}
}
return buf[:(z.fieldOrder.BitLen()+7)/8]
} | field_element.go | 0.864739 | 0.504822 | field_element.go | starcoder |
package timeseries
import (
"fmt"
"os"
"strconv"
"text/tabwriter"
"time"
)
// a DataUnit is the smallest unity of communication. The DataUnit is supposed to be transferred through any context,
// internet amongst others. It is supposed to be informative enough to live on its own, a bit like a packet in TCP/IP protocol.
// It is easily transformed into text/json object. More specifically, all the metadata are located in the "Measurement" field.
// A map of strings or a json can be used as a more sophisticated identity device, but is not used here for simplicity. Using a map requires
// specific initialization. Differential fields are created from the start because any time series work needs them sooner or later.
type DataUnit struct {
Measurement string // Where to classify the Datum. This can be used as a table name in a SQL environment.
Chron time.Time // time stamp according to golang time
Meas float64 // measure. In this setting measure is float.
Dchron time.Duration // Duration time from preceding Observation
Dmeas float64 // Delta measure from preceding observation
State string // State of measuring device ("ok","nok"....) Could be used as non floating measuring device if any
}
const(
NotNihil float64 =2.2250738585072014e-308 //NotNihil==math.SmallestNonzeroFloat64
)
// NewDataUnit creates a DataUnit from input. Warning: 0 as a Meas(ure) is significant, notwithstanding the fact that
// golang creates a 0 value field by default. If the data is not 0, use math.NaN() function.
func NewDataUnit(table string,chr time.Time,meas float64,st string)DataUnit{
var du DataUnit
du.Measurement=table
du.Chron=chr
du.Meas=meas
du.State=st
return du
}
// AddDataUnit adds well formed DataUnit (s) to a TimeSeries. Variadic form
func (ts *TimeSeries) AddDataUnit(dus ...DataUnit){
for _,du :=range dus{
ts.DataSeries =append(ts.DataSeries,du)
}
}
// AddData adds DataUnit with data inputs. Empty fields are golang default values
func (ts *TimeSeries) AddData(table string,chr time.Time,meas float64,st string){
du:=NewDataUnit(table ,chr ,meas ,st)
ts.DataSeries =append(ts.DataSeries,du)
}
// PrettyPrint prints DataUnit as readable form to Terminal
func (du *DataUnit)PrettyPrint(){
w:=new(tabwriter.Writer)
w.Init(os.Stdout, 5, 0, 3, ' ', tabwriter.AlignRight)
fmt.Fprintf(w, "%s|\t%v|\t%v|\t%v|\t%v|\t%v|\t\n","Measurement","Chron","Measure","State","Dchron","Dmeas")
fmt.Fprintln(w, "------------|\t--------------------------------------|\t----------|\t------------|\t------------|\t------------|\t")
fmt.Fprintf(w, "%s|\t%v|\t%v|\t%v|\t%v|\t%v|\t\n",du.Measurement,du.Chron.Round(0), du.Meas,du.State,du.Dchron,du.Dmeas)
fmt.Fprintln(w)
w.Flush()
}
// ParseRFC3339toTime parse a RFC3339 date type string to golang datetime type
func ParseRFC3339toTime(nimp string, location *time.Location)time.Time{
var dd time.Time
lastc:=nimp[len(nimp)-1:]
if lastc=="S" || lastc=="s" {
yy,_:=strconv.Atoi(nimp[:2])
yy=yy+2000
mm,_:=strconv.Atoi(nimp[2:4])
dda,_:=strconv.Atoi(nimp[4:6])
hh,_:=strconv.Atoi(nimp[6:8])
min,_:=strconv.Atoi(nimp[8:10])
ss,_:=strconv.Atoi(nimp[10:12])
dd=time.Date(yy,time.Month(mm),dda,hh,min,ss,0.0,location)
return dd
}
layout := "2006-01-02T15:04:05.000Z"
dd, _ = time.Parse(layout, nimp)
return dd
} | timeseries/dataunit.go | 0.551332 | 0.526891 | dataunit.go | starcoder |
package util
import (
"encoding/binary"
)
// BinaryReader reads primitive data types as binary values.
type BinaryReader struct {
buffer []byte
pos int
}
// NewBinaryReader returns a new instance of the BinaryReader class based on the specified byte array.
func NewBinaryReader(packet []byte) *BinaryReader {
return &BinaryReader{
buffer: packet,
pos: 0,
}
}
// Pos returns the current position in the buffer
func (reader *BinaryReader) Pos() int {
return reader.pos
}
func (reader *BinaryReader) Read(count int) []byte {
b := reader.buffer[reader.pos : reader.pos+count]
reader.pos += count
return b
}
// ReadUInt8 reads the next uint8 from the current stream and advances the position of the stream by one byte.
func (reader *BinaryReader) ReadUInt8() uint8 {
return reader.Read(1)[0]
}
// ReadUInt16 reads the next uint16 from the current stream and advances the position of the stream by two bytes.
func (reader *BinaryReader) ReadUInt16() uint16 {
return binary.LittleEndian.Uint16(reader.Read(2))
}
// ReadUInt32 reads the next uint32 from the current stream and advances the position of the stream by four bytes.
func (reader *BinaryReader) ReadUInt32() uint32 {
return binary.LittleEndian.Uint32(reader.Read(4))
}
// ReadUInt64 reads the next uint64 from the current stream and advances the position of the stream by eight bytes.
func (reader *BinaryReader) ReadUInt64() uint64 {
return binary.LittleEndian.Uint64(reader.Read(8))
}
// ReadInt8 reads the next int8 from the current stream and advances the position of the stream by one byte.
func (reader *BinaryReader) ReadInt8() int8 {
return int8(reader.ReadUInt8())
}
// ReadInt16 reads the next int16 from the current stream and advances the position of the stream by two bytes.
func (reader *BinaryReader) ReadInt16() int16 {
return int16(reader.ReadUInt16())
}
// ReadInt32 reads the next int32 from the current stream and advances the position of the stream by four bytes.
func (reader *BinaryReader) ReadInt32() int32 {
return int32(reader.ReadUInt32())
}
// ReadInt64 reads the next int64 from the current stream and advances the position of the stream by eight bytes.
func (reader *BinaryReader) ReadInt64() int64 {
return int64(reader.ReadUInt64())
}
// ReadBool reads a bool from the current stream and advances the position of the stream by one byte.
func (reader *BinaryReader) ReadBool() bool {
b := reader.ReadUInt8()
return b != 0
}
// ReadCString reads a null terminated string from the current stream and advanced the position by the length of the string.
func (reader *BinaryReader) ReadCString() string {
start := reader.pos
for {
if reader.buffer[reader.pos] == 0 {
reader.pos++
break
}
reader.pos++
}
return string(reader.buffer[start : reader.pos-1])
}
// More ...
func (reader *BinaryReader) More() bool {
return reader.pos < len(reader.buffer)
} | util/reader.go | 0.832032 | 0.48121 | reader.go | starcoder |
package sv
import "github.com/rannoch/cldr"
var calendar = cldr.Calendar{
Formats: cldr.CalendarFormats{
Date: cldr.CalendarDateFormat{Full: "EEEE d MMMM y", Long: "d MMMM y", Medium: "d MMM y", Short: "y-MM-dd"},
Time: cldr.CalendarDateFormat{Full: "'kl'. HH:mm:ss zzzz", Long: "HH:mm:ss z", Medium: "HH:mm:ss", Short: "HH:mm"},
DateTime: cldr.CalendarDateFormat{Full: "{1} {0}", Long: "{1} {0}", Medium: "{1} {0}", Short: "{1} {0}"},
},
FormatNames: cldr.CalendarFormatNames{
Months: cldr.CalendarMonthFormatNames{
Abbreviated: cldr.CalendarMonthFormatNameValue{Jan: "Jan.", Feb: "Feb.", Mar: "Mars", Apr: "Apr.", May: "Maj", Jun: "Juni", Jul: "Juli", Aug: "Aug.", Sep: "Sep.", Oct: "Okt.", Nov: "Nov.", Dec: "Dec."},
Narrow: cldr.CalendarMonthFormatNameValue{Jan: "J", Feb: "F", Mar: "M", Apr: "A", May: "M", Jun: "J", Jul: "J", Aug: "A", Sep: "S", Oct: "O", Nov: "N", Dec: "D"},
Short: cldr.CalendarMonthFormatNameValue{},
Wide: cldr.CalendarMonthFormatNameValue{Jan: "Januari", Feb: "Februari", Mar: "Mars", Apr: "April", May: "Maj", Jun: "Juni", Jul: "Juli", Aug: "Augusti", Sep: "September", Oct: "Oktober", Nov: "November", Dec: "December"},
},
Days: cldr.CalendarDayFormatNames{
Abbreviated: cldr.CalendarDayFormatNameValue{Sun: "Sön", Mon: "Mån", Tue: "Tis", Wed: "Ons", Thu: "Tor", Fri: "Fre", Sat: "Lör"},
Narrow: cldr.CalendarDayFormatNameValue{Sun: "S", Mon: "M", Tue: "T", Wed: "O", Thu: "T", Fri: "F", Sat: "L"},
Short: cldr.CalendarDayFormatNameValue{Sun: "Sö", Mon: "Må", Tue: "Ti", Wed: "On", Thu: "To", Fri: "Fr", Sat: "Lö"},
Wide: cldr.CalendarDayFormatNameValue{Sun: "Söndag", Mon: "Måndag", Tue: "Tisdag", Wed: "Onsdag", Thu: "Torsdag", Fri: "Fredag", Sat: "Lördag"},
},
Periods: cldr.CalendarPeriodFormatNames{
Abbreviated: cldr.CalendarPeriodFormatNameValue{AM: "fm", PM: "em"},
Narrow: cldr.CalendarPeriodFormatNameValue{AM: "f.m.", PM: "e.m."},
Short: cldr.CalendarPeriodFormatNameValue{},
Wide: cldr.CalendarPeriodFormatNameValue{AM: "förmiddag", PM: "eftermiddag"},
},
},
} | resources/locales/sv/calendar.go | 0.520984 | 0.455138 | calendar.go | starcoder |
package course
import (
"sort"
"strconv"
"github.com/pkg/errors"
)
type TaskType uint8
const (
ManualCheckingType TaskType = iota + 1
AutoCodeCheckingType
TestingType
)
func (t TaskType) String() string {
switch t {
case ManualCheckingType:
return "manual checking"
case AutoCodeCheckingType:
return "auto code checking"
case TestingType:
return "testing"
}
return "%!TaskType(" + strconv.Itoa(int(t)) + ")"
}
func (t TaskType) IsValid() bool {
switch t {
case ManualCheckingType, AutoCodeCheckingType, TestingType:
return true
}
return false
}
type taskOptional struct {
deadline Deadline
testPoints []TestPoint
testData []TestData
}
type Task struct {
number int
title string
description string
taskType TaskType
optional taskOptional
}
func (t *Task) Number() int {
return t.number
}
func (t *Task) Title() string {
return t.title
}
func (t *Task) Description() string {
return t.description
}
func (t *Task) Type() TaskType {
return t.taskType
}
func (t *Task) Deadline() (Deadline, bool) {
if t.taskType == ManualCheckingType ||
t.taskType == AutoCodeCheckingType {
return t.deadline(), true
}
return Deadline{}, false
}
func (t *Task) TestData() ([]TestData, bool) {
if t.taskType == AutoCodeCheckingType {
return t.testData(), true
}
return nil, false
}
func (t *Task) TestPoints() ([]TestPoint, bool) {
if t.taskType == TestingType {
return t.testPoints(), true
}
return nil, false
}
func (t *Task) deadline() Deadline {
return t.optional.deadline
}
func (t *Task) testData() []TestData {
testDataCopy := make([]TestData, len(t.optional.testData))
copy(testDataCopy, t.optional.testData)
return testDataCopy
}
func (t *Task) testPoints() []TestPoint {
testPointsCopy := make([]TestPoint, len(t.optional.testPoints))
copy(testPointsCopy, t.optional.testPoints)
return testPointsCopy
}
const (
taskTitleMaxLen = 200
taskDescriptionMaxLen = 1000
)
var (
ErrTaskHasNoDeadline = errors.New("task has no deadline")
ErrTaskHasNoTestPoints = errors.New("task has no test points")
ErrTaskHasNoTestData = errors.New("task has no test data")
ErrTaskTitleTooLong = errors.New("task title too long")
ErrTaskDescriptionTooLong = errors.New("task description too long")
ErrCourseHasNoSuchTask = errors.New("course has no such task")
)
func IsInvalidTaskParametersError(err error) bool {
return errors.Is(err, ErrTaskTitleTooLong) ||
errors.Is(err, ErrTaskDescriptionTooLong)
}
func (t *Task) rename(title string) error {
if len(title) > taskTitleMaxLen {
return ErrTaskTitleTooLong
}
t.title = title
return nil
}
func (t *Task) replaceDescription(description string) error {
if len(description) > taskDescriptionMaxLen {
return ErrTaskDescriptionTooLong
}
t.description = description
return nil
}
func (t *Task) replaceDeadline(deadline Deadline) error {
if t.taskType == TestingType {
return ErrTaskHasNoDeadline
}
t.optional.deadline = deadline
return nil
}
func (t *Task) replaceTestPoints(testPoints []TestPoint) error {
if t.taskType != TestingType {
return ErrTaskHasNoTestPoints
}
t.optional.testPoints = testPoints
return nil
}
func (t *Task) replaceTestData(testData []TestData) error {
if t.taskType != AutoCodeCheckingType {
return ErrTaskHasNoTestData
}
t.optional.testData = testData
return nil
}
func (t *Task) copy() *Task {
return &Task{
number: t.Number(),
title: t.Title(),
description: t.Description(),
taskType: t.Type(),
optional: taskOptional{
deadline: Deadline{},
testPoints: t.testPoints(),
testData: t.testData(),
},
}
}
func (c *Course) Task(taskNumber int) (Task, error) {
task, err := c.obtainTask(taskNumber)
if err != nil {
return Task{}, err
}
return *task, nil
}
func (c *Course) Tasks() []Task {
tasks := make([]Task, 0, len(c.tasks))
for _, t := range c.tasks {
tasks = append(tasks, *t)
}
return tasks
}
type ManualCheckingTaskCreationParams struct {
Title string
Description string
Deadline Deadline
}
func (c *Course) AddManualCheckingTask(academic Academic, params ManualCheckingTaskCreationParams) (int, error) {
if err := c.canAcademicEditWithAccess(academic, TeacherAccess); err != nil {
return 0, err
}
task, err := c.newTask(params.Title, params.Description, ManualCheckingType, taskOptional{deadline: params.Deadline})
if err != nil {
return 0, err
}
return task.number, nil
}
type AutoCodeCheckingTaskCreationParams struct {
Title string
Description string
Deadline Deadline
TestData []TestData
}
func (c *Course) AddAutoCodeCheckingTask(academic Academic, params AutoCodeCheckingTaskCreationParams) (int, error) {
if err := c.canAcademicEditWithAccess(academic, TeacherAccess); err != nil {
return 0, err
}
testDataCopy := make([]TestData, len(params.TestData))
copy(testDataCopy, params.TestData)
task, err := c.newTask(params.Title, params.Description, AutoCodeCheckingType, taskOptional{
deadline: params.Deadline,
testData: testDataCopy,
})
if err != nil {
return 0, err
}
return task.number, nil
}
type TestingTaskCreationParams struct {
Title string
Description string
TestPoints []TestPoint
}
func (c *Course) AddTestingTask(academic Academic, params TestingTaskCreationParams) (int, error) {
if err := c.canAcademicEditWithAccess(academic, TeacherAccess); err != nil {
return 0, err
}
testPointsCopy := make([]TestPoint, len(params.TestPoints))
copy(testPointsCopy, params.TestPoints)
task, err := c.newTask(params.Title, params.Description, TestingType, taskOptional{testPoints: testPointsCopy})
if err != nil {
return 0, err
}
return task.number, nil
}
func (c *Course) RenameTask(academic Academic, taskNumber int, title string) error {
if err := c.canAcademicEditWithAccess(academic, TeacherAccess); err != nil {
return err
}
task, err := c.obtainTask(taskNumber)
if err != nil {
return err
}
return task.rename(title)
}
func (c *Course) ReplaceTaskDescription(academic Academic, taskNumber int, description string) error {
if err := c.canAcademicEditWithAccess(academic, TeacherAccess); err != nil {
return err
}
task, err := c.obtainTask(taskNumber)
if err != nil {
return err
}
return task.replaceDescription(description)
}
func (c *Course) ReplaceTaskDeadline(academic Academic, taskNumber int, deadline Deadline) error {
if err := c.canAcademicEditWithAccess(academic, TeacherAccess); err != nil {
return err
}
task, err := c.obtainTask(taskNumber)
if err != nil {
return err
}
return task.replaceDeadline(deadline)
}
func (c *Course) ReplaceTaskTestPoints(academic Academic, taskNumber int, testPoints []TestPoint) error {
if err := c.canAcademicEditWithAccess(academic, TeacherAccess); err != nil {
return err
}
task, err := c.obtainTask(taskNumber)
if err != nil {
return err
}
return task.replaceTestPoints(testPoints)
}
func (c *Course) ReplaceTaskTestData(academic Academic, taskNumber int, testData []TestData) error {
if err := c.canAcademicEditWithAccess(academic, TeacherAccess); err != nil {
return err
}
task, err := c.obtainTask(taskNumber)
if err != nil {
return err
}
return task.replaceTestData(testData)
}
func (c *Course) TasksNumber() int {
return len(c.tasks)
}
func (c *Course) newTask(title string, description string, taskType TaskType, optional taskOptional) (*Task, error) {
task := &Task{
number: c.nextTaskNumber,
taskType: taskType,
optional: optional,
}
if err := task.rename(title); err != nil {
return nil, err
}
if err := task.replaceDescription(description); err != nil {
return nil, err
}
c.tasks[c.nextTaskNumber] = task
c.nextTaskNumber++
return task, nil
}
func (c *Course) obtainTask(taskNumber int) (*Task, error) {
task, ok := c.tasks[taskNumber]
if !ok {
return nil, ErrCourseHasNoSuchTask
}
return task, nil
}
func (c *Course) tasksCopy() []*Task {
tasks := make([]*Task, 0, len(c.tasks))
for _, t := range c.tasks {
tasks = append(tasks, t.copy())
}
sort.SliceStable(tasks, func(i, j int) bool {
return tasks[i].Number() < tasks[j].Number()
})
return tasks
} | internal/domain/course/task.go | 0.527803 | 0.479138 | task.go | starcoder |
package num
import (
"github.com/cpmech/gosl/fun"
"github.com/cpmech/gosl/io"
"github.com/cpmech/gosl/la"
"github.com/cpmech/gosl/plt"
"github.com/cpmech/gosl/utl"
)
// LineSolver finds the scalar λ that zeroes or minimizes f(x+λ⋅n)
type LineSolver struct {
// configuration
UseDeriv bool // use Jacobian function [default = true if Jfcn is provided]
// inernal
ffcn fun.Sv // scalar function of vector: y = f({x})
Jfcn fun.Vv // vector function of vector: {J} = df/d{x} @ {x} [optional / may be nil]
y la.Vector // {y} = {x} + λ⋅{n}
dfdx la.Vector // derivative df/d{x}
bracket *Bracket // bracket
solver *Brent // scalar minimizer
// Stat
NumFeval int // number of function evalutions
NumJeval int // number of Jacobian evaluations
// pointers
x la.Vector // starting point
n la.Vector // direction
}
// NewLineSolver returns a new LineSolver object
// size -- length(x)
// ffcn -- scalar function of vector: y = f({x})
// Jfcn -- vector function of vector: {J} = df/d{x} @ {x} [optional / may be nil]
func NewLineSolver(size int, ffcn fun.Sv, Jfcn fun.Vv) (o *LineSolver) {
o = new(LineSolver)
o.ffcn = ffcn
o.Jfcn = Jfcn
o.y = la.NewVector(size)
o.dfdx = la.NewVector(size)
o.bracket = NewBracket(o.G)
o.solver = NewBrent(o.G, o.H)
if Jfcn != nil {
o.UseDeriv = true
}
return
}
// Root finds the scalar λ that zeroes f(x+λ⋅n)
func (o *LineSolver) Root(x, n la.Vector) (λ float64) {
o.Set(x, n)
λ = o.solver.Root(0, 1)
o.NumFeval = o.solver.NumFeval + o.bracket.NumFeval
o.NumJeval = o.solver.NumJeval
return
}
// Min finds the scalar λ that minimizes f(x+λ⋅n)
func (o *LineSolver) Min(x, n la.Vector) (λ float64) {
o.Set(x, n)
λmin, _, λmax, _, _, _ := o.bracket.Min(0, 1)
if o.UseDeriv {
λ = o.solver.MinUseD(λmin, λmax)
} else {
λ = o.solver.Min(λmin, λmax)
}
o.NumFeval = o.solver.NumFeval + o.bracket.NumFeval
o.NumJeval = o.solver.NumJeval
return
}
// MinUpdateX finds the scalar λ that minimizes f(x+λ⋅n), updates x and returns fmin = f({x})
// Input:
// x -- initial point
// n -- direction
// Output:
// λ -- scale parameter
// x -- x @ minimum
// fmin -- f({x})
func (o *LineSolver) MinUpdateX(x, n la.Vector) (λ, fmin float64) {
λ = o.Min(x, n)
la.VecAdd(o.x, 1, x, λ, n) // x := x + λ⋅n
fmin = o.ffcn(o.x)
o.NumFeval++
return
}
// Set sets x and n vectors as required by G(λ) and H(λ) functions
func (o *LineSolver) Set(x, n la.Vector) {
o.x = x
o.n = n
}
// G implements g(λ) := f({y}(λ)) where {y}(λ) := {x} + λ⋅{n}
func (o *LineSolver) G(λ float64) float64 {
la.VecAdd(o.y, 1, o.x, λ, o.n) // xpn := x + λ⋅n
return o.ffcn(o.y)
}
// H implements h(λ) = dg/dλ = df/d{y} ⋅ d{y}/dλ where {y} == {x} + λ⋅{n}
func (o *LineSolver) H(λ float64) float64 {
la.VecAdd(o.y, 1, o.x, λ, o.n) // y := x + λ⋅n
o.Jfcn(o.dfdx, o.y) // dfdx @ y
return la.VecDot(o.dfdx, o.n) // dfdx ⋅ n
}
// PlotC plots contour for current x and n vectors
// i, j -- the indices in x[i] and x[j] to plot x[j] versus x[i]
func (o *LineSolver) PlotC(i, j int, λ, xmin, xmax, ymin, ymax float64, npts int) {
// auxiliary
x2d := []float64{o.x[i], o.x[j]}
n2d := []float64{o.n[i], o.n[j]}
xvec := la.NewVector(len(o.x))
copy(xvec, o.x)
// contour
xx, yy, zz := utl.MeshGrid2dF(xmin, xmax, ymin, ymax, npts, npts, func(u, v float64) float64 {
xvec[i], xvec[j] = u, v
return o.ffcn(xvec)
})
plt.ContourF(xx, yy, zz, nil)
plt.PlotOne(x2d[0]+λ*n2d[0], x2d[1]+λ*n2d[1], &plt.A{C: "y", M: "o", NoClip: true})
plt.DrawArrow2d(x2d, n2d, false, 1, nil)
plt.Gll(io.Sf("$x_{%d}$", i), io.Sf("$x_{%d}$", j), nil)
plt.HideTRborders()
}
// PlotG plots g(λ) curve for current x and n vectors
func (o *LineSolver) PlotG(λ, λmin, λmax float64, npts int, useBracket bool) {
// auxiliary
if useBracket {
λmin, _, λmax, _, _, _ = o.bracket.Min(0, 1)
}
ll := utl.LinSpace(λmin, λmax, npts)
// scalar function along n
gg := utl.GetMapped(ll, o.G)
plt.Plot(ll, gg, &plt.A{C: plt.C(0, 0), L: "$g(\\lambda)$", NoClip: true})
plt.PlotOne(λmin, o.G(λmin), &plt.A{C: "r", M: "|", Ms: 40, NoClip: true})
plt.PlotOne(λmax, o.G(λmax), &plt.A{C: "r", M: "|", Ms: 40, NoClip: true})
plt.PlotOne(λ, o.G(λ), &plt.A{C: "y", M: "o", NoClip: true})
plt.Cross(0, 0, nil)
plt.Gll("$\\lambda$", "$g(\\lambda)$", nil)
plt.HideTRborders()
} | num/linesolver.go | 0.732783 | 0.512449 | linesolver.go | starcoder |
package onedb
import (
"net"
"reflect"
"time"
"github.com/pkg/errors"
)
// QueryValues runs a query against the provided Backender and populates result values
func QueryValues(backend Backender, query *Query, result ...interface{}) error {
if query == nil {
return ErrQueryIsNil
}
row := backend.QueryRow(query.Query, query.Args)
return row.Scan(result...)
}
// QueryJSON runs a query against the provided Backender and returns the JSON result
func QueryJSON(backend Backender, query string, args ...interface{}) (string, error) {
rows, err := backend.Query(query, args...)
if err != nil {
return "", err
}
defer rows.Close()
return getJSON(rows)
}
// QueryJSONRow runs a query against the provided Backender and returns the JSON result
func QueryJSONRow(backend Backender, query string, args ...interface{}) (string, error) {
rows, err := backend.Query(query, args...)
if err != nil {
return "", err
}
defer rows.Close()
return getJSONRow(rows)
}
// QueryStruct runs a query against the provided Backender and populates the provided result
func QueryStruct(backend Backender, result interface{}, query string, args ...interface{}) error {
resultType := reflect.TypeOf(result)
if !IsPointer(resultType) || !IsSlice(resultType.Elem()) {
return errors.New("Invalid result argument. Must be a pointer to a slice")
}
rows, err := backend.Query(query, args...)
if err != nil {
return err
}
defer rows.Close()
return getStruct(rows, result)
}
// QueryStructRow runs a query against the provided Backender and populates the provided result
func QueryStructRow(backend Backender, result interface{}, query string, args ...interface{}) error {
if !IsPointer(reflect.TypeOf(result)) {
return errors.New("Invalid result argument. Must be a pointer to a struct")
}
rows, err := backend.Query(query, args...)
if err != nil {
return err
}
defer rows.Close()
return getStructRow(rows, result)
}
// IsPointer is used to determine if a reflect.Type is a pointer
func IsPointer(item reflect.Type) bool {
return item.Kind() == reflect.Ptr
}
// IsSlice is used to determine if a reflect.Type is a slice
func IsSlice(item reflect.Type) bool {
return item.Kind() == reflect.Slice
}
// IsStruct is used to determine if a reflect.Type is a struct
func IsStruct(item reflect.Type) bool {
return item.Kind() == reflect.Struct
}
// Query is a generic struct that houses a query string and arguments used to construct a query
type Query struct {
Query string
Args []interface{}
}
// NewQuery is tne constructor for a Query struct
func NewQuery(query string, args ...interface{}) *Query {
return &Query{Query: query, Args: args}
}
// DialFunc is the shape of the function used to dial a TCP connection
type DialFunc func(network, addr string) (net.Conn, error)
// NewMockDialer returns a onedb.DialFunc for testing purposes
func NewMockDialer(err error) DialFunc {
return func(network, addr string) (net.Conn, error) {
return nil, err
}
}
// DialTCP is a helper function that will dial a TCP port and set a 2 minute time period
func DialTCP(network, addr string) (net.Conn, error) {
tcpAddr, err := net.ResolveTCPAddr(network, addr)
if err != nil {
return nil, err
}
tc, err := net.DialTCP(network, nil, tcpAddr)
if err != nil {
return nil, err
}
if err := tc.SetKeepAlive(true); err != nil {
return nil, err
}
if err := tc.SetKeepAlivePeriod(2 * time.Minute); err != nil {
return nil, err
}
return tc, nil
} | onedb.go | 0.754825 | 0.435841 | onedb.go | starcoder |
package show
import (
"fmt"
"path/filepath"
"strings"
"github.com/oakmound/oak/v3/render/mod"
"github.com/oakmound/oak/v3/render"
)
var (
width, height float64
)
// SetDims for the whole presentation global
func SetDims(w, h float64) {
width = w
height = h
}
var (
titleFont *render.Font
)
// SetTitleFont on the presentation
func SetTitleFont(f *render.Font) {
if f == nil {
fmt.Println("title font nil")
}
titleFont = f
}
// TxtSetAt creates text starting from a given location and advancing each text by an offset
func TxtSetAt(f *render.Font, xpos, ypos, xadv, yadv float64, txts ...string) []render.Renderable {
rs := make([]render.Renderable, len(txts))
for i, txt := range txts {
rs[i] = TxtAt(f, txt, xpos, ypos)
xpos += xadv
ypos += yadv
}
return rs
}
// TxtAt creates string on screen at a given location
func TxtAt(f *render.Font, txt string, xpos, ypos float64) render.Renderable {
return Pos(f.NewText(txt, 0, 0), xpos, ypos)
}
// Title draws a string as the title of a slide
func Title(str string) render.Renderable {
return TxtAt(titleFont, str, .5, .4)
}
// Header draws a header for the slide
func Header(str string) render.Renderable {
return TxtAt(titleFont, str, .5, .2)
}
// TextSetFrom draws a series of text with offsets from top right not left
func TxtSetFrom(f *render.Font, xpos, ypos, xadv, yadv float64, txts ...string) []render.Renderable {
rs := make([]render.Renderable, len(txts))
for i, txt := range txts {
rs[i] = TxtFrom(f, txt, xpos, ypos)
xpos += xadv
ypos += yadv
}
return rs
}
// TxtFrom draws a new string starting from the right rather than the left
func TxtFrom(f *render.Font, txt string, xpos, ypos float64) render.Renderable {
return f.NewText(txt, width*xpos, height*ypos)
}
// Pos sets the center x and y for a renderable
func Pos(r render.Renderable, xpos, ypos float64) render.Renderable {
XPos(r, xpos)
YPos(r, ypos)
return r
}
// XPos sets the centered X pos of a renderable
func XPos(r render.Renderable, pos float64) render.Renderable {
w, _ := r.GetDims()
r.SetPos(width*pos-float64(w/2), r.Y())
return r
}
// YPos sets the centered Y pos of a renderable
func YPos(r render.Renderable, pos float64) render.Renderable {
_, h := r.GetDims()
r.SetPos(r.X(), height*pos-float64(h/2))
return r
}
// Image renders a static image at a location
func Image(file string, xpos, ypos float64) render.Modifiable {
s, err := render.LoadSprite(filepath.Join("assets", "images", "raw", file))
if err != nil {
fmt.Println(err)
return nil
}
s.SetPos(width*xpos, height*ypos)
return s
}
// ImageAt creates an image, centers it and applies modifications
func ImageAt(file string, xpos, ypos float64, mods ...mod.Mod) render.Modifiable {
m := Image(file, xpos, ypos)
m.Modify(mods...)
w, h := m.GetDims()
m.ShiftX(float64(-w / 2))
m.ShiftY(float64(-h / 2))
return m
}
// ImageCaptionSize set the caption and its size
func ImageCaptionSize(file string, xpos, ypos float64, w, h float64, f *render.Font, cap string) render.Renderable {
r, err := render.LoadSprite(filepath.Join("assets", "images", "raw", file))
if err != nil {
fmt.Println(err)
return nil
}
w2, h2 := r.GetDims()
w3 := float64(w2) / width
h3 := float64(h2) / height
wScale := w / w3
hScale := h / h3
if wScale > hScale {
wScale = hScale
} else {
hScale = wScale
}
r.Modify(mod.Scale(wScale, hScale))
w4, h4 := r.GetDims()
r.SetPos(width*xpos, height*ypos)
r.ShiftX(float64(-w4 / 2))
r.ShiftY(float64(-h4 / 2))
x := r.X() + float64(w4)/2
y := r.Y() + float64(h4) + 42
caps := strings.Split(cap, "\n")
for i := 1; i < len(caps); i++ {
// remove whitespace
caps[i] = strings.TrimSpace(caps[i])
}
s := TxtSetAt(f, float64(x)/width, float64(y)/height, 0, .04, caps...)
return render.NewCompositeR(append(s, r)...)
}
// ImageCaption creates caption text
func ImageCaption(file string, xpos, ypos float64, scale float64, f *render.Font, cap string) render.Renderable {
r := Image(file, xpos, ypos)
r.Modify(mod.Scale(scale, scale))
w, h := r.GetDims()
x := r.X() + float64(w)/2
y := r.Y() + float64(h) + 28
s := f.NewText(cap, x, y)
s.Center()
return render.NewCompositeR(r, s)
} | examples/slide/show/helpers.go | 0.668447 | 0.512815 | helpers.go | starcoder |
package main
import (
"math"
"math/rand"
"github.com/faiface/beep"
)
var noise = beep.StreamerFunc(func(samples [][2]float64) (n int, ok bool) {
for i := range samples {
samples[i][0] = rand.Float64()*2 - 1
samples[i][1] = rand.Float64()*2 - 1
}
return len(samples), true
})
func wave(sr beep.SampleRate, waveForm func(t float64) float64) beep.Streamer {
t := 0.0
return beep.StreamerFunc(func(samples [][2]float64) (n int, ok bool) {
sampleLength := len(samples)
for i := range samples {
y := waveForm(t)
samples[i][0] = y
samples[i][1] = y
t += sr.D(1).Seconds()
}
return sampleLength, true
})
}
func sineWave(sr beep.SampleRate, freq float64) beep.Streamer {
t := 0.0
sineFn := sine(1, freq, 0)
return beep.StreamerFunc(func(samples [][2]float64) (n int, ok bool) {
sampleLength := len(samples)
for i := range samples {
y := sineFn(t)
samples[i][0] = y
samples[i][1] = y
t += sr.D(1).Seconds()
}
return sampleLength, true
})
}
func sine(amplitude float64, frequency float64, phaseShift float64) func(t float64) float64 {
return func(t float64) float64 {
return amplitude * math.Sin(
2*math.Pi*frequency*t+phaseShift,
)
}
}
func sawtoothWave(sr beep.SampleRate, freq float64) beep.Streamer {
t := 0.0
sawFn := sawtooth(1, freq, 0)
return beep.StreamerFunc(func(samples [][2]float64) (n int, ok bool) {
sampleLength := len(samples)
for i := range samples {
samples[i][0] = sawFn(t)
samples[i][1] = sawFn(t)
t += sr.D(1).Seconds()
}
return sampleLength, true
})
}
func sawtooth(amplitude float64, frequency float64, phaseShift float64) func(t float64) float64 {
return func(t float64) float64 {
return -(amplitude / 2 / math.Pi) * math.Atan(
1/math.Tan(
t*math.Pi*frequency,
),
)
}
}
func triangleWave(sr beep.SampleRate, freq float64) beep.Streamer {
t := 0.0
triangleFn := triangle(1, freq, 0)
return beep.StreamerFunc(func(samples [][2]float64) (n int, ok bool) {
sampleLength := len(samples)
for i := range samples {
samples[i][0] = triangleFn(t)
samples[i][1] = triangleFn(t)
t += sr.D(1).Seconds()
}
return sampleLength, true
})
}
func triangle(amplitude float64, frequency float64, phaseShift float64) func(t float64) float64 {
return func(t float64) float64 {
return (2 * amplitude / math.Pi) * math.Asin(
math.Sin(
((2*math.Pi)/(1/frequency))*t,
),
)
}
}
func squareWave(sr beep.SampleRate, freq float64) beep.Streamer {
t := 0.0
squareFn := square(1, freq, 0)
return beep.StreamerFunc(func(samples [][2]float64) (n int, ok bool) {
sampleLength := len(samples)
for i := range samples {
samples[i][0] = squareFn(t)
samples[i][1] = squareFn(t)
t += sr.D(1).Seconds()
}
return sampleLength, true
})
}
func square(amplitude float64, frequency float64, phaseShift float64) func(t float64) float64 {
return func(t float64) float64 {
return amplitude / 4 * math.Copysign(1,
math.Sin(
2*math.Pi*frequency*t+phaseShift,
),
)
}
}
func pulseWave(sr beep.SampleRate, freq float64, dutyCycle float64) beep.Streamer {
t := 0.0
sawFn := sawtooth(1, freq, 0)
sineFn := sine(1, freq, 0)
return beep.StreamerFunc(func(samples [][2]float64) (n int, ok bool) {
sampleLength := len(samples)
for i := range samples {
sine := sineFn(t)
saw := sawFn(t)
if sine > saw {
samples[i][0] = 1.0
samples[i][1] = 1.0
} else {
samples[i][0] = 0.0
samples[i][1] = 0.0
}
t += sr.D(1).Seconds()
}
return sampleLength, true
})
}
func lfo(sr beep.SampleRate, rate int, amount, freq float64) beep.Streamer {
Ac := 1.0
Am := 1.0
Kf := amount
fc := freq
fm := 1 / float64(rate)
deltaF := Kf * Am
t := 0.0
return beep.StreamerFunc(func(samples [][2]float64) (n int, ok bool) {
sampleLength := len(samples)
for i := range samples {
y := Ac * math.Cos(2*math.Pi*fc*t+(Am*deltaF)/fm*math.Sin(2*math.Pi*fm*t))
samples[i][0] = y
samples[i][1] = y
t += sr.D(1).Seconds()
}
return sampleLength, true
})
} | synth.go | 0.599837 | 0.632701 | synth.go | starcoder |
package clock
import (
"encoding/xml"
"fmt"
"io"
"math"
"time"
)
const (
secondsInHalfClock = 30
secondsInClock = 2 * secondsInHalfClock
minutesInHalfClock = 30
minutesInClock = 2 * minutesInHalfClock
hoursInHalfClock = 6
hoursInClock = 2 * hoursInHalfClock
secondHandLength = 90.0
minuteHandLength = 80.0
hourHandLength = 50.0
clockCentreX = 150
clockCentreY = 150
)
type Point struct {
X float64
Y float64
}
//XML2struct: https://www.onlinetool.io/xmltogo/
type SVG struct {
XMLName xml.Name `xml:"svg"`
Xmlns string `xml:"xmlns,attr"`
Width string `xml:"width,attr"`
Height string `xml:"height,attr"`
ViewBox string `xml:"viewBox,attr"`
Version string `xml:"version,attr"`
Circle Circle `xml:"circle"`
Line []Line `xml:"line"`
}
type Circle struct {
Cx float64 `xml:"cx,attr"`
Cy float64 `xml:"cy,attr"`
R float64 `xml:"r,attr"`
}
type Line struct {
X1 float64 `xml:"x1,attr"`
Y1 float64 `xml:"y1,attr"`
X2 float64 `xml:"x2,attr"`
Y2 float64 `xml:"y2,attr"`
}
func secondHand(w io.Writer, t time.Time) {
unitCirclePoint := secondHandPoint(t)
point := makeHand(secondHandLength, unitCirclePoint)
fmt.Fprintf(w, `<line x1="150" y1="150" x2="%.3f" y2="%.3f" style="fill:none;stroke:#f00;stroke-width:3px;"/>`, point.X, point.Y)
}
func minuteHand(w io.Writer, t time.Time) {
unitCirclePoint := minuteHandPoint(t)
point := makeHand(minuteHandLength, unitCirclePoint)
fmt.Fprintf(w, `<line x1="150" y1="150" x2="%.3f" y2="%.3f" style="fill:none;stroke:#000;stroke-width:4px;"/>`, point.X, point.Y)
}
func hourHand(w io.Writer, t time.Time) {
unitCirclePoint := hourHandPoint(t)
point := makeHand(hourHandLength, unitCirclePoint)
fmt.Fprintf(w, `<line x1="150" y1="150" x2="%.3f" y2="%.3f" style="fill:none;stroke:#000;stroke-width:5px;"/>`, point.X, point.Y)
}
func makeHand(handLength float64, unitCirclePoint Point) Point {
point := Point{
X: clockCentreX + handLength*unitCirclePoint.X,
Y: clockCentreY - handLength*unitCirclePoint.Y,
}
return point
}
//SVGWriter writes an SVG representation of an analogue clock, showing the time t, to the writer w
func SVGWriter(w io.Writer, t time.Time) {
io.WriteString(w, svgStart)
io.WriteString(w, bezel)
secondHand(w, t)
minuteHand(w, t)
hourHand(w, t)
io.WriteString(w, svgEnd)
}
func secondsInRadians(t time.Time) float64 {
val := float64(t.Second())
return math.Pi / (secondsInHalfClock / val)
}
func minutesInRadians(t time.Time) float64 {
val := float64(t.Minute()*minutesInClock + t.Second())
return math.Pi / ((secondsInHalfClock * minutesInClock) / val)
}
func hoursInRadians(t time.Time) float64 {
val := float64((t.Hour()%hoursInClock)*secondsInClock*minutesInClock + t.Minute()*minutesInClock + t.Second())
return math.Pi / ((secondsInHalfClock * minutesInClock * hoursInClock) / val)
}
func secondHandPoint(t time.Time) Point {
return angleToPoint(secondsInRadians(t))
}
func minuteHandPoint(t time.Time) Point {
return angleToPoint(minutesInRadians(t))
}
func hourHandPoint(t time.Time) Point {
return angleToPoint(hoursInRadians(t))
}
func angleToPoint(angle float64) Point {
return Point{
X: math.Sin(angle),
Y: math.Cos(angle),
}
}
func simpleTime(hours, minutes, seconds int) time.Time {
return time.Date(7, time.March, 13, hours, minutes, seconds, 0, time.UTC)
}
func testName(t time.Time) string {
return t.Format("15:04:05")
}
const svgStart = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg"
width="100%"
height="100%"
viewBox="0 0 300 300"
version="2.0">`
const bezel = `<circle cx="150" cy="150" r="100" style="fill:#fff;stroke:#000;stroke-width:5px;"/>`
const svgEnd = `</svg>` | basics/clock/clock.go | 0.764276 | 0.403567 | clock.go | starcoder |
package utils
import (
"fmt"
"reflect"
"strings"
"time"
"cloud.google.com/go/spanner"
)
func GetTableName(model interface{}) string {
results := reflect.Indirect(reflect.ValueOf(model))
if reflect.TypeOf(model).Kind() == reflect.String {
return model.(string)
}
if kind := results.Kind(); kind == reflect.Slice {
resultType := results.Type().Elem()
if resultType.Kind() == reflect.Ptr {
resultType = resultType.Elem()
elem := reflect.New(resultType).Interface()
return reflect.TypeOf(elem).Elem().Name()
} else {
return resultType.Name()
}
}
if reflect.TypeOf(model).Kind() == reflect.Ptr {
modelType := reflect.TypeOf(model)
modelValue := reflect.New(modelType.Elem()).Interface()
return reflect.TypeOf(modelValue).Elem().Name()
}
return results.Type().Name()
}
func GetDeleteColumnName(model interface{}) string {
results := reflect.Indirect(reflect.ValueOf(model))
if kind := results.Kind(); kind == reflect.Slice {
resultType := results.Type().Elem()
if resultType.Kind() == reflect.Ptr {
resultType = resultType.Elem()
elem := reflect.New(resultType).Interface()
e := reflect.Indirect(reflect.ValueOf(elem))
for i := 0; i < e.NumField(); i++ {
tag, varName, _, _ := ReflectValues(e, i)
if tag.Get(SSORM_TAG_KEY) == SSORM_TAG_DELETE_TIME {
return varName
}
}
}
return ""
}
if reflect.TypeOf(model).Kind() == reflect.Ptr {
modelType := reflect.TypeOf(model)
modelValue := reflect.New(modelType.Elem()).Interface()
e := reflect.Indirect(reflect.ValueOf(modelValue))
for i := 0; i < e.NumField(); i++ {
tag, varName, _, _ := ReflectValues(e, i)
if tag.Get(SSORM_TAG_KEY) == SSORM_TAG_DELETE_TIME {
return varName
}
}
}
if reflect.TypeOf(model).Kind() == reflect.Struct {
e := reflect.Indirect(reflect.ValueOf(model))
for i := 0; i < e.NumField(); i++ {
tag, varName, _, _ := ReflectValues(e, i)
if tag.Get(SSORM_TAG_KEY) == SSORM_TAG_DELETE_TIME {
return varName
}
}
}
return ""
}
func ArrayContains(arr []string, str string) bool {
for _, v := range arr {
if v == str {
return true
}
}
return false
}
func ReflectValues(reflectValue reflect.Value, i int) (reflect.StructTag, string, interface{}, reflect.Type) {
value := reflect.TypeOf(reflectValue.Interface())
tag := value.Field(i).Tag
varName := tag.Get(SPANER_KEY)
if varName == "" {
varName = reflectValue.Type().Field(i).Name
}
varType := reflectValue.Type().Field(i).Type
varValue := reflectValue.Field(i).Interface()
return tag, varName, varValue, varType
}
func GetTimestampStr(value interface{}) string {
timestampStr := "NULL"
switch v := value.(type) {
case time.Time:
if !v.IsZero() {
timestampStr = fmt.Sprintf("TIMESTAMP_MILLIS(%d)", v.UnixNano()/int64(time.Millisecond))
}
case spanner.NullTime:
if !v.IsNull() {
timestampStr = fmt.Sprintf("TIMESTAMP_MILLIS(%d)", v.Time.UnixNano()/int64(time.Millisecond))
}
}
return timestampStr
}
func IsTime(value interface{}) bool {
switch value.(type) {
case time.Time:
return true
case spanner.NullTime:
return true
}
return false
}
func IsNullable(value interface{}) bool {
switch value.(type) {
case spanner.NullInt64, spanner.NullFloat64, spanner.NullString, spanner.NullDate, spanner.NullTime, spanner.NullRow,
*spanner.NullInt64, *spanner.NullFloat64, *spanner.NullString, *spanner.NullDate, *spanner.NullTime, *spanner.NullRow:
return true
}
return false
}
func IsValid(value interface{}) bool {
if value == nil {
return false
}
switch value.(type) {
case spanner.NullInt64:
return value.(spanner.NullInt64).Valid
case *spanner.NullInt64:
return value.(*spanner.NullInt64).Valid
case spanner.NullFloat64:
return value.(spanner.NullFloat64).Valid
case *spanner.NullFloat64:
return value.(*spanner.NullFloat64).Valid
case spanner.NullString:
return value.(spanner.NullString).Valid
case *spanner.NullString:
return value.(*spanner.NullString).Valid
case spanner.NullDate:
return value.(spanner.NullDate).Valid
case *spanner.NullDate:
return value.(*spanner.NullDate).Valid
case spanner.NullTime:
return value.(spanner.NullTime).Valid
case *spanner.NullTime:
return value.(*spanner.NullTime).Valid
case spanner.NullRow:
return value.(spanner.NullRow).Valid
case *spanner.NullRow:
return value.(*spanner.NullRow).Valid
}
return false
}
func GetArrayStr(value interface{}, valType reflect.Type) string {
var res string
var stringVal []string
var valFormat string
switch valType.String() {
case "[]string", "[]*string", "[]spanner.NullString", "[]*spanner.NullString", "[]civil.Date", "[]*civil.Date", "[]spanner.NullDate", "[]*spanner.NullDate":
valFormat = `"%v"`
default:
valFormat = "%v"
}
val := reflect.ValueOf(value)
for i := 0; i < val.Len(); i++ {
stringVal = append(stringVal, fmt.Sprintf(valFormat, reflect.Indirect(val.Index(i)).Interface()))
}
elms := strings.Join(stringVal, ",")
res = fmt.Sprintf("[%v]", elms)
return res
}
func IsTypeString(valType reflect.Type) bool {
if valType.Kind() == reflect.String {
return true
}
switch valType.String() {
case "spanner.NullString", "*spanner.NullString", "civil.Date", "spanner.NullDate", "*civil.Date", "*spanner.NullDate":
return true
}
return false
} | utils/utils.go | 0.52683 | 0.44083 | utils.go | starcoder |
package utils
import (
"time"
)
type ti int
const Time ti = iota
const ymd = "2006-01-02"
const hms = "15:04:05"
const full = "2006-01-02 15:04:05"
const year = 1
const month = 2
const day = 3
const hour = 4
const minute = 5
const second = 6
type date struct {
err error
time time.Time
}
type tickerInfo struct {
duration time.Duration
fn func()
ticker *time.Ticker
}
type timeInfo struct {
flag int
time time.Time
}
func (d date) Format(format string) string {
return d.time.Format(format)
}
func (d date) Time() time.Time {
return d.time
}
func (d date) Second() timeInfo {
return timeInfo{time: d.time, flag: second}
}
func (d date) Minute() timeInfo {
return timeInfo{time: d.time, flag: minute}
}
func (d date) Hour() timeInfo {
return timeInfo{time: d.time, flag: hour}
}
func (d date) Day() timeInfo {
return timeInfo{time: d.time, flag: day}
}
func (d date) Month() timeInfo {
return timeInfo{time: d.time, flag: month}
}
func (d date) Year() timeInfo {
return timeInfo{time: d.time, flag: year}
}
func (d date) LastError() error {
return d.err
}
func (t timeInfo) Get() int {
switch t.flag {
case second:
return t.time.Second()
case minute:
return t.time.Minute()
case hour:
return t.time.Hour()
case day:
return t.time.Day()
case month:
return int(t.time.Month())
case year:
return t.time.Year()
default:
return 0
}
}
func (t timeInfo) Begin() int64 {
switch t.flag {
case second:
return t.time.Unix()
case minute:
return t.time.Unix() - int64(t.time.Second())
case hour:
return t.time.Unix() - int64(t.time.Second()+t.time.Minute()*60)
case day:
return t.time.Unix() - int64(t.time.Second()+t.time.Minute()*60+t.time.Hour()*60*60)
case month:
return time.Date(t.time.Year(), t.time.Month(), 1, 0, 0, 0, 0, t.time.Location()).Unix()
case year:
return time.Date(t.time.Year(), 1, 1, 0, 0, 0, 0, t.time.Location()).Unix()
default:
return 0
}
}
func (t timeInfo) End() int64 {
switch t.flag {
case second:
return t.time.Unix()
case minute:
return t.Begin() + 60
case hour:
return t.Begin() + 3600
case day:
return t.Begin() + 86400
case month:
return time.Date(t.time.Year(), t.time.Month()+1, 1, 0, 0, 0, 0, t.time.Location()).Unix()
case year:
return time.Date(t.time.Year()+1, 1, 1, 0, 0, 0, 0, t.time.Location()).Unix()
default:
return 0
}
}
func (ti ti) New() date {
return date{time: time.Now()}
}
func (ti ti) Time(t time.Time) date {
return date{time: t}
}
func (ti ti) Timestamp(timestamp int64) date {
return date{time: time.Unix(timestamp, 0)}
}
func (ti ti) String(format, dateString string) date {
var t, err = time.ParseInLocation(format, dateString, time.Local)
return date{time: t, err: err}
}
func (ti ti) FullString(dateString string) date {
var t, err = time.ParseInLocation(full, dateString, time.Local)
return date{time: t, err: err}
}
func (ti ti) Ticker(duration time.Duration, fn func()) *tickerInfo {
return &tickerInfo{fn: fn, duration: duration}
}
func (ticker *tickerInfo) Start() {
ticker.ticker = time.NewTicker(ticker.duration)
go func() {
for range ticker.ticker.C {
ticker.fn()
}
}()
}
func (ticker *tickerInfo) Stop() {
ticker.ticker.Stop()
} | time.go | 0.547464 | 0.449997 | time.go | starcoder |
package chart
import (
"fmt"
"strconv"
"time"
)
// ValueFormatter is a function that takes a value and produces a string.
type ValueFormatter func(v interface{}) string
// TimeValueFormatter is a ValueFormatter for timestamps.
func TimeValueFormatter(v interface{}) string {
return formatTime(v, DefaultDateFormat)
}
// TimeHourValueFormatter is a ValueFormatter for timestamps.
func TimeHourValueFormatter(v interface{}) string {
return formatTime(v, DefaultDateHourFormat)
}
// TimeMinuteValueFormatter is a ValueFormatter for timestamps.
func TimeMinuteValueFormatter(v interface{}) string {
return formatTime(v, DefaultDateMinuteFormat)
}
// TimeDateValueFormatter is a ValueFormatter for timestamps.
func TimeDateValueFormatter(v interface{}) string {
return formatTime(v, "2006-01-02")
}
// TimeValueFormatterWithFormat returns a time formatter with a given format.
func TimeValueFormatterWithFormat(format string) ValueFormatter {
return func(v interface{}) string {
return formatTime(v, format)
}
}
// TimeValueFormatterWithFormat is a ValueFormatter for timestamps with a given format.
func formatTime(v interface{}, dateFormat string) string {
if typed, isTyped := v.(time.Time); isTyped {
return typed.Format(dateFormat)
}
if typed, isTyped := v.(int64); isTyped {
return time.Unix(0, typed).Format(dateFormat)
}
if typed, isTyped := v.(float64); isTyped {
return time.Unix(0, int64(typed)).Format(dateFormat)
}
return ""
}
// IntValueFormatter is a ValueFormatter for float64.
func IntValueFormatter(v interface{}) string {
switch v.(type) {
case int:
return strconv.Itoa(v.(int))
case int64:
return strconv.FormatInt(v.(int64), 10)
case float32:
return strconv.FormatInt(int64(v.(float32)), 10)
case float64:
return strconv.FormatInt(int64(v.(float64)), 10)
default:
return ""
}
}
// FloatValueFormatter is a ValueFormatter for float64.
func FloatValueFormatter(v interface{}) string {
return FloatValueFormatterWithFormat(v, DefaultFloatFormat)
}
// PercentValueFormatter is a formatter for percent values.
// NOTE: it normalizes the values, i.e. multiplies by 100.0.
func PercentValueFormatter(v interface{}) string {
if typed, isTyped := v.(float64); isTyped {
return FloatValueFormatterWithFormat(typed*100.0, DefaultPercentValueFormat)
}
return ""
}
// FloatValueFormatterWithFormat is a ValueFormatter for float64 with a given format.
func FloatValueFormatterWithFormat(v interface{}, floatFormat string) string {
if typed, isTyped := v.(int); isTyped {
return fmt.Sprintf(floatFormat, float64(typed))
}
if typed, isTyped := v.(int64); isTyped {
return fmt.Sprintf(floatFormat, float64(typed))
}
if typed, isTyped := v.(float32); isTyped {
return fmt.Sprintf(floatFormat, typed)
}
if typed, isTyped := v.(float64); isTyped {
return fmt.Sprintf(floatFormat, typed)
}
return ""
}
// KValueFormatter is a formatter for K values.
func KValueFormatter(k float64, vf ValueFormatter) ValueFormatter {
return func(v interface{}) string {
return fmt.Sprintf("%0.0fσ %s", k, vf(v))
}
} | vendor/github.com/wcharczuk/go-chart/v2/value_formatter.go | 0.82425 | 0.526099 | value_formatter.go | starcoder |
package sql
// A Visitor's Visit method is invoked for each node encountered by Walk.
// If the result visitor w is not nil, Walk visits each of the children
// of node with the visitor w, followed by a call of w.Visit(nil).
type Visitor interface {
Visit(node Node) (w Visitor, err error)
VisitEnd(node Node) error
}
// Walk traverses an AST in depth-first order: It starts by calling
// v.Visit(node); node must not be nil. If the visitor w returned by
// v.Visit(node) is not nil, Walk is invoked recursively with visitor
// w for each of the non-nil children of node, followed by a call of
// w.Visit(nil).
func Walk(v Visitor, node Node) error {
return walk(v, node)
}
func walk(v Visitor, node Node) (err error) {
// Visit the node itself
if v, err = v.Visit(node); err != nil {
return err
} else if v == nil {
return nil
}
// Visit node's children.
switch n := node.(type) {
case *Assignment:
if err := walkIdentList(v, n.Columns); err != nil {
return err
}
if err := walkExpr(v, n.Expr); err != nil {
return err
}
case *ExplainStatement:
if n.Stmt != nil {
if err := walk(v, n.Stmt); err != nil {
return err
}
}
case *RollbackStatement:
if err := walkIdent(v, n.SavepointName); err != nil {
return err
}
case *SavepointStatement:
if err := walkIdent(v, n.Name); err != nil {
return err
}
case *ReleaseStatement:
if err := walkIdent(v, n.Name); err != nil {
return err
}
case *CreateTableStatement:
if err := walkIdent(v, n.Name); err != nil {
return err
}
if err := walkColumnDefinitionList(v, n.Columns); err != nil {
return err
}
if err := walkConstraintList(v, n.Constraints); err != nil {
return err
}
if n.Select != nil {
if err := walk(v, n.Select); err != nil {
return err
}
}
case *AlterTableStatement:
if err := walkIdent(v, n.Name); err != nil {
return err
}
if err := walkIdent(v, n.NewName); err != nil {
return err
}
if err := walkIdent(v, n.ColumnName); err != nil {
return err
}
if err := walkIdent(v, n.NewColumnName); err != nil {
return err
}
if n.ColumnDef != nil {
if err := walk(v, n.ColumnDef); err != nil {
return err
}
}
case *AnalyzeStatement:
if err := walkIdent(v, n.Name); err != nil {
return err
}
case *CreateViewStatement:
if err := walkIdent(v, n.Name); err != nil {
return err
}
if err := walkIdentList(v, n.Columns); err != nil {
return err
}
if n.Select != nil {
if err := walk(v, n.Select); err != nil {
return err
}
}
case *DropTableStatement:
if err := walkIdent(v, n.Name); err != nil {
return err
}
case *DropViewStatement:
if err := walkIdent(v, n.Name); err != nil {
return err
}
case *DropIndexStatement:
if err := walkIdent(v, n.Name); err != nil {
return err
}
case *DropTriggerStatement:
if err := walkIdent(v, n.Name); err != nil {
return err
}
case *CreateIndexStatement:
if err := walkIdent(v, n.Name); err != nil {
return err
}
if err := walkIdent(v, n.Table); err != nil {
return err
}
if err := walkIndexedColumnList(v, n.Columns); err != nil {
return err
}
if err := walkExpr(v, n.WhereExpr); err != nil {
return err
}
case *CreateTriggerStatement:
if err := walkIdent(v, n.Name); err != nil {
return err
}
if err := walkIdentList(v, n.UpdateOfColumns); err != nil {
return err
}
if err := walkIdent(v, n.Table); err != nil {
return err
}
if err := walkExpr(v, n.WhenExpr); err != nil {
return err
}
for _, x := range n.Body {
if err := walk(v, x); err != nil {
return err
}
}
case *SelectStatement:
if n.WithClause != nil {
if err := walk(v, n.WithClause); err != nil {
return err
}
}
for _, x := range n.ValueLists {
if err := walk(v, x); err != nil {
return err
}
}
for _, x := range n.Columns {
if err := walk(v, x); err != nil {
return err
}
}
if n.Source != nil {
if err := walk(v, n.Source); err != nil {
return err
}
}
if err := walkExpr(v, n.WhereExpr); err != nil {
return err
}
if err := walkExprList(v, n.GroupByExprs); err != nil {
return err
}
if err := walkExpr(v, n.HavingExpr); err != nil {
return err
}
for _, x := range n.Windows {
if err := walk(v, x); err != nil {
return err
}
}
if n.Compound != nil {
if err := walk(v, n.Compound); err != nil {
return err
}
}
for _, x := range n.OrderingTerms {
if err := walk(v, x); err != nil {
return err
}
}
if err := walkExpr(v, n.LimitExpr); err != nil {
return err
}
if err := walkExpr(v, n.OffsetExpr); err != nil {
return err
}
case *InsertStatement:
if n.WithClause != nil {
if err := walk(v, n.WithClause); err != nil {
return err
}
}
if err := walkIdent(v, n.Table); err != nil {
return err
}
if err := walkIdent(v, n.Alias); err != nil {
return err
}
if err := walkIdentList(v, n.Columns); err != nil {
return err
}
for _, x := range n.ValueLists {
if err := walk(v, x); err != nil {
return err
}
}
if n.Select != nil {
if err := walk(v, n.Select); err != nil {
return err
}
}
if n.UpsertClause != nil {
if err := walk(v, n.UpsertClause); err != nil {
return err
}
}
case *UpdateStatement:
if n.WithClause != nil {
if err := walk(v, n.WithClause); err != nil {
return err
}
}
if n.Table != nil {
if err := walk(v, n.Table); err != nil {
return err
}
}
for _, x := range n.Assignments {
if err := walk(v, x); err != nil {
return err
}
}
if err := walkExpr(v, n.WhereExpr); err != nil {
return err
}
case *UpsertClause:
if err := walkIndexedColumnList(v, n.Columns); err != nil {
return err
}
if err := walkExpr(v, n.WhereExpr); err != nil {
return err
}
for _, x := range n.Assignments {
if err := walk(v, x); err != nil {
return err
}
}
if err := walkExpr(v, n.UpdateWhereExpr); err != nil {
return err
}
case *DeleteStatement:
if n.WithClause != nil {
if err := walk(v, n.WithClause); err != nil {
return err
}
}
if n.Table != nil {
if err := walk(v, n.Table); err != nil {
return err
}
}
if err := walkExpr(v, n.WhereExpr); err != nil {
return err
}
for _, x := range n.OrderingTerms {
if err := walk(v, x); err != nil {
return err
}
}
if err := walkExpr(v, n.LimitExpr); err != nil {
return err
}
if err := walkExpr(v, n.OffsetExpr); err != nil {
return err
}
case *PrimaryKeyConstraint:
if err := walkIdent(v, n.Name); err != nil {
return err
}
if err := walkIdentList(v, n.Columns); err != nil {
return err
}
case *NotNullConstraint:
if err := walkIdent(v, n.Name); err != nil {
return err
}
case *UniqueConstraint:
if err := walkIdent(v, n.Name); err != nil {
return err
}
if err := walkIdentList(v, n.Columns); err != nil {
return err
}
case *CheckConstraint:
if err := walkIdent(v, n.Name); err != nil {
return err
}
if err := walkExpr(v, n.Expr); err != nil {
return err
}
case *DefaultConstraint:
if err := walkIdent(v, n.Name); err != nil {
return err
}
if err := walkExpr(v, n.Expr); err != nil {
return err
}
case *ForeignKeyConstraint:
if err := walkIdent(v, n.Name); err != nil {
return err
}
if err := walkIdentList(v, n.Columns); err != nil {
return err
}
if err := walkIdent(v, n.ForeignTable); err != nil {
return err
}
if err := walkIdentList(v, n.ForeignColumns); err != nil {
return err
}
for _, x := range n.Args {
if err := walk(v, x); err != nil {
return err
}
}
case *ParenExpr:
if err := walkExpr(v, n.X); err != nil {
return err
}
case *UnaryExpr:
if err := walkExpr(v, n.X); err != nil {
return err
}
case *BinaryExpr:
if err := walkExpr(v, n.X); err != nil {
return err
}
if err := walkExpr(v, n.Y); err != nil {
return err
}
case *CastExpr:
if err := walkExpr(v, n.X); err != nil {
return err
}
if n.Type != nil {
if err := walk(v, n.Type); err != nil {
return err
}
}
case *CaseBlock:
if err := walkExpr(v, n.Condition); err != nil {
return err
}
if err := walkExpr(v, n.Body); err != nil {
return err
}
case *CaseExpr:
if err := walkExpr(v, n.Operand); err != nil {
return err
}
for _, x := range n.Blocks {
if err := walk(v, x); err != nil {
return err
}
}
if err := walkExpr(v, n.ElseExpr); err != nil {
return err
}
case *ExprList:
if err := walkExprList(v, n.Exprs); err != nil {
return err
}
case *QualifiedRef:
if err := walkIdent(v, n.Table); err != nil {
return err
}
if err := walkIdent(v, n.Column); err != nil {
return err
}
case *Call:
if err := walkIdent(v, n.Name); err != nil {
return err
}
if err := walkExprList(v, n.Args); err != nil {
return err
}
if n.Filter != nil {
if err := walk(v, n.Filter); err != nil {
return err
}
}
if n.Over != nil {
if err := walk(v, n.Over); err != nil {
return err
}
}
case *FilterClause:
if err := walkExpr(v, n.X); err != nil {
return err
}
case *OverClause:
if err := walkIdent(v, n.Name); err != nil {
return err
}
if n.Definition != nil {
if err := walk(v, n.Definition); err != nil {
return err
}
}
case *OrderingTerm:
if err := walkExpr(v, n.X); err != nil {
return err
}
case *FrameSpec:
if err := walkExpr(v, n.X); err != nil {
return err
}
if err := walkExpr(v, n.Y); err != nil {
return err
}
case *Range:
if err := walkExpr(v, n.X); err != nil {
return err
}
if err := walkExpr(v, n.Y); err != nil {
return err
}
case *Raise:
if n.Error != nil {
if err := walk(v, n.Error); err != nil {
return err
}
}
case *Exists:
if n.Select != nil {
if err := walk(v, n.Select); err != nil {
return err
}
}
case *ParenSource:
if n.X != nil {
if err := walk(v, n.X); err != nil {
return err
}
}
if err := walkIdent(v, n.Alias); err != nil {
return err
}
case *QualifiedTableName:
if err := walkIdent(v, n.Name); err != nil {
return err
}
if err := walkIdent(v, n.Alias); err != nil {
return err
}
if err := walkIdent(v, n.Index); err != nil {
return err
}
case *JoinClause:
if n.X != nil {
if err := walk(v, n.X); err != nil {
return err
}
}
if n.Operator != nil {
if err := walk(v, n.Operator); err != nil {
return err
}
}
if n.Y != nil {
if err := walk(v, n.Y); err != nil {
return err
}
}
if n.Constraint != nil {
if err := walk(v, n.Constraint); err != nil {
return err
}
}
case *OnConstraint:
if err := walkExpr(v, n.X); err != nil {
return err
}
case *UsingConstraint:
if err := walkIdentList(v, n.Columns); err != nil {
return err
}
case *ColumnDefinition:
if err := walkIdent(v, n.Name); err != nil {
return err
}
if n.Type != nil {
if err := walk(v, n.Type); err != nil {
return err
}
}
if err := walkConstraintList(v, n.Constraints); err != nil {
return err
}
case *ResultColumn:
if err := walkExpr(v, n.Expr); err != nil {
return err
}
if err := walkIdent(v, n.Alias); err != nil {
return err
}
case *IndexedColumn:
if err := walkExpr(v, n.X); err != nil {
return err
}
case *Window:
if err := walkIdent(v, n.Name); err != nil {
return err
}
if n.Definition != nil {
if err := walk(v, n.Definition); err != nil {
return err
}
}
case *WindowDefinition:
if err := walkIdent(v, n.Base); err != nil {
return err
}
if err := walkExprList(v, n.Partitions); err != nil {
return err
}
for _, x := range n.OrderingTerms {
if err := walk(v, x); err != nil {
return err
}
}
if n.Frame != nil {
if err := walk(v, n.Frame); err != nil {
return err
}
}
case *Type:
if err := walkIdent(v, n.Name); err != nil {
return err
}
if n.Precision != nil {
if err := walk(v, n.Precision); err != nil {
return err
}
}
if n.Scale != nil {
if err := walk(v, n.Scale); err != nil {
return err
}
}
}
// Revisit original node after its children have been processed.
return v.VisitEnd(node)
}
// VisitFunc represents a function type that implements Visitor.
// Only executes on node entry.
type VisitFunc func(Node) error
// Visit executes fn. Walk visits node children if fn returns true.
func (fn VisitFunc) Visit(node Node) (Visitor, error) {
if err := fn(node); err != nil {
return nil, err
}
return fn, nil
}
// VisitEnd is a no-op.
func (fn VisitFunc) VisitEnd(node Node) error { return nil }
// VisitEndFunc represents a function type that implements Visitor.
// Only executes on node exit.
type VisitEndFunc func(Node) error
// Visit is a no-op.
func (fn VisitEndFunc) Visit(node Node) (Visitor, error) { return fn, nil }
// VisitEnd executes fn.
func (fn VisitEndFunc) VisitEnd(node Node) error { return fn(node) }
func walkIdent(v Visitor, x *Ident) error {
if x != nil {
if err := walk(v, x); err != nil {
return err
}
}
return nil
}
func walkIdentList(v Visitor, a []*Ident) error {
for _, x := range a {
if err := walk(v, x); err != nil {
return err
}
}
return nil
}
func walkExpr(v Visitor, x Expr) error {
if x != nil {
if err := walk(v, x); err != nil {
return err
}
}
return nil
}
func walkExprList(v Visitor, a []Expr) error {
for _, x := range a {
if err := walk(v, x); err != nil {
return err
}
}
return nil
}
func walkConstraintList(v Visitor, a []Constraint) error {
for _, x := range a {
if err := walk(v, x); err != nil {
return err
}
}
return nil
}
func walkIndexedColumnList(v Visitor, a []*IndexedColumn) error {
for _, x := range a {
if err := walk(v, x); err != nil {
return err
}
}
return nil
}
func walkColumnDefinitionList(v Visitor, a []*ColumnDefinition) error {
for _, x := range a {
if err := walk(v, x); err != nil {
return err
}
}
return nil
} | walk.go | 0.689619 | 0.450541 | walk.go | starcoder |
package pgsql
import (
"database/sql"
"database/sql/driver"
)
// BitArrayFromBoolSlice returns a driver.Valuer that produces a PostgreSQL bit[] from the given Go []bool.
func BitArrayFromBoolSlice(val []bool) driver.Valuer {
return bitArrayFromBoolSlice{val: val}
}
// BitArrayToBoolSlice returns an sql.Scanner that converts a PostgreSQL bit[] into a Go []bool and sets it to val.
func BitArrayToBoolSlice(val *[]bool) sql.Scanner {
return bitArrayToBoolSlice{val: val}
}
// BitArrayFromUint8Slice returns a driver.Valuer that produces a PostgreSQL bit[] from the given Go []uint8.
func BitArrayFromUint8Slice(val []uint8) driver.Valuer {
return bitArrayFromUint8Slice{val: val}
}
// BitArrayToUint8Slice returns an sql.Scanner that converts a PostgreSQL bit[] to a Go []uint8 and sets it to val.
func BitArrayToUint8Slice(val *[]uint8) sql.Scanner {
return bitArrayToUint8Slice{val: val}
}
// BitArrayFromUintSlice returns a driver.Valuer that produces a PostgreSQL bit[] from the given Go []uint.
func BitArrayFromUintSlice(val []uint) driver.Valuer {
return bitArrayFromUintSlice{val: val}
}
// BitArrayToUintSlice returns an sql.Scanner that converts a PostgreSQL bit[] to a Go []uint and sets it to val.
func BitArrayToUintSlice(val *[]uint) sql.Scanner {
return bitArrayToUintSlice{val: val}
}
type bitArrayFromBoolSlice struct {
val []bool
}
func (v bitArrayFromBoolSlice) Value() (driver.Value, error) {
if v.val == nil {
return nil, nil
}
if n := len(v.val); n > 0 {
out := make([]byte, 1+(n*2))
out[0] = '{'
j := 1
for i := 0; i < n; i++ {
if v.val[i] {
out[j] = '1'
} else {
out[j] = '0'
}
out[j+1] = ','
j += 2
}
out[len(out)-1] = '}'
return out, nil
}
return []byte{'{', '}'}, nil
}
type bitArrayFromUint8Slice struct {
val []uint8
}
func (v bitArrayFromUint8Slice) Value() (driver.Value, error) {
if v.val == nil {
return nil, nil
}
if n := len(v.val); n > 0 {
out := make([]byte, 1+(n*2))
out[0] = '{'
j := 1
for i := 0; i < n; i++ {
if v.val[i] == 0 {
out[j] = '0'
} else {
out[j] = '1'
}
out[j+1] = ','
j += 2
}
out[len(out)-1] = '}'
return out, nil
}
return []byte{'{', '}'}, nil
}
type bitArrayFromUintSlice struct {
val []uint
}
func (v bitArrayFromUintSlice) Value() (driver.Value, error) {
if v.val == nil {
return nil, nil
}
if n := len(v.val); n > 0 {
out := make([]byte, 1+(n*2))
out[0] = '{'
j := 1
for i := 0; i < n; i++ {
if v.val[i] == 0 {
out[j] = '0'
} else {
out[j] = '1'
}
out[j+1] = ','
j += 2
}
out[len(out)-1] = '}'
return out, nil
}
return []byte{'{', '}'}, nil
return nil, nil
}
type bitArrayToBoolSlice struct {
val *[]bool
}
func (v bitArrayToBoolSlice) Scan(src interface{}) error {
arr, err := srcbytes(src)
if err != nil {
return err
} else if arr == nil {
*v.val = nil
return nil
}
elems := pgParseCommaArray(arr)
bools := make([]bool, len(elems))
for i := 0; i < len(elems); i++ {
if elems[i][0] == '1' {
bools[i] = true
} else {
bools[i] = false
}
}
*v.val = bools
return nil
}
type bitArrayToUint8Slice struct {
val *[]uint8
}
func (v bitArrayToUint8Slice) Scan(src interface{}) error {
arr, err := srcbytes(src)
if err != nil {
return err
} else if arr == nil {
*v.val = nil
return nil
}
elems := pgParseCommaArray(arr)
uint8s := make([]uint8, len(elems))
for i := 0; i < len(elems); i++ {
if elems[i][0] == '1' {
uint8s[i] = 1
} else {
uint8s[i] = 0
}
}
*v.val = uint8s
return nil
}
type bitArrayToUintSlice struct {
val *[]uint
}
func (v bitArrayToUintSlice) Scan(src interface{}) error {
arr, err := srcbytes(src)
if err != nil {
return err
} else if arr == nil {
*v.val = nil
return nil
}
elems := pgParseCommaArray(arr)
uints := make([]uint, len(elems))
for i := 0; i < len(elems); i++ {
if elems[i][0] == '1' {
uints[i] = 1
} else {
uints[i] = 0
}
}
*v.val = uints
return nil
} | pgsql/bitarr.go | 0.67104 | 0.402803 | bitarr.go | starcoder |
package multipleconversions
import (
"math"
"strconv"
"strings"
)
// RPN returns the result of an expression using reverse polish notation (postfix) by exploding the string
// to a slice and editing the slice by replacing each op by its result until only a number is left or
// failing if the expression is invalid.
func RPN(RPNInput string) float64 {
words := strings.Fields(RPNInput)
index := 0
// Known vars are needed to hold values of strconv
var num, num2 float64
var err error
for len(words) != 1 {
//index = findFirstOperator(words)
//Skipping subroutine
err = nil
index = 0
for err == nil && index < len(words) {
_, err = strconv.ParseFloat(words[index], 64) //0 iso 64 returns an int for some reason
index++
}
index -= 1
if words[index] == "sqrt" {
//unary operator
if num, err = strconv.ParseFloat(words[index-1], 64); err != nil {
panic("Invalid value for sqrt")
}
// num = math.Sqrt(num)
words[index-1] = strconv.FormatFloat(math.Sqrt(num), 'f', 10, 64)
words = append(words[:index], words[index+1:]...) //removing sqrt
} else {
//binary operator
if num, err = strconv.ParseFloat(words[index-2], 64); err != nil {
panic("Invalid left operand")
}
if num2, err = strconv.ParseFloat(words[index-1], 64); err != nil {
panic("Invalid right operand")
}
words[index-2] = returnStringResult(num, num2, words[index])
/* removing binary operator by removing the slice until the item after the result */
words = append(words[:index-1], words[index+1:]...)
}
}
num, _ = strconv.ParseFloat(words[0], 64)
return num
}
func returnStringResult(leftOp, rightOp float64, operatorU string) string {
switch operatorU {
case "+":
return strconv.FormatFloat(leftOp+rightOp, 'f', 13, 64)
case "-":
return strconv.FormatFloat(leftOp-rightOp, 'f', 13, 64)
case "*":
return strconv.FormatFloat(leftOp*rightOp, 'f', 13, 64)
case "/":
return strconv.FormatFloat(leftOp/rightOp, 'f', 13, 64)
case "^":
return strconv.FormatFloat(math.Pow(leftOp, rightOp), 'f', 13, 64)
default:
panic("Invalid operator")
}
} | multipleconversions/multipleconversions.go | 0.631822 | 0.511961 | multipleconversions.go | starcoder |
package math
import "math"
type Vector2 struct {
X float64
Y float64
}
func (v *Vector2) GetWidth() float64 {
return v.X
}
func (v *Vector2) SetWidth( width float64 ) {
v.X = width
}
func (v *Vector2) GetHeight() float64 {
return v.Y
}
func (v *Vector2) SetHeight( height float64 ) {
v.Y = height
}
func (v *Vector2) Set( x, y float64 ) *Vector2 {
v.X = x
v.Y = y
return v
}
func (v *Vector2) SetScalar( scalar float64 ) {
v.X = scalar
v.Y = scalar
}
func (v *Vector2) SetX( x float64 ) *Vector2 {
v.X = x
return v
}
func (v *Vector2) SetY( y float64 ) *Vector2 {
v.Y = y
return v
}
func (v *Vector2) SetComponent( index int, value float64 ) {
switch index {
case 0:
v.X = value;
case 1:
v.Y = value
}
}
func (v *Vector2) GetComponent( index int ) float64 {
switch index {
case 0:
return v.X
case 1:
return v.Y
}
return 0.0
}
func (v *Vector2) Clone() *Vector2 {
v2 := &Vector2{ X:v.X, Y:v.Y }
return v2
}
func (v *Vector2) Copy( other *Vector2) *Vector2 {
v.X = other.X
v.Y = other.Y
return v
}
func (v *Vector2) Add( other *Vector2 ) *Vector2{
v.X += other.X;
v.Y += other.Y;
return v
}
func (v *Vector2) AddScalar( scalar float64) {
v.X += scalar
v.Y += scalar
}
func (v *Vector2) AddVectors( a *Vector2, b *Vector2 ) *Vector2 {
v.X = a.X + b.X
v.Y = a.Y + b.Y
return v
}
func (v *Vector2) AddScaledVector( other Vector2, scalar float64 ) *Vector2 {
v.X += other.X * scalar
v.Y += other.Y * scalar
return v
}
func (v *Vector2) Sub( other *Vector2 ) *Vector2 {
v.X -= other.X
v.Y -= other.Y
return v
}
func (v *Vector2) SubScalar( scalar float64 ) *Vector2 {
v.X -= scalar
v.Y -= scalar
return v
}
func (v *Vector2) SubVectors( a *Vector2, b *Vector2) *Vector2 {
v.X = a.X - b.X
v.Y = a.Y - b.Y
return v
}
func (v *Vector2) Multiply( other Vector2 ) *Vector2 {
v.X *= other.X
v.Y *= other.Y
return v
}
func (v *Vector2) MultiplyScalar( scalar float64 ) *Vector2 {
v.X *= scalar
v.Y *= scalar
return v
}
func (v *Vector2) Divide( other Vector2 ) *Vector2 {
v.X /= other.X
v.Y /= other.Y
return v
}
func (v *Vector2) DivideScalar( scalar float64) *Vector2 {
v.X /= scalar
v.Y /= scalar
return v
}
func (v *Vector2) Min( other *Vector2 ) *Vector2 {
v.X = math.Min( v.X, other.X )
v.Y = math.Min( v.Y, other.Y )
return v
}
func (v *Vector2) Max( other *Vector2) *Vector2 {
v.X = math.Max( v.X, other.X )
v.Y = math.Max( v.Y, other.Y )
return v
}
func (v *Vector2) Clamp( min, max *Vector2) *Vector2 {
v.X = math.Max( min.X, math.Min( max.X, v.X ))
v.Y = math.Max( min.Y, math.Min( max.Y, v.Y ))
return v
}
func (v *Vector2) ClampScalar( minScalar, maxScalar float64) *Vector2 {
min := &Vector2{ X:minScalar, Y:minScalar }
max := &Vector2{ X:maxScalar, Y:maxScalar }
return v.Clamp(min, max)
}
func (v *Vector2) ClampLength( min float64, max float64 ) *Vector2{
length := v.Length()
return v.MultiplyScalar( math.Max( min, math.Min( max, length)) / length )
}
func (v *Vector2) Floor() *Vector2 {
v.X = math.Floor( v.X )
v.Y = math.Floor( v.Y )
return v
}
func (v *Vector2) Ceil() *Vector2 {
v.X = math.Ceil( v.X )
v.Y = math.Ceil( v.Y )
return v
}
func (v *Vector2) Round() *Vector2 {
v.X = math.Floor( v.X + .5 )
v.Y = math.Floor( v.Y + .5 )
return v
}
func (v *Vector2) RoundToZero() *Vector2 {
if v.X < 0 {
v.X = math.Ceil( v.X )
} else {
v.X = math.Floor( v.X )
}
if v.Y < 0 {
v.Y = math.Ceil( v.Y )
} else {
v.Y = math.Floor( v.Y )
}
return v
}
func (v *Vector2) Negate() *Vector2 {
v.X = -v.X
v.Y = -v.Y
return v
}
func (v *Vector2) Dot( other *Vector2) float64 {
return v.X * other.X + v.Y * other.Y
}
func (v *Vector2) Length() float64 {
return math.Sqrt( v.X * v.X + v.Y * v.Y )
}
func (v *Vector2) LengthSq() float64 {
return v.X * v.X + v.Y * v.Y
}
func (v *Vector2) Normalize() *Vector2 {
return v.DivideScalar( v.Length() )
}
func (v *Vector2) Angle() float64 {
angle := math.Atan2( v.Y, v.X )
if angle < 0 {
angle += 2 * math.Pi
}
return angle
}
func (v *Vector2) DistanceTo( other *Vector2 ) float64 {
return math.Sqrt( v.DistanceToSquared(other) )
}
func (v *Vector2) DistanceToSquared( other *Vector2 ) float64 {
dx := v.X - other.X
dy := v.Y - other.Y
return dx * dx + dy * dy
}
func (v *Vector2) SetLength( length float64 ) *Vector2{
if v.Length() == 0 {
return v
}
orgLength := v.Length()
v.MultiplyScalar( length )
v.DivideScalar( orgLength )
return v
}
func (v *Vector2) Lerp( other *Vector2, alpha float64 ) *Vector2 {
v.X += ( other.X - v.X ) * alpha
v.Y += ( other.Y - v.Y ) * alpha
return v
}
func (v *Vector2) Equals( other *Vector2) bool {
return (( v.X == other.X ) && ( v.Y == other.Y ))
}
func (v *Vector2) FromArray( array []float64 ) {
v.X = array[0]
v.Y = array[1]
}
func (v *Vector2) ToArray( array []float64 ) []float64 {
array[0] = v.X
array[1] = v.Y
return array
}
func (v *Vector2) RotateAround( center Vector2, angle float64 ) *Vector2{
c := math.Cos( angle )
s := math.Sin( angle )
x := v.X - center.X
y := v.Y - center.Y
v.X = x * c - y * s + center.X
v.Y = y * s + y * c + center.Y
return v
} | math/vector2.go | 0.899423 | 0.767733 | vector2.go | starcoder |
package spdg
import (
"bytes"
"context"
"crypto/rand"
"crypto/rsa"
"crypto/sha512"
)
/*
Layer is the lowest level of the core SPDG model. It takes in byte buffers
which are commonly known as the "last known datatype" in the SPDG model.
That means it is the only other datatype next to SPDGs themselves that
can travel parts of the pipeline. Any ingress point's main concern should
be to get to SPDG as quick as possible by having a contained scope with a
layer of any to byte buffer converters catch any incoming types, and from
convert to go to SPDGs. Only then should real scope be granted.
The following features are important:
- Encrypted : Encryption is a first class citizen in SPDG and a clear
=========
policy is that data should not leak. That means multiple encodes and
decodes as data flows through the pipeline. No public method should
ever return or accept unencrypted packets.
- Private : The type follows the strictest privacy guidelines where
=======
only access to the correct key combination values can be inspected
or written. Access is granular to the packet level, so a validated
connection achieves nothing, and is therefor not needed. This keeps
the data type future proofed and inline with ever more complex
privacy regulations such as GDPR and the likes.
- Destructive : For reasons of tamper-proofing the type has the option
===========
to layer its own public key, after which the data is inaccessible.
Another benefit is that is gives the data an inherent value besides
its external value as a secure and trusted token of information.
It is important to note that the data is not lost in this case.
Canonically it exists and knowledge of it reverberates through the
objects it has interacted with. But it was considered void of value
and thus marked as non-grata. This will combat value inflation.
*/
type Layer interface {
State() (Status, Reason)
Peek(bytes.Buffer)
Poke(bytes.Buffer)
}
/* Layer defines the interface for the common way data is stored. Encryption and anonimity
are first class citizens in Layers. */
type ProtoLayer struct {
key *rsa.PublicKey
sec *rsa.PrivateKey
dat []byte
err error
}
func NewProtoLayer(ctx context.Context) Layer {
return ProtoLayer{}
}
func (layer ProtoLayer) State() (Status, Reason) {
return OK, BUSY
}
func (layer ProtoLayer) Peek(dat bytes.Buffer) {
layer.sec, layer.err = rsa.GenerateKey(rand.Reader, 2048)
layer.key = &layer.sec.PublicKey
layer.seal(dat)
}
func (layer ProtoLayer) Poke(dat bytes.Buffer) {
}
func (layer ProtoLayer) seal(dat bytes.Buffer) {
layer.dat, layer.err = rsa.EncryptOAEP(
sha512.New(),
rand.Reader,
layer.key,
dat.Bytes(),
nil,
)
} | layer.go | 0.568416 | 0.604136 | layer.go | starcoder |
package gmtls
type certificateRequestMsgGM struct {
raw []byte
// hasSignatureAlgorithm indicates whether this message includes a list of
// supported signature algorithms. This change was introduced with TLS 1.2.
hasSignatureAlgorithm bool
supportedSignatureAlgorithms []SignatureScheme
certificateTypes []byte
certificateAuthorities [][]byte
}
func (m *certificateRequestMsgGM) marshal() (x []byte) {
if m.raw != nil {
return m.raw
}
// See RFC 4346, Section 7.4.4.
length := 1 + len(m.certificateTypes) + 2
casLength := 0
for _, ca := range m.certificateAuthorities {
casLength += 2 + len(ca)
}
length += casLength
if m.hasSignatureAlgorithm {
length += 2 + 2*len(m.supportedSignatureAlgorithms)
}
x = make([]byte, 4+length)
x[0] = typeCertificateRequest
x[1] = uint8(length >> 16)
x[2] = uint8(length >> 8)
x[3] = uint8(length)
x[4] = uint8(len(m.certificateTypes))
copy(x[5:], m.certificateTypes)
y := x[5+len(m.certificateTypes):]
if m.hasSignatureAlgorithm {
n := len(m.supportedSignatureAlgorithms) * 2
y[0] = uint8(n >> 8)
y[1] = uint8(n)
y = y[2:]
for _, sigAlgo := range m.supportedSignatureAlgorithms {
y[0] = uint8(sigAlgo >> 8)
y[1] = uint8(sigAlgo)
y = y[2:]
}
}
y[0] = uint8(casLength >> 8)
y[1] = uint8(casLength)
y = y[2:]
for _, ca := range m.certificateAuthorities {
y[0] = uint8(len(ca) >> 8)
y[1] = uint8(len(ca))
y = y[2:]
copy(y, ca)
y = y[len(ca):]
}
m.raw = x
return
}
func (m *certificateRequestMsgGM) unmarshal(data []byte) bool {
m.raw = data
if len(data) < 5 {
return false
}
length := uint32(data[1])<<16 | uint32(data[2])<<8 | uint32(data[3])
if uint32(len(data))-4 != length {
return false
}
numCertTypes := int(data[4])
data = data[5:]
if numCertTypes == 0 || len(data) <= numCertTypes {
return false
}
m.certificateTypes = make([]byte, numCertTypes)
if copy(m.certificateTypes, data) != numCertTypes {
return false
}
data = data[numCertTypes:]
if m.hasSignatureAlgorithm {
if len(data) < 2 {
return false
}
sigAndHashLen := uint16(data[0])<<8 | uint16(data[1])
data = data[2:]
if sigAndHashLen&1 != 0 {
return false
}
if len(data) < int(sigAndHashLen) {
return false
}
numSigAlgos := sigAndHashLen / 2
m.supportedSignatureAlgorithms = make([]SignatureScheme, numSigAlgos)
for i := range m.supportedSignatureAlgorithms {
m.supportedSignatureAlgorithms[i] = SignatureScheme(data[0])<<8 | SignatureScheme(data[1])
data = data[2:]
}
}
if len(data) < 2 {
return false
}
casLength := uint16(data[0])<<8 | uint16(data[1])
data = data[2:]
if len(data) < int(casLength) {
return false
}
cas := make([]byte, casLength)
copy(cas, data)
data = data[casLength:]
m.certificateAuthorities = nil
for len(cas) > 0 {
if len(cas) < 2 {
return false
}
caLen := uint16(cas[0])<<8 | uint16(cas[1])
cas = cas[2:]
if len(cas) < int(caLen) {
return false
}
m.certificateAuthorities = append(m.certificateAuthorities, cas[:caLen])
cas = cas[caLen:]
}
return len(data) == 0
} | gmtls/gm_handshake_messages.go | 0.572723 | 0.415373 | gm_handshake_messages.go | starcoder |
Marching Squares
Convert an SDF2 boundary to a set of line segments.
*/
//-----------------------------------------------------------------------------
package sdf
//-----------------------------------------------------------------------------
// lineCache is a cache of SDF2 evaluations samples over a 2d line.
type lineCache struct {
base V2 // base coordinate of line
inc V2 // dx, dy for each step
steps V2i // number of x,y steps
val0 []float64 // SDF values for x line
val1 []float64 // SDF values for x + dx line
}
// newLineCache returns a line cache.
func newLineCache(base, inc V2, steps V2i) *lineCache {
return &lineCache{base, inc, steps, nil, nil}
}
// evaluate the SDF2 over a given x line.
func (l *lineCache) evaluate(sdf SDF2, x int) {
// Swap the layers
l.val0, l.val1 = l.val1, l.val0
ny := l.steps[1]
dx, dy := l.inc.X, l.inc.Y
// allocate storage
if l.val1 == nil {
l.val1 = make([]float64, ny+1)
}
// setup the loop variables
idx := 0
var p V2
p.X = l.base.X + float64(x)*dx
// evaluate the line
p.Y = l.base.Y
for y := 0; y < ny+1; y++ {
l.val1[idx] = sdf.Evaluate(p)
idx++
p.Y += dy
}
}
// get a value from a line cache.
func (l *lineCache) get(x, y int) float64 {
if x == 0 {
return l.val0[y]
}
return l.val1[y]
}
//-----------------------------------------------------------------------------
func marchingSquares(sdf SDF2, box Box2, step float64) []*Line {
var lines []*Line
size := box.Size()
base := box.Min
steps := size.DivScalar(step).Ceil().ToV2i()
inc := size.Div(steps.ToV2())
// create the line cache
l := newLineCache(base, inc, steps)
// evaluate the SDF for x = 0
l.evaluate(sdf, 0)
nx, ny := steps[0], steps[1]
dx, dy := inc.X, inc.Y
var p V2
p.X = base.X
for x := 0; x < nx; x++ {
// read the x + 1 layer
l.evaluate(sdf, x+1)
// process all squares in the x and x + 1 layers
p.Y = base.Y
for y := 0; y < ny; y++ {
x0, y0 := p.X, p.Y
x1, y1 := x0+dx, y0+dy
corners := [4]V2{
{x0, y0},
{x1, y0},
{x1, y1},
{x0, y1},
}
values := [4]float64{
l.get(0, y),
l.get(1, y),
l.get(1, y+1),
l.get(0, y+1),
}
lines = append(lines, msToLines(corners, values, 0)...)
p.Y += dy
}
p.X += dx
}
return lines
}
//-----------------------------------------------------------------------------
// generate the line segments for a square
func msToLines(p [4]V2, v [4]float64, x float64) []*Line {
// which of the 0..15 patterns do we have?
index := 0
for i := 0; i < 4; i++ {
if v[i] < x {
index |= 1 << uint(i)
}
}
// do we have any lines to create?
if msEdgeTable[index] == 0 {
return nil
}
// work out the interpolated points on the edges
var points [4]V2
for i := 0; i < 4; i++ {
bit := 1 << uint(i)
if msEdgeTable[index]&bit != 0 {
a := msPairTable[i][0]
b := msPairTable[i][1]
points[i] = msInterpolate(p[a], p[b], v[a], v[b], x)
}
}
// create the line segments
table := msLineTable[index]
count := len(table) / 2
result := make([]*Line, count)
for i := 0; i < count; i++ {
line := Line{}
line[1] = points[table[i*2+0]]
line[0] = points[table[i*2+1]]
result[i] = &line
}
return result
}
//-----------------------------------------------------------------------------
func msInterpolate(p1, p2 V2, v1, v2, x float64) V2 {
if Abs(x-v1) < epsilon {
return p1
}
if Abs(x-v2) < epsilon {
return p2
}
if Abs(v1-v2) < epsilon {
return p1
}
t := (x - v1) / (v2 - v1)
return V2{
p1.X + t*(p2.X-p1.X),
p1.Y + t*(p2.Y-p1.Y),
}
}
//-----------------------------------------------------------------------------
// These are the vertex pairs for the edges
var msPairTable = [4][2]int{
{0, 1}, // 0
{1, 2}, // 1
{2, 3}, // 2
{3, 0}, // 3
}
// 4 vertices -> 16 possible inside/outside combinations
// A 1 bit in the value indicates an edge with a line end point.
// 4 edges -> 4 bit values, note the fwd/rev symmetry
var msEdgeTable = [16]int{
0x0, 0x9, 0x3, 0xa,
0x6, 0xf, 0x5, 0xc,
0xc, 0x5, 0xf, 0x6,
0xa, 0x3, 0x9, 0x0,
}
// specify the edges used to create the line(s)
var msLineTable = [16][]int{
{}, // 0
{0, 3}, // 1
{0, 1}, // 2
{1, 3}, // 3
{1, 2}, // 4
{0, 1, 2, 3}, // 5
{0, 2}, // 6
{2, 3}, // 7
{2, 3}, // 8
{0, 2}, // 9
{0, 3, 1, 2}, // 10
{1, 2}, // 11
{1, 3}, // 12
{0, 1}, // 13
{0, 3}, // 14
{}, // 15
}
//----------------------------------------------------------------------------- | sdf/march2.go | 0.7181 | 0.547343 | march2.go | starcoder |
package asm
func (o Opcodes) Aad(ops ...Operand) { o.a.op("AAD", ops...) }
func (o Opcodes) AAD(ops ...Operand) { o.a.op("AAD", ops...) }
func (o Opcodes) Aam(ops ...Operand) { o.a.op("AAM", ops...) }
func (o Opcodes) AAM(ops ...Operand) { o.a.op("AAM", ops...) }
func (o Opcodes) Aas(ops ...Operand) { o.a.op("AAS", ops...) }
func (o Opcodes) AAS(ops ...Operand) { o.a.op("AAS", ops...) }
func (o Opcodes) Adcb(ops ...Operand) { o.a.op("ADCB", ops...) }
func (o Opcodes) ADCB(ops ...Operand) { o.a.op("ADCB", ops...) }
func (o Opcodes) Adcl(ops ...Operand) { o.a.op("ADCL", ops...) }
func (o Opcodes) ADCL(ops ...Operand) { o.a.op("ADCL", ops...) }
func (o Opcodes) Adcq(ops ...Operand) { o.a.op("ADCQ", ops...) }
func (o Opcodes) ADCQ(ops ...Operand) { o.a.op("ADCQ", ops...) }
func (o Opcodes) Adcw(ops ...Operand) { o.a.op("ADCW", ops...) }
func (o Opcodes) ADCW(ops ...Operand) { o.a.op("ADCW", ops...) }
func (o Opcodes) Adcxl(ops ...Operand) { o.a.op("ADCXL", ops...) }
func (o Opcodes) ADCXL(ops ...Operand) { o.a.op("ADCXL", ops...) }
func (o Opcodes) Adcxq(ops ...Operand) { o.a.op("ADCXQ", ops...) }
func (o Opcodes) ADCXQ(ops ...Operand) { o.a.op("ADCXQ", ops...) }
func (o Opcodes) Addb(ops ...Operand) { o.a.op("ADDB", ops...) }
func (o Opcodes) ADDB(ops ...Operand) { o.a.op("ADDB", ops...) }
func (o Opcodes) Addl(ops ...Operand) { o.a.op("ADDL", ops...) }
func (o Opcodes) ADDL(ops ...Operand) { o.a.op("ADDL", ops...) }
func (o Opcodes) Addpd(ops ...Operand) { o.a.op("ADDPD", ops...) }
func (o Opcodes) ADDPD(ops ...Operand) { o.a.op("ADDPD", ops...) }
func (o Opcodes) Addps(ops ...Operand) { o.a.op("ADDPS", ops...) }
func (o Opcodes) ADDPS(ops ...Operand) { o.a.op("ADDPS", ops...) }
func (o Opcodes) Addq(ops ...Operand) { o.a.op("ADDQ", ops...) }
func (o Opcodes) ADDQ(ops ...Operand) { o.a.op("ADDQ", ops...) }
func (o Opcodes) Addsd(ops ...Operand) { o.a.op("ADDSD", ops...) }
func (o Opcodes) ADDSD(ops ...Operand) { o.a.op("ADDSD", ops...) }
func (o Opcodes) Addss(ops ...Operand) { o.a.op("ADDSS", ops...) }
func (o Opcodes) ADDSS(ops ...Operand) { o.a.op("ADDSS", ops...) }
func (o Opcodes) Addsubpd(ops ...Operand) { o.a.op("ADDSUBPD", ops...) }
func (o Opcodes) ADDSUBPD(ops ...Operand) { o.a.op("ADDSUBPD", ops...) }
func (o Opcodes) Addsubps(ops ...Operand) { o.a.op("ADDSUBPS", ops...) }
func (o Opcodes) ADDSUBPS(ops ...Operand) { o.a.op("ADDSUBPS", ops...) }
func (o Opcodes) Addw(ops ...Operand) { o.a.op("ADDW", ops...) }
func (o Opcodes) ADDW(ops ...Operand) { o.a.op("ADDW", ops...) }
func (o Opcodes) Adjsp(ops ...Operand) { o.a.op("ADJSP", ops...) }
func (o Opcodes) ADJSP(ops ...Operand) { o.a.op("ADJSP", ops...) }
func (o Opcodes) Adoxl(ops ...Operand) { o.a.op("ADOXL", ops...) }
func (o Opcodes) ADOXL(ops ...Operand) { o.a.op("ADOXL", ops...) }
func (o Opcodes) Adoxq(ops ...Operand) { o.a.op("ADOXQ", ops...) }
func (o Opcodes) ADOXQ(ops ...Operand) { o.a.op("ADOXQ", ops...) }
func (o Opcodes) Aesdec(ops ...Operand) { o.a.op("AESDEC", ops...) }
func (o Opcodes) AESDEC(ops ...Operand) { o.a.op("AESDEC", ops...) }
func (o Opcodes) Aesdeclast(ops ...Operand) { o.a.op("AESDECLAST", ops...) }
func (o Opcodes) AESDECLAST(ops ...Operand) { o.a.op("AESDECLAST", ops...) }
func (o Opcodes) Aesenc(ops ...Operand) { o.a.op("AESENC", ops...) }
func (o Opcodes) AESENC(ops ...Operand) { o.a.op("AESENC", ops...) }
func (o Opcodes) Aesenclast(ops ...Operand) { o.a.op("AESENCLAST", ops...) }
func (o Opcodes) AESENCLAST(ops ...Operand) { o.a.op("AESENCLAST", ops...) }
func (o Opcodes) Aesimc(ops ...Operand) { o.a.op("AESIMC", ops...) }
func (o Opcodes) AESIMC(ops ...Operand) { o.a.op("AESIMC", ops...) }
func (o Opcodes) Aeskeygenassist(ops ...Operand) { o.a.op("AESKEYGENASSIST", ops...) }
func (o Opcodes) AESKEYGENASSIST(ops ...Operand) { o.a.op("AESKEYGENASSIST", ops...) }
func (o Opcodes) Andb(ops ...Operand) { o.a.op("ANDB", ops...) }
func (o Opcodes) ANDB(ops ...Operand) { o.a.op("ANDB", ops...) }
func (o Opcodes) Andl(ops ...Operand) { o.a.op("ANDL", ops...) }
func (o Opcodes) ANDL(ops ...Operand) { o.a.op("ANDL", ops...) }
func (o Opcodes) Andnl(ops ...Operand) { o.a.op("ANDNL", ops...) }
func (o Opcodes) ANDNL(ops ...Operand) { o.a.op("ANDNL", ops...) }
func (o Opcodes) Andnpd(ops ...Operand) { o.a.op("ANDNPD", ops...) }
func (o Opcodes) ANDNPD(ops ...Operand) { o.a.op("ANDNPD", ops...) }
func (o Opcodes) Andnps(ops ...Operand) { o.a.op("ANDNPS", ops...) }
func (o Opcodes) ANDNPS(ops ...Operand) { o.a.op("ANDNPS", ops...) }
func (o Opcodes) Andnq(ops ...Operand) { o.a.op("ANDNQ", ops...) }
func (o Opcodes) ANDNQ(ops ...Operand) { o.a.op("ANDNQ", ops...) }
func (o Opcodes) Andpd(ops ...Operand) { o.a.op("ANDPD", ops...) }
func (o Opcodes) ANDPD(ops ...Operand) { o.a.op("ANDPD", ops...) }
func (o Opcodes) Andps(ops ...Operand) { o.a.op("ANDPS", ops...) }
func (o Opcodes) ANDPS(ops ...Operand) { o.a.op("ANDPS", ops...) }
func (o Opcodes) Andq(ops ...Operand) { o.a.op("ANDQ", ops...) }
func (o Opcodes) ANDQ(ops ...Operand) { o.a.op("ANDQ", ops...) }
func (o Opcodes) Andw(ops ...Operand) { o.a.op("ANDW", ops...) }
func (o Opcodes) ANDW(ops ...Operand) { o.a.op("ANDW", ops...) }
func (o Opcodes) Arpl(ops ...Operand) { o.a.op("ARPL", ops...) }
func (o Opcodes) ARPL(ops ...Operand) { o.a.op("ARPL", ops...) }
func (o Opcodes) Bextrl(ops ...Operand) { o.a.op("BEXTRL", ops...) }
func (o Opcodes) BEXTRL(ops ...Operand) { o.a.op("BEXTRL", ops...) }
func (o Opcodes) Bextrq(ops ...Operand) { o.a.op("BEXTRQ", ops...) }
func (o Opcodes) BEXTRQ(ops ...Operand) { o.a.op("BEXTRQ", ops...) }
func (o Opcodes) Blendpd(ops ...Operand) { o.a.op("BLENDPD", ops...) }
func (o Opcodes) BLENDPD(ops ...Operand) { o.a.op("BLENDPD", ops...) }
func (o Opcodes) Blendps(ops ...Operand) { o.a.op("BLENDPS", ops...) }
func (o Opcodes) BLENDPS(ops ...Operand) { o.a.op("BLENDPS", ops...) }
func (o Opcodes) Blsil(ops ...Operand) { o.a.op("BLSIL", ops...) }
func (o Opcodes) BLSIL(ops ...Operand) { o.a.op("BLSIL", ops...) }
func (o Opcodes) Blsiq(ops ...Operand) { o.a.op("BLSIQ", ops...) }
func (o Opcodes) BLSIQ(ops ...Operand) { o.a.op("BLSIQ", ops...) }
func (o Opcodes) Blsmskl(ops ...Operand) { o.a.op("BLSMSKL", ops...) }
func (o Opcodes) BLSMSKL(ops ...Operand) { o.a.op("BLSMSKL", ops...) }
func (o Opcodes) Blsmskq(ops ...Operand) { o.a.op("BLSMSKQ", ops...) }
func (o Opcodes) BLSMSKQ(ops ...Operand) { o.a.op("BLSMSKQ", ops...) }
func (o Opcodes) Blsrl(ops ...Operand) { o.a.op("BLSRL", ops...) }
func (o Opcodes) BLSRL(ops ...Operand) { o.a.op("BLSRL", ops...) }
func (o Opcodes) Blsrq(ops ...Operand) { o.a.op("BLSRQ", ops...) }
func (o Opcodes) BLSRQ(ops ...Operand) { o.a.op("BLSRQ", ops...) }
func (o Opcodes) Boundl(ops ...Operand) { o.a.op("BOUNDL", ops...) }
func (o Opcodes) BOUNDL(ops ...Operand) { o.a.op("BOUNDL", ops...) }
func (o Opcodes) Boundw(ops ...Operand) { o.a.op("BOUNDW", ops...) }
func (o Opcodes) BOUNDW(ops ...Operand) { o.a.op("BOUNDW", ops...) }
func (o Opcodes) Bsfl(ops ...Operand) { o.a.op("BSFL", ops...) }
func (o Opcodes) BSFL(ops ...Operand) { o.a.op("BSFL", ops...) }
func (o Opcodes) Bsfq(ops ...Operand) { o.a.op("BSFQ", ops...) }
func (o Opcodes) BSFQ(ops ...Operand) { o.a.op("BSFQ", ops...) }
func (o Opcodes) Bsfw(ops ...Operand) { o.a.op("BSFW", ops...) }
func (o Opcodes) BSFW(ops ...Operand) { o.a.op("BSFW", ops...) }
func (o Opcodes) Bsrl(ops ...Operand) { o.a.op("BSRL", ops...) }
func (o Opcodes) BSRL(ops ...Operand) { o.a.op("BSRL", ops...) }
func (o Opcodes) Bsrq(ops ...Operand) { o.a.op("BSRQ", ops...) }
func (o Opcodes) BSRQ(ops ...Operand) { o.a.op("BSRQ", ops...) }
func (o Opcodes) Bsrw(ops ...Operand) { o.a.op("BSRW", ops...) }
func (o Opcodes) BSRW(ops ...Operand) { o.a.op("BSRW", ops...) }
func (o Opcodes) Bswapl(ops ...Operand) { o.a.op("BSWAPL", ops...) }
func (o Opcodes) BSWAPL(ops ...Operand) { o.a.op("BSWAPL", ops...) }
func (o Opcodes) Bswapq(ops ...Operand) { o.a.op("BSWAPQ", ops...) }
func (o Opcodes) BSWAPQ(ops ...Operand) { o.a.op("BSWAPQ", ops...) }
func (o Opcodes) Btcl(ops ...Operand) { o.a.op("BTCL", ops...) }
func (o Opcodes) BTCL(ops ...Operand) { o.a.op("BTCL", ops...) }
func (o Opcodes) Btcq(ops ...Operand) { o.a.op("BTCQ", ops...) }
func (o Opcodes) BTCQ(ops ...Operand) { o.a.op("BTCQ", ops...) }
func (o Opcodes) Btcw(ops ...Operand) { o.a.op("BTCW", ops...) }
func (o Opcodes) BTCW(ops ...Operand) { o.a.op("BTCW", ops...) }
func (o Opcodes) Btl(ops ...Operand) { o.a.op("BTL", ops...) }
func (o Opcodes) BTL(ops ...Operand) { o.a.op("BTL", ops...) }
func (o Opcodes) Btq(ops ...Operand) { o.a.op("BTQ", ops...) }
func (o Opcodes) BTQ(ops ...Operand) { o.a.op("BTQ", ops...) }
func (o Opcodes) Btrl(ops ...Operand) { o.a.op("BTRL", ops...) }
func (o Opcodes) BTRL(ops ...Operand) { o.a.op("BTRL", ops...) }
func (o Opcodes) Btrq(ops ...Operand) { o.a.op("BTRQ", ops...) }
func (o Opcodes) BTRQ(ops ...Operand) { o.a.op("BTRQ", ops...) }
func (o Opcodes) Btrw(ops ...Operand) { o.a.op("BTRW", ops...) }
func (o Opcodes) BTRW(ops ...Operand) { o.a.op("BTRW", ops...) }
func (o Opcodes) Btsl(ops ...Operand) { o.a.op("BTSL", ops...) }
func (o Opcodes) BTSL(ops ...Operand) { o.a.op("BTSL", ops...) }
func (o Opcodes) Btsq(ops ...Operand) { o.a.op("BTSQ", ops...) }
func (o Opcodes) BTSQ(ops ...Operand) { o.a.op("BTSQ", ops...) }
func (o Opcodes) Btsw(ops ...Operand) { o.a.op("BTSW", ops...) }
func (o Opcodes) BTSW(ops ...Operand) { o.a.op("BTSW", ops...) }
func (o Opcodes) Btw(ops ...Operand) { o.a.op("BTW", ops...) }
func (o Opcodes) BTW(ops ...Operand) { o.a.op("BTW", ops...) }
func (o Opcodes) Byte(ops ...Operand) { o.a.op("BYTE", ops...) }
func (o Opcodes) BYTE(ops ...Operand) { o.a.op("BYTE", ops...) }
func (o Opcodes) Bzhil(ops ...Operand) { o.a.op("BZHIL", ops...) }
func (o Opcodes) BZHIL(ops ...Operand) { o.a.op("BZHIL", ops...) }
func (o Opcodes) Bzhiq(ops ...Operand) { o.a.op("BZHIQ", ops...) }
func (o Opcodes) BZHIQ(ops ...Operand) { o.a.op("BZHIQ", ops...) }
func (o Opcodes) Cdq(ops ...Operand) { o.a.op("CDQ", ops...) }
func (o Opcodes) CDQ(ops ...Operand) { o.a.op("CDQ", ops...) }
func (o Opcodes) Clc(ops ...Operand) { o.a.op("CLC", ops...) }
func (o Opcodes) CLC(ops ...Operand) { o.a.op("CLC", ops...) }
func (o Opcodes) Cld(ops ...Operand) { o.a.op("CLD", ops...) }
func (o Opcodes) CLD(ops ...Operand) { o.a.op("CLD", ops...) }
func (o Opcodes) Clflush(ops ...Operand) { o.a.op("CLFLUSH", ops...) }
func (o Opcodes) CLFLUSH(ops ...Operand) { o.a.op("CLFLUSH", ops...) }
func (o Opcodes) Cli(ops ...Operand) { o.a.op("CLI", ops...) }
func (o Opcodes) CLI(ops ...Operand) { o.a.op("CLI", ops...) }
func (o Opcodes) Clts(ops ...Operand) { o.a.op("CLTS", ops...) }
func (o Opcodes) CLTS(ops ...Operand) { o.a.op("CLTS", ops...) }
func (o Opcodes) Cmc(ops ...Operand) { o.a.op("CMC", ops...) }
func (o Opcodes) CMC(ops ...Operand) { o.a.op("CMC", ops...) }
func (o Opcodes) Cmovlcc(ops ...Operand) { o.a.op("CMOVLCC", ops...) }
func (o Opcodes) CMOVLCC(ops ...Operand) { o.a.op("CMOVLCC", ops...) }
func (o Opcodes) Cmovlcs(ops ...Operand) { o.a.op("CMOVLCS", ops...) }
func (o Opcodes) CMOVLCS(ops ...Operand) { o.a.op("CMOVLCS", ops...) }
func (o Opcodes) Cmovleq(ops ...Operand) { o.a.op("CMOVLEQ", ops...) }
func (o Opcodes) CMOVLEQ(ops ...Operand) { o.a.op("CMOVLEQ", ops...) }
func (o Opcodes) Cmovlge(ops ...Operand) { o.a.op("CMOVLGE", ops...) }
func (o Opcodes) CMOVLGE(ops ...Operand) { o.a.op("CMOVLGE", ops...) }
func (o Opcodes) Cmovlgt(ops ...Operand) { o.a.op("CMOVLGT", ops...) }
func (o Opcodes) CMOVLGT(ops ...Operand) { o.a.op("CMOVLGT", ops...) }
func (o Opcodes) Cmovlhi(ops ...Operand) { o.a.op("CMOVLHI", ops...) }
func (o Opcodes) CMOVLHI(ops ...Operand) { o.a.op("CMOVLHI", ops...) }
func (o Opcodes) Cmovlle(ops ...Operand) { o.a.op("CMOVLLE", ops...) }
func (o Opcodes) CMOVLLE(ops ...Operand) { o.a.op("CMOVLLE", ops...) }
func (o Opcodes) Cmovlls(ops ...Operand) { o.a.op("CMOVLLS", ops...) }
func (o Opcodes) CMOVLLS(ops ...Operand) { o.a.op("CMOVLLS", ops...) }
func (o Opcodes) Cmovllt(ops ...Operand) { o.a.op("CMOVLLT", ops...) }
func (o Opcodes) CMOVLLT(ops ...Operand) { o.a.op("CMOVLLT", ops...) }
func (o Opcodes) Cmovlmi(ops ...Operand) { o.a.op("CMOVLMI", ops...) }
func (o Opcodes) CMOVLMI(ops ...Operand) { o.a.op("CMOVLMI", ops...) }
func (o Opcodes) Cmovlne(ops ...Operand) { o.a.op("CMOVLNE", ops...) }
func (o Opcodes) CMOVLNE(ops ...Operand) { o.a.op("CMOVLNE", ops...) }
func (o Opcodes) Cmovloc(ops ...Operand) { o.a.op("CMOVLOC", ops...) }
func (o Opcodes) CMOVLOC(ops ...Operand) { o.a.op("CMOVLOC", ops...) }
func (o Opcodes) Cmovlos(ops ...Operand) { o.a.op("CMOVLOS", ops...) }
func (o Opcodes) CMOVLOS(ops ...Operand) { o.a.op("CMOVLOS", ops...) }
func (o Opcodes) Cmovlpc(ops ...Operand) { o.a.op("CMOVLPC", ops...) }
func (o Opcodes) CMOVLPC(ops ...Operand) { o.a.op("CMOVLPC", ops...) }
func (o Opcodes) Cmovlpl(ops ...Operand) { o.a.op("CMOVLPL", ops...) }
func (o Opcodes) CMOVLPL(ops ...Operand) { o.a.op("CMOVLPL", ops...) }
func (o Opcodes) Cmovlps(ops ...Operand) { o.a.op("CMOVLPS", ops...) }
func (o Opcodes) CMOVLPS(ops ...Operand) { o.a.op("CMOVLPS", ops...) }
func (o Opcodes) Cmovqcc(ops ...Operand) { o.a.op("CMOVQCC", ops...) }
func (o Opcodes) CMOVQCC(ops ...Operand) { o.a.op("CMOVQCC", ops...) }
func (o Opcodes) Cmovqcs(ops ...Operand) { o.a.op("CMOVQCS", ops...) }
func (o Opcodes) CMOVQCS(ops ...Operand) { o.a.op("CMOVQCS", ops...) }
func (o Opcodes) Cmovqeq(ops ...Operand) { o.a.op("CMOVQEQ", ops...) }
func (o Opcodes) CMOVQEQ(ops ...Operand) { o.a.op("CMOVQEQ", ops...) }
func (o Opcodes) Cmovqge(ops ...Operand) { o.a.op("CMOVQGE", ops...) }
func (o Opcodes) CMOVQGE(ops ...Operand) { o.a.op("CMOVQGE", ops...) }
func (o Opcodes) Cmovqgt(ops ...Operand) { o.a.op("CMOVQGT", ops...) }
func (o Opcodes) CMOVQGT(ops ...Operand) { o.a.op("CMOVQGT", ops...) }
func (o Opcodes) Cmovqhi(ops ...Operand) { o.a.op("CMOVQHI", ops...) }
func (o Opcodes) CMOVQHI(ops ...Operand) { o.a.op("CMOVQHI", ops...) }
func (o Opcodes) Cmovqle(ops ...Operand) { o.a.op("CMOVQLE", ops...) }
func (o Opcodes) CMOVQLE(ops ...Operand) { o.a.op("CMOVQLE", ops...) }
func (o Opcodes) Cmovqls(ops ...Operand) { o.a.op("CMOVQLS", ops...) }
func (o Opcodes) CMOVQLS(ops ...Operand) { o.a.op("CMOVQLS", ops...) }
func (o Opcodes) Cmovqlt(ops ...Operand) { o.a.op("CMOVQLT", ops...) }
func (o Opcodes) CMOVQLT(ops ...Operand) { o.a.op("CMOVQLT", ops...) }
func (o Opcodes) Cmovqmi(ops ...Operand) { o.a.op("CMOVQMI", ops...) }
func (o Opcodes) CMOVQMI(ops ...Operand) { o.a.op("CMOVQMI", ops...) }
func (o Opcodes) Cmovqne(ops ...Operand) { o.a.op("CMOVQNE", ops...) }
func (o Opcodes) CMOVQNE(ops ...Operand) { o.a.op("CMOVQNE", ops...) }
func (o Opcodes) Cmovqoc(ops ...Operand) { o.a.op("CMOVQOC", ops...) }
func (o Opcodes) CMOVQOC(ops ...Operand) { o.a.op("CMOVQOC", ops...) }
func (o Opcodes) Cmovqos(ops ...Operand) { o.a.op("CMOVQOS", ops...) }
func (o Opcodes) CMOVQOS(ops ...Operand) { o.a.op("CMOVQOS", ops...) }
func (o Opcodes) Cmovqpc(ops ...Operand) { o.a.op("CMOVQPC", ops...) }
func (o Opcodes) CMOVQPC(ops ...Operand) { o.a.op("CMOVQPC", ops...) }
func (o Opcodes) Cmovqpl(ops ...Operand) { o.a.op("CMOVQPL", ops...) }
func (o Opcodes) CMOVQPL(ops ...Operand) { o.a.op("CMOVQPL", ops...) }
func (o Opcodes) Cmovqps(ops ...Operand) { o.a.op("CMOVQPS", ops...) }
func (o Opcodes) CMOVQPS(ops ...Operand) { o.a.op("CMOVQPS", ops...) }
func (o Opcodes) Cmovwcc(ops ...Operand) { o.a.op("CMOVWCC", ops...) }
func (o Opcodes) CMOVWCC(ops ...Operand) { o.a.op("CMOVWCC", ops...) }
func (o Opcodes) Cmovwcs(ops ...Operand) { o.a.op("CMOVWCS", ops...) }
func (o Opcodes) CMOVWCS(ops ...Operand) { o.a.op("CMOVWCS", ops...) }
func (o Opcodes) Cmovweq(ops ...Operand) { o.a.op("CMOVWEQ", ops...) }
func (o Opcodes) CMOVWEQ(ops ...Operand) { o.a.op("CMOVWEQ", ops...) }
func (o Opcodes) Cmovwge(ops ...Operand) { o.a.op("CMOVWGE", ops...) }
func (o Opcodes) CMOVWGE(ops ...Operand) { o.a.op("CMOVWGE", ops...) }
func (o Opcodes) Cmovwgt(ops ...Operand) { o.a.op("CMOVWGT", ops...) }
func (o Opcodes) CMOVWGT(ops ...Operand) { o.a.op("CMOVWGT", ops...) }
func (o Opcodes) Cmovwhi(ops ...Operand) { o.a.op("CMOVWHI", ops...) }
func (o Opcodes) CMOVWHI(ops ...Operand) { o.a.op("CMOVWHI", ops...) }
func (o Opcodes) Cmovwle(ops ...Operand) { o.a.op("CMOVWLE", ops...) }
func (o Opcodes) CMOVWLE(ops ...Operand) { o.a.op("CMOVWLE", ops...) }
func (o Opcodes) Cmovwls(ops ...Operand) { o.a.op("CMOVWLS", ops...) }
func (o Opcodes) CMOVWLS(ops ...Operand) { o.a.op("CMOVWLS", ops...) }
func (o Opcodes) Cmovwlt(ops ...Operand) { o.a.op("CMOVWLT", ops...) }
func (o Opcodes) CMOVWLT(ops ...Operand) { o.a.op("CMOVWLT", ops...) }
func (o Opcodes) Cmovwmi(ops ...Operand) { o.a.op("CMOVWMI", ops...) }
func (o Opcodes) CMOVWMI(ops ...Operand) { o.a.op("CMOVWMI", ops...) }
func (o Opcodes) Cmovwne(ops ...Operand) { o.a.op("CMOVWNE", ops...) }
func (o Opcodes) CMOVWNE(ops ...Operand) { o.a.op("CMOVWNE", ops...) }
func (o Opcodes) Cmovwoc(ops ...Operand) { o.a.op("CMOVWOC", ops...) }
func (o Opcodes) CMOVWOC(ops ...Operand) { o.a.op("CMOVWOC", ops...) }
func (o Opcodes) Cmovwos(ops ...Operand) { o.a.op("CMOVWOS", ops...) }
func (o Opcodes) CMOVWOS(ops ...Operand) { o.a.op("CMOVWOS", ops...) }
func (o Opcodes) Cmovwpc(ops ...Operand) { o.a.op("CMOVWPC", ops...) }
func (o Opcodes) CMOVWPC(ops ...Operand) { o.a.op("CMOVWPC", ops...) }
func (o Opcodes) Cmovwpl(ops ...Operand) { o.a.op("CMOVWPL", ops...) }
func (o Opcodes) CMOVWPL(ops ...Operand) { o.a.op("CMOVWPL", ops...) }
func (o Opcodes) Cmovwps(ops ...Operand) { o.a.op("CMOVWPS", ops...) }
func (o Opcodes) CMOVWPS(ops ...Operand) { o.a.op("CMOVWPS", ops...) }
func (o Opcodes) Cmpb(ops ...Operand) { o.a.op("CMPB", ops...) }
func (o Opcodes) CMPB(ops ...Operand) { o.a.op("CMPB", ops...) }
func (o Opcodes) Cmpl(ops ...Operand) { o.a.op("CMPL", ops...) }
func (o Opcodes) CMPL(ops ...Operand) { o.a.op("CMPL", ops...) }
func (o Opcodes) Cmppd(ops ...Operand) { o.a.op("CMPPD", ops...) }
func (o Opcodes) CMPPD(ops ...Operand) { o.a.op("CMPPD", ops...) }
func (o Opcodes) Cmpps(ops ...Operand) { o.a.op("CMPPS", ops...) }
func (o Opcodes) CMPPS(ops ...Operand) { o.a.op("CMPPS", ops...) }
func (o Opcodes) Cmpq(ops ...Operand) { o.a.op("CMPQ", ops...) }
func (o Opcodes) CMPQ(ops ...Operand) { o.a.op("CMPQ", ops...) }
func (o Opcodes) Cmpsb(ops ...Operand) { o.a.op("CMPSB", ops...) }
func (o Opcodes) CMPSB(ops ...Operand) { o.a.op("CMPSB", ops...) }
func (o Opcodes) Cmpsd(ops ...Operand) { o.a.op("CMPSD", ops...) }
func (o Opcodes) CMPSD(ops ...Operand) { o.a.op("CMPSD", ops...) }
func (o Opcodes) Cmpsl(ops ...Operand) { o.a.op("CMPSL", ops...) }
func (o Opcodes) CMPSL(ops ...Operand) { o.a.op("CMPSL", ops...) }
func (o Opcodes) Cmpsq(ops ...Operand) { o.a.op("CMPSQ", ops...) }
func (o Opcodes) CMPSQ(ops ...Operand) { o.a.op("CMPSQ", ops...) }
func (o Opcodes) Cmpss(ops ...Operand) { o.a.op("CMPSS", ops...) }
func (o Opcodes) CMPSS(ops ...Operand) { o.a.op("CMPSS", ops...) }
func (o Opcodes) Cmpsw(ops ...Operand) { o.a.op("CMPSW", ops...) }
func (o Opcodes) CMPSW(ops ...Operand) { o.a.op("CMPSW", ops...) }
func (o Opcodes) Cmpw(ops ...Operand) { o.a.op("CMPW", ops...) }
func (o Opcodes) CMPW(ops ...Operand) { o.a.op("CMPW", ops...) }
func (o Opcodes) Cmpxchg8b(ops ...Operand) { o.a.op("CMPXCHG8B", ops...) }
func (o Opcodes) CMPXCHG8B(ops ...Operand) { o.a.op("CMPXCHG8B", ops...) }
func (o Opcodes) Cmpxchgb(ops ...Operand) { o.a.op("CMPXCHGB", ops...) }
func (o Opcodes) CMPXCHGB(ops ...Operand) { o.a.op("CMPXCHGB", ops...) }
func (o Opcodes) Cmpxchgl(ops ...Operand) { o.a.op("CMPXCHGL", ops...) }
func (o Opcodes) CMPXCHGL(ops ...Operand) { o.a.op("CMPXCHGL", ops...) }
func (o Opcodes) Cmpxchgq(ops ...Operand) { o.a.op("CMPXCHGQ", ops...) }
func (o Opcodes) CMPXCHGQ(ops ...Operand) { o.a.op("CMPXCHGQ", ops...) }
func (o Opcodes) Cmpxchgw(ops ...Operand) { o.a.op("CMPXCHGW", ops...) }
func (o Opcodes) CMPXCHGW(ops ...Operand) { o.a.op("CMPXCHGW", ops...) }
func (o Opcodes) Comisd(ops ...Operand) { o.a.op("COMISD", ops...) }
func (o Opcodes) COMISD(ops ...Operand) { o.a.op("COMISD", ops...) }
func (o Opcodes) Comiss(ops ...Operand) { o.a.op("COMISS", ops...) }
func (o Opcodes) COMISS(ops ...Operand) { o.a.op("COMISS", ops...) }
func (o Opcodes) Cpuid(ops ...Operand) { o.a.op("CPUID", ops...) }
func (o Opcodes) CPUID(ops ...Operand) { o.a.op("CPUID", ops...) }
func (o Opcodes) Cqo(ops ...Operand) { o.a.op("CQO", ops...) }
func (o Opcodes) CQO(ops ...Operand) { o.a.op("CQO", ops...) }
func (o Opcodes) Crc32b(ops ...Operand) { o.a.op("CRC32B", ops...) }
func (o Opcodes) CRC32B(ops ...Operand) { o.a.op("CRC32B", ops...) }
func (o Opcodes) Crc32q(ops ...Operand) { o.a.op("CRC32Q", ops...) }
func (o Opcodes) CRC32Q(ops ...Operand) { o.a.op("CRC32Q", ops...) }
func (o Opcodes) Cvtpd2pl(ops ...Operand) { o.a.op("CVTPD2PL", ops...) }
func (o Opcodes) CVTPD2PL(ops ...Operand) { o.a.op("CVTPD2PL", ops...) }
func (o Opcodes) Cvtpd2ps(ops ...Operand) { o.a.op("CVTPD2PS", ops...) }
func (o Opcodes) CVTPD2PS(ops ...Operand) { o.a.op("CVTPD2PS", ops...) }
func (o Opcodes) Cvtpl2pd(ops ...Operand) { o.a.op("CVTPL2PD", ops...) }
func (o Opcodes) CVTPL2PD(ops ...Operand) { o.a.op("CVTPL2PD", ops...) }
func (o Opcodes) Cvtpl2ps(ops ...Operand) { o.a.op("CVTPL2PS", ops...) }
func (o Opcodes) CVTPL2PS(ops ...Operand) { o.a.op("CVTPL2PS", ops...) }
func (o Opcodes) Cvtps2pd(ops ...Operand) { o.a.op("CVTPS2PD", ops...) }
func (o Opcodes) CVTPS2PD(ops ...Operand) { o.a.op("CVTPS2PD", ops...) }
func (o Opcodes) Cvtps2pl(ops ...Operand) { o.a.op("CVTPS2PL", ops...) }
func (o Opcodes) CVTPS2PL(ops ...Operand) { o.a.op("CVTPS2PL", ops...) }
func (o Opcodes) Cvtsd2sl(ops ...Operand) { o.a.op("CVTSD2SL", ops...) }
func (o Opcodes) CVTSD2SL(ops ...Operand) { o.a.op("CVTSD2SL", ops...) }
func (o Opcodes) Cvtsd2sq(ops ...Operand) { o.a.op("CVTSD2SQ", ops...) }
func (o Opcodes) CVTSD2SQ(ops ...Operand) { o.a.op("CVTSD2SQ", ops...) }
func (o Opcodes) Cvtsd2ss(ops ...Operand) { o.a.op("CVTSD2SS", ops...) }
func (o Opcodes) CVTSD2SS(ops ...Operand) { o.a.op("CVTSD2SS", ops...) }
func (o Opcodes) Cvtsl2sd(ops ...Operand) { o.a.op("CVTSL2SD", ops...) }
func (o Opcodes) CVTSL2SD(ops ...Operand) { o.a.op("CVTSL2SD", ops...) }
func (o Opcodes) Cvtsl2ss(ops ...Operand) { o.a.op("CVTSL2SS", ops...) }
func (o Opcodes) CVTSL2SS(ops ...Operand) { o.a.op("CVTSL2SS", ops...) }
func (o Opcodes) Cvtsq2sd(ops ...Operand) { o.a.op("CVTSQ2SD", ops...) }
func (o Opcodes) CVTSQ2SD(ops ...Operand) { o.a.op("CVTSQ2SD", ops...) }
func (o Opcodes) Cvtsq2ss(ops ...Operand) { o.a.op("CVTSQ2SS", ops...) }
func (o Opcodes) CVTSQ2SS(ops ...Operand) { o.a.op("CVTSQ2SS", ops...) }
func (o Opcodes) Cvtss2sd(ops ...Operand) { o.a.op("CVTSS2SD", ops...) }
func (o Opcodes) CVTSS2SD(ops ...Operand) { o.a.op("CVTSS2SD", ops...) }
func (o Opcodes) Cvtss2sl(ops ...Operand) { o.a.op("CVTSS2SL", ops...) }
func (o Opcodes) CVTSS2SL(ops ...Operand) { o.a.op("CVTSS2SL", ops...) }
func (o Opcodes) Cvtss2sq(ops ...Operand) { o.a.op("CVTSS2SQ", ops...) }
func (o Opcodes) CVTSS2SQ(ops ...Operand) { o.a.op("CVTSS2SQ", ops...) }
func (o Opcodes) Cvttpd2pl(ops ...Operand) { o.a.op("CVTTPD2PL", ops...) }
func (o Opcodes) CVTTPD2PL(ops ...Operand) { o.a.op("CVTTPD2PL", ops...) }
func (o Opcodes) Cvttps2pl(ops ...Operand) { o.a.op("CVTTPS2PL", ops...) }
func (o Opcodes) CVTTPS2PL(ops ...Operand) { o.a.op("CVTTPS2PL", ops...) }
func (o Opcodes) Cvttsd2sl(ops ...Operand) { o.a.op("CVTTSD2SL", ops...) }
func (o Opcodes) CVTTSD2SL(ops ...Operand) { o.a.op("CVTTSD2SL", ops...) }
func (o Opcodes) Cvttsd2sq(ops ...Operand) { o.a.op("CVTTSD2SQ", ops...) }
func (o Opcodes) CVTTSD2SQ(ops ...Operand) { o.a.op("CVTTSD2SQ", ops...) }
func (o Opcodes) Cvttss2sl(ops ...Operand) { o.a.op("CVTTSS2SL", ops...) }
func (o Opcodes) CVTTSS2SL(ops ...Operand) { o.a.op("CVTTSS2SL", ops...) }
func (o Opcodes) Cvttss2sq(ops ...Operand) { o.a.op("CVTTSS2SQ", ops...) }
func (o Opcodes) CVTTSS2SQ(ops ...Operand) { o.a.op("CVTTSS2SQ", ops...) }
func (o Opcodes) Cwd(ops ...Operand) { o.a.op("CWD", ops...) }
func (o Opcodes) CWD(ops ...Operand) { o.a.op("CWD", ops...) }
func (o Opcodes) Daa(ops ...Operand) { o.a.op("DAA", ops...) }
func (o Opcodes) DAA(ops ...Operand) { o.a.op("DAA", ops...) }
func (o Opcodes) Das(ops ...Operand) { o.a.op("DAS", ops...) }
func (o Opcodes) DAS(ops ...Operand) { o.a.op("DAS", ops...) }
func (o Opcodes) Decb(ops ...Operand) { o.a.op("DECB", ops...) }
func (o Opcodes) DECB(ops ...Operand) { o.a.op("DECB", ops...) }
func (o Opcodes) Decl(ops ...Operand) { o.a.op("DECL", ops...) }
func (o Opcodes) DECL(ops ...Operand) { o.a.op("DECL", ops...) }
func (o Opcodes) Decq(ops ...Operand) { o.a.op("DECQ", ops...) }
func (o Opcodes) DECQ(ops ...Operand) { o.a.op("DECQ", ops...) }
func (o Opcodes) Decw(ops ...Operand) { o.a.op("DECW", ops...) }
func (o Opcodes) DECW(ops ...Operand) { o.a.op("DECW", ops...) }
func (o Opcodes) Divb(ops ...Operand) { o.a.op("DIVB", ops...) }
func (o Opcodes) DIVB(ops ...Operand) { o.a.op("DIVB", ops...) }
func (o Opcodes) Divl(ops ...Operand) { o.a.op("DIVL", ops...) }
func (o Opcodes) DIVL(ops ...Operand) { o.a.op("DIVL", ops...) }
func (o Opcodes) Divpd(ops ...Operand) { o.a.op("DIVPD", ops...) }
func (o Opcodes) DIVPD(ops ...Operand) { o.a.op("DIVPD", ops...) }
func (o Opcodes) Divps(ops ...Operand) { o.a.op("DIVPS", ops...) }
func (o Opcodes) DIVPS(ops ...Operand) { o.a.op("DIVPS", ops...) }
func (o Opcodes) Divq(ops ...Operand) { o.a.op("DIVQ", ops...) }
func (o Opcodes) DIVQ(ops ...Operand) { o.a.op("DIVQ", ops...) }
func (o Opcodes) Divsd(ops ...Operand) { o.a.op("DIVSD", ops...) }
func (o Opcodes) DIVSD(ops ...Operand) { o.a.op("DIVSD", ops...) }
func (o Opcodes) Divss(ops ...Operand) { o.a.op("DIVSS", ops...) }
func (o Opcodes) DIVSS(ops ...Operand) { o.a.op("DIVSS", ops...) }
func (o Opcodes) Divw(ops ...Operand) { o.a.op("DIVW", ops...) }
func (o Opcodes) DIVW(ops ...Operand) { o.a.op("DIVW", ops...) }
func (o Opcodes) Dppd(ops ...Operand) { o.a.op("DPPD", ops...) }
func (o Opcodes) DPPD(ops ...Operand) { o.a.op("DPPD", ops...) }
func (o Opcodes) Dpps(ops ...Operand) { o.a.op("DPPS", ops...) }
func (o Opcodes) DPPS(ops ...Operand) { o.a.op("DPPS", ops...) }
func (o Opcodes) Emms(ops ...Operand) { o.a.op("EMMS", ops...) }
func (o Opcodes) EMMS(ops ...Operand) { o.a.op("EMMS", ops...) }
func (o Opcodes) Enter(ops ...Operand) { o.a.op("ENTER", ops...) }
func (o Opcodes) ENTER(ops ...Operand) { o.a.op("ENTER", ops...) }
func (o Opcodes) Extractps(ops ...Operand) { o.a.op("EXTRACTPS", ops...) }
func (o Opcodes) EXTRACTPS(ops ...Operand) { o.a.op("EXTRACTPS", ops...) }
func (o Opcodes) F2xm1(ops ...Operand) { o.a.op("F2XM1", ops...) }
func (o Opcodes) F2XM1(ops ...Operand) { o.a.op("F2XM1", ops...) }
func (o Opcodes) Fabs(ops ...Operand) { o.a.op("FABS", ops...) }
func (o Opcodes) FABS(ops ...Operand) { o.a.op("FABS", ops...) }
func (o Opcodes) Faddd(ops ...Operand) { o.a.op("FADDD", ops...) }
func (o Opcodes) FADDD(ops ...Operand) { o.a.op("FADDD", ops...) }
func (o Opcodes) Fadddp(ops ...Operand) { o.a.op("FADDDP", ops...) }
func (o Opcodes) FADDDP(ops ...Operand) { o.a.op("FADDDP", ops...) }
func (o Opcodes) Faddf(ops ...Operand) { o.a.op("FADDF", ops...) }
func (o Opcodes) FADDF(ops ...Operand) { o.a.op("FADDF", ops...) }
func (o Opcodes) Faddl(ops ...Operand) { o.a.op("FADDL", ops...) }
func (o Opcodes) FADDL(ops ...Operand) { o.a.op("FADDL", ops...) }
func (o Opcodes) Faddw(ops ...Operand) { o.a.op("FADDW", ops...) }
func (o Opcodes) FADDW(ops ...Operand) { o.a.op("FADDW", ops...) }
func (o Opcodes) Fchs(ops ...Operand) { o.a.op("FCHS", ops...) }
func (o Opcodes) FCHS(ops ...Operand) { o.a.op("FCHS", ops...) }
func (o Opcodes) Fclex(ops ...Operand) { o.a.op("FCLEX", ops...) }
func (o Opcodes) FCLEX(ops ...Operand) { o.a.op("FCLEX", ops...) }
func (o Opcodes) Fcmovcc(ops ...Operand) { o.a.op("FCMOVCC", ops...) }
func (o Opcodes) FCMOVCC(ops ...Operand) { o.a.op("FCMOVCC", ops...) }
func (o Opcodes) Fcmovcs(ops ...Operand) { o.a.op("FCMOVCS", ops...) }
func (o Opcodes) FCMOVCS(ops ...Operand) { o.a.op("FCMOVCS", ops...) }
func (o Opcodes) Fcmoveq(ops ...Operand) { o.a.op("FCMOVEQ", ops...) }
func (o Opcodes) FCMOVEQ(ops ...Operand) { o.a.op("FCMOVEQ", ops...) }
func (o Opcodes) Fcmovhi(ops ...Operand) { o.a.op("FCMOVHI", ops...) }
func (o Opcodes) FCMOVHI(ops ...Operand) { o.a.op("FCMOVHI", ops...) }
func (o Opcodes) Fcmovls(ops ...Operand) { o.a.op("FCMOVLS", ops...) }
func (o Opcodes) FCMOVLS(ops ...Operand) { o.a.op("FCMOVLS", ops...) }
func (o Opcodes) Fcmovne(ops ...Operand) { o.a.op("FCMOVNE", ops...) }
func (o Opcodes) FCMOVNE(ops ...Operand) { o.a.op("FCMOVNE", ops...) }
func (o Opcodes) Fcmovnu(ops ...Operand) { o.a.op("FCMOVNU", ops...) }
func (o Opcodes) FCMOVNU(ops ...Operand) { o.a.op("FCMOVNU", ops...) }
func (o Opcodes) Fcmovun(ops ...Operand) { o.a.op("FCMOVUN", ops...) }
func (o Opcodes) FCMOVUN(ops ...Operand) { o.a.op("FCMOVUN", ops...) }
func (o Opcodes) Fcomd(ops ...Operand) { o.a.op("FCOMD", ops...) }
func (o Opcodes) FCOMD(ops ...Operand) { o.a.op("FCOMD", ops...) }
func (o Opcodes) Fcomdp(ops ...Operand) { o.a.op("FCOMDP", ops...) }
func (o Opcodes) FCOMDP(ops ...Operand) { o.a.op("FCOMDP", ops...) }
func (o Opcodes) Fcomdpp(ops ...Operand) { o.a.op("FCOMDPP", ops...) }
func (o Opcodes) FCOMDPP(ops ...Operand) { o.a.op("FCOMDPP", ops...) }
func (o Opcodes) Fcomf(ops ...Operand) { o.a.op("FCOMF", ops...) }
func (o Opcodes) FCOMF(ops ...Operand) { o.a.op("FCOMF", ops...) }
func (o Opcodes) Fcomfp(ops ...Operand) { o.a.op("FCOMFP", ops...) }
func (o Opcodes) FCOMFP(ops ...Operand) { o.a.op("FCOMFP", ops...) }
func (o Opcodes) Fcomi(ops ...Operand) { o.a.op("FCOMI", ops...) }
func (o Opcodes) FCOMI(ops ...Operand) { o.a.op("FCOMI", ops...) }
func (o Opcodes) Fcomip(ops ...Operand) { o.a.op("FCOMIP", ops...) }
func (o Opcodes) FCOMIP(ops ...Operand) { o.a.op("FCOMIP", ops...) }
func (o Opcodes) Fcoml(ops ...Operand) { o.a.op("FCOML", ops...) }
func (o Opcodes) FCOML(ops ...Operand) { o.a.op("FCOML", ops...) }
func (o Opcodes) Fcomlp(ops ...Operand) { o.a.op("FCOMLP", ops...) }
func (o Opcodes) FCOMLP(ops ...Operand) { o.a.op("FCOMLP", ops...) }
func (o Opcodes) Fcomw(ops ...Operand) { o.a.op("FCOMW", ops...) }
func (o Opcodes) FCOMW(ops ...Operand) { o.a.op("FCOMW", ops...) }
func (o Opcodes) Fcomwp(ops ...Operand) { o.a.op("FCOMWP", ops...) }
func (o Opcodes) FCOMWP(ops ...Operand) { o.a.op("FCOMWP", ops...) }
func (o Opcodes) Fcos(ops ...Operand) { o.a.op("FCOS", ops...) }
func (o Opcodes) FCOS(ops ...Operand) { o.a.op("FCOS", ops...) }
func (o Opcodes) Fdecstp(ops ...Operand) { o.a.op("FDECSTP", ops...) }
func (o Opcodes) FDECSTP(ops ...Operand) { o.a.op("FDECSTP", ops...) }
func (o Opcodes) Fdivd(ops ...Operand) { o.a.op("FDIVD", ops...) }
func (o Opcodes) FDIVD(ops ...Operand) { o.a.op("FDIVD", ops...) }
func (o Opcodes) Fdivdp(ops ...Operand) { o.a.op("FDIVDP", ops...) }
func (o Opcodes) FDIVDP(ops ...Operand) { o.a.op("FDIVDP", ops...) }
func (o Opcodes) Fdivf(ops ...Operand) { o.a.op("FDIVF", ops...) }
func (o Opcodes) FDIVF(ops ...Operand) { o.a.op("FDIVF", ops...) }
func (o Opcodes) Fdivl(ops ...Operand) { o.a.op("FDIVL", ops...) }
func (o Opcodes) FDIVL(ops ...Operand) { o.a.op("FDIVL", ops...) }
func (o Opcodes) Fdivrd(ops ...Operand) { o.a.op("FDIVRD", ops...) }
func (o Opcodes) FDIVRD(ops ...Operand) { o.a.op("FDIVRD", ops...) }
func (o Opcodes) Fdivrdp(ops ...Operand) { o.a.op("FDIVRDP", ops...) }
func (o Opcodes) FDIVRDP(ops ...Operand) { o.a.op("FDIVRDP", ops...) }
func (o Opcodes) Fdivrf(ops ...Operand) { o.a.op("FDIVRF", ops...) }
func (o Opcodes) FDIVRF(ops ...Operand) { o.a.op("FDIVRF", ops...) }
func (o Opcodes) Fdivrl(ops ...Operand) { o.a.op("FDIVRL", ops...) }
func (o Opcodes) FDIVRL(ops ...Operand) { o.a.op("FDIVRL", ops...) }
func (o Opcodes) Fdivrw(ops ...Operand) { o.a.op("FDIVRW", ops...) }
func (o Opcodes) FDIVRW(ops ...Operand) { o.a.op("FDIVRW", ops...) }
func (o Opcodes) Fdivw(ops ...Operand) { o.a.op("FDIVW", ops...) }
func (o Opcodes) FDIVW(ops ...Operand) { o.a.op("FDIVW", ops...) }
func (o Opcodes) Ffree(ops ...Operand) { o.a.op("FFREE", ops...) }
func (o Opcodes) FFREE(ops ...Operand) { o.a.op("FFREE", ops...) }
func (o Opcodes) Fincstp(ops ...Operand) { o.a.op("FINCSTP", ops...) }
func (o Opcodes) FINCSTP(ops ...Operand) { o.a.op("FINCSTP", ops...) }
func (o Opcodes) Finit(ops ...Operand) { o.a.op("FINIT", ops...) }
func (o Opcodes) FINIT(ops ...Operand) { o.a.op("FINIT", ops...) }
func (o Opcodes) Fld1(ops ...Operand) { o.a.op("FLD1", ops...) }
func (o Opcodes) FLD1(ops ...Operand) { o.a.op("FLD1", ops...) }
func (o Opcodes) Fldcw(ops ...Operand) { o.a.op("FLDCW", ops...) }
func (o Opcodes) FLDCW(ops ...Operand) { o.a.op("FLDCW", ops...) }
func (o Opcodes) Fldenv(ops ...Operand) { o.a.op("FLDENV", ops...) }
func (o Opcodes) FLDENV(ops ...Operand) { o.a.op("FLDENV", ops...) }
func (o Opcodes) Fldl2e(ops ...Operand) { o.a.op("FLDL2E", ops...) }
func (o Opcodes) FLDL2E(ops ...Operand) { o.a.op("FLDL2E", ops...) }
func (o Opcodes) Fldl2t(ops ...Operand) { o.a.op("FLDL2T", ops...) }
func (o Opcodes) FLDL2T(ops ...Operand) { o.a.op("FLDL2T", ops...) }
func (o Opcodes) Fldlg2(ops ...Operand) { o.a.op("FLDLG2", ops...) }
func (o Opcodes) FLDLG2(ops ...Operand) { o.a.op("FLDLG2", ops...) }
func (o Opcodes) Fldln2(ops ...Operand) { o.a.op("FLDLN2", ops...) }
func (o Opcodes) FLDLN2(ops ...Operand) { o.a.op("FLDLN2", ops...) }
func (o Opcodes) Fldpi(ops ...Operand) { o.a.op("FLDPI", ops...) }
func (o Opcodes) FLDPI(ops ...Operand) { o.a.op("FLDPI", ops...) }
func (o Opcodes) Fldz(ops ...Operand) { o.a.op("FLDZ", ops...) }
func (o Opcodes) FLDZ(ops ...Operand) { o.a.op("FLDZ", ops...) }
func (o Opcodes) Fmovb(ops ...Operand) { o.a.op("FMOVB", ops...) }
func (o Opcodes) FMOVB(ops ...Operand) { o.a.op("FMOVB", ops...) }
func (o Opcodes) Fmovbp(ops ...Operand) { o.a.op("FMOVBP", ops...) }
func (o Opcodes) FMOVBP(ops ...Operand) { o.a.op("FMOVBP", ops...) }
func (o Opcodes) Fmovd(ops ...Operand) { o.a.op("FMOVD", ops...) }
func (o Opcodes) FMOVD(ops ...Operand) { o.a.op("FMOVD", ops...) }
func (o Opcodes) Fmovdp(ops ...Operand) { o.a.op("FMOVDP", ops...) }
func (o Opcodes) FMOVDP(ops ...Operand) { o.a.op("FMOVDP", ops...) }
func (o Opcodes) Fmovf(ops ...Operand) { o.a.op("FMOVF", ops...) }
func (o Opcodes) FMOVF(ops ...Operand) { o.a.op("FMOVF", ops...) }
func (o Opcodes) Fmovfp(ops ...Operand) { o.a.op("FMOVFP", ops...) }
func (o Opcodes) FMOVFP(ops ...Operand) { o.a.op("FMOVFP", ops...) }
func (o Opcodes) Fmovl(ops ...Operand) { o.a.op("FMOVL", ops...) }
func (o Opcodes) FMOVL(ops ...Operand) { o.a.op("FMOVL", ops...) }
func (o Opcodes) Fmovlp(ops ...Operand) { o.a.op("FMOVLP", ops...) }
func (o Opcodes) FMOVLP(ops ...Operand) { o.a.op("FMOVLP", ops...) }
func (o Opcodes) Fmovv(ops ...Operand) { o.a.op("FMOVV", ops...) }
func (o Opcodes) FMOVV(ops ...Operand) { o.a.op("FMOVV", ops...) }
func (o Opcodes) Fmovvp(ops ...Operand) { o.a.op("FMOVVP", ops...) }
func (o Opcodes) FMOVVP(ops ...Operand) { o.a.op("FMOVVP", ops...) }
func (o Opcodes) Fmovw(ops ...Operand) { o.a.op("FMOVW", ops...) }
func (o Opcodes) FMOVW(ops ...Operand) { o.a.op("FMOVW", ops...) }
func (o Opcodes) Fmovwp(ops ...Operand) { o.a.op("FMOVWP", ops...) }
func (o Opcodes) FMOVWP(ops ...Operand) { o.a.op("FMOVWP", ops...) }
func (o Opcodes) Fmovx(ops ...Operand) { o.a.op("FMOVX", ops...) }
func (o Opcodes) FMOVX(ops ...Operand) { o.a.op("FMOVX", ops...) }
func (o Opcodes) Fmovxp(ops ...Operand) { o.a.op("FMOVXP", ops...) }
func (o Opcodes) FMOVXP(ops ...Operand) { o.a.op("FMOVXP", ops...) }
func (o Opcodes) Fmuld(ops ...Operand) { o.a.op("FMULD", ops...) }
func (o Opcodes) FMULD(ops ...Operand) { o.a.op("FMULD", ops...) }
func (o Opcodes) Fmuldp(ops ...Operand) { o.a.op("FMULDP", ops...) }
func (o Opcodes) FMULDP(ops ...Operand) { o.a.op("FMULDP", ops...) }
func (o Opcodes) Fmulf(ops ...Operand) { o.a.op("FMULF", ops...) }
func (o Opcodes) FMULF(ops ...Operand) { o.a.op("FMULF", ops...) }
func (o Opcodes) Fmull(ops ...Operand) { o.a.op("FMULL", ops...) }
func (o Opcodes) FMULL(ops ...Operand) { o.a.op("FMULL", ops...) }
func (o Opcodes) Fmulw(ops ...Operand) { o.a.op("FMULW", ops...) }
func (o Opcodes) FMULW(ops ...Operand) { o.a.op("FMULW", ops...) }
func (o Opcodes) Fnop(ops ...Operand) { o.a.op("FNOP", ops...) }
func (o Opcodes) FNOP(ops ...Operand) { o.a.op("FNOP", ops...) }
func (o Opcodes) Fpatan(ops ...Operand) { o.a.op("FPATAN", ops...) }
func (o Opcodes) FPATAN(ops ...Operand) { o.a.op("FPATAN", ops...) }
func (o Opcodes) Fprem(ops ...Operand) { o.a.op("FPREM", ops...) }
func (o Opcodes) FPREM(ops ...Operand) { o.a.op("FPREM", ops...) }
func (o Opcodes) Fprem1(ops ...Operand) { o.a.op("FPREM1", ops...) }
func (o Opcodes) FPREM1(ops ...Operand) { o.a.op("FPREM1", ops...) }
func (o Opcodes) Fptan(ops ...Operand) { o.a.op("FPTAN", ops...) }
func (o Opcodes) FPTAN(ops ...Operand) { o.a.op("FPTAN", ops...) }
func (o Opcodes) Frndint(ops ...Operand) { o.a.op("FRNDINT", ops...) }
func (o Opcodes) FRNDINT(ops ...Operand) { o.a.op("FRNDINT", ops...) }
func (o Opcodes) Frstor(ops ...Operand) { o.a.op("FRSTOR", ops...) }
func (o Opcodes) FRSTOR(ops ...Operand) { o.a.op("FRSTOR", ops...) }
func (o Opcodes) Fsave(ops ...Operand) { o.a.op("FSAVE", ops...) }
func (o Opcodes) FSAVE(ops ...Operand) { o.a.op("FSAVE", ops...) }
func (o Opcodes) Fscale(ops ...Operand) { o.a.op("FSCALE", ops...) }
func (o Opcodes) FSCALE(ops ...Operand) { o.a.op("FSCALE", ops...) }
func (o Opcodes) Fsin(ops ...Operand) { o.a.op("FSIN", ops...) }
func (o Opcodes) FSIN(ops ...Operand) { o.a.op("FSIN", ops...) }
func (o Opcodes) Fsincos(ops ...Operand) { o.a.op("FSINCOS", ops...) }
func (o Opcodes) FSINCOS(ops ...Operand) { o.a.op("FSINCOS", ops...) }
func (o Opcodes) Fsqrt(ops ...Operand) { o.a.op("FSQRT", ops...) }
func (o Opcodes) FSQRT(ops ...Operand) { o.a.op("FSQRT", ops...) }
func (o Opcodes) Fstcw(ops ...Operand) { o.a.op("FSTCW", ops...) }
func (o Opcodes) FSTCW(ops ...Operand) { o.a.op("FSTCW", ops...) }
func (o Opcodes) Fstenv(ops ...Operand) { o.a.op("FSTENV", ops...) }
func (o Opcodes) FSTENV(ops ...Operand) { o.a.op("FSTENV", ops...) }
func (o Opcodes) Fstsw(ops ...Operand) { o.a.op("FSTSW", ops...) }
func (o Opcodes) FSTSW(ops ...Operand) { o.a.op("FSTSW", ops...) }
func (o Opcodes) Fsubd(ops ...Operand) { o.a.op("FSUBD", ops...) }
func (o Opcodes) FSUBD(ops ...Operand) { o.a.op("FSUBD", ops...) }
func (o Opcodes) Fsubdp(ops ...Operand) { o.a.op("FSUBDP", ops...) }
func (o Opcodes) FSUBDP(ops ...Operand) { o.a.op("FSUBDP", ops...) }
func (o Opcodes) Fsubf(ops ...Operand) { o.a.op("FSUBF", ops...) }
func (o Opcodes) FSUBF(ops ...Operand) { o.a.op("FSUBF", ops...) }
func (o Opcodes) Fsubl(ops ...Operand) { o.a.op("FSUBL", ops...) }
func (o Opcodes) FSUBL(ops ...Operand) { o.a.op("FSUBL", ops...) }
func (o Opcodes) Fsubrd(ops ...Operand) { o.a.op("FSUBRD", ops...) }
func (o Opcodes) FSUBRD(ops ...Operand) { o.a.op("FSUBRD", ops...) }
func (o Opcodes) Fsubrdp(ops ...Operand) { o.a.op("FSUBRDP", ops...) }
func (o Opcodes) FSUBRDP(ops ...Operand) { o.a.op("FSUBRDP", ops...) }
func (o Opcodes) Fsubrf(ops ...Operand) { o.a.op("FSUBRF", ops...) }
func (o Opcodes) FSUBRF(ops ...Operand) { o.a.op("FSUBRF", ops...) }
func (o Opcodes) Fsubrl(ops ...Operand) { o.a.op("FSUBRL", ops...) }
func (o Opcodes) FSUBRL(ops ...Operand) { o.a.op("FSUBRL", ops...) }
func (o Opcodes) Fsubrw(ops ...Operand) { o.a.op("FSUBRW", ops...) }
func (o Opcodes) FSUBRW(ops ...Operand) { o.a.op("FSUBRW", ops...) }
func (o Opcodes) Fsubw(ops ...Operand) { o.a.op("FSUBW", ops...) }
func (o Opcodes) FSUBW(ops ...Operand) { o.a.op("FSUBW", ops...) }
func (o Opcodes) Ftst(ops ...Operand) { o.a.op("FTST", ops...) }
func (o Opcodes) FTST(ops ...Operand) { o.a.op("FTST", ops...) }
func (o Opcodes) Fucom(ops ...Operand) { o.a.op("FUCOM", ops...) }
func (o Opcodes) FUCOM(ops ...Operand) { o.a.op("FUCOM", ops...) }
func (o Opcodes) Fucomi(ops ...Operand) { o.a.op("FUCOMI", ops...) }
func (o Opcodes) FUCOMI(ops ...Operand) { o.a.op("FUCOMI", ops...) }
func (o Opcodes) Fucomip(ops ...Operand) { o.a.op("FUCOMIP", ops...) }
func (o Opcodes) FUCOMIP(ops ...Operand) { o.a.op("FUCOMIP", ops...) }
func (o Opcodes) Fucomp(ops ...Operand) { o.a.op("FUCOMP", ops...) }
func (o Opcodes) FUCOMP(ops ...Operand) { o.a.op("FUCOMP", ops...) }
func (o Opcodes) Fucompp(ops ...Operand) { o.a.op("FUCOMPP", ops...) }
func (o Opcodes) FUCOMPP(ops ...Operand) { o.a.op("FUCOMPP", ops...) }
func (o Opcodes) Fxam(ops ...Operand) { o.a.op("FXAM", ops...) }
func (o Opcodes) FXAM(ops ...Operand) { o.a.op("FXAM", ops...) }
func (o Opcodes) Fxchd(ops ...Operand) { o.a.op("FXCHD", ops...) }
func (o Opcodes) FXCHD(ops ...Operand) { o.a.op("FXCHD", ops...) }
func (o Opcodes) Fxrstor(ops ...Operand) { o.a.op("FXRSTOR", ops...) }
func (o Opcodes) FXRSTOR(ops ...Operand) { o.a.op("FXRSTOR", ops...) }
func (o Opcodes) Fxrstor64(ops ...Operand) { o.a.op("FXRSTOR64", ops...) }
func (o Opcodes) FXRSTOR64(ops ...Operand) { o.a.op("FXRSTOR64", ops...) }
func (o Opcodes) Fxsave(ops ...Operand) { o.a.op("FXSAVE", ops...) }
func (o Opcodes) FXSAVE(ops ...Operand) { o.a.op("FXSAVE", ops...) }
func (o Opcodes) Fxsave64(ops ...Operand) { o.a.op("FXSAVE64", ops...) }
func (o Opcodes) FXSAVE64(ops ...Operand) { o.a.op("FXSAVE64", ops...) }
func (o Opcodes) Fxtract(ops ...Operand) { o.a.op("FXTRACT", ops...) }
func (o Opcodes) FXTRACT(ops ...Operand) { o.a.op("FXTRACT", ops...) }
func (o Opcodes) Fyl2x(ops ...Operand) { o.a.op("FYL2X", ops...) }
func (o Opcodes) FYL2X(ops ...Operand) { o.a.op("FYL2X", ops...) }
func (o Opcodes) Fyl2xp1(ops ...Operand) { o.a.op("FYL2XP1", ops...) }
func (o Opcodes) FYL2XP1(ops ...Operand) { o.a.op("FYL2XP1", ops...) }
func (o Opcodes) Haddpd(ops ...Operand) { o.a.op("HADDPD", ops...) }
func (o Opcodes) HADDPD(ops ...Operand) { o.a.op("HADDPD", ops...) }
func (o Opcodes) Haddps(ops ...Operand) { o.a.op("HADDPS", ops...) }
func (o Opcodes) HADDPS(ops ...Operand) { o.a.op("HADDPS", ops...) }
func (o Opcodes) Hlt(ops ...Operand) { o.a.op("HLT", ops...) }
func (o Opcodes) HLT(ops ...Operand) { o.a.op("HLT", ops...) }
func (o Opcodes) Hsubpd(ops ...Operand) { o.a.op("HSUBPD", ops...) }
func (o Opcodes) HSUBPD(ops ...Operand) { o.a.op("HSUBPD", ops...) }
func (o Opcodes) Hsubps(ops ...Operand) { o.a.op("HSUBPS", ops...) }
func (o Opcodes) HSUBPS(ops ...Operand) { o.a.op("HSUBPS", ops...) }
func (o Opcodes) Idivb(ops ...Operand) { o.a.op("IDIVB", ops...) }
func (o Opcodes) IDIVB(ops ...Operand) { o.a.op("IDIVB", ops...) }
func (o Opcodes) Idivl(ops ...Operand) { o.a.op("IDIVL", ops...) }
func (o Opcodes) IDIVL(ops ...Operand) { o.a.op("IDIVL", ops...) }
func (o Opcodes) Idivq(ops ...Operand) { o.a.op("IDIVQ", ops...) }
func (o Opcodes) IDIVQ(ops ...Operand) { o.a.op("IDIVQ", ops...) }
func (o Opcodes) Idivw(ops ...Operand) { o.a.op("IDIVW", ops...) }
func (o Opcodes) IDIVW(ops ...Operand) { o.a.op("IDIVW", ops...) }
func (o Opcodes) Imul3q(ops ...Operand) { o.a.op("IMUL3Q", ops...) }
func (o Opcodes) IMUL3Q(ops ...Operand) { o.a.op("IMUL3Q", ops...) }
func (o Opcodes) Imulb(ops ...Operand) { o.a.op("IMULB", ops...) }
func (o Opcodes) IMULB(ops ...Operand) { o.a.op("IMULB", ops...) }
func (o Opcodes) Imull(ops ...Operand) { o.a.op("IMULL", ops...) }
func (o Opcodes) IMULL(ops ...Operand) { o.a.op("IMULL", ops...) }
func (o Opcodes) Imulq(ops ...Operand) { o.a.op("IMULQ", ops...) }
func (o Opcodes) IMULQ(ops ...Operand) { o.a.op("IMULQ", ops...) }
func (o Opcodes) Imulw(ops ...Operand) { o.a.op("IMULW", ops...) }
func (o Opcodes) IMULW(ops ...Operand) { o.a.op("IMULW", ops...) }
func (o Opcodes) Inb(ops ...Operand) { o.a.op("INB", ops...) }
func (o Opcodes) INB(ops ...Operand) { o.a.op("INB", ops...) }
func (o Opcodes) Incb(ops ...Operand) { o.a.op("INCB", ops...) }
func (o Opcodes) INCB(ops ...Operand) { o.a.op("INCB", ops...) }
func (o Opcodes) Incl(ops ...Operand) { o.a.op("INCL", ops...) }
func (o Opcodes) INCL(ops ...Operand) { o.a.op("INCL", ops...) }
func (o Opcodes) Incq(ops ...Operand) { o.a.op("INCQ", ops...) }
func (o Opcodes) INCQ(ops ...Operand) { o.a.op("INCQ", ops...) }
func (o Opcodes) Incw(ops ...Operand) { o.a.op("INCW", ops...) }
func (o Opcodes) INCW(ops ...Operand) { o.a.op("INCW", ops...) }
func (o Opcodes) Inl(ops ...Operand) { o.a.op("INL", ops...) }
func (o Opcodes) INL(ops ...Operand) { o.a.op("INL", ops...) }
func (o Opcodes) Insb(ops ...Operand) { o.a.op("INSB", ops...) }
func (o Opcodes) INSB(ops ...Operand) { o.a.op("INSB", ops...) }
func (o Opcodes) Insertps(ops ...Operand) { o.a.op("INSERTPS", ops...) }
func (o Opcodes) INSERTPS(ops ...Operand) { o.a.op("INSERTPS", ops...) }
func (o Opcodes) Insl(ops ...Operand) { o.a.op("INSL", ops...) }
func (o Opcodes) INSL(ops ...Operand) { o.a.op("INSL", ops...) }
func (o Opcodes) Insw(ops ...Operand) { o.a.op("INSW", ops...) }
func (o Opcodes) INSW(ops ...Operand) { o.a.op("INSW", ops...) }
func (o Opcodes) Int(ops ...Operand) { o.a.op("INT", ops...) }
func (o Opcodes) INT(ops ...Operand) { o.a.op("INT", ops...) }
func (o Opcodes) Into(ops ...Operand) { o.a.op("INTO", ops...) }
func (o Opcodes) INTO(ops ...Operand) { o.a.op("INTO", ops...) }
func (o Opcodes) Invd(ops ...Operand) { o.a.op("INVD", ops...) }
func (o Opcodes) INVD(ops ...Operand) { o.a.op("INVD", ops...) }
func (o Opcodes) Invlpg(ops ...Operand) { o.a.op("INVLPG", ops...) }
func (o Opcodes) INVLPG(ops ...Operand) { o.a.op("INVLPG", ops...) }
func (o Opcodes) Inw(ops ...Operand) { o.a.op("INW", ops...) }
func (o Opcodes) INW(ops ...Operand) { o.a.op("INW", ops...) }
func (o Opcodes) Iretl(ops ...Operand) { o.a.op("IRETL", ops...) }
func (o Opcodes) IRETL(ops ...Operand) { o.a.op("IRETL", ops...) }
func (o Opcodes) Iretq(ops ...Operand) { o.a.op("IRETQ", ops...) }
func (o Opcodes) IRETQ(ops ...Operand) { o.a.op("IRETQ", ops...) }
func (o Opcodes) Iretw(ops ...Operand) { o.a.op("IRETW", ops...) }
func (o Opcodes) IRETW(ops ...Operand) { o.a.op("IRETW", ops...) }
func (o Opcodes) Jcc(ops ...Operand) { o.a.op("JCC", ops...) }
func (o Opcodes) JCC(ops ...Operand) { o.a.op("JCC", ops...) }
func (o Opcodes) Jcs(ops ...Operand) { o.a.op("JCS", ops...) }
func (o Opcodes) JCS(ops ...Operand) { o.a.op("JCS", ops...) }
func (o Opcodes) Jcxzl(ops ...Operand) { o.a.op("JCXZL", ops...) }
func (o Opcodes) JCXZL(ops ...Operand) { o.a.op("JCXZL", ops...) }
func (o Opcodes) Jcxzq(ops ...Operand) { o.a.op("JCXZQ", ops...) }
func (o Opcodes) JCXZQ(ops ...Operand) { o.a.op("JCXZQ", ops...) }
func (o Opcodes) Jcxzw(ops ...Operand) { o.a.op("JCXZW", ops...) }
func (o Opcodes) JCXZW(ops ...Operand) { o.a.op("JCXZW", ops...) }
func (o Opcodes) Jeq(ops ...Operand) { o.a.op("JEQ", ops...) }
func (o Opcodes) JEQ(ops ...Operand) { o.a.op("JEQ", ops...) }
func (o Opcodes) Jge(ops ...Operand) { o.a.op("JGE", ops...) }
func (o Opcodes) JGE(ops ...Operand) { o.a.op("JGE", ops...) }
func (o Opcodes) Jgt(ops ...Operand) { o.a.op("JGT", ops...) }
func (o Opcodes) JGT(ops ...Operand) { o.a.op("JGT", ops...) }
func (o Opcodes) Jhi(ops ...Operand) { o.a.op("JHI", ops...) }
func (o Opcodes) JHI(ops ...Operand) { o.a.op("JHI", ops...) }
func (o Opcodes) Jle(ops ...Operand) { o.a.op("JLE", ops...) }
func (o Opcodes) JLE(ops ...Operand) { o.a.op("JLE", ops...) }
func (o Opcodes) Jls(ops ...Operand) { o.a.op("JLS", ops...) }
func (o Opcodes) JLS(ops ...Operand) { o.a.op("JLS", ops...) }
func (o Opcodes) Jlt(ops ...Operand) { o.a.op("JLT", ops...) }
func (o Opcodes) JLT(ops ...Operand) { o.a.op("JLT", ops...) }
func (o Opcodes) Jmi(ops ...Operand) { o.a.op("JMI", ops...) }
func (o Opcodes) JMI(ops ...Operand) { o.a.op("JMI", ops...) }
func (o Opcodes) Jne(ops ...Operand) { o.a.op("JNE", ops...) }
func (o Opcodes) JNE(ops ...Operand) { o.a.op("JNE", ops...) }
func (o Opcodes) Joc(ops ...Operand) { o.a.op("JOC", ops...) }
func (o Opcodes) JOC(ops ...Operand) { o.a.op("JOC", ops...) }
func (o Opcodes) Jos(ops ...Operand) { o.a.op("JOS", ops...) }
func (o Opcodes) JOS(ops ...Operand) { o.a.op("JOS", ops...) }
func (o Opcodes) Jpc(ops ...Operand) { o.a.op("JPC", ops...) }
func (o Opcodes) JPC(ops ...Operand) { o.a.op("JPC", ops...) }
func (o Opcodes) Jpl(ops ...Operand) { o.a.op("JPL", ops...) }
func (o Opcodes) JPL(ops ...Operand) { o.a.op("JPL", ops...) }
func (o Opcodes) Jps(ops ...Operand) { o.a.op("JPS", ops...) }
func (o Opcodes) JPS(ops ...Operand) { o.a.op("JPS", ops...) }
func (o Opcodes) Lahf(ops ...Operand) { o.a.op("LAHF", ops...) }
func (o Opcodes) LAHF(ops ...Operand) { o.a.op("LAHF", ops...) }
func (o Opcodes) Larl(ops ...Operand) { o.a.op("LARL", ops...) }
func (o Opcodes) LARL(ops ...Operand) { o.a.op("LARL", ops...) }
func (o Opcodes) Larw(ops ...Operand) { o.a.op("LARW", ops...) }
func (o Opcodes) LARW(ops ...Operand) { o.a.op("LARW", ops...) }
func (o Opcodes) Lddqu(ops ...Operand) { o.a.op("LDDQU", ops...) }
func (o Opcodes) LDDQU(ops ...Operand) { o.a.op("LDDQU", ops...) }
func (o Opcodes) Ldmxcsr(ops ...Operand) { o.a.op("LDMXCSR", ops...) }
func (o Opcodes) LDMXCSR(ops ...Operand) { o.a.op("LDMXCSR", ops...) }
func (o Opcodes) Leal(ops ...Operand) { o.a.op("LEAL", ops...) }
func (o Opcodes) LEAL(ops ...Operand) { o.a.op("LEAL", ops...) }
func (o Opcodes) Leaq(ops ...Operand) { o.a.op("LEAQ", ops...) }
func (o Opcodes) LEAQ(ops ...Operand) { o.a.op("LEAQ", ops...) }
func (o Opcodes) Leavel(ops ...Operand) { o.a.op("LEAVEL", ops...) }
func (o Opcodes) LEAVEL(ops ...Operand) { o.a.op("LEAVEL", ops...) }
func (o Opcodes) Leaveq(ops ...Operand) { o.a.op("LEAVEQ", ops...) }
func (o Opcodes) LEAVEQ(ops ...Operand) { o.a.op("LEAVEQ", ops...) }
func (o Opcodes) Leavew(ops ...Operand) { o.a.op("LEAVEW", ops...) }
func (o Opcodes) LEAVEW(ops ...Operand) { o.a.op("LEAVEW", ops...) }
func (o Opcodes) Leaw(ops ...Operand) { o.a.op("LEAW", ops...) }
func (o Opcodes) LEAW(ops ...Operand) { o.a.op("LEAW", ops...) }
func (o Opcodes) Lfence(ops ...Operand) { o.a.op("LFENCE", ops...) }
func (o Opcodes) LFENCE(ops ...Operand) { o.a.op("LFENCE", ops...) }
func (o Opcodes) Lock(ops ...Operand) { o.a.op("LOCK", ops...) }
func (o Opcodes) LOCK(ops ...Operand) { o.a.op("LOCK", ops...) }
func (o Opcodes) Lodsb(ops ...Operand) { o.a.op("LODSB", ops...) }
func (o Opcodes) LODSB(ops ...Operand) { o.a.op("LODSB", ops...) }
func (o Opcodes) Lodsl(ops ...Operand) { o.a.op("LODSL", ops...) }
func (o Opcodes) LODSL(ops ...Operand) { o.a.op("LODSL", ops...) }
func (o Opcodes) Lodsq(ops ...Operand) { o.a.op("LODSQ", ops...) }
func (o Opcodes) LODSQ(ops ...Operand) { o.a.op("LODSQ", ops...) }
func (o Opcodes) Lodsw(ops ...Operand) { o.a.op("LODSW", ops...) }
func (o Opcodes) LODSW(ops ...Operand) { o.a.op("LODSW", ops...) }
func (o Opcodes) Long(ops ...Operand) { o.a.op("LONG", ops...) }
func (o Opcodes) LONG(ops ...Operand) { o.a.op("LONG", ops...) }
func (o Opcodes) Loop(ops ...Operand) { o.a.op("LOOP", ops...) }
func (o Opcodes) LOOP(ops ...Operand) { o.a.op("LOOP", ops...) }
func (o Opcodes) Loopeq(ops ...Operand) { o.a.op("LOOPEQ", ops...) }
func (o Opcodes) LOOPEQ(ops ...Operand) { o.a.op("LOOPEQ", ops...) }
func (o Opcodes) Loopne(ops ...Operand) { o.a.op("LOOPNE", ops...) }
func (o Opcodes) LOOPNE(ops ...Operand) { o.a.op("LOOPNE", ops...) }
func (o Opcodes) Lsll(ops ...Operand) { o.a.op("LSLL", ops...) }
func (o Opcodes) LSLL(ops ...Operand) { o.a.op("LSLL", ops...) }
func (o Opcodes) Lslw(ops ...Operand) { o.a.op("LSLW", ops...) }
func (o Opcodes) LSLW(ops ...Operand) { o.a.op("LSLW", ops...) }
func (o Opcodes) Maskmovou(ops ...Operand) { o.a.op("MASKMOVOU", ops...) }
func (o Opcodes) MASKMOVOU(ops ...Operand) { o.a.op("MASKMOVOU", ops...) }
func (o Opcodes) Maskmovq(ops ...Operand) { o.a.op("MASKMOVQ", ops...) }
func (o Opcodes) MASKMOVQ(ops ...Operand) { o.a.op("MASKMOVQ", ops...) }
func (o Opcodes) Maxpd(ops ...Operand) { o.a.op("MAXPD", ops...) }
func (o Opcodes) MAXPD(ops ...Operand) { o.a.op("MAXPD", ops...) }
func (o Opcodes) Maxps(ops ...Operand) { o.a.op("MAXPS", ops...) }
func (o Opcodes) MAXPS(ops ...Operand) { o.a.op("MAXPS", ops...) }
func (o Opcodes) Maxsd(ops ...Operand) { o.a.op("MAXSD", ops...) }
func (o Opcodes) MAXSD(ops ...Operand) { o.a.op("MAXSD", ops...) }
func (o Opcodes) Maxss(ops ...Operand) { o.a.op("MAXSS", ops...) }
func (o Opcodes) MAXSS(ops ...Operand) { o.a.op("MAXSS", ops...) }
func (o Opcodes) Mfence(ops ...Operand) { o.a.op("MFENCE", ops...) }
func (o Opcodes) MFENCE(ops ...Operand) { o.a.op("MFENCE", ops...) }
func (o Opcodes) Minpd(ops ...Operand) { o.a.op("MINPD", ops...) }
func (o Opcodes) MINPD(ops ...Operand) { o.a.op("MINPD", ops...) }
func (o Opcodes) Minps(ops ...Operand) { o.a.op("MINPS", ops...) }
func (o Opcodes) MINPS(ops ...Operand) { o.a.op("MINPS", ops...) }
func (o Opcodes) Minsd(ops ...Operand) { o.a.op("MINSD", ops...) }
func (o Opcodes) MINSD(ops ...Operand) { o.a.op("MINSD", ops...) }
func (o Opcodes) Minss(ops ...Operand) { o.a.op("MINSS", ops...) }
func (o Opcodes) MINSS(ops ...Operand) { o.a.op("MINSS", ops...) }
func (o Opcodes) Movapd(ops ...Operand) { o.a.op("MOVAPD", ops...) }
func (o Opcodes) MOVAPD(ops ...Operand) { o.a.op("MOVAPD", ops...) }
func (o Opcodes) Movaps(ops ...Operand) { o.a.op("MOVAPS", ops...) }
func (o Opcodes) MOVAPS(ops ...Operand) { o.a.op("MOVAPS", ops...) }
func (o Opcodes) Movb(ops ...Operand) { o.a.op("MOVB", ops...) }
func (o Opcodes) MOVB(ops ...Operand) { o.a.op("MOVB", ops...) }
func (o Opcodes) Movblsx(ops ...Operand) { o.a.op("MOVBLSX", ops...) }
func (o Opcodes) MOVBLSX(ops ...Operand) { o.a.op("MOVBLSX", ops...) }
func (o Opcodes) Movblzx(ops ...Operand) { o.a.op("MOVBLZX", ops...) }
func (o Opcodes) MOVBLZX(ops ...Operand) { o.a.op("MOVBLZX", ops...) }
func (o Opcodes) Movbqsx(ops ...Operand) { o.a.op("MOVBQSX", ops...) }
func (o Opcodes) MOVBQSX(ops ...Operand) { o.a.op("MOVBQSX", ops...) }
func (o Opcodes) Movbqzx(ops ...Operand) { o.a.op("MOVBQZX", ops...) }
func (o Opcodes) MOVBQZX(ops ...Operand) { o.a.op("MOVBQZX", ops...) }
func (o Opcodes) Movbwsx(ops ...Operand) { o.a.op("MOVBWSX", ops...) }
func (o Opcodes) MOVBWSX(ops ...Operand) { o.a.op("MOVBWSX", ops...) }
func (o Opcodes) Movbwzx(ops ...Operand) { o.a.op("MOVBWZX", ops...) }
func (o Opcodes) MOVBWZX(ops ...Operand) { o.a.op("MOVBWZX", ops...) }
func (o Opcodes) Movddup(ops ...Operand) { o.a.op("MOVDDUP", ops...) }
func (o Opcodes) MOVDDUP(ops ...Operand) { o.a.op("MOVDDUP", ops...) }
func (o Opcodes) Movhlps(ops ...Operand) { o.a.op("MOVHLPS", ops...) }
func (o Opcodes) MOVHLPS(ops ...Operand) { o.a.op("MOVHLPS", ops...) }
func (o Opcodes) Movhpd(ops ...Operand) { o.a.op("MOVHPD", ops...) }
func (o Opcodes) MOVHPD(ops ...Operand) { o.a.op("MOVHPD", ops...) }
func (o Opcodes) Movhps(ops ...Operand) { o.a.op("MOVHPS", ops...) }
func (o Opcodes) MOVHPS(ops ...Operand) { o.a.op("MOVHPS", ops...) }
func (o Opcodes) Movl(ops ...Operand) { o.a.op("MOVL", ops...) }
func (o Opcodes) MOVL(ops ...Operand) { o.a.op("MOVL", ops...) }
func (o Opcodes) Movlhps(ops ...Operand) { o.a.op("MOVLHPS", ops...) }
func (o Opcodes) MOVLHPS(ops ...Operand) { o.a.op("MOVLHPS", ops...) }
func (o Opcodes) Movlpd(ops ...Operand) { o.a.op("MOVLPD", ops...) }
func (o Opcodes) MOVLPD(ops ...Operand) { o.a.op("MOVLPD", ops...) }
func (o Opcodes) Movlps(ops ...Operand) { o.a.op("MOVLPS", ops...) }
func (o Opcodes) MOVLPS(ops ...Operand) { o.a.op("MOVLPS", ops...) }
func (o Opcodes) Movlqsx(ops ...Operand) { o.a.op("MOVLQSX", ops...) }
func (o Opcodes) MOVLQSX(ops ...Operand) { o.a.op("MOVLQSX", ops...) }
func (o Opcodes) Movlqzx(ops ...Operand) { o.a.op("MOVLQZX", ops...) }
func (o Opcodes) MOVLQZX(ops ...Operand) { o.a.op("MOVLQZX", ops...) }
func (o Opcodes) Movmskpd(ops ...Operand) { o.a.op("MOVMSKPD", ops...) }
func (o Opcodes) MOVMSKPD(ops ...Operand) { o.a.op("MOVMSKPD", ops...) }
func (o Opcodes) Movmskps(ops ...Operand) { o.a.op("MOVMSKPS", ops...) }
func (o Opcodes) MOVMSKPS(ops ...Operand) { o.a.op("MOVMSKPS", ops...) }
func (o Opcodes) Movntdqa(ops ...Operand) { o.a.op("MOVNTDQA", ops...) }
func (o Opcodes) MOVNTDQA(ops ...Operand) { o.a.op("MOVNTDQA", ops...) }
func (o Opcodes) Movntil(ops ...Operand) { o.a.op("MOVNTIL", ops...) }
func (o Opcodes) MOVNTIL(ops ...Operand) { o.a.op("MOVNTIL", ops...) }
func (o Opcodes) Movntiq(ops ...Operand) { o.a.op("MOVNTIQ", ops...) }
func (o Opcodes) MOVNTIQ(ops ...Operand) { o.a.op("MOVNTIQ", ops...) }
func (o Opcodes) Movnto(ops ...Operand) { o.a.op("MOVNTO", ops...) }
func (o Opcodes) MOVNTO(ops ...Operand) { o.a.op("MOVNTO", ops...) }
func (o Opcodes) Movntpd(ops ...Operand) { o.a.op("MOVNTPD", ops...) }
func (o Opcodes) MOVNTPD(ops ...Operand) { o.a.op("MOVNTPD", ops...) }
func (o Opcodes) Movntps(ops ...Operand) { o.a.op("MOVNTPS", ops...) }
func (o Opcodes) MOVNTPS(ops ...Operand) { o.a.op("MOVNTPS", ops...) }
func (o Opcodes) Movntq(ops ...Operand) { o.a.op("MOVNTQ", ops...) }
func (o Opcodes) MOVNTQ(ops ...Operand) { o.a.op("MOVNTQ", ops...) }
func (o Opcodes) Movo(ops ...Operand) { o.a.op("MOVO", ops...) }
func (o Opcodes) MOVO(ops ...Operand) { o.a.op("MOVO", ops...) }
func (o Opcodes) Movou(ops ...Operand) { o.a.op("MOVOU", ops...) }
func (o Opcodes) MOVOU(ops ...Operand) { o.a.op("MOVOU", ops...) }
func (o Opcodes) Movq(ops ...Operand) { o.a.op("MOVQ", ops...) }
func (o Opcodes) MOVQ(ops ...Operand) { o.a.op("MOVQ", ops...) }
func (o Opcodes) Movql(ops ...Operand) { o.a.op("MOVQL", ops...) }
func (o Opcodes) MOVQL(ops ...Operand) { o.a.op("MOVQL", ops...) }
func (o Opcodes) Movqozx(ops ...Operand) { o.a.op("MOVQOZX", ops...) }
func (o Opcodes) MOVQOZX(ops ...Operand) { o.a.op("MOVQOZX", ops...) }
func (o Opcodes) Movsb(ops ...Operand) { o.a.op("MOVSB", ops...) }
func (o Opcodes) MOVSB(ops ...Operand) { o.a.op("MOVSB", ops...) }
func (o Opcodes) Movsd(ops ...Operand) { o.a.op("MOVSD", ops...) }
func (o Opcodes) MOVSD(ops ...Operand) { o.a.op("MOVSD", ops...) }
func (o Opcodes) Movshdup(ops ...Operand) { o.a.op("MOVSHDUP", ops...) }
func (o Opcodes) MOVSHDUP(ops ...Operand) { o.a.op("MOVSHDUP", ops...) }
func (o Opcodes) Movsl(ops ...Operand) { o.a.op("MOVSL", ops...) }
func (o Opcodes) MOVSL(ops ...Operand) { o.a.op("MOVSL", ops...) }
func (o Opcodes) Movsldup(ops ...Operand) { o.a.op("MOVSLDUP", ops...) }
func (o Opcodes) MOVSLDUP(ops ...Operand) { o.a.op("MOVSLDUP", ops...) }
func (o Opcodes) Movsq(ops ...Operand) { o.a.op("MOVSQ", ops...) }
func (o Opcodes) MOVSQ(ops ...Operand) { o.a.op("MOVSQ", ops...) }
func (o Opcodes) Movss(ops ...Operand) { o.a.op("MOVSS", ops...) }
func (o Opcodes) MOVSS(ops ...Operand) { o.a.op("MOVSS", ops...) }
func (o Opcodes) Movsw(ops ...Operand) { o.a.op("MOVSW", ops...) }
func (o Opcodes) MOVSW(ops ...Operand) { o.a.op("MOVSW", ops...) }
func (o Opcodes) Movupd(ops ...Operand) { o.a.op("MOVUPD", ops...) }
func (o Opcodes) MOVUPD(ops ...Operand) { o.a.op("MOVUPD", ops...) }
func (o Opcodes) Movups(ops ...Operand) { o.a.op("MOVUPS", ops...) }
func (o Opcodes) MOVUPS(ops ...Operand) { o.a.op("MOVUPS", ops...) }
func (o Opcodes) Movw(ops ...Operand) { o.a.op("MOVW", ops...) }
func (o Opcodes) MOVW(ops ...Operand) { o.a.op("MOVW", ops...) }
func (o Opcodes) Movwlsx(ops ...Operand) { o.a.op("MOVWLSX", ops...) }
func (o Opcodes) MOVWLSX(ops ...Operand) { o.a.op("MOVWLSX", ops...) }
func (o Opcodes) Movwlzx(ops ...Operand) { o.a.op("MOVWLZX", ops...) }
func (o Opcodes) MOVWLZX(ops ...Operand) { o.a.op("MOVWLZX", ops...) }
func (o Opcodes) Movwqsx(ops ...Operand) { o.a.op("MOVWQSX", ops...) }
func (o Opcodes) MOVWQSX(ops ...Operand) { o.a.op("MOVWQSX", ops...) }
func (o Opcodes) Movwqzx(ops ...Operand) { o.a.op("MOVWQZX", ops...) }
func (o Opcodes) MOVWQZX(ops ...Operand) { o.a.op("MOVWQZX", ops...) }
func (o Opcodes) Mpsadbw(ops ...Operand) { o.a.op("MPSADBW", ops...) }
func (o Opcodes) MPSADBW(ops ...Operand) { o.a.op("MPSADBW", ops...) }
func (o Opcodes) Mulb(ops ...Operand) { o.a.op("MULB", ops...) }
func (o Opcodes) MULB(ops ...Operand) { o.a.op("MULB", ops...) }
func (o Opcodes) Mull(ops ...Operand) { o.a.op("MULL", ops...) }
func (o Opcodes) MULL(ops ...Operand) { o.a.op("MULL", ops...) }
func (o Opcodes) Mulpd(ops ...Operand) { o.a.op("MULPD", ops...) }
func (o Opcodes) MULPD(ops ...Operand) { o.a.op("MULPD", ops...) }
func (o Opcodes) Mulps(ops ...Operand) { o.a.op("MULPS", ops...) }
func (o Opcodes) MULPS(ops ...Operand) { o.a.op("MULPS", ops...) }
func (o Opcodes) Mulq(ops ...Operand) { o.a.op("MULQ", ops...) }
func (o Opcodes) MULQ(ops ...Operand) { o.a.op("MULQ", ops...) }
func (o Opcodes) Mulsd(ops ...Operand) { o.a.op("MULSD", ops...) }
func (o Opcodes) MULSD(ops ...Operand) { o.a.op("MULSD", ops...) }
func (o Opcodes) Mulss(ops ...Operand) { o.a.op("MULSS", ops...) }
func (o Opcodes) MULSS(ops ...Operand) { o.a.op("MULSS", ops...) }
func (o Opcodes) Mulw(ops ...Operand) { o.a.op("MULW", ops...) }
func (o Opcodes) MULW(ops ...Operand) { o.a.op("MULW", ops...) }
func (o Opcodes) Mulxl(ops ...Operand) { o.a.op("MULXL", ops...) }
func (o Opcodes) MULXL(ops ...Operand) { o.a.op("MULXL", ops...) }
func (o Opcodes) Mulxq(ops ...Operand) { o.a.op("MULXQ", ops...) }
func (o Opcodes) MULXQ(ops ...Operand) { o.a.op("MULXQ", ops...) }
func (o Opcodes) Negb(ops ...Operand) { o.a.op("NEGB", ops...) }
func (o Opcodes) NEGB(ops ...Operand) { o.a.op("NEGB", ops...) }
func (o Opcodes) Negl(ops ...Operand) { o.a.op("NEGL", ops...) }
func (o Opcodes) NEGL(ops ...Operand) { o.a.op("NEGL", ops...) }
func (o Opcodes) Negq(ops ...Operand) { o.a.op("NEGQ", ops...) }
func (o Opcodes) NEGQ(ops ...Operand) { o.a.op("NEGQ", ops...) }
func (o Opcodes) Negw(ops ...Operand) { o.a.op("NEGW", ops...) }
func (o Opcodes) NEGW(ops ...Operand) { o.a.op("NEGW", ops...) }
func (o Opcodes) Notb(ops ...Operand) { o.a.op("NOTB", ops...) }
func (o Opcodes) NOTB(ops ...Operand) { o.a.op("NOTB", ops...) }
func (o Opcodes) Notl(ops ...Operand) { o.a.op("NOTL", ops...) }
func (o Opcodes) NOTL(ops ...Operand) { o.a.op("NOTL", ops...) }
func (o Opcodes) Notq(ops ...Operand) { o.a.op("NOTQ", ops...) }
func (o Opcodes) NOTQ(ops ...Operand) { o.a.op("NOTQ", ops...) }
func (o Opcodes) Notw(ops ...Operand) { o.a.op("NOTW", ops...) }
func (o Opcodes) NOTW(ops ...Operand) { o.a.op("NOTW", ops...) }
func (o Opcodes) Orb(ops ...Operand) { o.a.op("ORB", ops...) }
func (o Opcodes) ORB(ops ...Operand) { o.a.op("ORB", ops...) }
func (o Opcodes) Orl(ops ...Operand) { o.a.op("ORL", ops...) }
func (o Opcodes) ORL(ops ...Operand) { o.a.op("ORL", ops...) }
func (o Opcodes) Orpd(ops ...Operand) { o.a.op("ORPD", ops...) }
func (o Opcodes) ORPD(ops ...Operand) { o.a.op("ORPD", ops...) }
func (o Opcodes) Orps(ops ...Operand) { o.a.op("ORPS", ops...) }
func (o Opcodes) ORPS(ops ...Operand) { o.a.op("ORPS", ops...) }
func (o Opcodes) Orq(ops ...Operand) { o.a.op("ORQ", ops...) }
func (o Opcodes) ORQ(ops ...Operand) { o.a.op("ORQ", ops...) }
func (o Opcodes) Orw(ops ...Operand) { o.a.op("ORW", ops...) }
func (o Opcodes) ORW(ops ...Operand) { o.a.op("ORW", ops...) }
func (o Opcodes) Outb(ops ...Operand) { o.a.op("OUTB", ops...) }
func (o Opcodes) OUTB(ops ...Operand) { o.a.op("OUTB", ops...) }
func (o Opcodes) Outl(ops ...Operand) { o.a.op("OUTL", ops...) }
func (o Opcodes) OUTL(ops ...Operand) { o.a.op("OUTL", ops...) }
func (o Opcodes) Outsb(ops ...Operand) { o.a.op("OUTSB", ops...) }
func (o Opcodes) OUTSB(ops ...Operand) { o.a.op("OUTSB", ops...) }
func (o Opcodes) Outsl(ops ...Operand) { o.a.op("OUTSL", ops...) }
func (o Opcodes) OUTSL(ops ...Operand) { o.a.op("OUTSL", ops...) }
func (o Opcodes) Outsw(ops ...Operand) { o.a.op("OUTSW", ops...) }
func (o Opcodes) OUTSW(ops ...Operand) { o.a.op("OUTSW", ops...) }
func (o Opcodes) Outw(ops ...Operand) { o.a.op("OUTW", ops...) }
func (o Opcodes) OUTW(ops ...Operand) { o.a.op("OUTW", ops...) }
func (o Opcodes) Pabsb(ops ...Operand) { o.a.op("PABSB", ops...) }
func (o Opcodes) PABSB(ops ...Operand) { o.a.op("PABSB", ops...) }
func (o Opcodes) Pabsd(ops ...Operand) { o.a.op("PABSD", ops...) }
func (o Opcodes) PABSD(ops ...Operand) { o.a.op("PABSD", ops...) }
func (o Opcodes) Pabsw(ops ...Operand) { o.a.op("PABSW", ops...) }
func (o Opcodes) PABSW(ops ...Operand) { o.a.op("PABSW", ops...) }
func (o Opcodes) Packsslw(ops ...Operand) { o.a.op("PACKSSLW", ops...) }
func (o Opcodes) PACKSSLW(ops ...Operand) { o.a.op("PACKSSLW", ops...) }
func (o Opcodes) Packsswb(ops ...Operand) { o.a.op("PACKSSWB", ops...) }
func (o Opcodes) PACKSSWB(ops ...Operand) { o.a.op("PACKSSWB", ops...) }
func (o Opcodes) Packusdw(ops ...Operand) { o.a.op("PACKUSDW", ops...) }
func (o Opcodes) PACKUSDW(ops ...Operand) { o.a.op("PACKUSDW", ops...) }
func (o Opcodes) Packuswb(ops ...Operand) { o.a.op("PACKUSWB", ops...) }
func (o Opcodes) PACKUSWB(ops ...Operand) { o.a.op("PACKUSWB", ops...) }
func (o Opcodes) Paddb(ops ...Operand) { o.a.op("PADDB", ops...) }
func (o Opcodes) PADDB(ops ...Operand) { o.a.op("PADDB", ops...) }
func (o Opcodes) Paddl(ops ...Operand) { o.a.op("PADDL", ops...) }
func (o Opcodes) PADDL(ops ...Operand) { o.a.op("PADDL", ops...) }
func (o Opcodes) Paddq(ops ...Operand) { o.a.op("PADDQ", ops...) }
func (o Opcodes) PADDQ(ops ...Operand) { o.a.op("PADDQ", ops...) }
func (o Opcodes) Paddsb(ops ...Operand) { o.a.op("PADDSB", ops...) }
func (o Opcodes) PADDSB(ops ...Operand) { o.a.op("PADDSB", ops...) }
func (o Opcodes) Paddsw(ops ...Operand) { o.a.op("PADDSW", ops...) }
func (o Opcodes) PADDSW(ops ...Operand) { o.a.op("PADDSW", ops...) }
func (o Opcodes) Paddusb(ops ...Operand) { o.a.op("PADDUSB", ops...) }
func (o Opcodes) PADDUSB(ops ...Operand) { o.a.op("PADDUSB", ops...) }
func (o Opcodes) Paddusw(ops ...Operand) { o.a.op("PADDUSW", ops...) }
func (o Opcodes) PADDUSW(ops ...Operand) { o.a.op("PADDUSW", ops...) }
func (o Opcodes) Paddw(ops ...Operand) { o.a.op("PADDW", ops...) }
func (o Opcodes) PADDW(ops ...Operand) { o.a.op("PADDW", ops...) }
func (o Opcodes) Palignr(ops ...Operand) { o.a.op("PALIGNR", ops...) }
func (o Opcodes) PALIGNR(ops ...Operand) { o.a.op("PALIGNR", ops...) }
func (o Opcodes) Pand(ops ...Operand) { o.a.op("PAND", ops...) }
func (o Opcodes) PAND(ops ...Operand) { o.a.op("PAND", ops...) }
func (o Opcodes) Pandn(ops ...Operand) { o.a.op("PANDN", ops...) }
func (o Opcodes) PANDN(ops ...Operand) { o.a.op("PANDN", ops...) }
func (o Opcodes) Pause(ops ...Operand) { o.a.op("PAUSE", ops...) }
func (o Opcodes) PAUSE(ops ...Operand) { o.a.op("PAUSE", ops...) }
func (o Opcodes) Pavgb(ops ...Operand) { o.a.op("PAVGB", ops...) }
func (o Opcodes) PAVGB(ops ...Operand) { o.a.op("PAVGB", ops...) }
func (o Opcodes) Pavgw(ops ...Operand) { o.a.op("PAVGW", ops...) }
func (o Opcodes) PAVGW(ops ...Operand) { o.a.op("PAVGW", ops...) }
func (o Opcodes) Pblendw(ops ...Operand) { o.a.op("PBLENDW", ops...) }
func (o Opcodes) PBLENDW(ops ...Operand) { o.a.op("PBLENDW", ops...) }
func (o Opcodes) Pclmulqdq(ops ...Operand) { o.a.op("PCLMULQDQ", ops...) }
func (o Opcodes) PCLMULQDQ(ops ...Operand) { o.a.op("PCLMULQDQ", ops...) }
func (o Opcodes) Pcmpeqb(ops ...Operand) { o.a.op("PCMPEQB", ops...) }
func (o Opcodes) PCMPEQB(ops ...Operand) { o.a.op("PCMPEQB", ops...) }
func (o Opcodes) Pcmpeql(ops ...Operand) { o.a.op("PCMPEQL", ops...) }
func (o Opcodes) PCMPEQL(ops ...Operand) { o.a.op("PCMPEQL", ops...) }
func (o Opcodes) Pcmpeqq(ops ...Operand) { o.a.op("PCMPEQQ", ops...) }
func (o Opcodes) PCMPEQQ(ops ...Operand) { o.a.op("PCMPEQQ", ops...) }
func (o Opcodes) Pcmpeqw(ops ...Operand) { o.a.op("PCMPEQW", ops...) }
func (o Opcodes) PCMPEQW(ops ...Operand) { o.a.op("PCMPEQW", ops...) }
func (o Opcodes) Pcmpestri(ops ...Operand) { o.a.op("PCMPESTRI", ops...) }
func (o Opcodes) PCMPESTRI(ops ...Operand) { o.a.op("PCMPESTRI", ops...) }
func (o Opcodes) Pcmpestrm(ops ...Operand) { o.a.op("PCMPESTRM", ops...) }
func (o Opcodes) PCMPESTRM(ops ...Operand) { o.a.op("PCMPESTRM", ops...) }
func (o Opcodes) Pcmpgtb(ops ...Operand) { o.a.op("PCMPGTB", ops...) }
func (o Opcodes) PCMPGTB(ops ...Operand) { o.a.op("PCMPGTB", ops...) }
func (o Opcodes) Pcmpgtl(ops ...Operand) { o.a.op("PCMPGTL", ops...) }
func (o Opcodes) PCMPGTL(ops ...Operand) { o.a.op("PCMPGTL", ops...) }
func (o Opcodes) Pcmpgtq(ops ...Operand) { o.a.op("PCMPGTQ", ops...) }
func (o Opcodes) PCMPGTQ(ops ...Operand) { o.a.op("PCMPGTQ", ops...) }
func (o Opcodes) Pcmpgtw(ops ...Operand) { o.a.op("PCMPGTW", ops...) }
func (o Opcodes) PCMPGTW(ops ...Operand) { o.a.op("PCMPGTW", ops...) }
func (o Opcodes) Pcmpistri(ops ...Operand) { o.a.op("PCMPISTRI", ops...) }
func (o Opcodes) PCMPISTRI(ops ...Operand) { o.a.op("PCMPISTRI", ops...) }
func (o Opcodes) Pcmpistrm(ops ...Operand) { o.a.op("PCMPISTRM", ops...) }
func (o Opcodes) PCMPISTRM(ops ...Operand) { o.a.op("PCMPISTRM", ops...) }
func (o Opcodes) Pdepl(ops ...Operand) { o.a.op("PDEPL", ops...) }
func (o Opcodes) PDEPL(ops ...Operand) { o.a.op("PDEPL", ops...) }
func (o Opcodes) Pdepq(ops ...Operand) { o.a.op("PDEPQ", ops...) }
func (o Opcodes) PDEPQ(ops ...Operand) { o.a.op("PDEPQ", ops...) }
func (o Opcodes) Pextl(ops ...Operand) { o.a.op("PEXTL", ops...) }
func (o Opcodes) PEXTL(ops ...Operand) { o.a.op("PEXTL", ops...) }
func (o Opcodes) Pextq(ops ...Operand) { o.a.op("PEXTQ", ops...) }
func (o Opcodes) PEXTQ(ops ...Operand) { o.a.op("PEXTQ", ops...) }
func (o Opcodes) Pextrb(ops ...Operand) { o.a.op("PEXTRB", ops...) }
func (o Opcodes) PEXTRB(ops ...Operand) { o.a.op("PEXTRB", ops...) }
func (o Opcodes) Pextrd(ops ...Operand) { o.a.op("PEXTRD", ops...) }
func (o Opcodes) PEXTRD(ops ...Operand) { o.a.op("PEXTRD", ops...) }
func (o Opcodes) Pextrq(ops ...Operand) { o.a.op("PEXTRQ", ops...) }
func (o Opcodes) PEXTRQ(ops ...Operand) { o.a.op("PEXTRQ", ops...) }
func (o Opcodes) Phaddd(ops ...Operand) { o.a.op("PHADDD", ops...) }
func (o Opcodes) PHADDD(ops ...Operand) { o.a.op("PHADDD", ops...) }
func (o Opcodes) Phaddsw(ops ...Operand) { o.a.op("PHADDSW", ops...) }
func (o Opcodes) PHADDSW(ops ...Operand) { o.a.op("PHADDSW", ops...) }
func (o Opcodes) Phaddw(ops ...Operand) { o.a.op("PHADDW", ops...) }
func (o Opcodes) PHADDW(ops ...Operand) { o.a.op("PHADDW", ops...) }
func (o Opcodes) Phminposuw(ops ...Operand) { o.a.op("PHMINPOSUW", ops...) }
func (o Opcodes) PHMINPOSUW(ops ...Operand) { o.a.op("PHMINPOSUW", ops...) }
func (o Opcodes) Phsubd(ops ...Operand) { o.a.op("PHSUBD", ops...) }
func (o Opcodes) PHSUBD(ops ...Operand) { o.a.op("PHSUBD", ops...) }
func (o Opcodes) Phsubsw(ops ...Operand) { o.a.op("PHSUBSW", ops...) }
func (o Opcodes) PHSUBSW(ops ...Operand) { o.a.op("PHSUBSW", ops...) }
func (o Opcodes) Phsubw(ops ...Operand) { o.a.op("PHSUBW", ops...) }
func (o Opcodes) PHSUBW(ops ...Operand) { o.a.op("PHSUBW", ops...) }
func (o Opcodes) Pinsrb(ops ...Operand) { o.a.op("PINSRB", ops...) }
func (o Opcodes) PINSRB(ops ...Operand) { o.a.op("PINSRB", ops...) }
func (o Opcodes) Pinsrd(ops ...Operand) { o.a.op("PINSRD", ops...) }
func (o Opcodes) PINSRD(ops ...Operand) { o.a.op("PINSRD", ops...) }
func (o Opcodes) Pinsrq(ops ...Operand) { o.a.op("PINSRQ", ops...) }
func (o Opcodes) PINSRQ(ops ...Operand) { o.a.op("PINSRQ", ops...) }
func (o Opcodes) Pinsrw(ops ...Operand) { o.a.op("PINSRW", ops...) }
func (o Opcodes) PINSRW(ops ...Operand) { o.a.op("PINSRW", ops...) }
func (o Opcodes) Pmaddubsw(ops ...Operand) { o.a.op("PMADDUBSW", ops...) }
func (o Opcodes) PMADDUBSW(ops ...Operand) { o.a.op("PMADDUBSW", ops...) }
func (o Opcodes) Pmaddwl(ops ...Operand) { o.a.op("PMADDWL", ops...) }
func (o Opcodes) PMADDWL(ops ...Operand) { o.a.op("PMADDWL", ops...) }
func (o Opcodes) Pmaxsb(ops ...Operand) { o.a.op("PMAXSB", ops...) }
func (o Opcodes) PMAXSB(ops ...Operand) { o.a.op("PMAXSB", ops...) }
func (o Opcodes) Pmaxsd(ops ...Operand) { o.a.op("PMAXSD", ops...) }
func (o Opcodes) PMAXSD(ops ...Operand) { o.a.op("PMAXSD", ops...) }
func (o Opcodes) Pmaxsw(ops ...Operand) { o.a.op("PMAXSW", ops...) }
func (o Opcodes) PMAXSW(ops ...Operand) { o.a.op("PMAXSW", ops...) }
func (o Opcodes) Pmaxub(ops ...Operand) { o.a.op("PMAXUB", ops...) }
func (o Opcodes) PMAXUB(ops ...Operand) { o.a.op("PMAXUB", ops...) }
func (o Opcodes) Pmaxud(ops ...Operand) { o.a.op("PMAXUD", ops...) }
func (o Opcodes) PMAXUD(ops ...Operand) { o.a.op("PMAXUD", ops...) }
func (o Opcodes) Pmaxuw(ops ...Operand) { o.a.op("PMAXUW", ops...) }
func (o Opcodes) PMAXUW(ops ...Operand) { o.a.op("PMAXUW", ops...) }
func (o Opcodes) Pminsb(ops ...Operand) { o.a.op("PMINSB", ops...) }
func (o Opcodes) PMINSB(ops ...Operand) { o.a.op("PMINSB", ops...) }
func (o Opcodes) Pminsd(ops ...Operand) { o.a.op("PMINSD", ops...) }
func (o Opcodes) PMINSD(ops ...Operand) { o.a.op("PMINSD", ops...) }
func (o Opcodes) Pminsw(ops ...Operand) { o.a.op("PMINSW", ops...) }
func (o Opcodes) PMINSW(ops ...Operand) { o.a.op("PMINSW", ops...) }
func (o Opcodes) Pminub(ops ...Operand) { o.a.op("PMINUB", ops...) }
func (o Opcodes) PMINUB(ops ...Operand) { o.a.op("PMINUB", ops...) }
func (o Opcodes) Pminud(ops ...Operand) { o.a.op("PMINUD", ops...) }
func (o Opcodes) PMINUD(ops ...Operand) { o.a.op("PMINUD", ops...) }
func (o Opcodes) Pminuw(ops ...Operand) { o.a.op("PMINUW", ops...) }
func (o Opcodes) PMINUW(ops ...Operand) { o.a.op("PMINUW", ops...) }
func (o Opcodes) Pmovmskb(ops ...Operand) { o.a.op("PMOVMSKB", ops...) }
func (o Opcodes) PMOVMSKB(ops ...Operand) { o.a.op("PMOVMSKB", ops...) }
func (o Opcodes) Pmovsxbd(ops ...Operand) { o.a.op("PMOVSXBD", ops...) }
func (o Opcodes) PMOVSXBD(ops ...Operand) { o.a.op("PMOVSXBD", ops...) }
func (o Opcodes) Pmovsxbq(ops ...Operand) { o.a.op("PMOVSXBQ", ops...) }
func (o Opcodes) PMOVSXBQ(ops ...Operand) { o.a.op("PMOVSXBQ", ops...) }
func (o Opcodes) Pmovsxbw(ops ...Operand) { o.a.op("PMOVSXBW", ops...) }
func (o Opcodes) PMOVSXBW(ops ...Operand) { o.a.op("PMOVSXBW", ops...) }
func (o Opcodes) Pmovsxdq(ops ...Operand) { o.a.op("PMOVSXDQ", ops...) }
func (o Opcodes) PMOVSXDQ(ops ...Operand) { o.a.op("PMOVSXDQ", ops...) }
func (o Opcodes) Pmovsxwd(ops ...Operand) { o.a.op("PMOVSXWD", ops...) }
func (o Opcodes) PMOVSXWD(ops ...Operand) { o.a.op("PMOVSXWD", ops...) }
func (o Opcodes) Pmovsxwq(ops ...Operand) { o.a.op("PMOVSXWQ", ops...) }
func (o Opcodes) PMOVSXWQ(ops ...Operand) { o.a.op("PMOVSXWQ", ops...) }
func (o Opcodes) Pmovzxbd(ops ...Operand) { o.a.op("PMOVZXBD", ops...) }
func (o Opcodes) PMOVZXBD(ops ...Operand) { o.a.op("PMOVZXBD", ops...) }
func (o Opcodes) Pmovzxbq(ops ...Operand) { o.a.op("PMOVZXBQ", ops...) }
func (o Opcodes) PMOVZXBQ(ops ...Operand) { o.a.op("PMOVZXBQ", ops...) }
func (o Opcodes) Pmovzxbw(ops ...Operand) { o.a.op("PMOVZXBW", ops...) }
func (o Opcodes) PMOVZXBW(ops ...Operand) { o.a.op("PMOVZXBW", ops...) }
func (o Opcodes) Pmovzxdq(ops ...Operand) { o.a.op("PMOVZXDQ", ops...) }
func (o Opcodes) PMOVZXDQ(ops ...Operand) { o.a.op("PMOVZXDQ", ops...) }
func (o Opcodes) Pmovzxwd(ops ...Operand) { o.a.op("PMOVZXWD", ops...) }
func (o Opcodes) PMOVZXWD(ops ...Operand) { o.a.op("PMOVZXWD", ops...) }
func (o Opcodes) Pmovzxwq(ops ...Operand) { o.a.op("PMOVZXWQ", ops...) }
func (o Opcodes) PMOVZXWQ(ops ...Operand) { o.a.op("PMOVZXWQ", ops...) }
func (o Opcodes) Pmuldq(ops ...Operand) { o.a.op("PMULDQ", ops...) }
func (o Opcodes) PMULDQ(ops ...Operand) { o.a.op("PMULDQ", ops...) }
func (o Opcodes) Pmulhrsw(ops ...Operand) { o.a.op("PMULHRSW", ops...) }
func (o Opcodes) PMULHRSW(ops ...Operand) { o.a.op("PMULHRSW", ops...) }
func (o Opcodes) Pmulhuw(ops ...Operand) { o.a.op("PMULHUW", ops...) }
func (o Opcodes) PMULHUW(ops ...Operand) { o.a.op("PMULHUW", ops...) }
func (o Opcodes) Pmulhw(ops ...Operand) { o.a.op("PMULHW", ops...) }
func (o Opcodes) PMULHW(ops ...Operand) { o.a.op("PMULHW", ops...) }
func (o Opcodes) Pmulld(ops ...Operand) { o.a.op("PMULLD", ops...) }
func (o Opcodes) PMULLD(ops ...Operand) { o.a.op("PMULLD", ops...) }
func (o Opcodes) Pmullw(ops ...Operand) { o.a.op("PMULLW", ops...) }
func (o Opcodes) PMULLW(ops ...Operand) { o.a.op("PMULLW", ops...) }
func (o Opcodes) Pmululq(ops ...Operand) { o.a.op("PMULULQ", ops...) }
func (o Opcodes) PMULULQ(ops ...Operand) { o.a.op("PMULULQ", ops...) }
func (o Opcodes) Popal(ops ...Operand) { o.a.op("POPAL", ops...) }
func (o Opcodes) POPAL(ops ...Operand) { o.a.op("POPAL", ops...) }
func (o Opcodes) Popaw(ops ...Operand) { o.a.op("POPAW", ops...) }
func (o Opcodes) POPAW(ops ...Operand) { o.a.op("POPAW", ops...) }
func (o Opcodes) Popcntl(ops ...Operand) { o.a.op("POPCNTL", ops...) }
func (o Opcodes) POPCNTL(ops ...Operand) { o.a.op("POPCNTL", ops...) }
func (o Opcodes) Popcntq(ops ...Operand) { o.a.op("POPCNTQ", ops...) }
func (o Opcodes) POPCNTQ(ops ...Operand) { o.a.op("POPCNTQ", ops...) }
func (o Opcodes) Popcntw(ops ...Operand) { o.a.op("POPCNTW", ops...) }
func (o Opcodes) POPCNTW(ops ...Operand) { o.a.op("POPCNTW", ops...) }
func (o Opcodes) Popfl(ops ...Operand) { o.a.op("POPFL", ops...) }
func (o Opcodes) POPFL(ops ...Operand) { o.a.op("POPFL", ops...) }
func (o Opcodes) Popfq(ops ...Operand) { o.a.op("POPFQ", ops...) }
func (o Opcodes) POPFQ(ops ...Operand) { o.a.op("POPFQ", ops...) }
func (o Opcodes) Popfw(ops ...Operand) { o.a.op("POPFW", ops...) }
func (o Opcodes) POPFW(ops ...Operand) { o.a.op("POPFW", ops...) }
func (o Opcodes) Popl(ops ...Operand) { o.a.op("POPL", ops...) }
func (o Opcodes) POPL(ops ...Operand) { o.a.op("POPL", ops...) }
func (o Opcodes) Popq(ops ...Operand) { o.a.op("POPQ", ops...) }
func (o Opcodes) POPQ(ops ...Operand) { o.a.op("POPQ", ops...) }
func (o Opcodes) Popw(ops ...Operand) { o.a.op("POPW", ops...) }
func (o Opcodes) POPW(ops ...Operand) { o.a.op("POPW", ops...) }
func (o Opcodes) Por(ops ...Operand) { o.a.op("POR", ops...) }
func (o Opcodes) POR(ops ...Operand) { o.a.op("POR", ops...) }
func (o Opcodes) Prefetchnta(ops ...Operand) { o.a.op("PREFETCHNTA", ops...) }
func (o Opcodes) PREFETCHNTA(ops ...Operand) { o.a.op("PREFETCHNTA", ops...) }
func (o Opcodes) Prefetcht0(ops ...Operand) { o.a.op("PREFETCHT0", ops...) }
func (o Opcodes) PREFETCHT0(ops ...Operand) { o.a.op("PREFETCHT0", ops...) }
func (o Opcodes) Prefetcht1(ops ...Operand) { o.a.op("PREFETCHT1", ops...) }
func (o Opcodes) PREFETCHT1(ops ...Operand) { o.a.op("PREFETCHT1", ops...) }
func (o Opcodes) Prefetcht2(ops ...Operand) { o.a.op("PREFETCHT2", ops...) }
func (o Opcodes) PREFETCHT2(ops ...Operand) { o.a.op("PREFETCHT2", ops...) }
func (o Opcodes) Psadbw(ops ...Operand) { o.a.op("PSADBW", ops...) }
func (o Opcodes) PSADBW(ops ...Operand) { o.a.op("PSADBW", ops...) }
func (o Opcodes) Pshufb(ops ...Operand) { o.a.op("PSHUFB", ops...) }
func (o Opcodes) PSHUFB(ops ...Operand) { o.a.op("PSHUFB", ops...) }
func (o Opcodes) Pshufd(ops ...Operand) { o.a.op("PSHUFD", ops...) }
func (o Opcodes) PSHUFD(ops ...Operand) { o.a.op("PSHUFD", ops...) }
func (o Opcodes) Pshufhw(ops ...Operand) { o.a.op("PSHUFHW", ops...) }
func (o Opcodes) PSHUFHW(ops ...Operand) { o.a.op("PSHUFHW", ops...) }
func (o Opcodes) Pshufl(ops ...Operand) { o.a.op("PSHUFL", ops...) }
func (o Opcodes) PSHUFL(ops ...Operand) { o.a.op("PSHUFL", ops...) }
func (o Opcodes) Pshuflw(ops ...Operand) { o.a.op("PSHUFLW", ops...) }
func (o Opcodes) PSHUFLW(ops ...Operand) { o.a.op("PSHUFLW", ops...) }
func (o Opcodes) Pshufw(ops ...Operand) { o.a.op("PSHUFW", ops...) }
func (o Opcodes) PSHUFW(ops ...Operand) { o.a.op("PSHUFW", ops...) }
func (o Opcodes) Psignb(ops ...Operand) { o.a.op("PSIGNB", ops...) }
func (o Opcodes) PSIGNB(ops ...Operand) { o.a.op("PSIGNB", ops...) }
func (o Opcodes) Psignd(ops ...Operand) { o.a.op("PSIGND", ops...) }
func (o Opcodes) PSIGND(ops ...Operand) { o.a.op("PSIGND", ops...) }
func (o Opcodes) Psignw(ops ...Operand) { o.a.op("PSIGNW", ops...) }
func (o Opcodes) PSIGNW(ops ...Operand) { o.a.op("PSIGNW", ops...) }
func (o Opcodes) Pslll(ops ...Operand) { o.a.op("PSLLL", ops...) }
func (o Opcodes) PSLLL(ops ...Operand) { o.a.op("PSLLL", ops...) }
func (o Opcodes) Psllo(ops ...Operand) { o.a.op("PSLLO", ops...) }
func (o Opcodes) PSLLO(ops ...Operand) { o.a.op("PSLLO", ops...) }
func (o Opcodes) Psllq(ops ...Operand) { o.a.op("PSLLQ", ops...) }
func (o Opcodes) PSLLQ(ops ...Operand) { o.a.op("PSLLQ", ops...) }
func (o Opcodes) Psllw(ops ...Operand) { o.a.op("PSLLW", ops...) }
func (o Opcodes) PSLLW(ops ...Operand) { o.a.op("PSLLW", ops...) }
func (o Opcodes) Psral(ops ...Operand) { o.a.op("PSRAL", ops...) }
func (o Opcodes) PSRAL(ops ...Operand) { o.a.op("PSRAL", ops...) }
func (o Opcodes) Psraw(ops ...Operand) { o.a.op("PSRAW", ops...) }
func (o Opcodes) PSRAW(ops ...Operand) { o.a.op("PSRAW", ops...) }
func (o Opcodes) Psrll(ops ...Operand) { o.a.op("PSRLL", ops...) }
func (o Opcodes) PSRLL(ops ...Operand) { o.a.op("PSRLL", ops...) }
func (o Opcodes) Psrlo(ops ...Operand) { o.a.op("PSRLO", ops...) }
func (o Opcodes) PSRLO(ops ...Operand) { o.a.op("PSRLO", ops...) }
func (o Opcodes) Psrlq(ops ...Operand) { o.a.op("PSRLQ", ops...) }
func (o Opcodes) PSRLQ(ops ...Operand) { o.a.op("PSRLQ", ops...) }
func (o Opcodes) Psrlw(ops ...Operand) { o.a.op("PSRLW", ops...) }
func (o Opcodes) PSRLW(ops ...Operand) { o.a.op("PSRLW", ops...) }
func (o Opcodes) Psubb(ops ...Operand) { o.a.op("PSUBB", ops...) }
func (o Opcodes) PSUBB(ops ...Operand) { o.a.op("PSUBB", ops...) }
func (o Opcodes) Psubl(ops ...Operand) { o.a.op("PSUBL", ops...) }
func (o Opcodes) PSUBL(ops ...Operand) { o.a.op("PSUBL", ops...) }
func (o Opcodes) Psubq(ops ...Operand) { o.a.op("PSUBQ", ops...) }
func (o Opcodes) PSUBQ(ops ...Operand) { o.a.op("PSUBQ", ops...) }
func (o Opcodes) Psubsb(ops ...Operand) { o.a.op("PSUBSB", ops...) }
func (o Opcodes) PSUBSB(ops ...Operand) { o.a.op("PSUBSB", ops...) }
func (o Opcodes) Psubsw(ops ...Operand) { o.a.op("PSUBSW", ops...) }
func (o Opcodes) PSUBSW(ops ...Operand) { o.a.op("PSUBSW", ops...) }
func (o Opcodes) Psubusb(ops ...Operand) { o.a.op("PSUBUSB", ops...) }
func (o Opcodes) PSUBUSB(ops ...Operand) { o.a.op("PSUBUSB", ops...) }
func (o Opcodes) Psubusw(ops ...Operand) { o.a.op("PSUBUSW", ops...) }
func (o Opcodes) PSUBUSW(ops ...Operand) { o.a.op("PSUBUSW", ops...) }
func (o Opcodes) Psubw(ops ...Operand) { o.a.op("PSUBW", ops...) }
func (o Opcodes) PSUBW(ops ...Operand) { o.a.op("PSUBW", ops...) }
func (o Opcodes) Ptest(ops ...Operand) { o.a.op("PTEST", ops...) }
func (o Opcodes) PTEST(ops ...Operand) { o.a.op("PTEST", ops...) }
func (o Opcodes) Punpckhbw(ops ...Operand) { o.a.op("PUNPCKHBW", ops...) }
func (o Opcodes) PUNPCKHBW(ops ...Operand) { o.a.op("PUNPCKHBW", ops...) }
func (o Opcodes) Punpckhlq(ops ...Operand) { o.a.op("PUNPCKHLQ", ops...) }
func (o Opcodes) PUNPCKHLQ(ops ...Operand) { o.a.op("PUNPCKHLQ", ops...) }
func (o Opcodes) Punpckhqdq(ops ...Operand) { o.a.op("PUNPCKHQDQ", ops...) }
func (o Opcodes) PUNPCKHQDQ(ops ...Operand) { o.a.op("PUNPCKHQDQ", ops...) }
func (o Opcodes) Punpckhwl(ops ...Operand) { o.a.op("PUNPCKHWL", ops...) }
func (o Opcodes) PUNPCKHWL(ops ...Operand) { o.a.op("PUNPCKHWL", ops...) }
func (o Opcodes) Punpcklbw(ops ...Operand) { o.a.op("PUNPCKLBW", ops...) }
func (o Opcodes) PUNPCKLBW(ops ...Operand) { o.a.op("PUNPCKLBW", ops...) }
func (o Opcodes) Punpckllq(ops ...Operand) { o.a.op("PUNPCKLLQ", ops...) }
func (o Opcodes) PUNPCKLLQ(ops ...Operand) { o.a.op("PUNPCKLLQ", ops...) }
func (o Opcodes) Punpcklqdq(ops ...Operand) { o.a.op("PUNPCKLQDQ", ops...) }
func (o Opcodes) PUNPCKLQDQ(ops ...Operand) { o.a.op("PUNPCKLQDQ", ops...) }
func (o Opcodes) Punpcklwl(ops ...Operand) { o.a.op("PUNPCKLWL", ops...) }
func (o Opcodes) PUNPCKLWL(ops ...Operand) { o.a.op("PUNPCKLWL", ops...) }
func (o Opcodes) Pushal(ops ...Operand) { o.a.op("PUSHAL", ops...) }
func (o Opcodes) PUSHAL(ops ...Operand) { o.a.op("PUSHAL", ops...) }
func (o Opcodes) Pushaw(ops ...Operand) { o.a.op("PUSHAW", ops...) }
func (o Opcodes) PUSHAW(ops ...Operand) { o.a.op("PUSHAW", ops...) }
func (o Opcodes) Pushfl(ops ...Operand) { o.a.op("PUSHFL", ops...) }
func (o Opcodes) PUSHFL(ops ...Operand) { o.a.op("PUSHFL", ops...) }
func (o Opcodes) Pushfq(ops ...Operand) { o.a.op("PUSHFQ", ops...) }
func (o Opcodes) PUSHFQ(ops ...Operand) { o.a.op("PUSHFQ", ops...) }
func (o Opcodes) Pushfw(ops ...Operand) { o.a.op("PUSHFW", ops...) }
func (o Opcodes) PUSHFW(ops ...Operand) { o.a.op("PUSHFW", ops...) }
func (o Opcodes) Pushl(ops ...Operand) { o.a.op("PUSHL", ops...) }
func (o Opcodes) PUSHL(ops ...Operand) { o.a.op("PUSHL", ops...) }
func (o Opcodes) Pushq(ops ...Operand) { o.a.op("PUSHQ", ops...) }
func (o Opcodes) PUSHQ(ops ...Operand) { o.a.op("PUSHQ", ops...) }
func (o Opcodes) Pushw(ops ...Operand) { o.a.op("PUSHW", ops...) }
func (o Opcodes) PUSHW(ops ...Operand) { o.a.op("PUSHW", ops...) }
func (o Opcodes) Pxor(ops ...Operand) { o.a.op("PXOR", ops...) }
func (o Opcodes) PXOR(ops ...Operand) { o.a.op("PXOR", ops...) }
func (o Opcodes) Quad(ops ...Operand) { o.a.op("QUAD", ops...) }
func (o Opcodes) QUAD(ops ...Operand) { o.a.op("QUAD", ops...) }
func (o Opcodes) Rclb(ops ...Operand) { o.a.op("RCLB", ops...) }
func (o Opcodes) RCLB(ops ...Operand) { o.a.op("RCLB", ops...) }
func (o Opcodes) Rcll(ops ...Operand) { o.a.op("RCLL", ops...) }
func (o Opcodes) RCLL(ops ...Operand) { o.a.op("RCLL", ops...) }
func (o Opcodes) Rclq(ops ...Operand) { o.a.op("RCLQ", ops...) }
func (o Opcodes) RCLQ(ops ...Operand) { o.a.op("RCLQ", ops...) }
func (o Opcodes) Rclw(ops ...Operand) { o.a.op("RCLW", ops...) }
func (o Opcodes) RCLW(ops ...Operand) { o.a.op("RCLW", ops...) }
func (o Opcodes) Rcpps(ops ...Operand) { o.a.op("RCPPS", ops...) }
func (o Opcodes) RCPPS(ops ...Operand) { o.a.op("RCPPS", ops...) }
func (o Opcodes) Rcpss(ops ...Operand) { o.a.op("RCPSS", ops...) }
func (o Opcodes) RCPSS(ops ...Operand) { o.a.op("RCPSS", ops...) }
func (o Opcodes) Rcrb(ops ...Operand) { o.a.op("RCRB", ops...) }
func (o Opcodes) RCRB(ops ...Operand) { o.a.op("RCRB", ops...) }
func (o Opcodes) Rcrl(ops ...Operand) { o.a.op("RCRL", ops...) }
func (o Opcodes) RCRL(ops ...Operand) { o.a.op("RCRL", ops...) }
func (o Opcodes) Rcrq(ops ...Operand) { o.a.op("RCRQ", ops...) }
func (o Opcodes) RCRQ(ops ...Operand) { o.a.op("RCRQ", ops...) }
func (o Opcodes) Rcrw(ops ...Operand) { o.a.op("RCRW", ops...) }
func (o Opcodes) RCRW(ops ...Operand) { o.a.op("RCRW", ops...) }
func (o Opcodes) Rdmsr(ops ...Operand) { o.a.op("RDMSR", ops...) }
func (o Opcodes) RDMSR(ops ...Operand) { o.a.op("RDMSR", ops...) }
func (o Opcodes) Rdpmc(ops ...Operand) { o.a.op("RDPMC", ops...) }
func (o Opcodes) RDPMC(ops ...Operand) { o.a.op("RDPMC", ops...) }
func (o Opcodes) Rdtsc(ops ...Operand) { o.a.op("RDTSC", ops...) }
func (o Opcodes) RDTSC(ops ...Operand) { o.a.op("RDTSC", ops...) }
func (o Opcodes) Rep(ops ...Operand) { o.a.op("REP", ops...) }
func (o Opcodes) REP(ops ...Operand) { o.a.op("REP", ops...) }
func (o Opcodes) Repn(ops ...Operand) { o.a.op("REPN", ops...) }
func (o Opcodes) REPN(ops ...Operand) { o.a.op("REPN", ops...) }
func (o Opcodes) Retfl(ops ...Operand) { o.a.op("RETFL", ops...) }
func (o Opcodes) RETFL(ops ...Operand) { o.a.op("RETFL", ops...) }
func (o Opcodes) Retfq(ops ...Operand) { o.a.op("RETFQ", ops...) }
func (o Opcodes) RETFQ(ops ...Operand) { o.a.op("RETFQ", ops...) }
func (o Opcodes) Retfw(ops ...Operand) { o.a.op("RETFW", ops...) }
func (o Opcodes) RETFW(ops ...Operand) { o.a.op("RETFW", ops...) }
func (o Opcodes) Rolb(ops ...Operand) { o.a.op("ROLB", ops...) }
func (o Opcodes) ROLB(ops ...Operand) { o.a.op("ROLB", ops...) }
func (o Opcodes) Roll(ops ...Operand) { o.a.op("ROLL", ops...) }
func (o Opcodes) ROLL(ops ...Operand) { o.a.op("ROLL", ops...) }
func (o Opcodes) Rolq(ops ...Operand) { o.a.op("ROLQ", ops...) }
func (o Opcodes) ROLQ(ops ...Operand) { o.a.op("ROLQ", ops...) }
func (o Opcodes) Rolw(ops ...Operand) { o.a.op("ROLW", ops...) }
func (o Opcodes) ROLW(ops ...Operand) { o.a.op("ROLW", ops...) }
func (o Opcodes) Rorb(ops ...Operand) { o.a.op("RORB", ops...) }
func (o Opcodes) RORB(ops ...Operand) { o.a.op("RORB", ops...) }
func (o Opcodes) Rorl(ops ...Operand) { o.a.op("RORL", ops...) }
func (o Opcodes) RORL(ops ...Operand) { o.a.op("RORL", ops...) }
func (o Opcodes) Rorq(ops ...Operand) { o.a.op("RORQ", ops...) }
func (o Opcodes) RORQ(ops ...Operand) { o.a.op("RORQ", ops...) }
func (o Opcodes) Rorw(ops ...Operand) { o.a.op("RORW", ops...) }
func (o Opcodes) RORW(ops ...Operand) { o.a.op("RORW", ops...) }
func (o Opcodes) Rorxl(ops ...Operand) { o.a.op("RORXL", ops...) }
func (o Opcodes) RORXL(ops ...Operand) { o.a.op("RORXL", ops...) }
func (o Opcodes) Rorxq(ops ...Operand) { o.a.op("RORXQ", ops...) }
func (o Opcodes) RORXQ(ops ...Operand) { o.a.op("RORXQ", ops...) }
func (o Opcodes) Roundpd(ops ...Operand) { o.a.op("ROUNDPD", ops...) }
func (o Opcodes) ROUNDPD(ops ...Operand) { o.a.op("ROUNDPD", ops...) }
func (o Opcodes) Roundps(ops ...Operand) { o.a.op("ROUNDPS", ops...) }
func (o Opcodes) ROUNDPS(ops ...Operand) { o.a.op("ROUNDPS", ops...) }
func (o Opcodes) Roundsd(ops ...Operand) { o.a.op("ROUNDSD", ops...) }
func (o Opcodes) ROUNDSD(ops ...Operand) { o.a.op("ROUNDSD", ops...) }
func (o Opcodes) Roundss(ops ...Operand) { o.a.op("ROUNDSS", ops...) }
func (o Opcodes) ROUNDSS(ops ...Operand) { o.a.op("ROUNDSS", ops...) }
func (o Opcodes) Rsm(ops ...Operand) { o.a.op("RSM", ops...) }
func (o Opcodes) RSM(ops ...Operand) { o.a.op("RSM", ops...) }
func (o Opcodes) Rsqrtps(ops ...Operand) { o.a.op("RSQRTPS", ops...) }
func (o Opcodes) RSQRTPS(ops ...Operand) { o.a.op("RSQRTPS", ops...) }
func (o Opcodes) Rsqrtss(ops ...Operand) { o.a.op("RSQRTSS", ops...) }
func (o Opcodes) RSQRTSS(ops ...Operand) { o.a.op("RSQRTSS", ops...) }
func (o Opcodes) Sahf(ops ...Operand) { o.a.op("SAHF", ops...) }
func (o Opcodes) SAHF(ops ...Operand) { o.a.op("SAHF", ops...) }
func (o Opcodes) Salb(ops ...Operand) { o.a.op("SALB", ops...) }
func (o Opcodes) SALB(ops ...Operand) { o.a.op("SALB", ops...) }
func (o Opcodes) Sall(ops ...Operand) { o.a.op("SALL", ops...) }
func (o Opcodes) SALL(ops ...Operand) { o.a.op("SALL", ops...) }
func (o Opcodes) Salq(ops ...Operand) { o.a.op("SALQ", ops...) }
func (o Opcodes) SALQ(ops ...Operand) { o.a.op("SALQ", ops...) }
func (o Opcodes) Salw(ops ...Operand) { o.a.op("SALW", ops...) }
func (o Opcodes) SALW(ops ...Operand) { o.a.op("SALW", ops...) }
func (o Opcodes) Sarb(ops ...Operand) { o.a.op("SARB", ops...) }
func (o Opcodes) SARB(ops ...Operand) { o.a.op("SARB", ops...) }
func (o Opcodes) Sarl(ops ...Operand) { o.a.op("SARL", ops...) }
func (o Opcodes) SARL(ops ...Operand) { o.a.op("SARL", ops...) }
func (o Opcodes) Sarq(ops ...Operand) { o.a.op("SARQ", ops...) }
func (o Opcodes) SARQ(ops ...Operand) { o.a.op("SARQ", ops...) }
func (o Opcodes) Sarw(ops ...Operand) { o.a.op("SARW", ops...) }
func (o Opcodes) SARW(ops ...Operand) { o.a.op("SARW", ops...) }
func (o Opcodes) Sarxl(ops ...Operand) { o.a.op("SARXL", ops...) }
func (o Opcodes) SARXL(ops ...Operand) { o.a.op("SARXL", ops...) }
func (o Opcodes) Sarxq(ops ...Operand) { o.a.op("SARXQ", ops...) }
func (o Opcodes) SARXQ(ops ...Operand) { o.a.op("SARXQ", ops...) }
func (o Opcodes) Sbbb(ops ...Operand) { o.a.op("SBBB", ops...) }
func (o Opcodes) SBBB(ops ...Operand) { o.a.op("SBBB", ops...) }
func (o Opcodes) Sbbl(ops ...Operand) { o.a.op("SBBL", ops...) }
func (o Opcodes) SBBL(ops ...Operand) { o.a.op("SBBL", ops...) }
func (o Opcodes) Sbbq(ops ...Operand) { o.a.op("SBBQ", ops...) }
func (o Opcodes) SBBQ(ops ...Operand) { o.a.op("SBBQ", ops...) }
func (o Opcodes) Sbbw(ops ...Operand) { o.a.op("SBBW", ops...) }
func (o Opcodes) SBBW(ops ...Operand) { o.a.op("SBBW", ops...) }
func (o Opcodes) Scasb(ops ...Operand) { o.a.op("SCASB", ops...) }
func (o Opcodes) SCASB(ops ...Operand) { o.a.op("SCASB", ops...) }
func (o Opcodes) Scasl(ops ...Operand) { o.a.op("SCASL", ops...) }
func (o Opcodes) SCASL(ops ...Operand) { o.a.op("SCASL", ops...) }
func (o Opcodes) Scasq(ops ...Operand) { o.a.op("SCASQ", ops...) }
func (o Opcodes) SCASQ(ops ...Operand) { o.a.op("SCASQ", ops...) }
func (o Opcodes) Scasw(ops ...Operand) { o.a.op("SCASW", ops...) }
func (o Opcodes) SCASW(ops ...Operand) { o.a.op("SCASW", ops...) }
func (o Opcodes) Setcc(ops ...Operand) { o.a.op("SETCC", ops...) }
func (o Opcodes) SETCC(ops ...Operand) { o.a.op("SETCC", ops...) }
func (o Opcodes) Setcs(ops ...Operand) { o.a.op("SETCS", ops...) }
func (o Opcodes) SETCS(ops ...Operand) { o.a.op("SETCS", ops...) }
func (o Opcodes) Seteq(ops ...Operand) { o.a.op("SETEQ", ops...) }
func (o Opcodes) SETEQ(ops ...Operand) { o.a.op("SETEQ", ops...) }
func (o Opcodes) Setge(ops ...Operand) { o.a.op("SETGE", ops...) }
func (o Opcodes) SETGE(ops ...Operand) { o.a.op("SETGE", ops...) }
func (o Opcodes) Setgt(ops ...Operand) { o.a.op("SETGT", ops...) }
func (o Opcodes) SETGT(ops ...Operand) { o.a.op("SETGT", ops...) }
func (o Opcodes) Sethi(ops ...Operand) { o.a.op("SETHI", ops...) }
func (o Opcodes) SETHI(ops ...Operand) { o.a.op("SETHI", ops...) }
func (o Opcodes) Setle(ops ...Operand) { o.a.op("SETLE", ops...) }
func (o Opcodes) SETLE(ops ...Operand) { o.a.op("SETLE", ops...) }
func (o Opcodes) Setls(ops ...Operand) { o.a.op("SETLS", ops...) }
func (o Opcodes) SETLS(ops ...Operand) { o.a.op("SETLS", ops...) }
func (o Opcodes) Setlt(ops ...Operand) { o.a.op("SETLT", ops...) }
func (o Opcodes) SETLT(ops ...Operand) { o.a.op("SETLT", ops...) }
func (o Opcodes) Setmi(ops ...Operand) { o.a.op("SETMI", ops...) }
func (o Opcodes) SETMI(ops ...Operand) { o.a.op("SETMI", ops...) }
func (o Opcodes) Setne(ops ...Operand) { o.a.op("SETNE", ops...) }
func (o Opcodes) SETNE(ops ...Operand) { o.a.op("SETNE", ops...) }
func (o Opcodes) Setoc(ops ...Operand) { o.a.op("SETOC", ops...) }
func (o Opcodes) SETOC(ops ...Operand) { o.a.op("SETOC", ops...) }
func (o Opcodes) Setos(ops ...Operand) { o.a.op("SETOS", ops...) }
func (o Opcodes) SETOS(ops ...Operand) { o.a.op("SETOS", ops...) }
func (o Opcodes) Setpc(ops ...Operand) { o.a.op("SETPC", ops...) }
func (o Opcodes) SETPC(ops ...Operand) { o.a.op("SETPC", ops...) }
func (o Opcodes) Setpl(ops ...Operand) { o.a.op("SETPL", ops...) }
func (o Opcodes) SETPL(ops ...Operand) { o.a.op("SETPL", ops...) }
func (o Opcodes) Setps(ops ...Operand) { o.a.op("SETPS", ops...) }
func (o Opcodes) SETPS(ops ...Operand) { o.a.op("SETPS", ops...) }
func (o Opcodes) Sfence(ops ...Operand) { o.a.op("SFENCE", ops...) }
func (o Opcodes) SFENCE(ops ...Operand) { o.a.op("SFENCE", ops...) }
func (o Opcodes) Shlb(ops ...Operand) { o.a.op("SHLB", ops...) }
func (o Opcodes) SHLB(ops ...Operand) { o.a.op("SHLB", ops...) }
func (o Opcodes) Shll(ops ...Operand) { o.a.op("SHLL", ops...) }
func (o Opcodes) SHLL(ops ...Operand) { o.a.op("SHLL", ops...) }
func (o Opcodes) Shlq(ops ...Operand) { o.a.op("SHLQ", ops...) }
func (o Opcodes) SHLQ(ops ...Operand) { o.a.op("SHLQ", ops...) }
func (o Opcodes) Shlw(ops ...Operand) { o.a.op("SHLW", ops...) }
func (o Opcodes) SHLW(ops ...Operand) { o.a.op("SHLW", ops...) }
func (o Opcodes) Shlxl(ops ...Operand) { o.a.op("SHLXL", ops...) }
func (o Opcodes) SHLXL(ops ...Operand) { o.a.op("SHLXL", ops...) }
func (o Opcodes) Shlxq(ops ...Operand) { o.a.op("SHLXQ", ops...) }
func (o Opcodes) SHLXQ(ops ...Operand) { o.a.op("SHLXQ", ops...) }
func (o Opcodes) Shrb(ops ...Operand) { o.a.op("SHRB", ops...) }
func (o Opcodes) SHRB(ops ...Operand) { o.a.op("SHRB", ops...) }
func (o Opcodes) Shrl(ops ...Operand) { o.a.op("SHRL", ops...) }
func (o Opcodes) SHRL(ops ...Operand) { o.a.op("SHRL", ops...) }
func (o Opcodes) Shrq(ops ...Operand) { o.a.op("SHRQ", ops...) }
func (o Opcodes) SHRQ(ops ...Operand) { o.a.op("SHRQ", ops...) }
func (o Opcodes) Shrw(ops ...Operand) { o.a.op("SHRW", ops...) }
func (o Opcodes) SHRW(ops ...Operand) { o.a.op("SHRW", ops...) }
func (o Opcodes) Shrxl(ops ...Operand) { o.a.op("SHRXL", ops...) }
func (o Opcodes) SHRXL(ops ...Operand) { o.a.op("SHRXL", ops...) }
func (o Opcodes) Shrxq(ops ...Operand) { o.a.op("SHRXQ", ops...) }
func (o Opcodes) SHRXQ(ops ...Operand) { o.a.op("SHRXQ", ops...) }
func (o Opcodes) Shufpd(ops ...Operand) { o.a.op("SHUFPD", ops...) }
func (o Opcodes) SHUFPD(ops ...Operand) { o.a.op("SHUFPD", ops...) }
func (o Opcodes) Shufps(ops ...Operand) { o.a.op("SHUFPS", ops...) }
func (o Opcodes) SHUFPS(ops ...Operand) { o.a.op("SHUFPS", ops...) }
func (o Opcodes) Sqrtpd(ops ...Operand) { o.a.op("SQRTPD", ops...) }
func (o Opcodes) SQRTPD(ops ...Operand) { o.a.op("SQRTPD", ops...) }
func (o Opcodes) Sqrtps(ops ...Operand) { o.a.op("SQRTPS", ops...) }
func (o Opcodes) SQRTPS(ops ...Operand) { o.a.op("SQRTPS", ops...) }
func (o Opcodes) Sqrtsd(ops ...Operand) { o.a.op("SQRTSD", ops...) }
func (o Opcodes) SQRTSD(ops ...Operand) { o.a.op("SQRTSD", ops...) }
func (o Opcodes) Sqrtss(ops ...Operand) { o.a.op("SQRTSS", ops...) }
func (o Opcodes) SQRTSS(ops ...Operand) { o.a.op("SQRTSS", ops...) }
func (o Opcodes) Stc(ops ...Operand) { o.a.op("STC", ops...) }
func (o Opcodes) STC(ops ...Operand) { o.a.op("STC", ops...) }
func (o Opcodes) Std(ops ...Operand) { o.a.op("STD", ops...) }
func (o Opcodes) STD(ops ...Operand) { o.a.op("STD", ops...) }
func (o Opcodes) Sti(ops ...Operand) { o.a.op("STI", ops...) }
func (o Opcodes) STI(ops ...Operand) { o.a.op("STI", ops...) }
func (o Opcodes) Stmxcsr(ops ...Operand) { o.a.op("STMXCSR", ops...) }
func (o Opcodes) STMXCSR(ops ...Operand) { o.a.op("STMXCSR", ops...) }
func (o Opcodes) Stosb(ops ...Operand) { o.a.op("STOSB", ops...) }
func (o Opcodes) STOSB(ops ...Operand) { o.a.op("STOSB", ops...) }
func (o Opcodes) Stosl(ops ...Operand) { o.a.op("STOSL", ops...) }
func (o Opcodes) STOSL(ops ...Operand) { o.a.op("STOSL", ops...) }
func (o Opcodes) Stosq(ops ...Operand) { o.a.op("STOSQ", ops...) }
func (o Opcodes) STOSQ(ops ...Operand) { o.a.op("STOSQ", ops...) }
func (o Opcodes) Stosw(ops ...Operand) { o.a.op("STOSW", ops...) }
func (o Opcodes) STOSW(ops ...Operand) { o.a.op("STOSW", ops...) }
func (o Opcodes) Subb(ops ...Operand) { o.a.op("SUBB", ops...) }
func (o Opcodes) SUBB(ops ...Operand) { o.a.op("SUBB", ops...) }
func (o Opcodes) Subl(ops ...Operand) { o.a.op("SUBL", ops...) }
func (o Opcodes) SUBL(ops ...Operand) { o.a.op("SUBL", ops...) }
func (o Opcodes) Subpd(ops ...Operand) { o.a.op("SUBPD", ops...) }
func (o Opcodes) SUBPD(ops ...Operand) { o.a.op("SUBPD", ops...) }
func (o Opcodes) Subps(ops ...Operand) { o.a.op("SUBPS", ops...) }
func (o Opcodes) SUBPS(ops ...Operand) { o.a.op("SUBPS", ops...) }
func (o Opcodes) Subq(ops ...Operand) { o.a.op("SUBQ", ops...) }
func (o Opcodes) SUBQ(ops ...Operand) { o.a.op("SUBQ", ops...) }
func (o Opcodes) Subsd(ops ...Operand) { o.a.op("SUBSD", ops...) }
func (o Opcodes) SUBSD(ops ...Operand) { o.a.op("SUBSD", ops...) }
func (o Opcodes) Subss(ops ...Operand) { o.a.op("SUBSS", ops...) }
func (o Opcodes) SUBSS(ops ...Operand) { o.a.op("SUBSS", ops...) }
func (o Opcodes) Subw(ops ...Operand) { o.a.op("SUBW", ops...) }
func (o Opcodes) SUBW(ops ...Operand) { o.a.op("SUBW", ops...) }
func (o Opcodes) Swapgs(ops ...Operand) { o.a.op("SWAPGS", ops...) }
func (o Opcodes) SWAPGS(ops ...Operand) { o.a.op("SWAPGS", ops...) }
func (o Opcodes) Syscall(ops ...Operand) { o.a.op("SYSCALL", ops...) }
func (o Opcodes) SYSCALL(ops ...Operand) { o.a.op("SYSCALL", ops...) }
func (o Opcodes) Sysret(ops ...Operand) { o.a.op("SYSRET", ops...) }
func (o Opcodes) SYSRET(ops ...Operand) { o.a.op("SYSRET", ops...) }
func (o Opcodes) Testb(ops ...Operand) { o.a.op("TESTB", ops...) }
func (o Opcodes) TESTB(ops ...Operand) { o.a.op("TESTB", ops...) }
func (o Opcodes) Testl(ops ...Operand) { o.a.op("TESTL", ops...) }
func (o Opcodes) TESTL(ops ...Operand) { o.a.op("TESTL", ops...) }
func (o Opcodes) Testq(ops ...Operand) { o.a.op("TESTQ", ops...) }
func (o Opcodes) TESTQ(ops ...Operand) { o.a.op("TESTQ", ops...) }
func (o Opcodes) Testw(ops ...Operand) { o.a.op("TESTW", ops...) }
func (o Opcodes) TESTW(ops ...Operand) { o.a.op("TESTW", ops...) }
func (o Opcodes) Ucomisd(ops ...Operand) { o.a.op("UCOMISD", ops...) }
func (o Opcodes) UCOMISD(ops ...Operand) { o.a.op("UCOMISD", ops...) }
func (o Opcodes) Ucomiss(ops ...Operand) { o.a.op("UCOMISS", ops...) }
func (o Opcodes) UCOMISS(ops ...Operand) { o.a.op("UCOMISS", ops...) }
func (o Opcodes) Unpckhpd(ops ...Operand) { o.a.op("UNPCKHPD", ops...) }
func (o Opcodes) UNPCKHPD(ops ...Operand) { o.a.op("UNPCKHPD", ops...) }
func (o Opcodes) Unpckhps(ops ...Operand) { o.a.op("UNPCKHPS", ops...) }
func (o Opcodes) UNPCKHPS(ops ...Operand) { o.a.op("UNPCKHPS", ops...) }
func (o Opcodes) Unpcklpd(ops ...Operand) { o.a.op("UNPCKLPD", ops...) }
func (o Opcodes) UNPCKLPD(ops ...Operand) { o.a.op("UNPCKLPD", ops...) }
func (o Opcodes) Unpcklps(ops ...Operand) { o.a.op("UNPCKLPS", ops...) }
func (o Opcodes) UNPCKLPS(ops ...Operand) { o.a.op("UNPCKLPS", ops...) }
func (o Opcodes) Vaddpd(ops ...Operand) { o.a.op("VADDPD", ops...) }
func (o Opcodes) VADDPD(ops ...Operand) { o.a.op("VADDPD", ops...) }
func (o Opcodes) Vaddps(ops ...Operand) { o.a.op("VADDPS", ops...) }
func (o Opcodes) VADDPS(ops ...Operand) { o.a.op("VADDPS", ops...) }
func (o Opcodes) Vaddsd(ops ...Operand) { o.a.op("VADDSD", ops...) }
func (o Opcodes) VADDSD(ops ...Operand) { o.a.op("VADDSD", ops...) }
func (o Opcodes) Vaddss(ops ...Operand) { o.a.op("VADDSS", ops...) }
func (o Opcodes) VADDSS(ops ...Operand) { o.a.op("VADDSS", ops...) }
func (o Opcodes) Vaddsubpd(ops ...Operand) { o.a.op("VADDSUBPD", ops...) }
func (o Opcodes) VADDSUBPD(ops ...Operand) { o.a.op("VADDSUBPD", ops...) }
func (o Opcodes) Vaddsubps(ops ...Operand) { o.a.op("VADDSUBPS", ops...) }
func (o Opcodes) VADDSUBPS(ops ...Operand) { o.a.op("VADDSUBPS", ops...) }
func (o Opcodes) Vaesdec(ops ...Operand) { o.a.op("VAESDEC", ops...) }
func (o Opcodes) VAESDEC(ops ...Operand) { o.a.op("VAESDEC", ops...) }
func (o Opcodes) Vaesdeclast(ops ...Operand) { o.a.op("VAESDECLAST", ops...) }
func (o Opcodes) VAESDECLAST(ops ...Operand) { o.a.op("VAESDECLAST", ops...) }
func (o Opcodes) Vaesenc(ops ...Operand) { o.a.op("VAESENC", ops...) }
func (o Opcodes) VAESENC(ops ...Operand) { o.a.op("VAESENC", ops...) }
func (o Opcodes) Vaesenclast(ops ...Operand) { o.a.op("VAESENCLAST", ops...) }
func (o Opcodes) VAESENCLAST(ops ...Operand) { o.a.op("VAESENCLAST", ops...) }
func (o Opcodes) Vaesimc(ops ...Operand) { o.a.op("VAESIMC", ops...) }
func (o Opcodes) VAESIMC(ops ...Operand) { o.a.op("VAESIMC", ops...) }
func (o Opcodes) Vaeskeygenassist(ops ...Operand) { o.a.op("VAESKEYGENASSIST", ops...) }
func (o Opcodes) VAESKEYGENASSIST(ops ...Operand) { o.a.op("VAESKEYGENASSIST", ops...) }
func (o Opcodes) Vandnpd(ops ...Operand) { o.a.op("VANDNPD", ops...) }
func (o Opcodes) VANDNPD(ops ...Operand) { o.a.op("VANDNPD", ops...) }
func (o Opcodes) Vandnps(ops ...Operand) { o.a.op("VANDNPS", ops...) }
func (o Opcodes) VANDNPS(ops ...Operand) { o.a.op("VANDNPS", ops...) }
func (o Opcodes) Vandpd(ops ...Operand) { o.a.op("VANDPD", ops...) }
func (o Opcodes) VANDPD(ops ...Operand) { o.a.op("VANDPD", ops...) }
func (o Opcodes) Vandps(ops ...Operand) { o.a.op("VANDPS", ops...) }
func (o Opcodes) VANDPS(ops ...Operand) { o.a.op("VANDPS", ops...) }
func (o Opcodes) Vblendpd(ops ...Operand) { o.a.op("VBLENDPD", ops...) }
func (o Opcodes) VBLENDPD(ops ...Operand) { o.a.op("VBLENDPD", ops...) }
func (o Opcodes) Vblendps(ops ...Operand) { o.a.op("VBLENDPS", ops...) }
func (o Opcodes) VBLENDPS(ops ...Operand) { o.a.op("VBLENDPS", ops...) }
func (o Opcodes) Vblendvpd(ops ...Operand) { o.a.op("VBLENDVPD", ops...) }
func (o Opcodes) VBLENDVPD(ops ...Operand) { o.a.op("VBLENDVPD", ops...) }
func (o Opcodes) Vblendvps(ops ...Operand) { o.a.op("VBLENDVPS", ops...) }
func (o Opcodes) VBLENDVPS(ops ...Operand) { o.a.op("VBLENDVPS", ops...) }
func (o Opcodes) Vbroadcastf128(ops ...Operand) { o.a.op("VBROADCASTF128", ops...) }
func (o Opcodes) VBROADCASTF128(ops ...Operand) { o.a.op("VBROADCASTF128", ops...) }
func (o Opcodes) Vbroadcasti128(ops ...Operand) { o.a.op("VBROADCASTI128", ops...) }
func (o Opcodes) VBROADCASTI128(ops ...Operand) { o.a.op("VBROADCASTI128", ops...) }
func (o Opcodes) Vbroadcastsd(ops ...Operand) { o.a.op("VBROADCASTSD", ops...) }
func (o Opcodes) VBROADCASTSD(ops ...Operand) { o.a.op("VBROADCASTSD", ops...) }
func (o Opcodes) Vbroadcastss(ops ...Operand) { o.a.op("VBROADCASTSS", ops...) }
func (o Opcodes) VBROADCASTSS(ops ...Operand) { o.a.op("VBROADCASTSS", ops...) }
func (o Opcodes) Vcmppd(ops ...Operand) { o.a.op("VCMPPD", ops...) }
func (o Opcodes) VCMPPD(ops ...Operand) { o.a.op("VCMPPD", ops...) }
func (o Opcodes) Vcmpps(ops ...Operand) { o.a.op("VCMPPS", ops...) }
func (o Opcodes) VCMPPS(ops ...Operand) { o.a.op("VCMPPS", ops...) }
func (o Opcodes) Vcmpsd(ops ...Operand) { o.a.op("VCMPSD", ops...) }
func (o Opcodes) VCMPSD(ops ...Operand) { o.a.op("VCMPSD", ops...) }
func (o Opcodes) Vcmpss(ops ...Operand) { o.a.op("VCMPSS", ops...) }
func (o Opcodes) VCMPSS(ops ...Operand) { o.a.op("VCMPSS", ops...) }
func (o Opcodes) Vcomisd(ops ...Operand) { o.a.op("VCOMISD", ops...) }
func (o Opcodes) VCOMISD(ops ...Operand) { o.a.op("VCOMISD", ops...) }
func (o Opcodes) Vcomiss(ops ...Operand) { o.a.op("VCOMISS", ops...) }
func (o Opcodes) VCOMISS(ops ...Operand) { o.a.op("VCOMISS", ops...) }
func (o Opcodes) Vcvtdq2pd(ops ...Operand) { o.a.op("VCVTDQ2PD", ops...) }
func (o Opcodes) VCVTDQ2PD(ops ...Operand) { o.a.op("VCVTDQ2PD", ops...) }
func (o Opcodes) Vcvtdq2ps(ops ...Operand) { o.a.op("VCVTDQ2PS", ops...) }
func (o Opcodes) VCVTDQ2PS(ops ...Operand) { o.a.op("VCVTDQ2PS", ops...) }
func (o Opcodes) Vcvtpd2dqx(ops ...Operand) { o.a.op("VCVTPD2DQX", ops...) }
func (o Opcodes) VCVTPD2DQX(ops ...Operand) { o.a.op("VCVTPD2DQX", ops...) }
func (o Opcodes) Vcvtpd2dqy(ops ...Operand) { o.a.op("VCVTPD2DQY", ops...) }
func (o Opcodes) VCVTPD2DQY(ops ...Operand) { o.a.op("VCVTPD2DQY", ops...) }
func (o Opcodes) Vcvtpd2psx(ops ...Operand) { o.a.op("VCVTPD2PSX", ops...) }
func (o Opcodes) VCVTPD2PSX(ops ...Operand) { o.a.op("VCVTPD2PSX", ops...) }
func (o Opcodes) Vcvtpd2psy(ops ...Operand) { o.a.op("VCVTPD2PSY", ops...) }
func (o Opcodes) VCVTPD2PSY(ops ...Operand) { o.a.op("VCVTPD2PSY", ops...) }
func (o Opcodes) Vcvtph2ps(ops ...Operand) { o.a.op("VCVTPH2PS", ops...) }
func (o Opcodes) VCVTPH2PS(ops ...Operand) { o.a.op("VCVTPH2PS", ops...) }
func (o Opcodes) Vcvtps2dq(ops ...Operand) { o.a.op("VCVTPS2DQ", ops...) }
func (o Opcodes) VCVTPS2DQ(ops ...Operand) { o.a.op("VCVTPS2DQ", ops...) }
func (o Opcodes) Vcvtps2pd(ops ...Operand) { o.a.op("VCVTPS2PD", ops...) }
func (o Opcodes) VCVTPS2PD(ops ...Operand) { o.a.op("VCVTPS2PD", ops...) }
func (o Opcodes) Vcvtps2ph(ops ...Operand) { o.a.op("VCVTPS2PH", ops...) }
func (o Opcodes) VCVTPS2PH(ops ...Operand) { o.a.op("VCVTPS2PH", ops...) }
func (o Opcodes) Vcvtsd2si(ops ...Operand) { o.a.op("VCVTSD2SI", ops...) }
func (o Opcodes) VCVTSD2SI(ops ...Operand) { o.a.op("VCVTSD2SI", ops...) }
func (o Opcodes) Vcvtsd2siq(ops ...Operand) { o.a.op("VCVTSD2SIQ", ops...) }
func (o Opcodes) VCVTSD2SIQ(ops ...Operand) { o.a.op("VCVTSD2SIQ", ops...) }
func (o Opcodes) Vcvtsd2ss(ops ...Operand) { o.a.op("VCVTSD2SS", ops...) }
func (o Opcodes) VCVTSD2SS(ops ...Operand) { o.a.op("VCVTSD2SS", ops...) }
func (o Opcodes) Vcvtsi2sdl(ops ...Operand) { o.a.op("VCVTSI2SDL", ops...) }
func (o Opcodes) VCVTSI2SDL(ops ...Operand) { o.a.op("VCVTSI2SDL", ops...) }
func (o Opcodes) Vcvtsi2sdq(ops ...Operand) { o.a.op("VCVTSI2SDQ", ops...) }
func (o Opcodes) VCVTSI2SDQ(ops ...Operand) { o.a.op("VCVTSI2SDQ", ops...) }
func (o Opcodes) Vcvtsi2ssl(ops ...Operand) { o.a.op("VCVTSI2SSL", ops...) }
func (o Opcodes) VCVTSI2SSL(ops ...Operand) { o.a.op("VCVTSI2SSL", ops...) }
func (o Opcodes) Vcvtsi2ssq(ops ...Operand) { o.a.op("VCVTSI2SSQ", ops...) }
func (o Opcodes) VCVTSI2SSQ(ops ...Operand) { o.a.op("VCVTSI2SSQ", ops...) }
func (o Opcodes) Vcvtss2sd(ops ...Operand) { o.a.op("VCVTSS2SD", ops...) }
func (o Opcodes) VCVTSS2SD(ops ...Operand) { o.a.op("VCVTSS2SD", ops...) }
func (o Opcodes) Vcvtss2si(ops ...Operand) { o.a.op("VCVTSS2SI", ops...) }
func (o Opcodes) VCVTSS2SI(ops ...Operand) { o.a.op("VCVTSS2SI", ops...) }
func (o Opcodes) Vcvtss2siq(ops ...Operand) { o.a.op("VCVTSS2SIQ", ops...) }
func (o Opcodes) VCVTSS2SIQ(ops ...Operand) { o.a.op("VCVTSS2SIQ", ops...) }
func (o Opcodes) Vcvttpd2dqx(ops ...Operand) { o.a.op("VCVTTPD2DQX", ops...) }
func (o Opcodes) VCVTTPD2DQX(ops ...Operand) { o.a.op("VCVTTPD2DQX", ops...) }
func (o Opcodes) Vcvttpd2dqy(ops ...Operand) { o.a.op("VCVTTPD2DQY", ops...) }
func (o Opcodes) VCVTTPD2DQY(ops ...Operand) { o.a.op("VCVTTPD2DQY", ops...) }
func (o Opcodes) Vcvttps2dq(ops ...Operand) { o.a.op("VCVTTPS2DQ", ops...) }
func (o Opcodes) VCVTTPS2DQ(ops ...Operand) { o.a.op("VCVTTPS2DQ", ops...) }
func (o Opcodes) Vcvttsd2si(ops ...Operand) { o.a.op("VCVTTSD2SI", ops...) }
func (o Opcodes) VCVTTSD2SI(ops ...Operand) { o.a.op("VCVTTSD2SI", ops...) }
func (o Opcodes) Vcvttsd2siq(ops ...Operand) { o.a.op("VCVTTSD2SIQ", ops...) }
func (o Opcodes) VCVTTSD2SIQ(ops ...Operand) { o.a.op("VCVTTSD2SIQ", ops...) }
func (o Opcodes) Vcvttss2si(ops ...Operand) { o.a.op("VCVTTSS2SI", ops...) }
func (o Opcodes) VCVTTSS2SI(ops ...Operand) { o.a.op("VCVTTSS2SI", ops...) }
func (o Opcodes) Vcvttss2siq(ops ...Operand) { o.a.op("VCVTTSS2SIQ", ops...) }
func (o Opcodes) VCVTTSS2SIQ(ops ...Operand) { o.a.op("VCVTTSS2SIQ", ops...) }
func (o Opcodes) Vdivpd(ops ...Operand) { o.a.op("VDIVPD", ops...) }
func (o Opcodes) VDIVPD(ops ...Operand) { o.a.op("VDIVPD", ops...) }
func (o Opcodes) Vdivps(ops ...Operand) { o.a.op("VDIVPS", ops...) }
func (o Opcodes) VDIVPS(ops ...Operand) { o.a.op("VDIVPS", ops...) }
func (o Opcodes) Vdivsd(ops ...Operand) { o.a.op("VDIVSD", ops...) }
func (o Opcodes) VDIVSD(ops ...Operand) { o.a.op("VDIVSD", ops...) }
func (o Opcodes) Vdivss(ops ...Operand) { o.a.op("VDIVSS", ops...) }
func (o Opcodes) VDIVSS(ops ...Operand) { o.a.op("VDIVSS", ops...) }
func (o Opcodes) Vdppd(ops ...Operand) { o.a.op("VDPPD", ops...) }
func (o Opcodes) VDPPD(ops ...Operand) { o.a.op("VDPPD", ops...) }
func (o Opcodes) Vdpps(ops ...Operand) { o.a.op("VDPPS", ops...) }
func (o Opcodes) VDPPS(ops ...Operand) { o.a.op("VDPPS", ops...) }
func (o Opcodes) Verr(ops ...Operand) { o.a.op("VERR", ops...) }
func (o Opcodes) VERR(ops ...Operand) { o.a.op("VERR", ops...) }
func (o Opcodes) Verw(ops ...Operand) { o.a.op("VERW", ops...) }
func (o Opcodes) VERW(ops ...Operand) { o.a.op("VERW", ops...) }
func (o Opcodes) Vextractf128(ops ...Operand) { o.a.op("VEXTRACTF128", ops...) }
func (o Opcodes) VEXTRACTF128(ops ...Operand) { o.a.op("VEXTRACTF128", ops...) }
func (o Opcodes) Vextracti128(ops ...Operand) { o.a.op("VEXTRACTI128", ops...) }
func (o Opcodes) VEXTRACTI128(ops ...Operand) { o.a.op("VEXTRACTI128", ops...) }
func (o Opcodes) Vextractps(ops ...Operand) { o.a.op("VEXTRACTPS", ops...) }
func (o Opcodes) VEXTRACTPS(ops ...Operand) { o.a.op("VEXTRACTPS", ops...) }
func (o Opcodes) Vfmadd132pd(ops ...Operand) { o.a.op("VFMADD132PD", ops...) }
func (o Opcodes) VFMADD132PD(ops ...Operand) { o.a.op("VFMADD132PD", ops...) }
func (o Opcodes) Vfmadd132ps(ops ...Operand) { o.a.op("VFMADD132PS", ops...) }
func (o Opcodes) VFMADD132PS(ops ...Operand) { o.a.op("VFMADD132PS", ops...) }
func (o Opcodes) Vfmadd132sd(ops ...Operand) { o.a.op("VFMADD132SD", ops...) }
func (o Opcodes) VFMADD132SD(ops ...Operand) { o.a.op("VFMADD132SD", ops...) }
func (o Opcodes) Vfmadd132ss(ops ...Operand) { o.a.op("VFMADD132SS", ops...) }
func (o Opcodes) VFMADD132SS(ops ...Operand) { o.a.op("VFMADD132SS", ops...) }
func (o Opcodes) Vfmadd213pd(ops ...Operand) { o.a.op("VFMADD213PD", ops...) }
func (o Opcodes) VFMADD213PD(ops ...Operand) { o.a.op("VFMADD213PD", ops...) }
func (o Opcodes) Vfmadd213ps(ops ...Operand) { o.a.op("VFMADD213PS", ops...) }
func (o Opcodes) VFMADD213PS(ops ...Operand) { o.a.op("VFMADD213PS", ops...) }
func (o Opcodes) Vfmadd213sd(ops ...Operand) { o.a.op("VFMADD213SD", ops...) }
func (o Opcodes) VFMADD213SD(ops ...Operand) { o.a.op("VFMADD213SD", ops...) }
func (o Opcodes) Vfmadd213ss(ops ...Operand) { o.a.op("VFMADD213SS", ops...) }
func (o Opcodes) VFMADD213SS(ops ...Operand) { o.a.op("VFMADD213SS", ops...) }
func (o Opcodes) Vfmadd231pd(ops ...Operand) { o.a.op("VFMADD231PD", ops...) }
func (o Opcodes) VFMADD231PD(ops ...Operand) { o.a.op("VFMADD231PD", ops...) }
func (o Opcodes) Vfmadd231ps(ops ...Operand) { o.a.op("VFMADD231PS", ops...) }
func (o Opcodes) VFMADD231PS(ops ...Operand) { o.a.op("VFMADD231PS", ops...) }
func (o Opcodes) Vfmadd231sd(ops ...Operand) { o.a.op("VFMADD231SD", ops...) }
func (o Opcodes) VFMADD231SD(ops ...Operand) { o.a.op("VFMADD231SD", ops...) }
func (o Opcodes) Vfmadd231ss(ops ...Operand) { o.a.op("VFMADD231SS", ops...) }
func (o Opcodes) VFMADD231SS(ops ...Operand) { o.a.op("VFMADD231SS", ops...) }
func (o Opcodes) Vfmaddsub132pd(ops ...Operand) { o.a.op("VFMADDSUB132PD", ops...) }
func (o Opcodes) VFMADDSUB132PD(ops ...Operand) { o.a.op("VFMADDSUB132PD", ops...) }
func (o Opcodes) Vfmaddsub132ps(ops ...Operand) { o.a.op("VFMADDSUB132PS", ops...) }
func (o Opcodes) VFMADDSUB132PS(ops ...Operand) { o.a.op("VFMADDSUB132PS", ops...) }
func (o Opcodes) Vfmaddsub213pd(ops ...Operand) { o.a.op("VFMADDSUB213PD", ops...) }
func (o Opcodes) VFMADDSUB213PD(ops ...Operand) { o.a.op("VFMADDSUB213PD", ops...) }
func (o Opcodes) Vfmaddsub213ps(ops ...Operand) { o.a.op("VFMADDSUB213PS", ops...) }
func (o Opcodes) VFMADDSUB213PS(ops ...Operand) { o.a.op("VFMADDSUB213PS", ops...) }
func (o Opcodes) Vfmaddsub231pd(ops ...Operand) { o.a.op("VFMADDSUB231PD", ops...) }
func (o Opcodes) VFMADDSUB231PD(ops ...Operand) { o.a.op("VFMADDSUB231PD", ops...) }
func (o Opcodes) Vfmaddsub231ps(ops ...Operand) { o.a.op("VFMADDSUB231PS", ops...) }
func (o Opcodes) VFMADDSUB231PS(ops ...Operand) { o.a.op("VFMADDSUB231PS", ops...) }
func (o Opcodes) Vfmsub132pd(ops ...Operand) { o.a.op("VFMSUB132PD", ops...) }
func (o Opcodes) VFMSUB132PD(ops ...Operand) { o.a.op("VFMSUB132PD", ops...) }
func (o Opcodes) Vfmsub132ps(ops ...Operand) { o.a.op("VFMSUB132PS", ops...) }
func (o Opcodes) VFMSUB132PS(ops ...Operand) { o.a.op("VFMSUB132PS", ops...) }
func (o Opcodes) Vfmsub132sd(ops ...Operand) { o.a.op("VFMSUB132SD", ops...) }
func (o Opcodes) VFMSUB132SD(ops ...Operand) { o.a.op("VFMSUB132SD", ops...) }
func (o Opcodes) Vfmsub132ss(ops ...Operand) { o.a.op("VFMSUB132SS", ops...) }
func (o Opcodes) VFMSUB132SS(ops ...Operand) { o.a.op("VFMSUB132SS", ops...) }
func (o Opcodes) Vfmsub213pd(ops ...Operand) { o.a.op("VFMSUB213PD", ops...) }
func (o Opcodes) VFMSUB213PD(ops ...Operand) { o.a.op("VFMSUB213PD", ops...) }
func (o Opcodes) Vfmsub213ps(ops ...Operand) { o.a.op("VFMSUB213PS", ops...) }
func (o Opcodes) VFMSUB213PS(ops ...Operand) { o.a.op("VFMSUB213PS", ops...) }
func (o Opcodes) Vfmsub213sd(ops ...Operand) { o.a.op("VFMSUB213SD", ops...) }
func (o Opcodes) VFMSUB213SD(ops ...Operand) { o.a.op("VFMSUB213SD", ops...) }
func (o Opcodes) Vfmsub213ss(ops ...Operand) { o.a.op("VFMSUB213SS", ops...) }
func (o Opcodes) VFMSUB213SS(ops ...Operand) { o.a.op("VFMSUB213SS", ops...) }
func (o Opcodes) Vfmsub231pd(ops ...Operand) { o.a.op("VFMSUB231PD", ops...) }
func (o Opcodes) VFMSUB231PD(ops ...Operand) { o.a.op("VFMSUB231PD", ops...) }
func (o Opcodes) Vfmsub231ps(ops ...Operand) { o.a.op("VFMSUB231PS", ops...) }
func (o Opcodes) VFMSUB231PS(ops ...Operand) { o.a.op("VFMSUB231PS", ops...) }
func (o Opcodes) Vfmsub231sd(ops ...Operand) { o.a.op("VFMSUB231SD", ops...) }
func (o Opcodes) VFMSUB231SD(ops ...Operand) { o.a.op("VFMSUB231SD", ops...) }
func (o Opcodes) Vfmsub231ss(ops ...Operand) { o.a.op("VFMSUB231SS", ops...) }
func (o Opcodes) VFMSUB231SS(ops ...Operand) { o.a.op("VFMSUB231SS", ops...) }
func (o Opcodes) Vfmsubadd132pd(ops ...Operand) { o.a.op("VFMSUBADD132PD", ops...) }
func (o Opcodes) VFMSUBADD132PD(ops ...Operand) { o.a.op("VFMSUBADD132PD", ops...) }
func (o Opcodes) Vfmsubadd132ps(ops ...Operand) { o.a.op("VFMSUBADD132PS", ops...) }
func (o Opcodes) VFMSUBADD132PS(ops ...Operand) { o.a.op("VFMSUBADD132PS", ops...) }
func (o Opcodes) Vfmsubadd213pd(ops ...Operand) { o.a.op("VFMSUBADD213PD", ops...) }
func (o Opcodes) VFMSUBADD213PD(ops ...Operand) { o.a.op("VFMSUBADD213PD", ops...) }
func (o Opcodes) Vfmsubadd213ps(ops ...Operand) { o.a.op("VFMSUBADD213PS", ops...) }
func (o Opcodes) VFMSUBADD213PS(ops ...Operand) { o.a.op("VFMSUBADD213PS", ops...) }
func (o Opcodes) Vfmsubadd231pd(ops ...Operand) { o.a.op("VFMSUBADD231PD", ops...) }
func (o Opcodes) VFMSUBADD231PD(ops ...Operand) { o.a.op("VFMSUBADD231PD", ops...) }
func (o Opcodes) Vfmsubadd231ps(ops ...Operand) { o.a.op("VFMSUBADD231PS", ops...) }
func (o Opcodes) VFMSUBADD231PS(ops ...Operand) { o.a.op("VFMSUBADD231PS", ops...) }
func (o Opcodes) Vfnmadd132pd(ops ...Operand) { o.a.op("VFNMADD132PD", ops...) }
func (o Opcodes) VFNMADD132PD(ops ...Operand) { o.a.op("VFNMADD132PD", ops...) }
func (o Opcodes) Vfnmadd132ps(ops ...Operand) { o.a.op("VFNMADD132PS", ops...) }
func (o Opcodes) VFNMADD132PS(ops ...Operand) { o.a.op("VFNMADD132PS", ops...) }
func (o Opcodes) Vfnmadd132sd(ops ...Operand) { o.a.op("VFNMADD132SD", ops...) }
func (o Opcodes) VFNMADD132SD(ops ...Operand) { o.a.op("VFNMADD132SD", ops...) }
func (o Opcodes) Vfnmadd132ss(ops ...Operand) { o.a.op("VFNMADD132SS", ops...) }
func (o Opcodes) VFNMADD132SS(ops ...Operand) { o.a.op("VFNMADD132SS", ops...) }
func (o Opcodes) Vfnmadd213pd(ops ...Operand) { o.a.op("VFNMADD213PD", ops...) }
func (o Opcodes) VFNMADD213PD(ops ...Operand) { o.a.op("VFNMADD213PD", ops...) }
func (o Opcodes) Vfnmadd213ps(ops ...Operand) { o.a.op("VFNMADD213PS", ops...) }
func (o Opcodes) VFNMADD213PS(ops ...Operand) { o.a.op("VFNMADD213PS", ops...) }
func (o Opcodes) Vfnmadd213sd(ops ...Operand) { o.a.op("VFNMADD213SD", ops...) }
func (o Opcodes) VFNMADD213SD(ops ...Operand) { o.a.op("VFNMADD213SD", ops...) }
func (o Opcodes) Vfnmadd213ss(ops ...Operand) { o.a.op("VFNMADD213SS", ops...) }
func (o Opcodes) VFNMADD213SS(ops ...Operand) { o.a.op("VFNMADD213SS", ops...) }
func (o Opcodes) Vfnmadd231pd(ops ...Operand) { o.a.op("VFNMADD231PD", ops...) }
func (o Opcodes) VFNMADD231PD(ops ...Operand) { o.a.op("VFNMADD231PD", ops...) }
func (o Opcodes) Vfnmadd231ps(ops ...Operand) { o.a.op("VFNMADD231PS", ops...) }
func (o Opcodes) VFNMADD231PS(ops ...Operand) { o.a.op("VFNMADD231PS", ops...) }
func (o Opcodes) Vfnmadd231sd(ops ...Operand) { o.a.op("VFNMADD231SD", ops...) }
func (o Opcodes) VFNMADD231SD(ops ...Operand) { o.a.op("VFNMADD231SD", ops...) }
func (o Opcodes) Vfnmadd231ss(ops ...Operand) { o.a.op("VFNMADD231SS", ops...) }
func (o Opcodes) VFNMADD231SS(ops ...Operand) { o.a.op("VFNMADD231SS", ops...) }
func (o Opcodes) Vfnmsub132pd(ops ...Operand) { o.a.op("VFNMSUB132PD", ops...) }
func (o Opcodes) VFNMSUB132PD(ops ...Operand) { o.a.op("VFNMSUB132PD", ops...) }
func (o Opcodes) Vfnmsub132ps(ops ...Operand) { o.a.op("VFNMSUB132PS", ops...) }
func (o Opcodes) VFNMSUB132PS(ops ...Operand) { o.a.op("VFNMSUB132PS", ops...) }
func (o Opcodes) Vfnmsub132sd(ops ...Operand) { o.a.op("VFNMSUB132SD", ops...) }
func (o Opcodes) VFNMSUB132SD(ops ...Operand) { o.a.op("VFNMSUB132SD", ops...) }
func (o Opcodes) Vfnmsub132ss(ops ...Operand) { o.a.op("VFNMSUB132SS", ops...) }
func (o Opcodes) VFNMSUB132SS(ops ...Operand) { o.a.op("VFNMSUB132SS", ops...) }
func (o Opcodes) Vfnmsub213pd(ops ...Operand) { o.a.op("VFNMSUB213PD", ops...) }
func (o Opcodes) VFNMSUB213PD(ops ...Operand) { o.a.op("VFNMSUB213PD", ops...) }
func (o Opcodes) Vfnmsub213ps(ops ...Operand) { o.a.op("VFNMSUB213PS", ops...) }
func (o Opcodes) VFNMSUB213PS(ops ...Operand) { o.a.op("VFNMSUB213PS", ops...) }
func (o Opcodes) Vfnmsub213sd(ops ...Operand) { o.a.op("VFNMSUB213SD", ops...) }
func (o Opcodes) VFNMSUB213SD(ops ...Operand) { o.a.op("VFNMSUB213SD", ops...) }
func (o Opcodes) Vfnmsub213ss(ops ...Operand) { o.a.op("VFNMSUB213SS", ops...) }
func (o Opcodes) VFNMSUB213SS(ops ...Operand) { o.a.op("VFNMSUB213SS", ops...) }
func (o Opcodes) Vfnmsub231pd(ops ...Operand) { o.a.op("VFNMSUB231PD", ops...) }
func (o Opcodes) VFNMSUB231PD(ops ...Operand) { o.a.op("VFNMSUB231PD", ops...) }
func (o Opcodes) Vfnmsub231ps(ops ...Operand) { o.a.op("VFNMSUB231PS", ops...) }
func (o Opcodes) VFNMSUB231PS(ops ...Operand) { o.a.op("VFNMSUB231PS", ops...) }
func (o Opcodes) Vfnmsub231sd(ops ...Operand) { o.a.op("VFNMSUB231SD", ops...) }
func (o Opcodes) VFNMSUB231SD(ops ...Operand) { o.a.op("VFNMSUB231SD", ops...) }
func (o Opcodes) Vfnmsub231ss(ops ...Operand) { o.a.op("VFNMSUB231SS", ops...) }
func (o Opcodes) VFNMSUB231SS(ops ...Operand) { o.a.op("VFNMSUB231SS", ops...) }
func (o Opcodes) Vgatherdpd(ops ...Operand) { o.a.op("VGATHERDPD", ops...) }
func (o Opcodes) VGATHERDPD(ops ...Operand) { o.a.op("VGATHERDPD", ops...) }
func (o Opcodes) Vgatherdps(ops ...Operand) { o.a.op("VGATHERDPS", ops...) }
func (o Opcodes) VGATHERDPS(ops ...Operand) { o.a.op("VGATHERDPS", ops...) }
func (o Opcodes) Vgatherqpd(ops ...Operand) { o.a.op("VGATHERQPD", ops...) }
func (o Opcodes) VGATHERQPD(ops ...Operand) { o.a.op("VGATHERQPD", ops...) }
func (o Opcodes) Vgatherqps(ops ...Operand) { o.a.op("VGATHERQPS", ops...) }
func (o Opcodes) VGATHERQPS(ops ...Operand) { o.a.op("VGATHERQPS", ops...) }
func (o Opcodes) Vhaddpd(ops ...Operand) { o.a.op("VHADDPD", ops...) }
func (o Opcodes) VHADDPD(ops ...Operand) { o.a.op("VHADDPD", ops...) }
func (o Opcodes) Vhaddps(ops ...Operand) { o.a.op("VHADDPS", ops...) }
func (o Opcodes) VHADDPS(ops ...Operand) { o.a.op("VHADDPS", ops...) }
func (o Opcodes) Vhsubpd(ops ...Operand) { o.a.op("VHSUBPD", ops...) }
func (o Opcodes) VHSUBPD(ops ...Operand) { o.a.op("VHSUBPD", ops...) }
func (o Opcodes) Vhsubps(ops ...Operand) { o.a.op("VHSUBPS", ops...) }
func (o Opcodes) VHSUBPS(ops ...Operand) { o.a.op("VHSUBPS", ops...) }
func (o Opcodes) Vinsertf128(ops ...Operand) { o.a.op("VINSERTF128", ops...) }
func (o Opcodes) VINSERTF128(ops ...Operand) { o.a.op("VINSERTF128", ops...) }
func (o Opcodes) Vinserti128(ops ...Operand) { o.a.op("VINSERTI128", ops...) }
func (o Opcodes) VINSERTI128(ops ...Operand) { o.a.op("VINSERTI128", ops...) }
func (o Opcodes) Vinsertps(ops ...Operand) { o.a.op("VINSERTPS", ops...) }
func (o Opcodes) VINSERTPS(ops ...Operand) { o.a.op("VINSERTPS", ops...) }
func (o Opcodes) Vlddqu(ops ...Operand) { o.a.op("VLDDQU", ops...) }
func (o Opcodes) VLDDQU(ops ...Operand) { o.a.op("VLDDQU", ops...) }
func (o Opcodes) Vldmxcsr(ops ...Operand) { o.a.op("VLDMXCSR", ops...) }
func (o Opcodes) VLDMXCSR(ops ...Operand) { o.a.op("VLDMXCSR", ops...) }
func (o Opcodes) Vmaskmovdqu(ops ...Operand) { o.a.op("VMASKMOVDQU", ops...) }
func (o Opcodes) VMASKMOVDQU(ops ...Operand) { o.a.op("VMASKMOVDQU", ops...) }
func (o Opcodes) Vmaskmovpd(ops ...Operand) { o.a.op("VMASKMOVPD", ops...) }
func (o Opcodes) VMASKMOVPD(ops ...Operand) { o.a.op("VMASKMOVPD", ops...) }
func (o Opcodes) Vmaskmovps(ops ...Operand) { o.a.op("VMASKMOVPS", ops...) }
func (o Opcodes) VMASKMOVPS(ops ...Operand) { o.a.op("VMASKMOVPS", ops...) }
func (o Opcodes) Vmaxpd(ops ...Operand) { o.a.op("VMAXPD", ops...) }
func (o Opcodes) VMAXPD(ops ...Operand) { o.a.op("VMAXPD", ops...) }
func (o Opcodes) Vmaxps(ops ...Operand) { o.a.op("VMAXPS", ops...) }
func (o Opcodes) VMAXPS(ops ...Operand) { o.a.op("VMAXPS", ops...) }
func (o Opcodes) Vmaxsd(ops ...Operand) { o.a.op("VMAXSD", ops...) }
func (o Opcodes) VMAXSD(ops ...Operand) { o.a.op("VMAXSD", ops...) }
func (o Opcodes) Vmaxss(ops ...Operand) { o.a.op("VMAXSS", ops...) }
func (o Opcodes) VMAXSS(ops ...Operand) { o.a.op("VMAXSS", ops...) }
func (o Opcodes) Vminpd(ops ...Operand) { o.a.op("VMINPD", ops...) }
func (o Opcodes) VMINPD(ops ...Operand) { o.a.op("VMINPD", ops...) }
func (o Opcodes) Vminps(ops ...Operand) { o.a.op("VMINPS", ops...) }
func (o Opcodes) VMINPS(ops ...Operand) { o.a.op("VMINPS", ops...) }
func (o Opcodes) Vminsd(ops ...Operand) { o.a.op("VMINSD", ops...) }
func (o Opcodes) VMINSD(ops ...Operand) { o.a.op("VMINSD", ops...) }
func (o Opcodes) Vminss(ops ...Operand) { o.a.op("VMINSS", ops...) }
func (o Opcodes) VMINSS(ops ...Operand) { o.a.op("VMINSS", ops...) }
func (o Opcodes) Vmovapd(ops ...Operand) { o.a.op("VMOVAPD", ops...) }
func (o Opcodes) VMOVAPD(ops ...Operand) { o.a.op("VMOVAPD", ops...) }
func (o Opcodes) Vmovaps(ops ...Operand) { o.a.op("VMOVAPS", ops...) }
func (o Opcodes) VMOVAPS(ops ...Operand) { o.a.op("VMOVAPS", ops...) }
func (o Opcodes) Vmovd(ops ...Operand) { o.a.op("VMOVD", ops...) }
func (o Opcodes) VMOVD(ops ...Operand) { o.a.op("VMOVD", ops...) }
func (o Opcodes) Vmovddup(ops ...Operand) { o.a.op("VMOVDDUP", ops...) }
func (o Opcodes) VMOVDDUP(ops ...Operand) { o.a.op("VMOVDDUP", ops...) }
func (o Opcodes) Vmovdqa(ops ...Operand) { o.a.op("VMOVDQA", ops...) }
func (o Opcodes) VMOVDQA(ops ...Operand) { o.a.op("VMOVDQA", ops...) }
func (o Opcodes) Vmovdqu(ops ...Operand) { o.a.op("VMOVDQU", ops...) }
func (o Opcodes) VMOVDQU(ops ...Operand) { o.a.op("VMOVDQU", ops...) }
func (o Opcodes) Vmovhlps(ops ...Operand) { o.a.op("VMOVHLPS", ops...) }
func (o Opcodes) VMOVHLPS(ops ...Operand) { o.a.op("VMOVHLPS", ops...) }
func (o Opcodes) Vmovhpd(ops ...Operand) { o.a.op("VMOVHPD", ops...) }
func (o Opcodes) VMOVHPD(ops ...Operand) { o.a.op("VMOVHPD", ops...) }
func (o Opcodes) Vmovhps(ops ...Operand) { o.a.op("VMOVHPS", ops...) }
func (o Opcodes) VMOVHPS(ops ...Operand) { o.a.op("VMOVHPS", ops...) }
func (o Opcodes) Vmovlhps(ops ...Operand) { o.a.op("VMOVLHPS", ops...) }
func (o Opcodes) VMOVLHPS(ops ...Operand) { o.a.op("VMOVLHPS", ops...) }
func (o Opcodes) Vmovlpd(ops ...Operand) { o.a.op("VMOVLPD", ops...) }
func (o Opcodes) VMOVLPD(ops ...Operand) { o.a.op("VMOVLPD", ops...) }
func (o Opcodes) Vmovlps(ops ...Operand) { o.a.op("VMOVLPS", ops...) }
func (o Opcodes) VMOVLPS(ops ...Operand) { o.a.op("VMOVLPS", ops...) }
func (o Opcodes) Vmovmskpd(ops ...Operand) { o.a.op("VMOVMSKPD", ops...) }
func (o Opcodes) VMOVMSKPD(ops ...Operand) { o.a.op("VMOVMSKPD", ops...) }
func (o Opcodes) Vmovmskps(ops ...Operand) { o.a.op("VMOVMSKPS", ops...) }
func (o Opcodes) VMOVMSKPS(ops ...Operand) { o.a.op("VMOVMSKPS", ops...) }
func (o Opcodes) Vmovntdq(ops ...Operand) { o.a.op("VMOVNTDQ", ops...) }
func (o Opcodes) VMOVNTDQ(ops ...Operand) { o.a.op("VMOVNTDQ", ops...) }
func (o Opcodes) Vmovntdqa(ops ...Operand) { o.a.op("VMOVNTDQA", ops...) }
func (o Opcodes) VMOVNTDQA(ops ...Operand) { o.a.op("VMOVNTDQA", ops...) }
func (o Opcodes) Vmovntpd(ops ...Operand) { o.a.op("VMOVNTPD", ops...) }
func (o Opcodes) VMOVNTPD(ops ...Operand) { o.a.op("VMOVNTPD", ops...) }
func (o Opcodes) Vmovntps(ops ...Operand) { o.a.op("VMOVNTPS", ops...) }
func (o Opcodes) VMOVNTPS(ops ...Operand) { o.a.op("VMOVNTPS", ops...) }
func (o Opcodes) Vmovq(ops ...Operand) { o.a.op("VMOVQ", ops...) }
func (o Opcodes) VMOVQ(ops ...Operand) { o.a.op("VMOVQ", ops...) }
func (o Opcodes) Vmovsd(ops ...Operand) { o.a.op("VMOVSD", ops...) }
func (o Opcodes) VMOVSD(ops ...Operand) { o.a.op("VMOVSD", ops...) }
func (o Opcodes) Vmovshdup(ops ...Operand) { o.a.op("VMOVSHDUP", ops...) }
func (o Opcodes) VMOVSHDUP(ops ...Operand) { o.a.op("VMOVSHDUP", ops...) }
func (o Opcodes) Vmovsldup(ops ...Operand) { o.a.op("VMOVSLDUP", ops...) }
func (o Opcodes) VMOVSLDUP(ops ...Operand) { o.a.op("VMOVSLDUP", ops...) }
func (o Opcodes) Vmovss(ops ...Operand) { o.a.op("VMOVSS", ops...) }
func (o Opcodes) VMOVSS(ops ...Operand) { o.a.op("VMOVSS", ops...) }
func (o Opcodes) Vmovupd(ops ...Operand) { o.a.op("VMOVUPD", ops...) }
func (o Opcodes) VMOVUPD(ops ...Operand) { o.a.op("VMOVUPD", ops...) }
func (o Opcodes) Vmovups(ops ...Operand) { o.a.op("VMOVUPS", ops...) }
func (o Opcodes) VMOVUPS(ops ...Operand) { o.a.op("VMOVUPS", ops...) }
func (o Opcodes) Vmpsadbw(ops ...Operand) { o.a.op("VMPSADBW", ops...) }
func (o Opcodes) VMPSADBW(ops ...Operand) { o.a.op("VMPSADBW", ops...) }
func (o Opcodes) Vmulpd(ops ...Operand) { o.a.op("VMULPD", ops...) }
func (o Opcodes) VMULPD(ops ...Operand) { o.a.op("VMULPD", ops...) }
func (o Opcodes) Vmulps(ops ...Operand) { o.a.op("VMULPS", ops...) }
func (o Opcodes) VMULPS(ops ...Operand) { o.a.op("VMULPS", ops...) }
func (o Opcodes) Vmulsd(ops ...Operand) { o.a.op("VMULSD", ops...) }
func (o Opcodes) VMULSD(ops ...Operand) { o.a.op("VMULSD", ops...) }
func (o Opcodes) Vmulss(ops ...Operand) { o.a.op("VMULSS", ops...) }
func (o Opcodes) VMULSS(ops ...Operand) { o.a.op("VMULSS", ops...) }
func (o Opcodes) Vorpd(ops ...Operand) { o.a.op("VORPD", ops...) }
func (o Opcodes) VORPD(ops ...Operand) { o.a.op("VORPD", ops...) }
func (o Opcodes) Vorps(ops ...Operand) { o.a.op("VORPS", ops...) }
func (o Opcodes) VORPS(ops ...Operand) { o.a.op("VORPS", ops...) }
func (o Opcodes) Vpabsb(ops ...Operand) { o.a.op("VPABSB", ops...) }
func (o Opcodes) VPABSB(ops ...Operand) { o.a.op("VPABSB", ops...) }
func (o Opcodes) Vpabsd(ops ...Operand) { o.a.op("VPABSD", ops...) }
func (o Opcodes) VPABSD(ops ...Operand) { o.a.op("VPABSD", ops...) }
func (o Opcodes) Vpabsw(ops ...Operand) { o.a.op("VPABSW", ops...) }
func (o Opcodes) VPABSW(ops ...Operand) { o.a.op("VPABSW", ops...) }
func (o Opcodes) Vpackssdw(ops ...Operand) { o.a.op("VPACKSSDW", ops...) }
func (o Opcodes) VPACKSSDW(ops ...Operand) { o.a.op("VPACKSSDW", ops...) }
func (o Opcodes) Vpacksswb(ops ...Operand) { o.a.op("VPACKSSWB", ops...) }
func (o Opcodes) VPACKSSWB(ops ...Operand) { o.a.op("VPACKSSWB", ops...) }
func (o Opcodes) Vpackusdw(ops ...Operand) { o.a.op("VPACKUSDW", ops...) }
func (o Opcodes) VPACKUSDW(ops ...Operand) { o.a.op("VPACKUSDW", ops...) }
func (o Opcodes) Vpackuswb(ops ...Operand) { o.a.op("VPACKUSWB", ops...) }
func (o Opcodes) VPACKUSWB(ops ...Operand) { o.a.op("VPACKUSWB", ops...) }
func (o Opcodes) Vpaddb(ops ...Operand) { o.a.op("VPADDB", ops...) }
func (o Opcodes) VPADDB(ops ...Operand) { o.a.op("VPADDB", ops...) }
func (o Opcodes) Vpaddd(ops ...Operand) { o.a.op("VPADDD", ops...) }
func (o Opcodes) VPADDD(ops ...Operand) { o.a.op("VPADDD", ops...) }
func (o Opcodes) Vpaddq(ops ...Operand) { o.a.op("VPADDQ", ops...) }
func (o Opcodes) VPADDQ(ops ...Operand) { o.a.op("VPADDQ", ops...) }
func (o Opcodes) Vpaddsb(ops ...Operand) { o.a.op("VPADDSB", ops...) }
func (o Opcodes) VPADDSB(ops ...Operand) { o.a.op("VPADDSB", ops...) }
func (o Opcodes) Vpaddsw(ops ...Operand) { o.a.op("VPADDSW", ops...) }
func (o Opcodes) VPADDSW(ops ...Operand) { o.a.op("VPADDSW", ops...) }
func (o Opcodes) Vpaddusb(ops ...Operand) { o.a.op("VPADDUSB", ops...) }
func (o Opcodes) VPADDUSB(ops ...Operand) { o.a.op("VPADDUSB", ops...) }
func (o Opcodes) Vpaddusw(ops ...Operand) { o.a.op("VPADDUSW", ops...) }
func (o Opcodes) VPADDUSW(ops ...Operand) { o.a.op("VPADDUSW", ops...) }
func (o Opcodes) Vpaddw(ops ...Operand) { o.a.op("VPADDW", ops...) }
func (o Opcodes) VPADDW(ops ...Operand) { o.a.op("VPADDW", ops...) }
func (o Opcodes) Vpalignr(ops ...Operand) { o.a.op("VPALIGNR", ops...) }
func (o Opcodes) VPALIGNR(ops ...Operand) { o.a.op("VPALIGNR", ops...) }
func (o Opcodes) Vpand(ops ...Operand) { o.a.op("VPAND", ops...) }
func (o Opcodes) VPAND(ops ...Operand) { o.a.op("VPAND", ops...) }
func (o Opcodes) Vpandn(ops ...Operand) { o.a.op("VPANDN", ops...) }
func (o Opcodes) VPANDN(ops ...Operand) { o.a.op("VPANDN", ops...) }
func (o Opcodes) Vpavgb(ops ...Operand) { o.a.op("VPAVGB", ops...) }
func (o Opcodes) VPAVGB(ops ...Operand) { o.a.op("VPAVGB", ops...) }
func (o Opcodes) Vpavgw(ops ...Operand) { o.a.op("VPAVGW", ops...) }
func (o Opcodes) VPAVGW(ops ...Operand) { o.a.op("VPAVGW", ops...) }
func (o Opcodes) Vpblendd(ops ...Operand) { o.a.op("VPBLENDD", ops...) }
func (o Opcodes) VPBLENDD(ops ...Operand) { o.a.op("VPBLENDD", ops...) }
func (o Opcodes) Vpblendvb(ops ...Operand) { o.a.op("VPBLENDVB", ops...) }
func (o Opcodes) VPBLENDVB(ops ...Operand) { o.a.op("VPBLENDVB", ops...) }
func (o Opcodes) Vpblendw(ops ...Operand) { o.a.op("VPBLENDW", ops...) }
func (o Opcodes) VPBLENDW(ops ...Operand) { o.a.op("VPBLENDW", ops...) }
func (o Opcodes) Vpbroadcastb(ops ...Operand) { o.a.op("VPBROADCASTB", ops...) }
func (o Opcodes) VPBROADCASTB(ops ...Operand) { o.a.op("VPBROADCASTB", ops...) }
func (o Opcodes) Vpbroadcastd(ops ...Operand) { o.a.op("VPBROADCASTD", ops...) }
func (o Opcodes) VPBROADCASTD(ops ...Operand) { o.a.op("VPBROADCASTD", ops...) }
func (o Opcodes) Vpbroadcastq(ops ...Operand) { o.a.op("VPBROADCASTQ", ops...) }
func (o Opcodes) VPBROADCASTQ(ops ...Operand) { o.a.op("VPBROADCASTQ", ops...) }
func (o Opcodes) Vpbroadcastw(ops ...Operand) { o.a.op("VPBROADCASTW", ops...) }
func (o Opcodes) VPBROADCASTW(ops ...Operand) { o.a.op("VPBROADCASTW", ops...) }
func (o Opcodes) Vpclmulqdq(ops ...Operand) { o.a.op("VPCLMULQDQ", ops...) }
func (o Opcodes) VPCLMULQDQ(ops ...Operand) { o.a.op("VPCLMULQDQ", ops...) }
func (o Opcodes) Vpcmpeqb(ops ...Operand) { o.a.op("VPCMPEQB", ops...) }
func (o Opcodes) VPCMPEQB(ops ...Operand) { o.a.op("VPCMPEQB", ops...) }
func (o Opcodes) Vpcmpeqd(ops ...Operand) { o.a.op("VPCMPEQD", ops...) }
func (o Opcodes) VPCMPEQD(ops ...Operand) { o.a.op("VPCMPEQD", ops...) }
func (o Opcodes) Vpcmpeqq(ops ...Operand) { o.a.op("VPCMPEQQ", ops...) }
func (o Opcodes) VPCMPEQQ(ops ...Operand) { o.a.op("VPCMPEQQ", ops...) }
func (o Opcodes) Vpcmpeqw(ops ...Operand) { o.a.op("VPCMPEQW", ops...) }
func (o Opcodes) VPCMPEQW(ops ...Operand) { o.a.op("VPCMPEQW", ops...) }
func (o Opcodes) Vpcmpestri(ops ...Operand) { o.a.op("VPCMPESTRI", ops...) }
func (o Opcodes) VPCMPESTRI(ops ...Operand) { o.a.op("VPCMPESTRI", ops...) }
func (o Opcodes) Vpcmpestrm(ops ...Operand) { o.a.op("VPCMPESTRM", ops...) }
func (o Opcodes) VPCMPESTRM(ops ...Operand) { o.a.op("VPCMPESTRM", ops...) }
func (o Opcodes) Vpcmpgtb(ops ...Operand) { o.a.op("VPCMPGTB", ops...) }
func (o Opcodes) VPCMPGTB(ops ...Operand) { o.a.op("VPCMPGTB", ops...) }
func (o Opcodes) Vpcmpgtd(ops ...Operand) { o.a.op("VPCMPGTD", ops...) }
func (o Opcodes) VPCMPGTD(ops ...Operand) { o.a.op("VPCMPGTD", ops...) }
func (o Opcodes) Vpcmpgtq(ops ...Operand) { o.a.op("VPCMPGTQ", ops...) }
func (o Opcodes) VPCMPGTQ(ops ...Operand) { o.a.op("VPCMPGTQ", ops...) }
func (o Opcodes) Vpcmpgtw(ops ...Operand) { o.a.op("VPCMPGTW", ops...) }
func (o Opcodes) VPCMPGTW(ops ...Operand) { o.a.op("VPCMPGTW", ops...) }
func (o Opcodes) Vpcmpistri(ops ...Operand) { o.a.op("VPCMPISTRI", ops...) }
func (o Opcodes) VPCMPISTRI(ops ...Operand) { o.a.op("VPCMPISTRI", ops...) }
func (o Opcodes) Vpcmpistrm(ops ...Operand) { o.a.op("VPCMPISTRM", ops...) }
func (o Opcodes) VPCMPISTRM(ops ...Operand) { o.a.op("VPCMPISTRM", ops...) }
func (o Opcodes) Vperm2f128(ops ...Operand) { o.a.op("VPERM2F128", ops...) }
func (o Opcodes) VPERM2F128(ops ...Operand) { o.a.op("VPERM2F128", ops...) }
func (o Opcodes) Vperm2i128(ops ...Operand) { o.a.op("VPERM2I128", ops...) }
func (o Opcodes) VPERM2I128(ops ...Operand) { o.a.op("VPERM2I128", ops...) }
func (o Opcodes) Vpermd(ops ...Operand) { o.a.op("VPERMD", ops...) }
func (o Opcodes) VPERMD(ops ...Operand) { o.a.op("VPERMD", ops...) }
func (o Opcodes) Vpermilpd(ops ...Operand) { o.a.op("VPERMILPD", ops...) }
func (o Opcodes) VPERMILPD(ops ...Operand) { o.a.op("VPERMILPD", ops...) }
func (o Opcodes) Vpermilps(ops ...Operand) { o.a.op("VPERMILPS", ops...) }
func (o Opcodes) VPERMILPS(ops ...Operand) { o.a.op("VPERMILPS", ops...) }
func (o Opcodes) Vpermpd(ops ...Operand) { o.a.op("VPERMPD", ops...) }
func (o Opcodes) VPERMPD(ops ...Operand) { o.a.op("VPERMPD", ops...) }
func (o Opcodes) Vpermps(ops ...Operand) { o.a.op("VPERMPS", ops...) }
func (o Opcodes) VPERMPS(ops ...Operand) { o.a.op("VPERMPS", ops...) }
func (o Opcodes) Vpermq(ops ...Operand) { o.a.op("VPERMQ", ops...) }
func (o Opcodes) VPERMQ(ops ...Operand) { o.a.op("VPERMQ", ops...) }
func (o Opcodes) Vpextrb(ops ...Operand) { o.a.op("VPEXTRB", ops...) }
func (o Opcodes) VPEXTRB(ops ...Operand) { o.a.op("VPEXTRB", ops...) }
func (o Opcodes) Vpextrd(ops ...Operand) { o.a.op("VPEXTRD", ops...) }
func (o Opcodes) VPEXTRD(ops ...Operand) { o.a.op("VPEXTRD", ops...) }
func (o Opcodes) Vpextrq(ops ...Operand) { o.a.op("VPEXTRQ", ops...) }
func (o Opcodes) VPEXTRQ(ops ...Operand) { o.a.op("VPEXTRQ", ops...) }
func (o Opcodes) Vpextrw(ops ...Operand) { o.a.op("VPEXTRW", ops...) }
func (o Opcodes) VPEXTRW(ops ...Operand) { o.a.op("VPEXTRW", ops...) }
func (o Opcodes) Vpgatherdd(ops ...Operand) { o.a.op("VPGATHERDD", ops...) }
func (o Opcodes) VPGATHERDD(ops ...Operand) { o.a.op("VPGATHERDD", ops...) }
func (o Opcodes) Vpgatherdq(ops ...Operand) { o.a.op("VPGATHERDQ", ops...) }
func (o Opcodes) VPGATHERDQ(ops ...Operand) { o.a.op("VPGATHERDQ", ops...) }
func (o Opcodes) Vpgatherqd(ops ...Operand) { o.a.op("VPGATHERQD", ops...) }
func (o Opcodes) VPGATHERQD(ops ...Operand) { o.a.op("VPGATHERQD", ops...) }
func (o Opcodes) Vpgatherqq(ops ...Operand) { o.a.op("VPGATHERQQ", ops...) }
func (o Opcodes) VPGATHERQQ(ops ...Operand) { o.a.op("VPGATHERQQ", ops...) }
func (o Opcodes) Vphaddd(ops ...Operand) { o.a.op("VPHADDD", ops...) }
func (o Opcodes) VPHADDD(ops ...Operand) { o.a.op("VPHADDD", ops...) }
func (o Opcodes) Vphaddsw(ops ...Operand) { o.a.op("VPHADDSW", ops...) }
func (o Opcodes) VPHADDSW(ops ...Operand) { o.a.op("VPHADDSW", ops...) }
func (o Opcodes) Vphaddw(ops ...Operand) { o.a.op("VPHADDW", ops...) }
func (o Opcodes) VPHADDW(ops ...Operand) { o.a.op("VPHADDW", ops...) }
func (o Opcodes) Vphminposuw(ops ...Operand) { o.a.op("VPHMINPOSUW", ops...) }
func (o Opcodes) VPHMINPOSUW(ops ...Operand) { o.a.op("VPHMINPOSUW", ops...) }
func (o Opcodes) Vphsubd(ops ...Operand) { o.a.op("VPHSUBD", ops...) }
func (o Opcodes) VPHSUBD(ops ...Operand) { o.a.op("VPHSUBD", ops...) }
func (o Opcodes) Vphsubsw(ops ...Operand) { o.a.op("VPHSUBSW", ops...) }
func (o Opcodes) VPHSUBSW(ops ...Operand) { o.a.op("VPHSUBSW", ops...) }
func (o Opcodes) Vphsubw(ops ...Operand) { o.a.op("VPHSUBW", ops...) }
func (o Opcodes) VPHSUBW(ops ...Operand) { o.a.op("VPHSUBW", ops...) }
func (o Opcodes) Vpinsrb(ops ...Operand) { o.a.op("VPINSRB", ops...) }
func (o Opcodes) VPINSRB(ops ...Operand) { o.a.op("VPINSRB", ops...) }
func (o Opcodes) Vpinsrd(ops ...Operand) { o.a.op("VPINSRD", ops...) }
func (o Opcodes) VPINSRD(ops ...Operand) { o.a.op("VPINSRD", ops...) }
func (o Opcodes) Vpinsrq(ops ...Operand) { o.a.op("VPINSRQ", ops...) }
func (o Opcodes) VPINSRQ(ops ...Operand) { o.a.op("VPINSRQ", ops...) }
func (o Opcodes) Vpinsrw(ops ...Operand) { o.a.op("VPINSRW", ops...) }
func (o Opcodes) VPINSRW(ops ...Operand) { o.a.op("VPINSRW", ops...) }
func (o Opcodes) Vpmaddubsw(ops ...Operand) { o.a.op("VPMADDUBSW", ops...) }
func (o Opcodes) VPMADDUBSW(ops ...Operand) { o.a.op("VPMADDUBSW", ops...) }
func (o Opcodes) Vpmaddwd(ops ...Operand) { o.a.op("VPMADDWD", ops...) }
func (o Opcodes) VPMADDWD(ops ...Operand) { o.a.op("VPMADDWD", ops...) }
func (o Opcodes) Vpmaskmovd(ops ...Operand) { o.a.op("VPMASKMOVD", ops...) }
func (o Opcodes) VPMASKMOVD(ops ...Operand) { o.a.op("VPMASKMOVD", ops...) }
func (o Opcodes) Vpmaskmovq(ops ...Operand) { o.a.op("VPMASKMOVQ", ops...) }
func (o Opcodes) VPMASKMOVQ(ops ...Operand) { o.a.op("VPMASKMOVQ", ops...) }
func (o Opcodes) Vpmaxsb(ops ...Operand) { o.a.op("VPMAXSB", ops...) }
func (o Opcodes) VPMAXSB(ops ...Operand) { o.a.op("VPMAXSB", ops...) }
func (o Opcodes) Vpmaxsd(ops ...Operand) { o.a.op("VPMAXSD", ops...) }
func (o Opcodes) VPMAXSD(ops ...Operand) { o.a.op("VPMAXSD", ops...) }
func (o Opcodes) Vpmaxsw(ops ...Operand) { o.a.op("VPMAXSW", ops...) }
func (o Opcodes) VPMAXSW(ops ...Operand) { o.a.op("VPMAXSW", ops...) }
func (o Opcodes) Vpmaxub(ops ...Operand) { o.a.op("VPMAXUB", ops...) }
func (o Opcodes) VPMAXUB(ops ...Operand) { o.a.op("VPMAXUB", ops...) }
func (o Opcodes) Vpmaxud(ops ...Operand) { o.a.op("VPMAXUD", ops...) }
func (o Opcodes) VPMAXUD(ops ...Operand) { o.a.op("VPMAXUD", ops...) }
func (o Opcodes) Vpmaxuw(ops ...Operand) { o.a.op("VPMAXUW", ops...) }
func (o Opcodes) VPMAXUW(ops ...Operand) { o.a.op("VPMAXUW", ops...) }
func (o Opcodes) Vpminsb(ops ...Operand) { o.a.op("VPMINSB", ops...) }
func (o Opcodes) VPMINSB(ops ...Operand) { o.a.op("VPMINSB", ops...) }
func (o Opcodes) Vpminsd(ops ...Operand) { o.a.op("VPMINSD", ops...) }
func (o Opcodes) VPMINSD(ops ...Operand) { o.a.op("VPMINSD", ops...) }
func (o Opcodes) Vpminsw(ops ...Operand) { o.a.op("VPMINSW", ops...) }
func (o Opcodes) VPMINSW(ops ...Operand) { o.a.op("VPMINSW", ops...) }
func (o Opcodes) Vpminub(ops ...Operand) { o.a.op("VPMINUB", ops...) }
func (o Opcodes) VPMINUB(ops ...Operand) { o.a.op("VPMINUB", ops...) }
func (o Opcodes) Vpminud(ops ...Operand) { o.a.op("VPMINUD", ops...) }
func (o Opcodes) VPMINUD(ops ...Operand) { o.a.op("VPMINUD", ops...) }
func (o Opcodes) Vpminuw(ops ...Operand) { o.a.op("VPMINUW", ops...) }
func (o Opcodes) VPMINUW(ops ...Operand) { o.a.op("VPMINUW", ops...) }
func (o Opcodes) Vpmovmskb(ops ...Operand) { o.a.op("VPMOVMSKB", ops...) }
func (o Opcodes) VPMOVMSKB(ops ...Operand) { o.a.op("VPMOVMSKB", ops...) }
func (o Opcodes) Vpmovsxbd(ops ...Operand) { o.a.op("VPMOVSXBD", ops...) }
func (o Opcodes) VPMOVSXBD(ops ...Operand) { o.a.op("VPMOVSXBD", ops...) }
func (o Opcodes) Vpmovsxbq(ops ...Operand) { o.a.op("VPMOVSXBQ", ops...) }
func (o Opcodes) VPMOVSXBQ(ops ...Operand) { o.a.op("VPMOVSXBQ", ops...) }
func (o Opcodes) Vpmovsxbw(ops ...Operand) { o.a.op("VPMOVSXBW", ops...) }
func (o Opcodes) VPMOVSXBW(ops ...Operand) { o.a.op("VPMOVSXBW", ops...) }
func (o Opcodes) Vpmovsxdq(ops ...Operand) { o.a.op("VPMOVSXDQ", ops...) }
func (o Opcodes) VPMOVSXDQ(ops ...Operand) { o.a.op("VPMOVSXDQ", ops...) }
func (o Opcodes) Vpmovsxwd(ops ...Operand) { o.a.op("VPMOVSXWD", ops...) }
func (o Opcodes) VPMOVSXWD(ops ...Operand) { o.a.op("VPMOVSXWD", ops...) }
func (o Opcodes) Vpmovsxwq(ops ...Operand) { o.a.op("VPMOVSXWQ", ops...) }
func (o Opcodes) VPMOVSXWQ(ops ...Operand) { o.a.op("VPMOVSXWQ", ops...) }
func (o Opcodes) Vpmovzxbd(ops ...Operand) { o.a.op("VPMOVZXBD", ops...) }
func (o Opcodes) VPMOVZXBD(ops ...Operand) { o.a.op("VPMOVZXBD", ops...) }
func (o Opcodes) Vpmovzxbq(ops ...Operand) { o.a.op("VPMOVZXBQ", ops...) }
func (o Opcodes) VPMOVZXBQ(ops ...Operand) { o.a.op("VPMOVZXBQ", ops...) }
func (o Opcodes) Vpmovzxbw(ops ...Operand) { o.a.op("VPMOVZXBW", ops...) }
func (o Opcodes) VPMOVZXBW(ops ...Operand) { o.a.op("VPMOVZXBW", ops...) }
func (o Opcodes) Vpmovzxdq(ops ...Operand) { o.a.op("VPMOVZXDQ", ops...) }
func (o Opcodes) VPMOVZXDQ(ops ...Operand) { o.a.op("VPMOVZXDQ", ops...) }
func (o Opcodes) Vpmovzxwd(ops ...Operand) { o.a.op("VPMOVZXWD", ops...) }
func (o Opcodes) VPMOVZXWD(ops ...Operand) { o.a.op("VPMOVZXWD", ops...) }
func (o Opcodes) Vpmovzxwq(ops ...Operand) { o.a.op("VPMOVZXWQ", ops...) }
func (o Opcodes) VPMOVZXWQ(ops ...Operand) { o.a.op("VPMOVZXWQ", ops...) }
func (o Opcodes) Vpmuldq(ops ...Operand) { o.a.op("VPMULDQ", ops...) }
func (o Opcodes) VPMULDQ(ops ...Operand) { o.a.op("VPMULDQ", ops...) }
func (o Opcodes) Vpmulhrsw(ops ...Operand) { o.a.op("VPMULHRSW", ops...) }
func (o Opcodes) VPMULHRSW(ops ...Operand) { o.a.op("VPMULHRSW", ops...) }
func (o Opcodes) Vpmulhuw(ops ...Operand) { o.a.op("VPMULHUW", ops...) }
func (o Opcodes) VPMULHUW(ops ...Operand) { o.a.op("VPMULHUW", ops...) }
func (o Opcodes) Vpmulhw(ops ...Operand) { o.a.op("VPMULHW", ops...) }
func (o Opcodes) VPMULHW(ops ...Operand) { o.a.op("VPMULHW", ops...) }
func (o Opcodes) Vpmulld(ops ...Operand) { o.a.op("VPMULLD", ops...) }
func (o Opcodes) VPMULLD(ops ...Operand) { o.a.op("VPMULLD", ops...) }
func (o Opcodes) Vpmullw(ops ...Operand) { o.a.op("VPMULLW", ops...) }
func (o Opcodes) VPMULLW(ops ...Operand) { o.a.op("VPMULLW", ops...) }
func (o Opcodes) Vpmuludq(ops ...Operand) { o.a.op("VPMULUDQ", ops...) }
func (o Opcodes) VPMULUDQ(ops ...Operand) { o.a.op("VPMULUDQ", ops...) }
func (o Opcodes) Vpor(ops ...Operand) { o.a.op("VPOR", ops...) }
func (o Opcodes) VPOR(ops ...Operand) { o.a.op("VPOR", ops...) }
func (o Opcodes) Vpsadbw(ops ...Operand) { o.a.op("VPSADBW", ops...) }
func (o Opcodes) VPSADBW(ops ...Operand) { o.a.op("VPSADBW", ops...) }
func (o Opcodes) Vpshufb(ops ...Operand) { o.a.op("VPSHUFB", ops...) }
func (o Opcodes) VPSHUFB(ops ...Operand) { o.a.op("VPSHUFB", ops...) }
func (o Opcodes) Vpshufd(ops ...Operand) { o.a.op("VPSHUFD", ops...) }
func (o Opcodes) VPSHUFD(ops ...Operand) { o.a.op("VPSHUFD", ops...) }
func (o Opcodes) Vpshufhw(ops ...Operand) { o.a.op("VPSHUFHW", ops...) }
func (o Opcodes) VPSHUFHW(ops ...Operand) { o.a.op("VPSHUFHW", ops...) }
func (o Opcodes) Vpshuflw(ops ...Operand) { o.a.op("VPSHUFLW", ops...) }
func (o Opcodes) VPSHUFLW(ops ...Operand) { o.a.op("VPSHUFLW", ops...) }
func (o Opcodes) Vpsignb(ops ...Operand) { o.a.op("VPSIGNB", ops...) }
func (o Opcodes) VPSIGNB(ops ...Operand) { o.a.op("VPSIGNB", ops...) }
func (o Opcodes) Vpsignd(ops ...Operand) { o.a.op("VPSIGND", ops...) }
func (o Opcodes) VPSIGND(ops ...Operand) { o.a.op("VPSIGND", ops...) }
func (o Opcodes) Vpsignw(ops ...Operand) { o.a.op("VPSIGNW", ops...) }
func (o Opcodes) VPSIGNW(ops ...Operand) { o.a.op("VPSIGNW", ops...) }
func (o Opcodes) Vpslld(ops ...Operand) { o.a.op("VPSLLD", ops...) }
func (o Opcodes) VPSLLD(ops ...Operand) { o.a.op("VPSLLD", ops...) }
func (o Opcodes) Vpslldq(ops ...Operand) { o.a.op("VPSLLDQ", ops...) }
func (o Opcodes) VPSLLDQ(ops ...Operand) { o.a.op("VPSLLDQ", ops...) }
func (o Opcodes) Vpsllq(ops ...Operand) { o.a.op("VPSLLQ", ops...) }
func (o Opcodes) VPSLLQ(ops ...Operand) { o.a.op("VPSLLQ", ops...) }
func (o Opcodes) Vpsllvd(ops ...Operand) { o.a.op("VPSLLVD", ops...) }
func (o Opcodes) VPSLLVD(ops ...Operand) { o.a.op("VPSLLVD", ops...) }
func (o Opcodes) Vpsllvq(ops ...Operand) { o.a.op("VPSLLVQ", ops...) }
func (o Opcodes) VPSLLVQ(ops ...Operand) { o.a.op("VPSLLVQ", ops...) }
func (o Opcodes) Vpsllw(ops ...Operand) { o.a.op("VPSLLW", ops...) }
func (o Opcodes) VPSLLW(ops ...Operand) { o.a.op("VPSLLW", ops...) }
func (o Opcodes) Vpsrad(ops ...Operand) { o.a.op("VPSRAD", ops...) }
func (o Opcodes) VPSRAD(ops ...Operand) { o.a.op("VPSRAD", ops...) }
func (o Opcodes) Vpsravd(ops ...Operand) { o.a.op("VPSRAVD", ops...) }
func (o Opcodes) VPSRAVD(ops ...Operand) { o.a.op("VPSRAVD", ops...) }
func (o Opcodes) Vpsraw(ops ...Operand) { o.a.op("VPSRAW", ops...) }
func (o Opcodes) VPSRAW(ops ...Operand) { o.a.op("VPSRAW", ops...) }
func (o Opcodes) Vpsrld(ops ...Operand) { o.a.op("VPSRLD", ops...) }
func (o Opcodes) VPSRLD(ops ...Operand) { o.a.op("VPSRLD", ops...) }
func (o Opcodes) Vpsrldq(ops ...Operand) { o.a.op("VPSRLDQ", ops...) }
func (o Opcodes) VPSRLDQ(ops ...Operand) { o.a.op("VPSRLDQ", ops...) }
func (o Opcodes) Vpsrlq(ops ...Operand) { o.a.op("VPSRLQ", ops...) }
func (o Opcodes) VPSRLQ(ops ...Operand) { o.a.op("VPSRLQ", ops...) }
func (o Opcodes) Vpsrlvd(ops ...Operand) { o.a.op("VPSRLVD", ops...) }
func (o Opcodes) VPSRLVD(ops ...Operand) { o.a.op("VPSRLVD", ops...) }
func (o Opcodes) Vpsrlvq(ops ...Operand) { o.a.op("VPSRLVQ", ops...) }
func (o Opcodes) VPSRLVQ(ops ...Operand) { o.a.op("VPSRLVQ", ops...) }
func (o Opcodes) Vpsrlw(ops ...Operand) { o.a.op("VPSRLW", ops...) }
func (o Opcodes) VPSRLW(ops ...Operand) { o.a.op("VPSRLW", ops...) }
func (o Opcodes) Vpsubb(ops ...Operand) { o.a.op("VPSUBB", ops...) }
func (o Opcodes) VPSUBB(ops ...Operand) { o.a.op("VPSUBB", ops...) }
func (o Opcodes) Vpsubd(ops ...Operand) { o.a.op("VPSUBD", ops...) }
func (o Opcodes) VPSUBD(ops ...Operand) { o.a.op("VPSUBD", ops...) }
func (o Opcodes) Vpsubq(ops ...Operand) { o.a.op("VPSUBQ", ops...) }
func (o Opcodes) VPSUBQ(ops ...Operand) { o.a.op("VPSUBQ", ops...) }
func (o Opcodes) Vpsubsb(ops ...Operand) { o.a.op("VPSUBSB", ops...) }
func (o Opcodes) VPSUBSB(ops ...Operand) { o.a.op("VPSUBSB", ops...) }
func (o Opcodes) Vpsubsw(ops ...Operand) { o.a.op("VPSUBSW", ops...) }
func (o Opcodes) VPSUBSW(ops ...Operand) { o.a.op("VPSUBSW", ops...) }
func (o Opcodes) Vpsubusb(ops ...Operand) { o.a.op("VPSUBUSB", ops...) }
func (o Opcodes) VPSUBUSB(ops ...Operand) { o.a.op("VPSUBUSB", ops...) }
func (o Opcodes) Vpsubusw(ops ...Operand) { o.a.op("VPSUBUSW", ops...) }
func (o Opcodes) VPSUBUSW(ops ...Operand) { o.a.op("VPSUBUSW", ops...) }
func (o Opcodes) Vpsubw(ops ...Operand) { o.a.op("VPSUBW", ops...) }
func (o Opcodes) VPSUBW(ops ...Operand) { o.a.op("VPSUBW", ops...) }
func (o Opcodes) Vptest(ops ...Operand) { o.a.op("VPTEST", ops...) }
func (o Opcodes) VPTEST(ops ...Operand) { o.a.op("VPTEST", ops...) }
func (o Opcodes) Vpunpckhbw(ops ...Operand) { o.a.op("VPUNPCKHBW", ops...) }
func (o Opcodes) VPUNPCKHBW(ops ...Operand) { o.a.op("VPUNPCKHBW", ops...) }
func (o Opcodes) Vpunpckhdq(ops ...Operand) { o.a.op("VPUNPCKHDQ", ops...) }
func (o Opcodes) VPUNPCKHDQ(ops ...Operand) { o.a.op("VPUNPCKHDQ", ops...) }
func (o Opcodes) Vpunpckhqdq(ops ...Operand) { o.a.op("VPUNPCKHQDQ", ops...) }
func (o Opcodes) VPUNPCKHQDQ(ops ...Operand) { o.a.op("VPUNPCKHQDQ", ops...) }
func (o Opcodes) Vpunpckhwd(ops ...Operand) { o.a.op("VPUNPCKHWD", ops...) }
func (o Opcodes) VPUNPCKHWD(ops ...Operand) { o.a.op("VPUNPCKHWD", ops...) }
func (o Opcodes) Vpunpcklbw(ops ...Operand) { o.a.op("VPUNPCKLBW", ops...) }
func (o Opcodes) VPUNPCKLBW(ops ...Operand) { o.a.op("VPUNPCKLBW", ops...) }
func (o Opcodes) Vpunpckldq(ops ...Operand) { o.a.op("VPUNPCKLDQ", ops...) }
func (o Opcodes) VPUNPCKLDQ(ops ...Operand) { o.a.op("VPUNPCKLDQ", ops...) }
func (o Opcodes) Vpunpcklqdq(ops ...Operand) { o.a.op("VPUNPCKLQDQ", ops...) }
func (o Opcodes) VPUNPCKLQDQ(ops ...Operand) { o.a.op("VPUNPCKLQDQ", ops...) }
func (o Opcodes) Vpunpcklwd(ops ...Operand) { o.a.op("VPUNPCKLWD", ops...) }
func (o Opcodes) VPUNPCKLWD(ops ...Operand) { o.a.op("VPUNPCKLWD", ops...) }
func (o Opcodes) Vpxor(ops ...Operand) { o.a.op("VPXOR", ops...) }
func (o Opcodes) VPXOR(ops ...Operand) { o.a.op("VPXOR", ops...) }
func (o Opcodes) Vrcpps(ops ...Operand) { o.a.op("VRCPPS", ops...) }
func (o Opcodes) VRCPPS(ops ...Operand) { o.a.op("VRCPPS", ops...) }
func (o Opcodes) Vrcpss(ops ...Operand) { o.a.op("VRCPSS", ops...) }
func (o Opcodes) VRCPSS(ops ...Operand) { o.a.op("VRCPSS", ops...) }
func (o Opcodes) Vroundpd(ops ...Operand) { o.a.op("VROUNDPD", ops...) }
func (o Opcodes) VROUNDPD(ops ...Operand) { o.a.op("VROUNDPD", ops...) }
func (o Opcodes) Vroundps(ops ...Operand) { o.a.op("VROUNDPS", ops...) }
func (o Opcodes) VROUNDPS(ops ...Operand) { o.a.op("VROUNDPS", ops...) }
func (o Opcodes) Vroundsd(ops ...Operand) { o.a.op("VROUNDSD", ops...) }
func (o Opcodes) VROUNDSD(ops ...Operand) { o.a.op("VROUNDSD", ops...) }
func (o Opcodes) Vroundss(ops ...Operand) { o.a.op("VROUNDSS", ops...) }
func (o Opcodes) VROUNDSS(ops ...Operand) { o.a.op("VROUNDSS", ops...) }
func (o Opcodes) Vrsqrtps(ops ...Operand) { o.a.op("VRSQRTPS", ops...) }
func (o Opcodes) VRSQRTPS(ops ...Operand) { o.a.op("VRSQRTPS", ops...) }
func (o Opcodes) Vrsqrtss(ops ...Operand) { o.a.op("VRSQRTSS", ops...) }
func (o Opcodes) VRSQRTSS(ops ...Operand) { o.a.op("VRSQRTSS", ops...) }
func (o Opcodes) Vshufpd(ops ...Operand) { o.a.op("VSHUFPD", ops...) }
func (o Opcodes) VSHUFPD(ops ...Operand) { o.a.op("VSHUFPD", ops...) }
func (o Opcodes) Vshufps(ops ...Operand) { o.a.op("VSHUFPS", ops...) }
func (o Opcodes) VSHUFPS(ops ...Operand) { o.a.op("VSHUFPS", ops...) }
func (o Opcodes) Vsqrtpd(ops ...Operand) { o.a.op("VSQRTPD", ops...) }
func (o Opcodes) VSQRTPD(ops ...Operand) { o.a.op("VSQRTPD", ops...) }
func (o Opcodes) Vsqrtps(ops ...Operand) { o.a.op("VSQRTPS", ops...) }
func (o Opcodes) VSQRTPS(ops ...Operand) { o.a.op("VSQRTPS", ops...) }
func (o Opcodes) Vsqrtsd(ops ...Operand) { o.a.op("VSQRTSD", ops...) }
func (o Opcodes) VSQRTSD(ops ...Operand) { o.a.op("VSQRTSD", ops...) }
func (o Opcodes) Vsqrtss(ops ...Operand) { o.a.op("VSQRTSS", ops...) }
func (o Opcodes) VSQRTSS(ops ...Operand) { o.a.op("VSQRTSS", ops...) }
func (o Opcodes) Vstmxcsr(ops ...Operand) { o.a.op("VSTMXCSR", ops...) }
func (o Opcodes) VSTMXCSR(ops ...Operand) { o.a.op("VSTMXCSR", ops...) }
func (o Opcodes) Vsubpd(ops ...Operand) { o.a.op("VSUBPD", ops...) }
func (o Opcodes) VSUBPD(ops ...Operand) { o.a.op("VSUBPD", ops...) }
func (o Opcodes) Vsubps(ops ...Operand) { o.a.op("VSUBPS", ops...) }
func (o Opcodes) VSUBPS(ops ...Operand) { o.a.op("VSUBPS", ops...) }
func (o Opcodes) Vsubsd(ops ...Operand) { o.a.op("VSUBSD", ops...) }
func (o Opcodes) VSUBSD(ops ...Operand) { o.a.op("VSUBSD", ops...) }
func (o Opcodes) Vsubss(ops ...Operand) { o.a.op("VSUBSS", ops...) }
func (o Opcodes) VSUBSS(ops ...Operand) { o.a.op("VSUBSS", ops...) }
func (o Opcodes) Vtestpd(ops ...Operand) { o.a.op("VTESTPD", ops...) }
func (o Opcodes) VTESTPD(ops ...Operand) { o.a.op("VTESTPD", ops...) }
func (o Opcodes) Vtestps(ops ...Operand) { o.a.op("VTESTPS", ops...) }
func (o Opcodes) VTESTPS(ops ...Operand) { o.a.op("VTESTPS", ops...) }
func (o Opcodes) Vucomisd(ops ...Operand) { o.a.op("VUCOMISD", ops...) }
func (o Opcodes) VUCOMISD(ops ...Operand) { o.a.op("VUCOMISD", ops...) }
func (o Opcodes) Vucomiss(ops ...Operand) { o.a.op("VUCOMISS", ops...) }
func (o Opcodes) VUCOMISS(ops ...Operand) { o.a.op("VUCOMISS", ops...) }
func (o Opcodes) Vunpckhpd(ops ...Operand) { o.a.op("VUNPCKHPD", ops...) }
func (o Opcodes) VUNPCKHPD(ops ...Operand) { o.a.op("VUNPCKHPD", ops...) }
func (o Opcodes) Vunpckhps(ops ...Operand) { o.a.op("VUNPCKHPS", ops...) }
func (o Opcodes) VUNPCKHPS(ops ...Operand) { o.a.op("VUNPCKHPS", ops...) }
func (o Opcodes) Vunpcklpd(ops ...Operand) { o.a.op("VUNPCKLPD", ops...) }
func (o Opcodes) VUNPCKLPD(ops ...Operand) { o.a.op("VUNPCKLPD", ops...) }
func (o Opcodes) Vunpcklps(ops ...Operand) { o.a.op("VUNPCKLPS", ops...) }
func (o Opcodes) VUNPCKLPS(ops ...Operand) { o.a.op("VUNPCKLPS", ops...) }
func (o Opcodes) Vxorpd(ops ...Operand) { o.a.op("VXORPD", ops...) }
func (o Opcodes) VXORPD(ops ...Operand) { o.a.op("VXORPD", ops...) }
func (o Opcodes) Vxorps(ops ...Operand) { o.a.op("VXORPS", ops...) }
func (o Opcodes) VXORPS(ops ...Operand) { o.a.op("VXORPS", ops...) }
func (o Opcodes) Vzeroall(ops ...Operand) { o.a.op("VZEROALL", ops...) }
func (o Opcodes) VZEROALL(ops ...Operand) { o.a.op("VZEROALL", ops...) }
func (o Opcodes) Vzeroupper(ops ...Operand) { o.a.op("VZEROUPPER", ops...) }
func (o Opcodes) VZEROUPPER(ops ...Operand) { o.a.op("VZEROUPPER", ops...) }
func (o Opcodes) Wait(ops ...Operand) { o.a.op("WAIT", ops...) }
func (o Opcodes) WAIT(ops ...Operand) { o.a.op("WAIT", ops...) }
func (o Opcodes) Wbinvd(ops ...Operand) { o.a.op("WBINVD", ops...) }
func (o Opcodes) WBINVD(ops ...Operand) { o.a.op("WBINVD", ops...) }
func (o Opcodes) Word(ops ...Operand) { o.a.op("WORD", ops...) }
func (o Opcodes) WORD(ops ...Operand) { o.a.op("WORD", ops...) }
func (o Opcodes) Wrmsr(ops ...Operand) { o.a.op("WRMSR", ops...) }
func (o Opcodes) WRMSR(ops ...Operand) { o.a.op("WRMSR", ops...) }
func (o Opcodes) Xabort(ops ...Operand) { o.a.op("XABORT", ops...) }
func (o Opcodes) XABORT(ops ...Operand) { o.a.op("XABORT", ops...) }
func (o Opcodes) Xacquire(ops ...Operand) { o.a.op("XACQUIRE", ops...) }
func (o Opcodes) XACQUIRE(ops ...Operand) { o.a.op("XACQUIRE", ops...) }
func (o Opcodes) Xaddb(ops ...Operand) { o.a.op("XADDB", ops...) }
func (o Opcodes) XADDB(ops ...Operand) { o.a.op("XADDB", ops...) }
func (o Opcodes) Xaddl(ops ...Operand) { o.a.op("XADDL", ops...) }
func (o Opcodes) XADDL(ops ...Operand) { o.a.op("XADDL", ops...) }
func (o Opcodes) Xaddq(ops ...Operand) { o.a.op("XADDQ", ops...) }
func (o Opcodes) XADDQ(ops ...Operand) { o.a.op("XADDQ", ops...) }
func (o Opcodes) Xaddw(ops ...Operand) { o.a.op("XADDW", ops...) }
func (o Opcodes) XADDW(ops ...Operand) { o.a.op("XADDW", ops...) }
func (o Opcodes) Xbegin(ops ...Operand) { o.a.op("XBEGIN", ops...) }
func (o Opcodes) XBEGIN(ops ...Operand) { o.a.op("XBEGIN", ops...) }
func (o Opcodes) Xchgb(ops ...Operand) { o.a.op("XCHGB", ops...) }
func (o Opcodes) XCHGB(ops ...Operand) { o.a.op("XCHGB", ops...) }
func (o Opcodes) Xchgl(ops ...Operand) { o.a.op("XCHGL", ops...) }
func (o Opcodes) XCHGL(ops ...Operand) { o.a.op("XCHGL", ops...) }
func (o Opcodes) Xchgq(ops ...Operand) { o.a.op("XCHGQ", ops...) }
func (o Opcodes) XCHGQ(ops ...Operand) { o.a.op("XCHGQ", ops...) }
func (o Opcodes) Xchgw(ops ...Operand) { o.a.op("XCHGW", ops...) }
func (o Opcodes) XCHGW(ops ...Operand) { o.a.op("XCHGW", ops...) }
func (o Opcodes) Xend(ops ...Operand) { o.a.op("XEND", ops...) }
func (o Opcodes) XEND(ops ...Operand) { o.a.op("XEND", ops...) }
func (o Opcodes) Xgetbv(ops ...Operand) { o.a.op("XGETBV", ops...) }
func (o Opcodes) XGETBV(ops ...Operand) { o.a.op("XGETBV", ops...) }
func (o Opcodes) Xlat(ops ...Operand) { o.a.op("XLAT", ops...) }
func (o Opcodes) XLAT(ops ...Operand) { o.a.op("XLAT", ops...) }
func (o Opcodes) Xorb(ops ...Operand) { o.a.op("XORB", ops...) }
func (o Opcodes) XORB(ops ...Operand) { o.a.op("XORB", ops...) }
func (o Opcodes) Xorl(ops ...Operand) { o.a.op("XORL", ops...) }
func (o Opcodes) XORL(ops ...Operand) { o.a.op("XORL", ops...) }
func (o Opcodes) Xorpd(ops ...Operand) { o.a.op("XORPD", ops...) }
func (o Opcodes) XORPD(ops ...Operand) { o.a.op("XORPD", ops...) }
func (o Opcodes) Xorps(ops ...Operand) { o.a.op("XORPS", ops...) }
func (o Opcodes) XORPS(ops ...Operand) { o.a.op("XORPS", ops...) }
func (o Opcodes) Xorq(ops ...Operand) { o.a.op("XORQ", ops...) }
func (o Opcodes) XORQ(ops ...Operand) { o.a.op("XORQ", ops...) }
func (o Opcodes) Xorw(ops ...Operand) { o.a.op("XORW", ops...) }
func (o Opcodes) XORW(ops ...Operand) { o.a.op("XORW", ops...) }
func (o Opcodes) Xrelease(ops ...Operand) { o.a.op("XRELEASE", ops...) }
func (o Opcodes) XRELEASE(ops ...Operand) { o.a.op("XRELEASE", ops...) }
func (o Opcodes) Xtest(ops ...Operand) { o.a.op("XTEST", ops...) }
func (o Opcodes) XTEST(ops ...Operand) { o.a.op("XTEST", ops...) }
func (o Opcodes) Last(ops ...Operand) { o.a.op("LAST", ops...) }
func (o Opcodes) LAST(ops ...Operand) { o.a.op("LAST", ops...) } | vendor/github.com/tmthrgd/asm/opcode.go | 0.548432 | 0.503662 | opcode.go | starcoder |
package timeseries
import (
"encoding/csv"
"io"
"math"
"strconv"
"strings"
"time"
)
// TODO: create a new type for map[string]Data.
type Datum struct {
Date time.Time
Value float64
}
// Data holds timeseries data.
type Data struct {
Name string
Data []Datum
}
func (h Data) String() string {
return h.Name
}
func (h Data) average() float64 {
var ret float64
for _, d := range h.Data {
ret += d.Value
}
return ret / float64(len(h.Data))
}
func (h Data) variance() float64 {
var ret float64
avg := h.average()
for _, d := range h.Data {
dev := d.Value - avg
ret += dev * dev
}
return ret / float64(len(h.Data))
}
func (h Data) stdDev() float64 {
return math.Sqrt(h.variance())
}
func (h Data) Volatility() float64 {
annualized := h.stdDev() * math.Sqrt(12)
return 100 * annualized
}
func (h Data) Returns() float64 {
var compounded float64 = 1.0
for _, d := range h.Data {
compounded *= 1.0 + d.Value
}
years := float64(len(h.Data)) / 12
annualized := math.Pow(compounded, 1/years)
return 100 * (annualized - 1)
}
func (h Data) SharpeRatio() float64 {
return h.Returns() / h.Volatility()
}
func (h Data) Min() float64 {
var ret float64
for _, d := range h.Data {
if ret == 0 || ret > d.Value {
ret = d.Value
}
}
return ret
}
func (h Data) Max() float64 {
var ret float64
for _, d := range h.Data {
if ret == 0 || ret < d.Value {
ret = d.Value
}
}
return ret
}
func (h Data) Last() float64 {
if len(h.Data) == 0 {
return math.NaN()
}
return h.Data[len(h.Data)-1].Value
}
// Load loads timeseries data from an io.Reader.
func Load(r io.Reader) (map[string]Data, error) {
data, err := csv.NewReader(r).ReadAll()
if err != nil {
return nil, err
}
header := data[0]
ret := make([]Data, len(header)-1)
for i := 1; i < len(header); i++ {
ret[i-1].Name = header[i]
}
for row := 1; row < len(data); row++ {
t, err := time.Parse("2006-01-02", data[row][0])
if err != nil {
return nil, err
}
for col := 1; col < len(data[row]); col++ {
// accept comma as decimal separator, too.
v, err := strconv.ParseFloat(strings.Replace(data[row][col], ",", ".", -1), 64)
if err != nil {
return nil, err
}
ret[col-1].Data = append(ret[col-1].Data, Datum{
Date: t,
Value: v / 100,
})
}
}
m := make(map[string]Data)
for i := 1; i < len(header); i++ {
m[header[i]] = ret[i-1]
}
return m, nil
}
type QuoteProvider interface {
Next() (time.Time, bool)
RelativeValue(string) (float64, error)
}
// Generate uses a QuoteProvider to generate a data set.
func Generate(names []string, qp QuoteProvider) (map[string]Data, error) {
histories := map[string]Data{}
for _, name := range names {
histories[name] = Data{
Name: name,
}
}
for {
date, ok := qp.Next()
if !ok {
break
}
for _, name := range names {
rv, err := qp.RelativeValue(name)
if err != nil {
return nil, err
}
h := histories[name]
h.Data = append(h.Data, Datum{
Date: date,
Value: rv - 1.0,
})
histories[name] = h
}
}
return histories, nil
}
// BySharpeRatio allows to sort a Data slice by their Sharpe Ratio.
type BySharpeRatio []Data
func (b BySharpeRatio) Len() int {
return len(b)
}
func (b BySharpeRatio) Less(i, j int) bool {
return b[i].SharpeRatio() < b[j].SharpeRatio()
}
func (b BySharpeRatio) Swap(i, j int) {
b[i], b[j] = b[j], b[i]
} | timeseries/timeseries.go | 0.583441 | 0.437283 | timeseries.go | starcoder |
package impl
import (
"errors"
"github.com/xichen2020/eventdb/document/field"
"github.com/xichen2020/eventdb/filter"
"github.com/xichen2020/eventdb/values"
"github.com/xichen2020/eventdb/values/iterator"
iterimpl "github.com/xichen2020/eventdb/values/iterator/impl"
"github.com/xichen2020/eventdb/x/pool"
)
var (
errBoolValuesBuilderAlreadyClosed = errors.New("bool values builder is already closed")
)
// ArrayBasedBoolValues is a bool values collection backed by an in-memory array.
// TODO(xichen): Investigate more compact encoding of the values for memory efficiency.
type ArrayBasedBoolValues struct {
closed bool
numTrues int
numFalses int
vals *pool.RefCountedPooledBoolArray
}
// NewArrayBasedBoolValues create a new array based bool values.
func NewArrayBasedBoolValues(p *pool.BucketizedBoolArrayPool) *ArrayBasedBoolValues {
rawArr := p.Get(defaultInitialFieldValuesCapacity)
refCountedArr := pool.NewRefCountedPooledBoolArray(rawArr, p, nil)
return &ArrayBasedBoolValues{
vals: refCountedArr,
}
}
// Metadata returns the values metadata.
func (b *ArrayBasedBoolValues) Metadata() values.BoolValuesMetadata {
return values.BoolValuesMetadata{
NumTrues: b.numTrues,
NumFalses: b.numFalses,
}
}
// Iter returns the values iterator.
func (b *ArrayBasedBoolValues) Iter() (iterator.ForwardBoolIterator, error) {
return iterimpl.NewArrayBasedBoolIterator(b.vals.Get()), nil
}
// Filter applies the given filter against the values, returning an iterator
// identifying the positions of values matching the filter.
func (b *ArrayBasedBoolValues) Filter(
op filter.Op,
filterValue *field.ValueUnion,
) (iterator.PositionIterator, error) {
return defaultFilteredArrayBasedBoolValueIterator(b, op, filterValue)
}
// Add adds a new bool value.
func (b *ArrayBasedBoolValues) Add(v bool) error {
if b.closed {
return errBoolValuesBuilderAlreadyClosed
}
if v {
b.numTrues++
} else {
b.numFalses++
}
b.vals.Append(v)
return nil
}
// Snapshot takes a snapshot of the bool values.
func (b *ArrayBasedBoolValues) Snapshot() values.CloseableBoolValues {
return &ArrayBasedBoolValues{
numTrues: b.numTrues,
numFalses: b.numFalses,
vals: b.vals.Snapshot(),
}
}
// Seal seals the bool values builder.
func (b *ArrayBasedBoolValues) Seal() values.CloseableBoolValues {
sealed := &ArrayBasedBoolValues{
numTrues: b.numTrues,
numFalses: b.numFalses,
vals: b.vals,
}
// Close the current values so it's no longer writable.
*b = ArrayBasedBoolValues{}
b.Close()
return sealed
}
// Close closes the bool values.
func (b *ArrayBasedBoolValues) Close() {
if b.closed {
return
}
b.closed = true
if b.vals != nil {
b.vals.Close()
b.vals = nil
}
} | values/impl/array_based_bool_values.go | 0.543348 | 0.411377 | array_based_bool_values.go | starcoder |
package bitfield
import (
"math/bits"
)
var _ = Bitfield(Bitvector32{})
// Bitvector32 is a bitfield with a fixed defined size of 32. There is no length bit
// present in the underlying byte array.
type Bitvector32 []byte
const bitvector32ByteSize = 4
const bitvector32BitSize = bitvector32ByteSize * 8
// NewBitvector32 creates a new bitvector of size 32.
func NewBitvector32() Bitvector32 {
byteArray := [bitvector32ByteSize]byte{}
return byteArray[:]
}
// BitAt returns the bit value at the given index. If the index requested
// exceeds the number of bits in the bitvector, then this method returns false.
func (b Bitvector32) BitAt(idx uint64) bool {
// Out of bounds, must be false.
if idx >= b.Len() || len(b) != bitvector32ByteSize {
return false
}
i := uint8(1 << (idx % 8))
return b[idx/8]&i == i
}
// SetBitAt will set the bit at the given index to the given value. If the index
// requested exceeds the number of bits in the bitvector, then this method returns
// false.
func (b Bitvector32) SetBitAt(idx uint64, val bool) {
// Out of bounds, do nothing.
if idx >= b.Len() || len(b) != bitvector32ByteSize {
return
}
bit := uint8(1 << (idx % 8))
if val {
b[idx/8] |= bit
} else {
b[idx/8] &^= bit
}
}
// Len returns the number of bits in the bitvector.
func (b Bitvector32) Len() uint64 {
return bitvector32BitSize
}
// Count returns the number of 1s in the bitvector.
func (b Bitvector32) Count() uint64 {
if len(b) == 0 {
return 0
}
c := 0
for i, bt := range b {
if i >= bitvector32ByteSize {
break
}
c += bits.OnesCount8(bt)
}
return uint64(c)
}
// Bytes returns the bytes data representing the bitvector32.
func (b Bitvector32) Bytes() []byte {
if len(b) == 0 {
return []byte{}
}
ln := min(len(b), bitvector32ByteSize)
ret := make([]byte, ln)
copy(ret, b[:ln])
return ret[:]
}
// BitIndices returns the list of indices which are set to 1.
func (b Bitvector32) BitIndices() []int {
indices := make([]int, 0, bitvector32BitSize)
for i, bt := range b {
if i >= bitvector32ByteSize {
break
}
for j := 0; j < 8; j++ {
bit := byte(1 << uint(j))
if bt&bit == bit {
indices = append(indices, i*8+j)
}
}
}
return indices
} | bitvector32.go | 0.776453 | 0.436262 | bitvector32.go | starcoder |
package main
import (
"fmt"
"math"
"math/rand"
"sort"
"time"
)
// point is a k-dimensional point.
type point []float64
// sqd returns the square of the euclidean distance.
func (p point) sqd(q point) float64 {
var sum float64
for dim, pCoord := range p {
d := pCoord - q[dim]
sum += d * d
}
return sum
}
// kdNode following field names in the paper.
// rangeElt would be whatever data is associated with the point. we don't
// bother with it for this example.
type kdNode struct {
domElt point
split int
left, right *kdNode
}
type kdTree struct {
n *kdNode
bounds hyperRect
}
type hyperRect struct {
min, max point
}
// Go slices are reference objects. The data must be copied if you want
// to modify one without modifying the original.
func (hr hyperRect) copy() hyperRect {
return hyperRect{append(point{}, hr.min...), append(point{}, hr.max...)}
}
// newKd constructs a kdTree from a list of points, also associating the
// bounds of the tree. The bounds could be computed of course, but in this
// example we know them already. The algorithm is table 6.3 in the paper.
func newKd(pts []point, bounds hyperRect) kdTree {
var nk2 func([]point, int) *kdNode
nk2 = func(exset []point, split int) *kdNode {
if len(exset) == 0 {
return nil
}
// pivot choosing procedure. we find median, then find largest
// index of points with median value. this satisfies the
// inequalities of steps 6 and 7 in the algorithm.
sort.Sort(part{exset, split})
m := len(exset) / 2
d := exset[m]
for m+1 < len(exset) && exset[m+1][split] == d[split] {
m++
}
// next split
s2 := split + 1
if s2 == len(d) {
s2 = 0
}
return &kdNode{d, split, nk2(exset[:m], s2), nk2(exset[m+1:], s2)}
}
return kdTree{nk2(pts, 0), bounds}
}
// a container type used for sorting. it holds the points to sort and
// the dimension to use for the sort key.
type part struct {
pts []point
dPart int
}
// satisfy sort.Interface
func (p part) Len() int { return len(p.pts) }
func (p part) Less(i, j int) bool {
return p.pts[i][p.dPart] < p.pts[j][p.dPart]
}
func (p part) Swap(i, j int) { p.pts[i], p.pts[j] = p.pts[j], p.pts[i] }
// nearest. find nearest neighbor. return values are:
// nearest neighbor--the point within the tree that is nearest p.
// square of the distance to that point.
// a count of the nodes visited in the search.
func (t kdTree) nearest(p point) (best point, bestSqd float64, nv int) {
return nn(t.n, p, t.bounds, math.Inf(1))
}
// algorithm is table 6.4 from the paper, with the addition of counting
// the number nodes visited.
func nn(kd *kdNode, target point, hr hyperRect,
maxDistSqd float64) (nearest point, distSqd float64, nodesVisited int) {
if kd == nil {
return nil, math.Inf(1), 0
}
nodesVisited++
s := kd.split
pivot := kd.domElt
leftHr := hr.copy()
rightHr := hr.copy()
leftHr.max[s] = pivot[s]
rightHr.min[s] = pivot[s]
targetInLeft := target[s] <= pivot[s]
var nearerKd, furtherKd *kdNode
var nearerHr, furtherHr hyperRect
if targetInLeft {
nearerKd, nearerHr = kd.left, leftHr
furtherKd, furtherHr = kd.right, rightHr
} else {
nearerKd, nearerHr = kd.right, rightHr
furtherKd, furtherHr = kd.left, leftHr
}
var nv int
nearest, distSqd, nv = nn(nearerKd, target, nearerHr, maxDistSqd)
nodesVisited += nv
if distSqd < maxDistSqd {
maxDistSqd = distSqd
}
d := pivot[s] - target[s]
d *= d
if d > maxDistSqd {
return
}
if d = pivot.sqd(target); d < distSqd {
nearest = pivot
distSqd = d
maxDistSqd = distSqd
}
tempNearest, tempSqd, nv := nn(furtherKd, target, furtherHr, maxDistSqd)
nodesVisited += nv
if tempSqd < distSqd {
nearest = tempNearest
distSqd = tempSqd
}
return
}
func main() {
rand.Seed(time.Now().Unix())
kd := newKd([]point{{2, 3}, {5, 4}, {9, 6}, {4, 7}, {8, 1}, {7, 2}},
hyperRect{point{0, 0}, point{10, 10}})
showNearest("WP example data", kd, point{9, 2})
kd = newKd(randomPts(3, 1000), hyperRect{point{0, 0, 0}, point{1, 1, 1}})
showNearest("1000 random 3d points", kd, randomPt(3))
}
func randomPt(dim int) point {
p := make(point, dim)
for d := range p {
p[d] = rand.Float64()
}
return p
}
func randomPts(dim, n int) []point {
p := make([]point, n)
for i := range p {
p[i] = randomPt(dim)
}
return p
}
func showNearest(heading string, kd kdTree, p point) {
fmt.Println()
fmt.Println(heading)
fmt.Println("point: ", p)
nn, ssq, nv := kd.nearest(p)
fmt.Println("nearest neighbor:", nn)
fmt.Println("distance: ", math.Sqrt(ssq))
fmt.Println("nodes visited: ", nv)
}
//\K-d-tree\k-d-tree.go | tasks/K-d-tree/k-d-tree.go | 0.781414 | 0.594581 | k-d-tree.go | starcoder |
package three
import (
"fmt"
"image"
"image/color"
"image/png"
"os"
"strconv"
"strings"
)
func FindDistanceToCross(wireOne, wireTwo string) int {
wOne := PointsFromString(wireOne)
wTwo := PointsFromString(wireTwo)
crossPoints := FindCrossPointsV2(wOne, wTwo)
shortestDist := -1
for _, d := range crossPoints {
if d.ManhattanDistance() < shortestDist || shortestDist == -1 {
shortestDist = d.ManhattanDistance()
}
}
return shortestDist
}
func FindCrossPoints(wOne, wTwo points) points {
pointsThatCross := make([]point, 0)
for _, p1 := range wOne {
for _, p2 := range wTwo {
if p1.Equal(p2) {
pointsThatCross = append(pointsThatCross, p1)
}
}
}
return pointsThatCross
}
func FindCrossPointsV2(wOne, wTwo points) points {
/* Possible Optimizations
1) Use pointers so as not to alloc so much
2) Setting 'x' is nice since the test check the char,
but really we don't need it so if we fix the test then we can drop it
3) only one map needs to have the points in it, so we could set the other to struct{} to save memory
4) might be able to merge the last 2 for loops
5) if you could make sue we only did the map check with the smallest map that would save some stuff.
*/
wOneMap := make(map[string]point)
for _, p := range wOne {
wOneMap[p.Key()] = p
}
wTwoMap := make(map[string]point)
for _, p := range wTwo {
wTwoMap[p.Key()] = p
}
pointsThatCross := make([]point, 0)
for k, _ := range wOneMap {
if mp, ok := wTwoMap[k]; ok {
mp.char = 'x'
pointsThatCross = append(pointsThatCross, mp)
}
}
return pointsThatCross
}
func FindBestSteps(wireOne string, wireTwo string) int {
wOne := PointsFromString(wireOne)
wTwo := PointsFromString(wireTwo)
crossPoints := FindCrossPoints(wOne, wTwo)
shortest := -1
for _, p := range crossPoints {
stepsToOne := FindStepsToPoint(wOne, p)
stepsToTwo := FindStepsToPoint(wTwo, p)
// Plus 2 because i am skipping the first step from 0,0
total := stepsToOne + stepsToTwo + 2
if total < shortest || shortest == -1 {
shortest = total
}
}
return shortest
}
func FindStepsToPoint(points []point, pointToFind point) int {
for i, p := range points {
if p.Equal(pointToFind) {
return i
}
}
return -1
}
func PointsFromString(wire string) points {
dirs := strings.Split(wire, ",")
points := make([]point, 0)
x := 0
y := 0
for _, instruction := range dirs {
direction := instruction[0:1]
dstring := instruction[1:]
distance, err := strconv.Atoi(dstring)
if err != nil {
// TODO
panic(err)
}
switch direction {
case "R":
for i := 0; i < distance; i++ {
x++
points = append(points, point{y: y, x: x, char: '-'})
}
points[len(points)-1].char = '+'
case "L":
for i := 0; i < distance; i++ {
x--
points = append(points, point{y: y, x: x, char: '-'})
}
points[len(points)-1].char = '+'
case "U":
for i := 0; i < distance; i++ {
y++
points = append(points, point{y: y, x: x, char: '|'})
}
points[len(points)-1].char = '+'
case "D":
for i := 0; i < distance; i++ {
y--
points = append(points, point{y: y, x: x, char: '|'})
}
points[len(points)-1].char = '+'
default:
// TODO
panic(direction)
}
}
return points
}
type point struct {
x, y int
char rune
}
func (p point) Equal(in point) bool {
return in.x == p.x && in.y == p.y
}
func (p point) LessThan(in point) bool {
return p.x < in.x
}
func (p point) ManhattanDistance() int {
absX := p.x
if absX < 0 {
absX *= -1
}
absY := p.y
if absY < 0 {
absY *= -1
}
return absX + absY
}
func (p point) Key() string {
return fmt.Sprintf("%d,%d", p.x, p.y)
}
type points []point
func (p points) Len() int {
return len(p)
}
func (p points) Swap(i, j int) {
p[i], p[j] = p[j], p[i]
}
func (p points) Less(i, j int) bool {
return p[i].ManhattanDistance() < p[j].ManhattanDistance()
}
func (p points) minMax() (xMin, yMin, xMax, yMax int) {
for _, r := range p {
if r.x > xMax {
xMax = r.x
}
if r.y > yMax {
yMax = r.y
}
if r.x < xMin {
xMin = r.x
}
if r.y < yMin {
yMin = r.y
}
}
return
}
func (p points) fillInImage(img *image.RGBA, color color.Color, xMin, yMin int, blockSize int) {
for _, r := range p {
for y := (r.y - yMin) * blockSize; y < (r.y-yMin+1)*blockSize; y++ {
for x := (r.x - xMin) * blockSize; x < (r.x-xMin+1)*blockSize; x++ {
img.Set(x, y, color)
}
}
}
}
func (p points) PNG() string {
xMin, yMin, xMax, yMax := p.minMax()
xMax += 2
yMax += 2
xMax = (xMin * -1) + xMax
yMax = (yMin * -1) + yMax
green := color.RGBA{14, 184, 14, 0xff}
squarSiz := 20
rect := image.Rect(0, 0, xMax*squarSiz, yMax*squarSiz)
img := image.NewRGBA(rect)
p.fillInImage(img, green, xMin, yMin, squarSiz)
f, _ := os.Create(fmt.Sprintf("image-%d-%d.png", xMax, yMax))
png.Encode(f, img)
return f.Name()
}
func (p points) PNGWithOverlay(o points) string {
xMin, yMin, xMax, yMax := p.minMax()
oxMin, oyMin, oxMax, oyMax := p.minMax()
if oxMin < xMin {
xMin = oxMin
}
if oyMin < yMin {
yMin = oyMin
}
if oxMax > xMax {
xMax = oxMax
}
if oyMax > yMax {
yMax = oyMax
}
xMax += 2
yMax += 2
xMax = (xMin * -1) + xMax
yMax = (yMin * -1) + yMax
squarSiz := 2
rect := image.Rect(0, 0, xMax*squarSiz, yMax*squarSiz)
img := image.NewRGBA(rect)
green := color.RGBA{14, 184, 14, 0xff}
blue := color.RGBA{0, 0, 0xff, 0xff}
p.fillInImage(img, green, xMin, yMin, squarSiz)
o.fillInImage(img, blue, xMin, yMin, squarSiz)
f, _ := os.Create(fmt.Sprintf("overlay-%d-%d.png", xMax, yMax))
png.Encode(f, img)
return f.Name()
} | nbutton/three/crossed_wires.go | 0.591487 | 0.55652 | crossed_wires.go | starcoder |
package sirpent
import (
"fmt"
"log"
)
type DirectionError struct {
DirectionValue Direction
}
func (e DirectionError) Error() string {
return fmt.Sprintf("Direction '%s' not found.", e.DirectionValue)
}
type Direction string
type Vector struct {
X int
Y int
}
func (v Vector) Eq(v2 Vector) bool {
return v.X == v2.X && v.Y == v2.Y
}
type HexagonalGrid struct {
Radius int `json:"radius"`
}
func (g *HexagonalGrid) origin() Vector {
return Vector{0, 0}
}
func (g *HexagonalGrid) Cells() ([]Vector, error) {
cells := make([]Vector, 0)
for x := -g.Radius; x <= g.Radius; x++ {
for y := -g.Radius; y <= g.Radius; y++ {
cells = append(cells, Vector{x, y})
}
}
return cells, nil
}
func (g *HexagonalGrid) CryptoRandomCell() (Vector, error) {
v := Vector{
X: crypto_int(-g.Radius, g.Radius),
Y: crypto_int(-g.Radius, g.Radius),
}
return v, nil
}
func (g *HexagonalGrid) Directions() []Direction {
return []Direction{"north", "northeast", "southeast", "south", "southwest", "northwest"}
}
func (g *HexagonalGrid) ValidateDirection(d Direction) error {
directions := g.Directions()
for i := range directions {
if directions[i] == d {
return nil
}
}
return DirectionError{DirectionValue: d}
}
func (g *HexagonalGrid) CellNeighbour(v Vector, d Direction) Vector {
neighbour := Vector{v.X, v.Y}
switch d {
case "north":
neighbour.Y--
case "northeast":
neighbour.X++
neighbour.Y--
case "southeast":
neighbour.X++
case "south":
neighbour.Y++
case "southwest":
neighbour.X--
neighbour.Y++
case "northwest":
neighbour.X--
default:
log.Fatal("Unknown direction.")
}
return neighbour
}
func (g *HexagonalGrid) CellNeighbours(v Vector) []Vector {
directions := g.Directions()
neighbours := make([]Vector, len(directions))
for i := range directions {
neighbours[i] = g.CellNeighbour(v, directions[i])
}
return neighbours
}
func (g *HexagonalGrid) IsCellWithinBounds(v Vector) bool {
return g.DistanceBetweenCells(v, g.origin()) <= g.Radius
}
func (g *HexagonalGrid) DistanceBetweenCells(v1, v2 Vector) int {
dx := abs(v2.X - v1.X)
dy := abs(v2.Y - v1.Y)
dz := abs((v1.X + v1.Y) - (v2.X + v2.Y))
return max(max(dx, dy), dz)
} | src/grid.go | 0.783947 | 0.455804 | grid.go | starcoder |
package raft
import (
"fmt"
pb "github.com/coreos/etcd/raft/raftpb"
)
// nextEnts returns the appliable entries and updates the applied index
func nextEnts(r *raft, s *MemoryStorage) (ents []pb.Entry) {
// Transfer all unstable entries to "stable" storage.
s.Append(r.raftLog.unstableEntries())
r.raftLog.stableTo(r.raftLog.lastIndex(), r.raftLog.lastTerm())
ents = r.raftLog.nextEnts()
r.raftLog.appliedTo(r.raftLog.committed)
return ents
}
type Interface interface {
Step(m pb.Message) error
readMessages() []pb.Message
}
func (r *raft) readMessages() []pb.Message {
msgs := r.msgs
r.msgs = make([]pb.Message, 0)
return msgs
}
func newTestConfig(id uint64, peers []uint64, election, heartbeat int, storage Storage) *Config {
return &Config{
ID: id,
peers: peers,
ElectionTick: election,
HeartbeatTick: heartbeat,
Storage: storage,
MaxSizePerMsg: noLimit,
MaxInflightMsgs: 256,
}
}
func newTestRaft(id uint64, peers []uint64, election, heartbeat int, storage Storage) *raft {
return newRaft(newTestConfig(id, peers, election, heartbeat, storage))
}
func Fuzz(data []byte) int {
r := newTestRaft(1, []uint64{1, 2}, 5, 1, NewMemoryStorage())
r.becomeCandidate()
r.becomeLeader()
pr2 := r.prs[2]
// force the progress to be in replicate state
pr2.becomeReplicate()
// fill in the inflights window
for i := 0; i < r.maxInflight; i++ {
r.Step(pb.Message{From: 1, To: 1, Type: pb.MsgProp, Entries: []pb.Entry{{Data: data}}})
ms := r.readMessages()
if len(ms) != 1 {
panic(fmt.Errorf("#%d: len(ms) = %d, want 1", i, len(ms)))
}
}
// ensure 1
if !pr2.ins.full() {
panic(fmt.Errorf("inflights.full = %t, want %t", pr2.ins.full(), true))
}
// ensure 2
for i := 0; i < 10; i++ {
r.Step(pb.Message{From: 1, To: 1, Type: pb.MsgProp, Entries: []pb.Entry{{Data: data}}})
ms := r.readMessages()
if len(ms) != 0 {
panic(fmt.Errorf("#%d: len(ms) = %d, want 0", i, len(ms)))
}
}
r = newTestRaft(1, []uint64{1, 2}, 5, 1, NewMemoryStorage())
r.becomeCandidate()
r.becomeLeader()
pr2 = r.prs[2]
// force the progress to be in replicate state
pr2.becomeReplicate()
// fill in the inflights window
for i := 0; i < r.maxInflight; i++ {
r.Step(pb.Message{From: 1, To: 1, Type: pb.MsgProp, Entries: []pb.Entry{{Data: data}}})
r.readMessages()
}
// 1 is noop, 2 is the first proposal we just sent.
// so we start with 2.
for tt := 2; tt < r.maxInflight; tt++ {
// move forward the window
r.Step(pb.Message{From: 2, To: 1, Type: pb.MsgAppResp, Index: uint64(tt)})
r.readMessages()
// fill in the inflights window again
r.Step(pb.Message{From: 1, To: 1, Type: pb.MsgProp, Entries: []pb.Entry{{Data: data}}})
ms := r.readMessages()
if len(ms) != 1 {
panic(fmt.Errorf("#%d: len(ms) = %d, want 1", tt, len(ms)))
}
// ensure 1
if !pr2.ins.full() {
panic(fmt.Errorf("inflights.full = %t, want %t", pr2.ins.full(), true))
}
// ensure 2
for i := 0; i < tt; i++ {
r.Step(pb.Message{From: 2, To: 1, Type: pb.MsgAppResp, Index: uint64(i)})
if !pr2.ins.full() {
panic(fmt.Errorf("#%d: inflights.full = %t, want %t", tt, pr2.ins.full(), true))
}
}
}
r = newTestRaft(1, []uint64{1, 2}, 5, 1, NewMemoryStorage())
r.becomeCandidate()
r.becomeLeader()
pr2 = r.prs[2]
// force the progress to be in replicate state
pr2.becomeReplicate()
// fill in the inflights window
for i := 0; i < r.maxInflight; i++ {
r.Step(pb.Message{From: 1, To: 1, Type: pb.MsgProp, Entries: []pb.Entry{{Data: data}}})
r.readMessages()
}
for tt := 1; tt < 5; tt++ {
if !pr2.ins.full() {
panic(fmt.Errorf("#%d: inflights.full = %t, want %t", tt, pr2.ins.full(), true))
}
// recv tt msgHeartbeatResp and expect one free slot
for i := 0; i < tt; i++ {
r.Step(pb.Message{From: 2, To: 1, Type: pb.MsgHeartbeatResp})
r.readMessages()
if pr2.ins.full() {
panic(fmt.Errorf("#%d.%d: inflights.full = %t, want %t", tt, i, pr2.ins.full(), false))
}
}
// one slot
r.Step(pb.Message{From: 1, To: 1, Type: pb.MsgProp, Entries: []pb.Entry{{Data: data}}})
ms := r.readMessages()
if len(ms) != 1 {
panic(fmt.Errorf("#%d: free slot = 0, want 1", tt))
}
// and just one slot
for i := 0; i < 10; i++ {
r.Step(pb.Message{From: 1, To: 1, Type: pb.MsgProp, Entries: []pb.Entry{{Data: data}}})
ms1 := r.readMessages()
if len(ms1) != 0 {
panic(fmt.Errorf("#%d.%d: len(ms) = %d, want 0", tt, i, len(ms1)))
}
}
// clear all pending messages.
r.Step(pb.Message{From: 2, To: 1, Type: pb.MsgHeartbeatResp})
r.readMessages()
}
return 1
} | doc/etcd_go_fuzz/code/fuzz_raft_2.go | 0.528047 | 0.400105 | fuzz_raft_2.go | starcoder |
package expression
import (
"fmt"
"github.com/dolthub/go-mysql-server/sql"
)
// Literal represents a literal expression (string, number, bool, ...).
type Literal struct {
value interface{}
val2 sql.Value
fieldType sql.Type
}
var _ sql.Expression = &Literal{}
var _ sql.Expression2 = &Literal{}
// NewLiteral creates a new Literal expression.
func NewLiteral(value interface{}, fieldType sql.Type) *Literal {
val2, _ := sql.ConvertToValue(value)
return &Literal{
value: value,
val2: val2,
fieldType: fieldType,
}
}
// Resolved implements the Expression interface.
func (lit *Literal) Resolved() bool {
return true
}
// IsNullable implements the Expression interface.
func (lit *Literal) IsNullable() bool {
return lit.value == nil
}
// Type implements the Expression interface.
func (lit *Literal) Type() sql.Type {
return lit.fieldType
}
// Eval implements the Expression interface.
func (lit *Literal) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
return lit.value, nil
}
func (lit *Literal) String() string {
switch v := lit.value.(type) {
case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64:
return fmt.Sprintf("%d", v)
case string:
return fmt.Sprintf("'%s'", v)
case []byte:
return "BLOB"
case nil:
return "NULL"
default:
return fmt.Sprint(v)
}
}
func (lit *Literal) DebugString() string {
typeStr := lit.fieldType.String()
switch v := lit.value.(type) {
case string:
return fmt.Sprintf("%s (%s)", v, typeStr)
case []byte:
return fmt.Sprintf("BLOB(%s)", string(v))
case nil:
return fmt.Sprintf("NULL (%s)", typeStr)
case int, uint, int8, uint8, int16, uint16, int32, uint32, int64, uint64:
return fmt.Sprintf("%d (%s)", v, typeStr)
case float32, float64:
return fmt.Sprintf("%f (%s)", v, typeStr)
default:
return fmt.Sprintf("%s (%s)", v, typeStr)
}
}
// WithChildren implements the Expression interface.
func (lit *Literal) WithChildren(children ...sql.Expression) (sql.Expression, error) {
if len(children) != 0 {
return nil, sql.ErrInvalidChildrenNumber.New(lit, len(children), 0)
}
return lit, nil
}
// Children implements the Expression interface.
func (*Literal) Children() []sql.Expression {
return nil
}
func (lit *Literal) Eval2(ctx *sql.Context, row sql.Row2) (sql.Value, error) {
return lit.val2, nil
}
func (lit *Literal) Type2() sql.Type2 {
t2, ok := lit.fieldType.(sql.Type2)
if !ok {
panic(fmt.Errorf("expected Type2, but was %T", lit.fieldType))
}
return t2
}
// Value returns the literal value.
func (p *Literal) Value() interface{} {
return p.value
} | sql/expression/literal.go | 0.786295 | 0.421969 | literal.go | starcoder |
package renderers
import (
"fmt"
"image/color"
"github.com/tdewolff/canvas"
"github.com/tdewolff/canvas/pdf"
"github.com/winkula/dragons/pkg/model"
)
var size = 5 // 5mm
var sizeFactor = float64(size)
var padding = 1 // 1mm
var gridLine = 0.05
var gridBorder = 0.3
var gridColor = canvas.Black
var symbolLine = 0.15
func RenderPdf(g *model.Grid, border bool, filename string) {
c := canvas.New(float64(g.Width*size+2*padding), float64(g.Height*size+2*padding))
ctx := canvas.NewContext(c)
ctx.SetFillColor(canvas.Transparent)
ctx.SetStrokeCapper(canvas.SquareCap)
ctx.SetStrokeJoiner(canvas.RoundJoin)
drawGrid(ctx, g, border)
drawSymbols(ctx, g)
c.WriteFile(fmt.Sprintf("%v.pdf", filename), pdf.Writer)
//c.WriteFile(fmt.Sprintf("%v.svg", filename), svg.Writer)
}
func drawGrid(ctx *canvas.Context, g *model.Grid, border bool) {
for y := 0; y < g.Height; y++ {
for x := 0; x < g.Width; x++ {
ctx.SetFillColor(canvas.Transparent)
ctx.SetStrokeColor(gridColor)
ctx.SetStrokeWidth(gridLine)
drawRect(ctx, sizeFactor*float64(x), sizeFactor*float64(y), sizeFactor, sizeFactor, gridLine, gridColor, canvas.White)
}
}
if border {
drawRect(ctx, 0.0, 0.0, sizeFactor*float64(g.Width), sizeFactor*float64(g.Height), gridBorder, gridColor, canvas.Transparent)
}
}
func drawSymbols(ctx *canvas.Context, g *model.Grid) {
for i, square := range g.Squares {
x, y := g.Coords(i)
yNorm := g.Height - y - 1
switch square {
case model.SquareDragon:
drawTriangle(ctx, x, yNorm, canvas.Black)
case model.SquareFire:
drawTriangle(ctx, x, yNorm, canvas.Transparent)
case model.SquareAir:
drawLine(ctx, x, yNorm)
case model.SquareNoDragon:
drawPoint(ctx, x, yNorm)
}
}
}
func drawRect(ctx *canvas.Context, x float64, y float64, width float64, height float64, strokeWidth float64, strokeColor color.RGBA, fillColor color.RGBA) {
polyline := &canvas.Polyline{}
polyline.Add(0.0, 0.0)
polyline.Add(width, 0.0)
polyline.Add(width, height)
polyline.Add(0.0, height)
polyline.Add(0.0, 0.0)
ctx.SetFillColor(fillColor)
ctx.SetStrokeColor(strokeColor)
ctx.SetStrokeWidth(strokeWidth)
ctx.DrawPath(x+float64(padding), y+float64(padding), polyline.ToPath())
}
func drawTriangle(ctx *canvas.Context, x int, y int, col color.RGBA) {
triangleSize := 0.75
sqrt3 := 1.73205080757
triangleHeight := sqrt3 / 2.0 * triangleSize
polyline := &canvas.Polyline{}
polyline.Add((1.0-triangleSize)/2.0*sizeFactor, (1.0-triangleHeight)/2.0*sizeFactor)
polyline.Add(0.5*sizeFactor, (1.0-(1.0-triangleHeight)/2.0)*sizeFactor)
polyline.Add((1.0-(1.0-triangleSize)/2.0)*sizeFactor, (1.0-triangleHeight)/2.0*sizeFactor)
polyline.Add((1.0-triangleSize)/2.0*sizeFactor, (1.0-triangleHeight)/2.0*sizeFactor)
ctx.SetFillColor(col)
ctx.SetStrokeColor(canvas.Black)
ctx.SetStrokeWidth(symbolLine)
ctx.DrawPath(float64(size*x+padding), float64(size*y+padding), polyline.ToPath())
}
func drawLine(ctx *canvas.Context, x int, y int) {
lineSize := 0.4
polyline := &canvas.Polyline{}
polyline.Add((1.0-lineSize)/2.0*sizeFactor, 0.5*sizeFactor)
polyline.Add((1.0-(1.0-lineSize)/2.0)*sizeFactor, 0.5*sizeFactor)
ctx.SetFillColor(canvas.Transparent)
ctx.SetStrokeColor(canvas.Black)
ctx.SetStrokeWidth(symbolLine)
ctx.DrawPath(float64(size*x+padding), float64(size*y+padding), polyline.ToPath())
}
func drawPoint(ctx *canvas.Context, x int, y int) {
pointSize := 0.02 * sizeFactor
ctx.SetFillColor(canvas.Black)
ctx.SetStrokeColor(canvas.Black)
ctx.SetStrokeWidth(symbolLine)
circle := canvas.Circle(pointSize).Translate(0.5*sizeFactor, 0.5*sizeFactor)
ctx.DrawPath(float64(size*x+padding), float64(size*y+padding), circle)
} | pkg/renderers/pdf.go | 0.642545 | 0.406273 | pdf.go | starcoder |
package levenshtein2
import (
"fmt"
"math"
)
const SinkState = uint32(0)
type DFA struct {
transitions [][256]uint32
distances []Distance
initState int
ed uint8
}
/// Returns the initial state
func (d *DFA) initialState() int {
return d.initState
}
/// Returns the Levenshtein distance associated to the
/// current state.
func (d *DFA) distance(stateId int) Distance {
return d.distances[stateId]
}
/// Returns the number of states in the `DFA`.
func (d *DFA) numStates() int {
return len(d.transitions)
}
/// Returns the destination state reached after consuming a given byte.
func (d *DFA) transition(fromState int, b uint8) int {
return int(d.transitions[fromState][b])
}
func (d *DFA) eval(bytes []uint8) Distance {
state := d.initialState()
for _, b := range bytes {
state = d.transition(state, b)
}
return d.distance(state)
}
func (d *DFA) Start() int {
return int(d.initialState())
}
func (d *DFA) IsMatch(state int) bool {
if _, ok := d.distance(state).(Exact); ok {
return true
}
return false
}
func (d *DFA) CanMatch(state int) bool {
return state > 0 && state < d.numStates()
}
func (d *DFA) Accept(state int, b byte) int {
return int(d.transition(state, b))
}
// WillAlwaysMatch returns if the specified state will always end in a
// matching state.
func (d *DFA) WillAlwaysMatch(state int) bool {
return false
}
func fill(dest []uint32, val uint32) {
for i := range dest {
dest[i] = val
}
}
func fillTransitions(dest *[256]uint32, val uint32) {
for i := range dest {
dest[i] = val
}
}
type Utf8DFAStateBuilder struct {
dfaBuilder *Utf8DFABuilder
stateID uint32
defaultSuccessor []uint32
}
func (sb *Utf8DFAStateBuilder) addTransitionID(fromStateID uint32, b uint8,
toStateID uint32) {
sb.dfaBuilder.transitions[fromStateID][b] = toStateID
}
func (sb *Utf8DFAStateBuilder) addTransition(in rune, toStateID uint32) {
fromStateID := sb.stateID
chars := []byte(string(in))
lastByte := chars[len(chars)-1]
for i, ch := range chars[:len(chars)-1] {
remNumBytes := len(chars) - i - 1
defaultSuccessor := sb.defaultSuccessor[remNumBytes]
intermediateStateID := sb.dfaBuilder.transitions[fromStateID][ch]
if intermediateStateID == defaultSuccessor {
intermediateStateID = sb.dfaBuilder.allocate()
fillTransitions(&sb.dfaBuilder.transitions[intermediateStateID],
sb.defaultSuccessor[remNumBytes-1])
}
sb.addTransitionID(fromStateID, ch, intermediateStateID)
fromStateID = intermediateStateID
}
toStateIDDecoded := sb.dfaBuilder.getOrAllocate(original(toStateID))
sb.addTransitionID(fromStateID, lastByte, toStateIDDecoded)
}
type Utf8StateId uint32
func original(stateId uint32) Utf8StateId {
return predecessor(stateId, 0)
}
func predecessor(stateId uint32, numSteps uint8) Utf8StateId {
return Utf8StateId(stateId*4 + uint32(numSteps))
}
// Utf8DFABuilder makes it possible to define a DFA
// that takes unicode character, and build a `DFA`
// that operates on utf-8 encoded
type Utf8DFABuilder struct {
index []uint32
distances []Distance
transitions [][256]uint32
initialState uint32
numStates uint32
maxNumStates uint32
}
func withMaxStates(maxStates uint32) *Utf8DFABuilder {
rv := &Utf8DFABuilder{
index: make([]uint32, maxStates*2+100),
distances: make([]Distance, 0, maxStates),
transitions: make([][256]uint32, 0, maxStates),
maxNumStates: maxStates,
}
for i := range rv.index {
rv.index[i] = math.MaxUint32
}
return rv
}
func (dfab *Utf8DFABuilder) allocate() uint32 {
newState := dfab.numStates
dfab.numStates++
dfab.distances = append(dfab.distances, Atleast{d: 255})
dfab.transitions = append(dfab.transitions, [256]uint32{})
return newState
}
func (dfab *Utf8DFABuilder) getOrAllocate(state Utf8StateId) uint32 {
if int(state) >= cap(dfab.index) {
cloneIndex := make([]uint32, int(state)*2)
copy(cloneIndex, dfab.index)
dfab.index = cloneIndex
}
if dfab.index[state] != math.MaxUint32 {
return dfab.index[state]
}
nstate := dfab.allocate()
dfab.index[state] = nstate
return nstate
}
func (dfab *Utf8DFABuilder) setInitialState(iState uint32) {
decodedID := dfab.getOrAllocate(original(iState))
dfab.initialState = decodedID
}
func (dfab *Utf8DFABuilder) build(ed uint8) *DFA {
return &DFA{
transitions: dfab.transitions,
distances: dfab.distances,
initState: int(dfab.initialState),
ed: ed,
}
}
func (dfab *Utf8DFABuilder) addState(state, default_suc_orig uint32,
distance Distance) (*Utf8DFAStateBuilder, error) {
if state > dfab.maxNumStates {
return nil, fmt.Errorf("State id is larger than maxNumStates")
}
stateID := dfab.getOrAllocate(original(state))
dfab.distances[stateID] = distance
defaultSuccID := dfab.getOrAllocate(original(default_suc_orig))
// creates a chain of states of predecessors of `default_suc_orig`.
// Accepting k-bytes (whatever the bytes are) from `predecessor_states[k-1]`
// leads to the `default_suc_orig` state.
predecessorStates := []uint32{defaultSuccID,
defaultSuccID,
defaultSuccID,
defaultSuccID}
for numBytes := uint8(1); numBytes < 4; numBytes++ {
predecessorState := predecessor(default_suc_orig, numBytes)
predecessorStateID := dfab.getOrAllocate(predecessorState)
predecessorStates[numBytes] = predecessorStateID
succ := predecessorStates[numBytes-1]
fillTransitions(&dfab.transitions[predecessorStateID], succ)
}
// 1-byte encoded chars.
fill(dfab.transitions[stateID][0:192], predecessorStates[0])
// 2-bytes encoded chars.
fill(dfab.transitions[stateID][192:224], predecessorStates[1])
// 3-bytes encoded chars.
fill(dfab.transitions[stateID][224:240], predecessorStates[2])
// 4-bytes encoded chars.
fill(dfab.transitions[stateID][240:256], predecessorStates[3])
return &Utf8DFAStateBuilder{
dfaBuilder: dfab,
stateID: stateID,
defaultSuccessor: predecessorStates}, nil
} | vendor/github.com/couchbase/vellum/levenshtein2/dfa.go | 0.783906 | 0.421671 | dfa.go | starcoder |
package std
import (
"github.com/mb0/xelf/cor"
"github.com/mb0/xelf/exp"
"github.com/mb0/xelf/lit"
"github.com/mb0/xelf/typ"
)
// failSpec returns an error, if c is an execution context it fails expression string as error,
// otherwise it uses ErrUnres. This is primarily useful for testing.
var failSpec = core.add(SpecDX("<form fail plain?; any>", func(x CallCtx) (exp.El, error) {
return nil, cor.Errorf("%s", x.Call)
}))
// orSpec resolves the arguments as short-circuiting logical or to a bool literal.
// The arguments must be plain literals and are considered true if not a zero value.
// An empty 'or' expression resolves to true.
var orSpec = core.add(SpecDXX("<form or plain?; bool>",
func(x CallCtx) (exp.El, error) {
args := x.Args(0)
for i, arg := range args {
el, err := x.Prog.Eval(x.Env, arg, typ.Void)
if err == exp.ErrUnres {
args = args[i:]
x.Groups[0] = args
if len(args) == 1 {
x.Spec = boolSpec
simplifyBool(x.Call)
}
return x.Call, err
}
if err != nil {
return nil, err
}
a := el.(*exp.Atom)
if !a.Lit.IsZero() {
return &exp.Atom{Lit: lit.True, Src: x.Src}, nil
}
}
return &exp.Atom{Lit: lit.False, Src: x.Src}, nil
}))
// andSpec resolves the arguments as short-circuiting logical 'and' to a bool literal.
// The arguments must be plain literals and are considered true if not a zero value.
// An empty 'and' expression resolves to true.
var andSpec = core.add(SpecDXX("<form and plain?; bool>", resolveAnd))
func resolveAnd(x CallCtx) (exp.El, error) {
args := x.Args(0)
for i, arg := range args {
el, err := x.Prog.Eval(x.Env, arg, typ.Void)
if err == exp.ErrUnres {
args = args[i:]
x.Groups[0] = args
if len(args) == 1 {
if x.Spec.Ref == "and" {
x.Spec = boolSpec
}
simplifyBool(x.Call)
}
return x.Call, err
}
if err != nil {
return nil, err
}
a := el.(*exp.Atom)
if a.Lit.IsZero() {
return &exp.Atom{Lit: lit.False, Src: x.Src}, nil
}
}
return &exp.Atom{Lit: lit.True, Src: x.Src}, nil
}
// boolSpec resolves the arguments similar to short-circuiting logical 'and' to a bool literal.
// The arguments must be plain literals and are considered true if not a zero value.
// An empty 'bool' expression resolves to false.
var boolSpec *exp.Spec
// notSpec will resolve the arguments similar to short-circuiting logical 'and' to a bool literal.
// The arguments must be plain literals and are considered true if a zero value.
// An empty 'not' expression resolves to true.
var notSpec *exp.Spec
func init() {
boolSpec = core.add(SpecDXX("<form ok plain?; bool>",
func(x CallCtx) (exp.El, error) {
res, err := resolveAnd(x)
if err != nil {
return x.Call, err
}
a := res.(*exp.Atom)
if len(x.Args(0)) == 0 {
a.Lit = lit.False
} else {
a.Lit = lit.Bool(!a.Lit.IsZero())
}
return a, nil
}))
notSpec = core.add(SpecDXX("<form not plain?; bool>",
func(x CallCtx) (exp.El, error) {
res, err := resolveAnd(x)
if err != nil {
return x.Call, err
}
a := res.(*exp.Atom)
if len(x.Args(0)) == 0 {
a.Lit = lit.True
} else {
a.Lit = lit.Bool(a.Lit.IsZero())
}
return a, nil
}))
}
func simplifyBool(e *exp.Call) {
if len(e.Args(0)) != 1 {
return
}
fst, ok := e.Arg(0).(*exp.Call)
if !ok {
return
}
switch fst.Spec {
case boolSpec:
e.Groups = fst.Groups
case notSpec:
e.Groups = fst.Groups
if e.Spec == boolSpec {
e.Spec = notSpec
} else {
e.Spec = boolSpec
}
}
}
// ifSpec resolves the arguments as condition, action pairs as part of an if-else condition.
// The odd end is the else action otherwise a zero value of the first action's type is used.
var ifSpec = core.add(SpecRX("<form if any any plain?; @>",
func(x CallCtx) (exp.El, error) {
// collect all possible action types in an alternative, then choose the common type
alt := typ.NewAlt()
var i int
var unres bool
all := x.All()
for i = 0; i+1 < len(all); i += 2 {
_, err := x.Prog.Resl(x.Env, all[i], typ.Any)
if err != nil && err != exp.ErrUnres {
return nil, err
}
hint := x.New()
_, err = x.Prog.Resl(x.Env, all[i+1], hint)
if err != nil && err != exp.ErrUnres {
return nil, err
}
unres = unres || err == exp.ErrUnres
alt = typ.Alt(alt, x.Prog.Apply(hint))
}
if i < len(all) {
hint := x.New()
_, err := x.Prog.Resl(x.Env, all[i], hint)
if err != nil && err != exp.ErrUnres {
return nil, err
}
unres = unres || err == exp.ErrUnres
alt = typ.Alt(alt, x.Prog.Apply(hint))
}
alt, err := typ.Choose(alt)
if err != nil {
return nil, err
}
if x.Hint != typ.Void {
alt, err = typ.Unify(x.Prog.Ctx, alt, x.Hint)
if err != nil {
return nil, err
}
}
if alt != typ.Void {
ps := x.Sig.Params
ps[len(ps)-1].Type = x.Prog.Inst(alt)
}
return x.Call, nil
},
func(x CallCtx) (exp.El, error) {
// collect all possible action types in an alternative, then choose the common type
var i int
all := x.All()
res := x.Call.Res()
for i = 0; i+1 < len(all); i += 2 {
cond, err := x.Prog.Eval(x.Env, all[i], typ.Any)
if err != nil {
if err != exp.ErrUnres {
return x.Call, err
}
// previous conditions did not match
x.Groups[0] = all[i : i+1]
x.Groups[1] = all[i+1 : i+2]
x.Groups[2] = all[i+2:]
return x.Call, err
}
a, ok := cond.(*exp.Atom)
if ok && !a.Lit.IsZero() {
return x.Prog.Eval(x.Env, all[i+1], res)
}
}
if i < len(all) { // we have an else expression
return x.Prog.Eval(x.Env, all[i], res)
}
return &exp.Atom{Lit: lit.Zero(res), Src: x.Src}, nil
},
)) | std/logic.go | 0.627495 | 0.412767 | logic.go | starcoder |
package funk
import (
"reflect"
)
type JoinFnc func(lx, rx reflect.Value) reflect.Value
// Join combines two collections using the given join method.
func Join(larr, rarr interface{}, fnc JoinFnc) interface{} {
if !IsCollection(larr) {
panic("First parameter must be a collection")
}
if !IsCollection(rarr) {
panic("Second parameter must be a collection")
}
lvalue := reflect.ValueOf(larr)
rvalue := reflect.ValueOf(rarr)
if NotEqual(lvalue.Type(), rvalue.Type()) {
panic("Parameters must have the same type")
}
return fnc(lvalue, rvalue).Interface()
}
// InnerJoin finds and returns matching data from two collections.
func InnerJoin(lx, rx reflect.Value) reflect.Value {
result := reflect.MakeSlice(reflect.SliceOf(lx.Type().Elem()), 0, lx.Len()+rx.Len())
rhash := hashSlice(rx)
lhash := make(map[interface{}]struct{}, lx.Len())
for i := 0; i < lx.Len(); i++ {
v := lx.Index(i)
_, ok := rhash[v.Interface()]
_, alreadyExists := lhash[v.Interface()]
if ok && !alreadyExists {
lhash[v.Interface()] = struct{}{}
result = reflect.Append(result, v)
}
}
return result
}
// OuterJoin finds and returns dissimilar data from two collections.
func OuterJoin(lx, rx reflect.Value) reflect.Value {
ljoin := LeftJoin(lx, rx)
rjoin := RightJoin(lx, rx)
result := reflect.MakeSlice(reflect.SliceOf(lx.Type().Elem()), ljoin.Len()+rjoin.Len(), ljoin.Len()+rjoin.Len())
for i := 0; i < ljoin.Len(); i++ {
result.Index(i).Set(ljoin.Index(i))
}
for i := 0; i < rjoin.Len(); i++ {
result.Index(ljoin.Len() + i).Set(rjoin.Index(i))
}
return result
}
// LeftJoin finds and returns dissimilar data from the first collection (left).
func LeftJoin(lx, rx reflect.Value) reflect.Value {
result := reflect.MakeSlice(reflect.SliceOf(lx.Type().Elem()), 0, lx.Len())
rhash := hashSlice(rx)
for i := 0; i < lx.Len(); i++ {
v := lx.Index(i)
_, ok := rhash[v.Interface()]
if !ok {
result = reflect.Append(result, v)
}
}
return result
}
// LeftJoin finds and returns dissimilar data from the second collection (right).
func RightJoin(lx, rx reflect.Value) reflect.Value { return LeftJoin(rx, lx) }
func hashSlice(arr reflect.Value) map[interface{}]struct{} {
hash := map[interface{}]struct{}{}
for i := 0; i < arr.Len(); i++ {
v := arr.Index(i).Interface()
hash[v] = struct{}{}
}
return hash
} | vendor/github.com/thoas/go-funk/join.go | 0.696062 | 0.412944 | join.go | starcoder |
package sphere
import (
"github.com/austingebauer/go-ray-tracer/material"
"github.com/austingebauer/go-ray-tracer/matrix"
"github.com/austingebauer/go-ray-tracer/point"
"github.com/austingebauer/go-ray-tracer/vector"
)
// Sphere is a sphere object with an origin and radius.
type Sphere struct {
Id string
Origin *point.Point
Radius float64
Transform *matrix.Matrix
Material *material.Material
}
// NewUnitSphere returns a new Sphere with id, origin (0,0,0), and a radius of 1.
func NewUnitSphere(id string) *Sphere {
return NewSphere(id, *point.NewPoint(0, 0, 0), 1.0)
}
// NewSphere returns a new Sphere with the passed id, origin, and radius.
func NewSphere(id string, origin point.Point, radius float64) *Sphere {
return &Sphere{
Id: id,
Origin: &origin,
Radius: radius,
Transform: matrix.NewIdentityMatrix(4),
Material: material.NewDefaultMaterial(),
}
}
// SetTransform sets the transform of this Sphere.
func (s *Sphere) SetTransform(m *matrix.Matrix) {
s.Transform = m
}
// NormalAt returns the normal vector on the passed Sphere, at the passed Point.
// The function assumes that the passed Point will always be on the surface of the sphere.
func NormalAt(s *Sphere, worldSpacePoint *point.Point) (*vector.Vector, error) {
// Get the inverse of the transform applied to the sphere
inverseTransform, err := matrix.Inverse(s.Transform)
if err != nil {
return nil, err
}
// Convert the passed point in world space into a point in object space
objectSpacePointM, err := matrix.Multiply(inverseTransform,
matrix.PointToMatrix(worldSpacePoint))
if err != nil {
return nil, err
}
objectSpacePoint, err := matrix.MatrixToPoint(objectSpacePointM)
if err != nil {
return nil, err
}
// Get the normal vector in object space by subtracting the sphere
// origin (always point(0,0,0)) from the object space point.
objectSpaceNormal := point.Subtract(*objectSpacePoint, *s.Origin).Normalize()
// Convert the object space normal vector back to world space by multiplying
// by the transposed, inverse of the transform applied to the sphere.
transposedInverseTransform := matrix.Transpose(*inverseTransform)
worldSpaceNormalM, err := matrix.Multiply(transposedInverseTransform,
matrix.VectorToMatrix(objectSpaceNormal))
if err != nil {
return nil, err
}
// Normalize and return the world space normal vector
worldSpaceNormalVector, err := matrix.MatrixToVector(worldSpaceNormalM)
if err != nil {
return nil, err
}
return worldSpaceNormalVector.Normalize(), nil
} | sphere/sphere.go | 0.879134 | 0.465995 | sphere.go | starcoder |
package tally
// ITally is a counter of type int.
type ITally int
// Cur returns the current int value of this ITally.
func (t ITally) Cur() int {
return int(t)
}
// Add increases this counter by the given value, returning the previous
// int value of this ITally.
func (t *ITally) Add(i int) (cur int) {
cur = int(*t)
*t += ITally(i)
return
}
// Inc increases this counter by 1, returning the previous int value of
// this ITally.
func (t *ITally) Inc() (cur int) {
cur = int(*t)
*t++
return
}
// Dec decreases this counter by 1, returning the previous int value of
// this ITally.
func (t *ITally) Dec() (cur int) {
cur = int(*t)
*t--
return
}
// Sub decreases this counter by the given value, returning the previous
// int value of this ITally.
func (t *ITally) Sub(i int) (cur int) {
cur = int(*t)
*t -= ITally(i)
return
}
// Zero sets the current counter value to 0, returning the previous int
// value of this ITally.
func (t *ITally) Zero() (cur int) {
cur = int(*t)
*t = 0
return
}
// ITally8 is a counter of type int8.
type ITally8 int8
// Cur returns the current int8 value of this ITally8.
func (t ITally8) Cur() int8 {
return int8(t)
}
// Add increases this counter by the given value, returning the previous
// int8 value of this ITally8.
func (t *ITally8) Add(i int8) (cur int8) {
cur = int8(*t)
*t += ITally8(i)
return
}
// Inc increases this counter by 1, returning the previous int8 value of
// this ITally8.
func (t *ITally8) Inc() (cur int8) {
cur = int8(*t)
*t++
return
}
// Dec decreases this counter by 1, returning the previous int8 value of
// this ITally8.
func (t *ITally8) Dec() (cur int8) {
cur = int8(*t)
*t--
return
}
// Sub decreases this counter by the given value, returning the previous
// int8 value of this ITally8.
func (t *ITally8) Sub(i int8) (cur int8) {
cur = int8(*t)
*t -= ITally8(i)
return
}
// Zero sets the current counter value to 0, returning the previous int8
// value of this ITally8.
func (t *ITally8) Zero() (cur int8) {
cur = int8(*t)
*t = 0
return
}
// ITally16 is a counter of type int16.
type ITally16 int16
// Cur returns the current int16 value of this ITally16.
func (t ITally16) Cur() int16 {
return int16(t)
}
// Add increases this counter by the given value, returning the previous
// int16 value of this ITally16.
func (t *ITally16) Add(i int16) (cur int16) {
cur = int16(*t)
*t += ITally16(i)
return
}
// Inc increases this counter by 1, returning the previous int16 value of
// this ITally16.
func (t *ITally16) Inc() (cur int16) {
cur = int16(*t)
*t++
return
}
// Dec decreases this counter by 1, returning the previous int16 value of
// this ITally16.
func (t *ITally16) Dec() (cur int16) {
cur = int16(*t)
*t--
return
}
// Sub decreases this counter by the given value, returning the previous
// int16 value of this ITally16.
func (t *ITally16) Sub(i int16) (cur int16) {
cur = int16(*t)
*t -= ITally16(i)
return
}
// Zero sets the current counter value to 0, returning the previous int16
// value of this ITally16.
func (t *ITally16) Zero() (cur int16) {
cur = int16(*t)
*t = 0
return
}
// ITally32 is a counter of type int32.
type ITally32 int32
// Cur returns the current int32 value of this ITally32.
func (t ITally32) Cur() int32 {
return int32(t)
}
// Add increases this counter by the given value, returning the previous
// int32 value of this ITally32.
func (t *ITally32) Add(i int32) (cur int32) {
cur = int32(*t)
*t += ITally32(i)
return
}
// Inc increases this counter by 1, returning the previous int32 value of
// this ITally32.
func (t *ITally32) Inc() (cur int32) {
cur = int32(*t)
*t++
return
}
// Dec decreases this counter by 1, returning the previous int32 value of
// this ITally32.
func (t *ITally32) Dec() (cur int32) {
cur = int32(*t)
*t--
return
}
// Sub decreases this counter by the given value, returning the previous
// int32 value of this ITally32.
func (t *ITally32) Sub(i int32) (cur int32) {
cur = int32(*t)
*t -= ITally32(i)
return
}
// Zero sets the current counter value to 0, returning the previous int32
// value of this ITally32.
func (t *ITally32) Zero() (cur int32) {
cur = int32(*t)
*t = 0
return
}
// ITally64 is a counter of type int64.
type ITally64 int64
// Cur returns the current int64 value of this ITally64.
func (t ITally64) Cur() int64 {
return int64(t)
}
// Add increases this counter by the given value, returning the previous
// int64 value of this ITally64.
func (t *ITally64) Add(i int64) (cur int64) {
cur = int64(*t)
*t += ITally64(i)
return
}
// Inc increases this counter by 1, returning the previous int64 value of
// this ITally64.
func (t *ITally64) Inc() (cur int64) {
cur = int64(*t)
*t++
return
}
// Dec decreases this counter by 1, returning the previous int64 value of
// this ITally64.
func (t *ITally64) Dec() (cur int64) {
cur = int64(*t)
*t--
return
}
// Sub decreases this counter by the given value, returning the previous
// int64 value of this ITally64.
func (t *ITally64) Sub(i int64) (cur int64) {
cur = int64(*t)
*t -= ITally64(i)
return
}
// Zero sets the current counter value to 0, returning the previous int64
// value of this ITally64.
func (t *ITally64) Zero() (cur int64) {
cur = int64(*t)
*t = 0
return
} | v1/tally/ints.go | 0.769687 | 0.490114 | ints.go | starcoder |
package hashfill
import (
"github.com/mmcloughlin/geohash"
"github.com/paulsmith/gogeos/geos"
geom "github.com/twpayne/go-geom"
)
// Container tests if a hash is contained.
type Container interface {
Contains(*geom.Polygon, string) (bool, error)
}
// Intersector tests if a hash intersects.
type Intersector interface {
Intersects(*geom.Polygon, string) (bool, error)
}
type predicate func(geofence *geom.Polygon, hash string) (bool, error)
type containsFunc predicate
func (f containsFunc) Contains(p *geom.Polygon, hash string) (bool, error) {
return f(p, hash)
}
type intersectsFunc predicate
func (f intersectsFunc) Intersects(p *geom.Polygon, hash string) (bool, error) {
return f(p, hash)
}
// Intersects tests if the geofence contains the hash by doing a geos intersection.
var Intersects = intersectsFunc(func(geofence *geom.Polygon, hash string) (bool, error) {
hashGeo := hashToGeometry(hash)
fence := polygonToGeometry(geofence)
return fence.Intersects(hashGeo)
})
// Contains tests if the geofence contains the hash by doing a geos contains.
var Contains = containsFunc(func(geofence *geom.Polygon, hash string) (bool, error) {
hashGeo := hashToGeometry(hash)
fence := polygonToGeometry(geofence)
return fence.Contains(hashGeo)
})
func geomToGeosCoord(coord geom.Coord) geos.Coord {
return geos.Coord{
X: coord.X(),
Y: coord.Y(),
}
}
func geomToGeosCoords(coords []geom.Coord) []geos.Coord {
out := make([]geos.Coord, len(coords))
for i := 0; i < len(coords); i++ {
out[i] = geomToGeosCoord(coords[i])
}
return out
}
// hashToGeometry converts a a geohash to a geos polygon by taking its bounding box.
func hashToGeometry(hash string) *geos.Geometry {
bounds := geohash.BoundingBox(hash)
return geos.Must(geos.NewPolygon([]geos.Coord{
geos.NewCoord(bounds.MinLng, bounds.MinLat),
geos.NewCoord(bounds.MinLng, bounds.MaxLat),
geos.NewCoord(bounds.MaxLng, bounds.MaxLat),
geos.NewCoord(bounds.MaxLng, bounds.MinLat),
geos.NewCoord(bounds.MinLng, bounds.MinLat),
}))
}
func polygonToGeometry(geofence *geom.Polygon) *geos.Geometry {
// Convert the outer shell to geos format.
shell := geofence.LinearRing(0).Coords()
shellGeos := geomToGeosCoords(shell)
// Convert each hole to geos format.
numHoles := geofence.NumLinearRings() - 1
holes := make([][]geos.Coord, numHoles)
for i := 0; i < numHoles; i++ {
holes[i] = geomToGeosCoords(geofence.LinearRing(i).Coords())
}
return geos.Must(geos.NewPolygon(shellGeos, holes...))
} | predicates.go | 0.839734 | 0.476701 | predicates.go | starcoder |
package btree
import (
"encoding/binary"
"fmt"
)
/*
Node is the BTree logical implementation
order: btree order which is the same number of pointers
in the node and the number of keys plus one
cells: key pointer pairs ordered by the key value
*/
type Node struct {
nodeType
order int
cells []cell
rightPointer uint32
pageSize int
}
/*
UnmarshalBinary reads in a page and attempts to return a typed
Node object. It accomplishes by doing the following things.
1. Read the node header (8 or 12 bytes).
2. Set the node type
4. Set the order based on page size
3. Read the cells
4. Set the page size for when the node needs to be serialized
*/
func (n *Node) UnmarshalBinary(data []byte) error {
if len(data) < 16 {
return fmt.Errorf(
"Node page too small: %d",
len(data),
)
}
/*
nodeHeader
0: node type
1-2: numCells
3-6: rightmost pointer
7: unused
*/
nodeHeader := data[:8]
n.nodeType = nodeType(nodeHeader[0])
numCells := binary.LittleEndian.Uint16(nodeHeader[1:3])
n.rightPointer = binary.LittleEndian.Uint32(nodeHeader[3:7])
if n.nodeType != interior && n.nodeType != leaf {
return fmt.Errorf("Unknown node type: %d", n.nodeType)
}
n.cells = make([]cell, numCells)
for i := uint16(0); i < numCells; i++ {
// Read cells in 8 byte increments
offset := (i * 8) + 8
cellBytes := data[offset : offset+8]
c := cell{
key: binary.LittleEndian.Uint32(cellBytes[:4]),
pointer: binary.LittleEndian.Uint32(cellBytes[4:8]),
}
n.cells[i] = c
}
// order is the number of pointers which is equal to
// the number of cells plus 1
n.order = ((len(data) - 8) / 8) + 1
// pagesize stored for when the node is reserialized
n.pageSize = len(data)
return nil
}
/*
MarshalBinary performs the opposite action of UnmarshalBinary
*/
func (n *Node) MarshalBinary() ([]byte, error) {
data := make([]byte, 0, n.pageSize)
data = append(data, byte(n.nodeType))
// append the numCells bytes
numCells16 := uint16(len(n.cells))
numCellsBytes := make([]byte, 2)
binary.LittleEndian.PutUint16(numCellsBytes, numCells16)
data = append(data, numCellsBytes...)
// append the right pointer
rightPointerBytes := make([]byte, 4)
binary.LittleEndian.PutUint32(rightPointerBytes, n.rightPointer)
data = append(data, rightPointerBytes...)
// append the empty header byte
data = append(data, 0)
// add the cells
for _, cell := range n.cells {
keyBytes := make([]byte, 4)
pointerBytes := make([]byte, 4)
binary.LittleEndian.PutUint32(keyBytes, cell.key)
binary.LittleEndian.PutUint32(pointerBytes, cell.pointer)
data = append(data, keyBytes...)
data = append(data, pointerBytes...)
}
// fill the remaining space
data = append(
data,
make([]byte, cap(data)-len(data))...,
)
return data, nil
}
/*
nodeType describes whether a node is a leaf or not
*/
type nodeType byte
const (
interior nodeType = 1
leaf
)
/*
cell is a key pointer pair in a btree node
key: corresponds to a value for comparison
pointer: left pointer for the key. all children's keys will
be less than or equal to the key value
serialized it is laid out on disk [key, pointer]
*/
type cell struct {
key uint32
pointer uint32
} | internal/backend/btree/node.go | 0.567817 | 0.477554 | node.go | starcoder |
package psinterpreter
import (
"errors"
"fmt"
)
// PathBounds represents a control bounds for
// a glyph outline (in font units).
type PathBounds struct {
Min, Max Point
}
// Enlarge enlarges the bounds to include pt
func (b *PathBounds) Enlarge(pt Point) {
if pt.X < b.Min.X {
b.Min.X = pt.X
}
if pt.X > b.Max.X {
b.Max.X = pt.X
}
if pt.Y < b.Min.Y {
b.Min.Y = pt.Y
}
if pt.Y > b.Max.Y {
b.Max.Y = pt.Y
}
}
// Point is a 2D Point in font units.
type Point struct{ X, Y int32 }
// Move translates the Point.
func (p *Point) Move(dx, dy int32) {
p.X += dx
p.Y += dy
}
// CharstringReader provides implementation
// of the operators found in a font charstring.
type CharstringReader struct {
Bounds PathBounds
vstemCount int32
hstemCount int32
hintmaskSize int32
CurrentPoint Point
isPathOpen bool
seenHintmask bool
// bounds for an empty path is {0,0,0,0}
// however, for the first point in the path,
// we must not compare the coordinates with {0,0,0,0}
seenPoint bool
}
// enlarges the current bounds to include the Point (x,y).
func (out *CharstringReader) updateBounds(pt Point) {
if !out.seenPoint {
out.Bounds.Min, out.Bounds.Max = pt, pt
out.seenPoint = true
return
}
out.Bounds.Enlarge(pt)
}
func (out *CharstringReader) Hstem(state *Machine) {
out.hstemCount += state.ArgStack.Top / 2
}
func (out *CharstringReader) Vstem(state *Machine) {
out.vstemCount += state.ArgStack.Top / 2
}
func (out *CharstringReader) determineHintmaskSize(state *Machine) {
if !out.seenHintmask {
out.vstemCount += state.ArgStack.Top / 2
out.hintmaskSize = (out.hstemCount + out.vstemCount + 7) >> 3
out.seenHintmask = true
}
}
func (out *CharstringReader) Hintmask(state *Machine) {
out.determineHintmaskSize(state)
state.SkipBytes(out.hintmaskSize)
}
func (out *CharstringReader) line(pt Point) {
if !out.isPathOpen {
out.isPathOpen = true
out.updateBounds(out.CurrentPoint)
}
out.CurrentPoint = pt
out.updateBounds(pt)
}
func (out *CharstringReader) curve(pt1, pt2, pt3 Point) {
if !out.isPathOpen {
out.isPathOpen = true
out.updateBounds(out.CurrentPoint)
}
/* include control Points */
out.updateBounds(pt1)
out.updateBounds(pt2)
out.CurrentPoint = pt3
out.updateBounds(pt3)
}
func (out *CharstringReader) doubleCurve(pt1, pt2, pt3, pt4, pt5, pt6 Point) {
out.curve(pt1, pt2, pt3)
out.curve(pt4, pt5, pt6)
}
func abs(x int32) int32 {
if x < 0 {
return -x
}
return x
}
// ------------------------------------------------------------
// LocalSubr pops the subroutine index and call it
func LocalSubr(state *Machine) error {
if state.ArgStack.Top < 1 {
return errors.New("invalid callsubr operator (empty stack)")
}
index := state.ArgStack.Pop()
return state.CallSubroutine(index, true)
}
// GlobalSubr pops the subroutine index and call it
func GlobalSubr(state *Machine) error {
if state.ArgStack.Top < 1 {
return errors.New("invalid callgsubr operator (empty stack)")
}
index := state.ArgStack.Pop()
return state.CallSubroutine(index, false)
}
func (out *CharstringReader) ClosePath() { out.isPathOpen = false }
func (out *CharstringReader) Rmoveto(state *Machine) error {
if state.ArgStack.Top < 2 {
return errors.New("invalid rmoveto operator")
}
out.CurrentPoint.Y += state.ArgStack.Pop()
out.CurrentPoint.X += state.ArgStack.Pop()
out.isPathOpen = false
return nil
}
func (out *CharstringReader) Vmoveto(state *Machine) error {
if state.ArgStack.Top < 1 {
return errors.New("invalid vmoveto operator")
}
out.CurrentPoint.Y += state.ArgStack.Pop()
out.isPathOpen = false
return nil
}
func (out *CharstringReader) Hmoveto(state *Machine) error {
if state.ArgStack.Top < 1 {
return errors.New("invalid hmoveto operator")
}
out.CurrentPoint.X += state.ArgStack.Pop()
out.isPathOpen = false
return nil
}
func (out *CharstringReader) Rlineto(state *Machine) {
for i := int32(0); i+2 <= state.ArgStack.Top; i += 2 {
newPoint := out.CurrentPoint
newPoint.Move(state.ArgStack.Vals[i], state.ArgStack.Vals[i+1])
out.line(newPoint)
}
state.ArgStack.Clear()
}
func (out *CharstringReader) Hlineto(state *Machine) {
var i int32
for ; i+2 <= state.ArgStack.Top; i += 2 {
newPoint := out.CurrentPoint
newPoint.X += state.ArgStack.Vals[i]
out.line(newPoint)
newPoint.Y += state.ArgStack.Vals[i+1]
out.line(newPoint)
}
if i < state.ArgStack.Top {
newPoint := out.CurrentPoint
newPoint.X += state.ArgStack.Vals[i]
out.line(newPoint)
}
}
func (out *CharstringReader) Vlineto(state *Machine) {
var i int32
for ; i+2 <= state.ArgStack.Top; i += 2 {
newPoint := out.CurrentPoint
newPoint.Y += state.ArgStack.Vals[i]
out.line(newPoint)
newPoint.X += state.ArgStack.Vals[i+1]
out.line(newPoint)
}
if i < state.ArgStack.Top {
newPoint := out.CurrentPoint
newPoint.Y += state.ArgStack.Vals[i]
out.line(newPoint)
}
}
// RelativeCurveTo draws a curve with controls points computed from
// the current point and `arg1`, `arg2`, `arg3`
func (out *CharstringReader) RelativeCurveTo(arg1, arg2, arg3 Point) {
pt1 := out.CurrentPoint
pt1.Move(arg1.X, arg1.Y)
pt2 := pt1
pt2.Move(arg2.X, arg2.Y)
pt3 := pt2
pt3.Move(arg3.X, arg3.Y)
out.curve(pt1, pt2, pt3)
}
func (out *CharstringReader) Rrcurveto(state *Machine) {
for i := int32(0); i+6 <= state.ArgStack.Top; i += 6 {
out.RelativeCurveTo(
Point{state.ArgStack.Vals[i], state.ArgStack.Vals[i+1]},
Point{state.ArgStack.Vals[i+2], state.ArgStack.Vals[i+3]},
Point{state.ArgStack.Vals[i+4], state.ArgStack.Vals[i+5]},
)
}
}
func (out *CharstringReader) Hhcurveto(state *Machine) {
var (
i int32
pt1 = out.CurrentPoint
)
if (state.ArgStack.Top & 1) != 0 {
pt1.Y += (state.ArgStack.Vals[i])
i++
}
for ; i+4 <= state.ArgStack.Top; i += 4 {
pt1.X += state.ArgStack.Vals[i]
pt2 := pt1
pt2.Move(state.ArgStack.Vals[i+1], state.ArgStack.Vals[i+2])
pt3 := pt2
pt3.X += state.ArgStack.Vals[i+3]
out.curve(pt1, pt2, pt3)
pt1 = out.CurrentPoint
}
}
func (out *CharstringReader) Vhcurveto(state *Machine) {
var i int32
if (state.ArgStack.Top % 8) >= 4 {
pt1 := out.CurrentPoint
pt1.Y += state.ArgStack.Vals[i]
pt2 := pt1
pt2.Move(state.ArgStack.Vals[i+1], state.ArgStack.Vals[i+2])
pt3 := pt2
pt3.X += state.ArgStack.Vals[i+3]
i += 4
for ; i+8 <= state.ArgStack.Top; i += 8 {
out.curve(pt1, pt2, pt3)
pt1 = out.CurrentPoint
pt1.X += (state.ArgStack.Vals[i])
pt2 = pt1
pt2.Move(state.ArgStack.Vals[i+1], state.ArgStack.Vals[i+2])
pt3 = pt2
pt3.Y += (state.ArgStack.Vals[i+3])
out.curve(pt1, pt2, pt3)
pt1 = pt3
pt1.Y += (state.ArgStack.Vals[i+4])
pt2 = pt1
pt2.Move(state.ArgStack.Vals[i+5], state.ArgStack.Vals[i+6])
pt3 = pt2
pt3.X += (state.ArgStack.Vals[i+7])
}
if i < state.ArgStack.Top {
pt3.Y += (state.ArgStack.Vals[i])
}
out.curve(pt1, pt2, pt3)
} else {
for ; i+8 <= state.ArgStack.Top; i += 8 {
pt1 := out.CurrentPoint
pt1.Y += (state.ArgStack.Vals[i])
pt2 := pt1
pt2.Move(state.ArgStack.Vals[i+1], state.ArgStack.Vals[i+2])
pt3 := pt2
pt3.X += (state.ArgStack.Vals[i+3])
out.curve(pt1, pt2, pt3)
pt1 = pt3
pt1.X += (state.ArgStack.Vals[i+4])
pt2 = pt1
pt2.Move(state.ArgStack.Vals[i+5], state.ArgStack.Vals[i+6])
pt3 = pt2
pt3.Y += (state.ArgStack.Vals[i+7])
if (state.ArgStack.Top-i < 16) && ((state.ArgStack.Top & 1) != 0) {
pt3.X += (state.ArgStack.Vals[i+8])
}
out.curve(pt1, pt2, pt3)
}
}
}
func (out *CharstringReader) Hvcurveto(state *Machine) {
// pt1,: pt2, pt3;
var i int32
if (state.ArgStack.Top % 8) >= 4 {
pt1 := out.CurrentPoint
pt1.X += (state.ArgStack.Vals[i])
pt2 := pt1
pt2.Move(state.ArgStack.Vals[i+1], state.ArgStack.Vals[i+2])
pt3 := pt2
pt3.Y += (state.ArgStack.Vals[i+3])
i += 4
for ; i+8 <= state.ArgStack.Top; i += 8 {
out.curve(pt1, pt2, pt3)
pt1 = out.CurrentPoint
pt1.Y += (state.ArgStack.Vals[i])
pt2 = pt1
pt2.Move(state.ArgStack.Vals[i+1], state.ArgStack.Vals[i+2])
pt3 = pt2
pt3.X += (state.ArgStack.Vals[i+3])
out.curve(pt1, pt2, pt3)
pt1 = pt3
pt1.X += state.ArgStack.Vals[i+4]
pt2 = pt1
pt2.Move(state.ArgStack.Vals[i+5], state.ArgStack.Vals[i+6])
pt3 = pt2
pt3.Y += state.ArgStack.Vals[i+7]
}
if i < state.ArgStack.Top {
pt3.X += (state.ArgStack.Vals[i])
}
out.curve(pt1, pt2, pt3)
} else {
for ; i+8 <= state.ArgStack.Top; i += 8 {
pt1 := out.CurrentPoint
pt1.X += (state.ArgStack.Vals[i])
pt2 := pt1
pt2.Move(state.ArgStack.Vals[i+1], state.ArgStack.Vals[i+2])
pt3 := pt2
pt3.Y += (state.ArgStack.Vals[i+3])
out.curve(pt1, pt2, pt3)
pt1 = pt3
pt1.Y += (state.ArgStack.Vals[i+4])
pt2 = pt1
pt2.Move(state.ArgStack.Vals[i+5], state.ArgStack.Vals[i+6])
pt3 = pt2
pt3.X += (state.ArgStack.Vals[i+7])
if (state.ArgStack.Top-i < 16) && ((state.ArgStack.Top & 1) != 0) {
pt3.Y += state.ArgStack.Vals[i+8]
}
out.curve(pt1, pt2, pt3)
}
}
}
func (out *CharstringReader) Rcurveline(state *Machine) error {
argCount := state.ArgStack.Top
if argCount < 8 {
return fmt.Errorf("expected at least 8 operands for <rcurveline>, got %d", argCount)
}
var i int32
curveLimit := argCount - 2
for ; i+6 <= curveLimit; i += 6 {
pt1 := out.CurrentPoint
pt1.Move(state.ArgStack.Vals[i], state.ArgStack.Vals[i+1])
pt2 := pt1
pt2.Move(state.ArgStack.Vals[i+2], state.ArgStack.Vals[i+3])
pt3 := pt2
pt3.Move(state.ArgStack.Vals[i+4], state.ArgStack.Vals[i+5])
out.curve(pt1, pt2, pt3)
}
pt1 := out.CurrentPoint
pt1.Move(state.ArgStack.Vals[i], state.ArgStack.Vals[i+1])
out.line(pt1)
return nil
}
func (out *CharstringReader) Rlinecurve(state *Machine) error {
argCount := state.ArgStack.Top
if argCount < 8 {
return fmt.Errorf("expected at least 8 operands for <rlinecurve>, got %d", argCount)
}
var i int32
lineLimit := argCount - 6
for ; i+2 <= lineLimit; i += 2 {
pt1 := out.CurrentPoint
pt1.Move(state.ArgStack.Vals[i], state.ArgStack.Vals[i+1])
out.line(pt1)
}
pt1 := out.CurrentPoint
pt1.Move(state.ArgStack.Vals[i], state.ArgStack.Vals[i+1])
pt2 := pt1
pt2.Move(state.ArgStack.Vals[i+2], state.ArgStack.Vals[i+3])
pt3 := pt2
pt3.Move(state.ArgStack.Vals[i+4], state.ArgStack.Vals[i+5])
out.curve(pt1, pt2, pt3)
return nil
}
func (out *CharstringReader) Vvcurveto(state *Machine) {
var i int32
pt1 := out.CurrentPoint
if (state.ArgStack.Top & 1) != 0 {
pt1.X += state.ArgStack.Vals[i]
i++
}
for ; i+4 <= state.ArgStack.Top; i += 4 {
pt1.Y += state.ArgStack.Vals[i]
pt2 := pt1
pt2.Move(state.ArgStack.Vals[i+1], state.ArgStack.Vals[i+2])
pt3 := pt2
pt3.Y += state.ArgStack.Vals[i+3]
out.curve(pt1, pt2, pt3)
pt1 = out.CurrentPoint
}
}
func (out *CharstringReader) Hflex(state *Machine) error {
if state.ArgStack.Top != 7 {
return fmt.Errorf("expected 7 operands for <hflex>, got %d", state.ArgStack.Top)
}
pt1 := out.CurrentPoint
pt1.X += state.ArgStack.Vals[0]
pt2 := pt1
pt2.Move(state.ArgStack.Vals[1], state.ArgStack.Vals[2])
pt3 := pt2
pt3.X += state.ArgStack.Vals[3]
pt4 := pt3
pt4.X += state.ArgStack.Vals[4]
pt5 := pt4
pt5.X += state.ArgStack.Vals[5]
pt5.Y = pt1.Y
pt6 := pt5
pt6.X += state.ArgStack.Vals[6]
out.doubleCurve(pt1, pt2, pt3, pt4, pt5, pt6)
return nil
}
func (out *CharstringReader) Flex(state *Machine) error {
if state.ArgStack.Top != 13 {
return fmt.Errorf("expected 13 operands for <flex>, got %d", state.ArgStack.Top)
}
pt1 := out.CurrentPoint
pt1.Move(state.ArgStack.Vals[0], state.ArgStack.Vals[1])
pt2 := pt1
pt2.Move(state.ArgStack.Vals[2], state.ArgStack.Vals[3])
pt3 := pt2
pt3.Move(state.ArgStack.Vals[4], state.ArgStack.Vals[5])
pt4 := pt3
pt4.Move(state.ArgStack.Vals[6], state.ArgStack.Vals[7])
pt5 := pt4
pt5.Move(state.ArgStack.Vals[8], state.ArgStack.Vals[9])
pt6 := pt5
pt6.Move(state.ArgStack.Vals[10], state.ArgStack.Vals[11])
out.doubleCurve(pt1, pt2, pt3, pt4, pt5, pt6)
return nil
}
func (out *CharstringReader) Hflex1(state *Machine) error {
if state.ArgStack.Top != 9 {
return fmt.Errorf("expected 9 operands for <hflex1>, got %d", state.ArgStack.Top)
}
pt1 := out.CurrentPoint
pt1.Move(state.ArgStack.Vals[0], state.ArgStack.Vals[1])
pt2 := pt1
pt2.Move(state.ArgStack.Vals[2], state.ArgStack.Vals[3])
pt3 := pt2
pt3.X += state.ArgStack.Vals[4]
pt4 := pt3
pt4.X += state.ArgStack.Vals[5]
pt5 := pt4
pt5.Move(state.ArgStack.Vals[6], state.ArgStack.Vals[7])
pt6 := pt5
pt6.X += state.ArgStack.Vals[8]
pt6.Y = out.CurrentPoint.Y
out.doubleCurve(pt1, pt2, pt3, pt4, pt5, pt6)
return nil
}
func (out *CharstringReader) Flex1(state *Machine) error {
if state.ArgStack.Top != 11 {
return fmt.Errorf("expected 11 operands for <flex1>, got %d", state.ArgStack.Top)
}
var d Point
for i := 0; i < 10; i += 2 {
d.Move(state.ArgStack.Vals[i], state.ArgStack.Vals[i+1])
}
pt1 := out.CurrentPoint
pt1.Move(state.ArgStack.Vals[0], state.ArgStack.Vals[1])
pt2 := pt1
pt2.Move(state.ArgStack.Vals[2], state.ArgStack.Vals[3])
pt3 := pt2
pt3.Move(state.ArgStack.Vals[4], state.ArgStack.Vals[5])
pt4 := pt3
pt4.Move(state.ArgStack.Vals[6], state.ArgStack.Vals[7])
pt5 := pt4
pt5.Move(state.ArgStack.Vals[8], state.ArgStack.Vals[9])
pt6 := pt5
if abs(d.X) > abs(d.Y) {
pt6.X += state.ArgStack.Vals[10]
pt6.Y = out.CurrentPoint.Y
} else {
pt6.X = out.CurrentPoint.X
pt6.Y += state.ArgStack.Vals[10]
}
out.doubleCurve(pt1, pt2, pt3, pt4, pt5, pt6)
return nil
} | fonts/psinterpreter/charstrings.go | 0.732687 | 0.422803 | charstrings.go | starcoder |
package continuous
import (
gsl "github.com/jtejido/ggsl"
"github.com/jtejido/stats"
"github.com/jtejido/stats/err"
"math"
"math/rand"
)
// Rayleigh distribution
// https://en.wikipedia.org/wiki/Rayleigh_distribution
type Rayleigh struct {
scale float64 // σ
src rand.Source
}
func NewRayleigh(scale float64) (*Rayleigh, error) {
return NewRayleighWithSource(scale, nil)
}
func NewRayleighWithSource(scale float64, src rand.Source) (*Rayleigh, error) {
if scale <= 0 {
return nil, err.Invalid()
}
return &Rayleigh{scale, src}, nil
}
// σ ∈ (0,∞)
func (r *Rayleigh) Parameters() stats.Limits {
return stats.Limits{
"σ": stats.Interval{0, math.Inf(1), true, true},
}
}
// x ∈ [0,∞)
func (r *Rayleigh) Support() stats.Interval {
return stats.Interval{0, math.Inf(1), false, true}
}
func (r *Rayleigh) Probability(x float64) float64 {
if r.Support().IsWithinInterval(x) {
return (x / (r.scale * r.scale)) * math.Exp((-(x * x))/(2*(r.scale*r.scale)))
}
return 0
}
func (r *Rayleigh) Distribution(x float64) float64 {
if r.Support().IsWithinInterval(x) {
return 1.0 - math.Exp((-(x * x))/(2*(r.scale*r.scale)))
}
return 0
}
func (r *Rayleigh) Entropy() float64 {
return 1.0 + math.Log(r.scale) - math.Log(math.Sqrt(2.0)) + gsl.Euler/2.0
}
func (r *Rayleigh) ExKurtosis() float64 {
return -(6.0*(math.Pi*math.Pi) - 24.0*math.Pi + 16.0) / ((4.0 - math.Pi) * (4.0 - math.Pi))
}
func (r *Rayleigh) Skewness() float64 {
num := 2 * math.Sqrt(math.Pi) * (math.Pi - 3)
denom := math.Pow(4-math.Pi, 1.5)
return num / denom
}
func (r *Rayleigh) Inverse(p float64) float64 {
if p <= 0 {
return 0
}
if p >= 1 {
return math.Inf(1)
}
return math.Sqrt(-2.0 * (r.scale * r.scale) * math.Log(1.0-p))
}
func (r *Rayleigh) Mean() float64 {
return r.scale * math.Sqrt(math.Pi/2.)
}
func (r *Rayleigh) Median() float64 {
return r.scale * math.Sqrt(2*math.Log(2.))
}
func (r *Rayleigh) Mode() float64 {
return r.scale
}
func (r *Rayleigh) Variance() float64 {
return ((4 - math.Pi) / 2) * (r.scale * r.scale)
}
func (r *Rayleigh) Rand() float64 {
var rnd float64
if r.src == nil {
rnd = rand.Float64()
} else {
rnd = rand.New(r.src).Float64()
}
return r.Inverse(rnd)
} | dist/continuous/rayleigh.go | 0.837885 | 0.550607 | rayleigh.go | starcoder |
package solutions
import (
"reflect"
"pokman/bulbasaur/leetcode/ds"
)
func maxProfitIII(prices []int) int {
size := len(prices)
if size < 2 {
return 0
}
pre := make([]int, size)
min := prices[0]
for i := 1; i < len(prices); i++ {
if prices[i] < min {
min = prices[i]
}
pre[i] = ds.MaxInt(pre[i-1], prices[i]-min)
}
max := prices[size-1]
post := make([]int, size)
for i := size - 2; i >= 0; i-- {
if prices[i] > max {
max = prices[i]
}
post[i] = ds.MaxInt(post[i+1], max-prices[i])
}
max_profit := 0
for i := 0; i < size; i++ {
max_profit = ds.MaxInt(max_profit, pre[i]+post[i])
}
return max_profit
}
func init() {
desc := `
Say you have an array for which the ith element is the price of a given stock on day i.
Design an algorithm to find the maximum profit. You may complete at most two transactions.
Note: You may not engage in multiple transactions at the same time (i.e., you must sell the stock before you buy again).
Example 1:
Input: [3,3,5,0,0,3,1,4]
Output: 6
Explanation: Buy on day 4 (price = 0) and sell on day 6 (price = 3), profit = 3-0 = 3.
Then buy on day 7 (price = 1) and sell on day 8 (price = 4), profit = 4-1 = 3.
Example 2:
Input: [1,2,3,4,5]
Output: 4
Explanation: Buy on day 1 (price = 1) and sell on day 5 (price = 5), profit = 5-1 = 4.
Note that you cannot buy on day 1, buy on day 2 and sell them later, as you are
engaging multiple transactions at the same time. You must sell before buying again.
Example 3:
Input: [7,6,4,3,1]
Output: 0
Explanation: In this case, no transaction is done, i.e. max profit = 0.
`
sol := Solution{
Title: "Best Time to Buy and Sell StockIII",
Desc: desc,
Method: reflect.ValueOf(maxProfitIII),
Tests: make([]TestCase, 0),
}
a := TestCase{}
a.Input = []interface{}{[]int{3, 3, 5, 0, 0, 3, 1, 4}}
a.Output = []interface{}{6}
sol.Tests = append(sol.Tests, a)
a.Input = []interface{}{[]int{1, 2, 3, 4, 5}}
a.Output = []interface{}{4}
sol.Tests = append(sol.Tests, a)
a.Input = []interface{}{[]int{7, 6, 4, 3, 1}}
a.Output = []interface{}{0}
sol.Tests = append(sol.Tests, a)
a.Input = []interface{}{[]int{1, 2, 4, 2, 5, 7, 2, 4, 9, 0}}
a.Output = []interface{}{13}
sol.Tests = append(sol.Tests, a)
SolutionMap["0123"] = sol
} | solutions/0123.go | 0.614741 | 0.5144 | 0123.go | starcoder |
package maybe
import (
"fmt"
)
// Maybe is an minimal interface definition for the Just and Nothing types to share
type Maybe[T any] interface {
// Helper method to be used for the monadic functions and extracting values from the Maybe interface
Unwrap() (T, error)
}
// Just is a struct that contains a value of type T
type Just[T any] struct {
just T
}
func (j Just[T]) Unwrap() (T, error) {
return j.just, nil
}
// Nothing is a struct that does not contain a value of type T
type Nothing[T any] struct{}
func (j Nothing[T]) Unwrap() (t T, err error) {
err = fmt.Errorf("nothing!")
return
}
// fmap :: (a -> b) -> m a -> m b
// Fmap is a function that applies a function to values within a Maybe interface.
// This functoin defines the plumbing to extract a value from Maybe, apply the function,
// and then wrap the value again in a Maybe
func Fmap[A, B any](f func(A) B, ma Maybe[A]) Maybe[B] {
if u,err := ma.Unwrap(); err == nil {
return Just[B]{f(u)}
}
return Nothing[B]{}
}
// andThen :: (a -> m b) -> m a -> m b
// AndThen is a function that lets you chain functions that return Maybe values.
// Another name for this commonly used is `bind` (in the Haskell world)
// This function defines the plumbing for extracting a value, and then applying the function.
// Since the function returns a Maybe, no further action is required.
func AndThen[A, B any](f func(a A) Maybe[B], ma Maybe[A]) Maybe[B] {
if u,err := ma.Unwrap(); err == nil {
return f(u)
}
return Nothing[B]{}
}
// pure :: a -> m a
// Pure is a simple constructor for making a Maybe interface value with Just.
// You could use typical struct construction for this too.
// This is defined here to emphasize that this is a necessary condition to making Maybe a monad.
// This name comes from the Haskell world, where your lifting a pure value
// (meaning no side-effects associated to the value) into your Monad/Functor type.
func Pure[A any](a A) Maybe[A] {
return Just[A]{a}
}
// Join is a function used for collapsing structure down.
//
func Join[A any](m Maybe[Maybe[A]]) Maybe[A] {
if u, err := m.Unwrap(); err == nil {
return u
}
return Nothing[A]{}
} | pkg/struct/maybe/maybe.go | 0.556882 | 0.473596 | maybe.go | starcoder |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.