ameda

package module
v2.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Host64bit = strconv.IntSize == 64
	Host32bit = ^uint(0)>>32 == 0
)

Variables

This section is empty.

Functions

func AppendInt

func AppendInt(dst []byte, i int64, base int) []byte

AppendInt appends the string form of the integer i, as generated by FormatInt, to dst and returns the extended buffer. NOTE:

Compatible with standard package strconv.

func AppendUint

func AppendUint(dst []byte, i uint64, base int) []byte

AppendUint appends the string form of the unsigned integer i, as generated by FormatUint, to dst and returns the extended buffer. NOTE:

Compatible with standard package strconv.

func Atoi

func Atoi(s string) (int, error)

Atoi is equivalent to ParseInt(s, 10, 0), converted to type int.

func BoolToDigit

func BoolToDigit[T ~bool, D digit.Digit](v T) D

BoolToDigit converts bool to digit.

func BoolsToDigits

func BoolsToDigits[T ~bool, D digit.Digit](a []T) (b []D)

func DereferenceImplementType

func DereferenceImplementType(v reflect.Value) reflect.Type

DereferenceImplementType returns the underlying type of the value that implements the interface v.

func DereferenceInterfaceValue

func DereferenceInterfaceValue(v reflect.Value) reflect.Value

DereferenceInterfaceValue returns the value of the underlying type that implements the interface v.

func DereferencePtrValue

func DereferencePtrValue(v reflect.Value) reflect.Value

DereferencePtrValue returns the underlying non-pointer type value.

func DereferenceSlice

func DereferenceSlice(v reflect.Value) reflect.Value

DereferenceSlice convert []*D to []D.

func DereferenceType

func DereferenceType(t reflect.Type) reflect.Type

DereferenceType dereference, get the underlying non-pointer type.

func DereferenceValue

func DereferenceValue(v reflect.Value) reflect.Value

DereferenceValue dereference and unpack interface, get the underlying non-pointer and non-interface value.

func DigitToDigit

func DigitToDigit[T digit.Digit, D digit.Digit](v T) (D, error)

func DigitToFloat64

func DigitToFloat64[T digit.Digit](v T) float64

DigitToFloat64 converts digit to float64.

func DigitsToDigits

func DigitsToDigits[T digit.Digit, D digit.Digit](a []T) (b []D, err error)

DigitsToDigits creates a copy of the digit slice.

func FormatInt

func FormatInt(i int64, base int) string

FormatInt returns the string representation of i in the given base, for 2 <= base <= 62. NOTE:

Compatible with standard package strconv.

func FormatUint

func FormatUint(i uint64, base int) string

FormatUint returns the string representation of i in the given base, for 2 <= base <= 62. NOTE:

Compatible with standard package strconv.

func FormatUintByDict

func FormatUintByDict(dict []byte, num uint64) string

FormatUintByDict convert num into corresponding string according to dict.

func IndirectValue

func IndirectValue(v reflect.Value) reflect.Value

IndirectValue gets the indirect value.

func InitBool

func InitBool(p *bool, def bool) (done bool)

InitBool initializes false bool pointer with def.

func InitByte

func InitByte(p *byte, def byte) (done bool)

InitByte initializes zero byte pointer with def.

func InitFloat32

func InitFloat32(p *float32, def float32) (done bool)

InitFloat32 initializes zero float32 pointer with def.

func InitFloat64

func InitFloat64(p *float64, def float64) (done bool)

InitFloat64 initializes zero float64 pointer with def.

func InitInt

func InitInt(p *int, def int) (done bool)

InitInt initializes zero int pointer with def.

func InitInt16

func InitInt16(p *int16, def int16) (done bool)

InitInt16 initializes zero int16 pointer with def.

func InitInt32

func InitInt32(p *int32, def int32) (done bool)

InitInt32 initializes zero int32 pointer with def.

func InitInt64

func InitInt64(p *int64, def int64) (done bool)

InitInt64 initializes zero int64 pointer with def.

func InitInt8

func InitInt8(p *int8, def int8) (done bool)

InitInt8 initializes zero int8 pointer with def.

func InitPointer

func InitPointer(v reflect.Value) (done bool)

InitPointer initializes nil pointer with zero value.

func InitSampleValue

func InitSampleValue(t reflect.Type, maxNestingDeep int) reflect.Value

InitSampleValue initialize the given type with some non-zero value( "?", $max_number, 0.1, true)

func InitString

func InitString(p *string, def string) (done bool)

InitString initializes empty string pointer with def.

func InitUint

func InitUint(p *uint, def uint) (done bool)

InitUint initializes zero uint pointer with def.

func InitUint16

func InitUint16(p *uint16, def uint16) (done bool)

InitUint16 initializes zero uint16 pointer with def.

func InitUint32

func InitUint32(p *uint32, def uint32) (done bool)

InitUint32 initializes zero uint32 pointer with def.

func InitUint64

func InitUint64(p *uint64, def uint64) (done bool)

InitUint64 initializes zero uint64 pointer with def.

func InitUint8

func InitUint8(p *uint8, def uint8) (done bool)

InitUint8 initializes zero uint8 pointer with def.

func Itoa

func Itoa(i int) string

Itoa is equivalent to FormatInt(int64(i), 10). NOTE:

Compatible with standard package strconv.

func ParseInt

func ParseInt(s string, base int, bitSize int) (i int64, err error)

ParseInt interprets a string s in the given base (0, 2 to 62) and bit size (0 to 64) and returns the corresponding value i.

If base == 0, the base is implied by the string's prefix: base 2 for "0b", base 8 for "0" or "0o", base 16 for "0x", and base 10 otherwise. Also, for base == 0 only, underscore characters are permitted per the Go integer literal syntax. If base is below 0, is 1, or is above 62, an error is returned.

The bitSize argument specifies the integer type that the result must fit into. Bit sizes 0, 8, 16, 32, and 64 correspond to int, int8, int16, int32, and int64. If bitSize is below 0 or above 64, an error is returned.

The errors that ParseInt returns have concrete type *NumError and include err.Num = s. If s is empty or contains invalid digits, err.Err = ErrSyntax and the returned value is 0; if the value corresponding to s cannot be represented by a signed integer of the given size, err.Err = ErrRange and the returned value is the maximum magnitude integer of the appropriate bitSize and sign. NOTE:

Compatible with standard package strconv.

func ParseUint

func ParseUint(s string, base int, bitSize int) (uint64, error)

ParseUint is like ParseInt but for unsigned numbers. NOTE:

Compatible with standard package strconv.

func ParseUintByDict

func ParseUintByDict[D digit.Digit](dict []byte, numStr string) (D, error)

ParseUintByDict convert numStr into corresponding uint64 according to dict.

func ReferenceSlice

func ReferenceSlice(v reflect.Value, ptrDepth int) reflect.Value

ReferenceSlice convert []D to []*D, the ptrDepth is the count of '*'.

func ReferenceType

func ReferenceType(t reflect.Type, ptrDepth int) reflect.Type

ReferenceType convert D to *D, the ptrDepth is the count of '*'.

func ReferenceValue

func ReferenceValue(v reflect.Value, ptrDepth int) reflect.Value

ReferenceValue convert D to *D, the ptrDepth is the count of '*'.

func RuntimeTypeID

func RuntimeTypeID(t reflect.Type) uintptr

RuntimeTypeID returns the underlying type ID in current runtime from reflect.Type. NOTE:

*A and A returns the different runtime type ID;
It is 10 times performance of t.String().

func RuntimeTypeIDOf

func RuntimeTypeIDOf(i interface{}) uintptr

RuntimeTypeIDOf returns the underlying type ID in current runtime from interface object. NOTE:

*A and A returns the different runtime type ID;
It is 10 times performance of t.String().

func SetsDifference

func SetsDifference[T comparable](set1, set2 []T, others ...[]T) []T

SetsDifference calculates between multiple collections: set1 - set2 - others... This method does not change the existing slices, but instead returns a new slice.

func SetsIntersect

func SetsIntersect[T comparable](set1, set2 []T, others ...[]T) []T

SetsIntersect calculates between multiple collections: set1 ∩ set2 ∩ others... This method does not change the existing slices, but instead returns a new slice.

func SetsUnion

func SetsUnion[T comparable](set1, set2 []T, others ...[]T) []T

SetsUnion calculates between multiple collections: set1 ∪ set2 ∪ others... This method does not change the existing slices, but instead returns a new slice.

func StringToDigit

func StringToDigit[T ~string, D digit.Digit](v T, base int, bitSize int) (D, error)

StringToDigit converts ~string to digit. If base == 0, the base is implied by the string's prefix: base 2 for "0b", base 8 for "0" or "0o", base 16 for "0x", and base 10 otherwise. Also, for base == 0 only, underscore characters are permitted per the Go integer literal syntax. If base is below 0, is 1, or is above 62, an error is returned.

func StringsToDigits

func StringsToDigits[T ~string, D digit.Digit](a []T, base int, bitSize int) (b []D, err error)

func ToBool

func ToBool[T ~string | digit.Digit](v T) bool

ToBool converts D to bool.

func ToBools

func ToBools[T ~string | digit.Digit](a []T) []bool

ToBools converts []D to []bool.

func ToInterface

func ToInterface(v interface{}) interface{}

ToInterface converts any to interface.

func ToInterfaces

func ToInterfaces[T any](a []T) []interface{}

ToInterfaces converts []any to []interface.

func ToPtr

func ToPtr[T any](v T) *T

ToPtr converts D to *D.

func ToPtrWithErr

func ToPtrWithErr[T any](v T, err error) (*T, error)

ToPtrWithErr converts D to *D.

func ToString

func ToString[T ~string](v interface{}) T

ToString converts any to ~string.

func ToStrings

func ToStrings[T any, D ~string](a []T) []D

ToStrings converts []T to []D.

func UnsafeBytesToString

func UnsafeBytesToString(b []byte) string

UnsafeBytesToString convert []byte type to string type.

func UnsafeStringToBytes

func UnsafeStringToBytes(s string) []byte

UnsafeStringToBytes convert string type to []byte type. NOTE:

panic if modify the member value of the []byte.

func VecConcat

func VecConcat[T any](s ...[]T) []T

VecConcat is used to merge two or more slices. This method does not change the existing slices, but instead returns a new slice.

func VecCopy

func VecCopy[T any](s []T) []T

VecCopy creates a copy of the slice.

func VecCopyWithin

func VecCopyWithin[T any](s []T, target, start int, end ...int)

VecCopyWithin copies part of an slice to another location in the current slice. @target

Zero-based index at which to copy the sequence to. If negative, target will be counted from the end.

@start

Zero-based index at which to start copying elements from. If negative, start will be counted from the end.

@end

Zero-based index at which to end copying elements from. VecCopyWithin copies up to but not including end.
If negative, end will be counted from the end.
If end is omitted, VecCopyWithin will copy until the last index (default to len(s)).

func VecDistinct

func VecDistinct[T comparable](s *[]T, changeSlice bool) (distinctCount map[T]int)

VecDistinct calculates the count of each different element, and only saves these different elements in place if changeSlice is true.

func VecEvery

func VecEvery[T any](s []T, fn func(s []T, k int, v T) bool) bool

VecEvery tests whether all elements in the slice pass the test implemented by the provided function. NOTE:

Calling this method on an empty slice will return true for any condition!

func VecFill

func VecFill[T any](s []T, value T, start int, end ...int)

VecFill changes all elements in the current slice to a value, from a start index to an end index. @value

Zero-based index at which to copy the sequence to. If negative, target will be counted from the end.

@start

Zero-based index at which to start copying elements from. If negative, start will be counted from the end.

@end

Zero-based index at which to end copying elements from. VecCopyWithin copies up to but not including end.
If negative, end will be counted from the end.
If end is omitted, VecCopyWithin will copy until the last index (default to len(s)).

func VecFilter

func VecFilter[T any](s []T, fn func(s []T, k int, v T) bool) []T

VecFilter creates a new slice with all elements that pass the test implemented by the provided function.

func VecFind

func VecFind[T any](s []T, fn func(s []T, k int, v T) bool) (k int, v T)

VecFind returns the key-value of the first element in the provided slice that satisfies the provided testing function. NOTE:

If not found, k = -1

func VecIncludes

func VecIncludes[T comparable](s []T, valueToFind T, fromIndex ...int) bool

VecIncludes determines whether an slice includes a certain value among its entries. @fromIndex

The index to start the search at. Defaults to 0.

func VecIndexOf

func VecIndexOf[T comparable](s []T, searchElement T, fromIndex ...int) int

VecIndexOf returns the first index at which a given element can be found in the slice, or -1 if it is not present. @fromIndex

The index to start the search at. Defaults to 0.

func VecIntersect

func VecIntersect[T comparable](s ...[]T) (intersectCount map[T]int)

VecIntersect calculates intersection of two or more slices, and returns the count of each element.

func VecLastIndexOf

func VecLastIndexOf[T comparable](s []T, searchElement T, fromIndex ...int) int

VecLastIndexOf returns the last index at which a given element can be found in the slice, or -1 if it is not present. @fromIndex

The index to start the search at. Defaults to 0.

func VecMap

func VecMap[T any](s []T, fn func(s []T, k int, v T) T) []T

VecMap creates a new slice populated with the results of calling a provided function on every element in the calling slice.

func VecOne

func VecOne[T any](s []T) T

VecOne try to return the first element, otherwise return zero value.

func VecPop

func VecPop[T any](s *[]T) (T, bool)

VecPop removes the last element from an slice and returns that element. This method changes the length of the slice.

func VecPush

func VecPush[T any](s *[]T, element ...T) int

VecPush adds one or more elements to the end of an slice and returns the new length of the slice.

func VecPushDistinct

func VecPushDistinct[T comparable](s []T, element ...T) []T

VecPushDistinct adds one or more new elements that do not exist in the current slice at the end.

func VecReduce

func VecReduce[T any](s []T, fn func(s []T, k int, v, accumulator T) T, initialValue ...T) T

VecReduce executes a reducer function (that you provide) on each element of the slice, resulting in a single output value. @accumulator

The accumulator accumulates callback's return values.
It is the accumulated value previously returned in the last invocation of the callback—or initialValue,
if it was supplied (see below).

@initialValue

A value to use as the first argument to the first call of the callback.
If no initialValue is supplied, the first element in the slice will be used and skipped.

func VecReduceRight

func VecReduceRight[T any](s []T, fn func(s []T, k int, v, accumulator T) T, initialValue ...T) T

VecReduceRight applies a function against an accumulator and each value of the slice (from right-to-left) to reduce it to a single value. @accumulator

The accumulator accumulates callback's return values.
It is the accumulated value previously returned in the last invocation of the callback—or initialValue,
if it was supplied (see below).

@initialValue

A value to use as the first argument to the first call of the callback.
If no initialValue is supplied, the first element in the slice will be used and skipped.

func VecRemoveEvery

func VecRemoveEvery[T comparable](p *[]T, elements ...T) int

VecRemoveEvery removes all the elements from the slice, and returns the new length of the slice.

func VecRemoveFirst

func VecRemoveFirst[T comparable](p *[]T, elements ...T) int

VecRemoveFirst removes the first matched elements from the slice, and returns the new length of the slice.

func VecReverse

func VecReverse[T any](s []T)

VecReverse reverses an slice in place.

func VecShift

func VecShift[T any](s *[]T) (T, bool)

VecShift removes the first element from an slice and returns that removed element. This method changes the length of the slice.

func VecSlice

func VecSlice[T any](s []T, begin int, end ...int) []T

VecSlice returns a copy of a portion of an slice into a new slice object selected from begin to end (end not included) where begin and end represent the index of items in that slice. The original slice will not be modified.

func VecSome

func VecSome[T any](s []T, fn func(s []T, k int, v T) bool) bool

VecSome tests whether at least one element in the slice passes the test implemented by the provided function. NOTE:

Calling this method on an empty slice returns false for any condition!

func VecSplice

func VecSplice[T any](s *[]T, start, deleteCount int, items ...T)

VecSplice changes the contents of an slice by removing or replacing existing elements and/or adding new elements in place.

func VecUnshift

func VecUnshift[T any](s *[]T, element ...T) int

VecUnshift adds one or more elements to the beginning of an slice and returns the new length of the slice.

func VecUnshiftDistinct

func VecUnshiftDistinct[T comparable](s *[]T, element ...T) int

VecUnshiftDistinct adds one or more new elements that do not exist in the current slice to the beginning and returns the new length of the slice.

func Zero

func Zero[T any]() T

Zero return zero value.

Types

type Value

type Value struct {
	// contains filtered or unexported fields
}

Value go underlying type data

func ValueFrom

func ValueFrom(v reflect.Value) Value

ValueFrom gets go underlying type data from reflect.Value.

func ValueFrom2

func ValueFrom2(v *reflect.Value) Value

ValueFrom2 gets go underlying type data from *reflect.Value.

func ValueOf

func ValueOf(i interface{}) Value

ValueOf unpacks i to go underlying type data.

func (Value) CanAddr

func (v Value) CanAddr() bool

CanAddr reports whether the value's address can be obtained with Addr. Such values are called addressable. A value is addressable if it is an element of a slice, an element of an addressable array, a field of an addressable struct, or the result of dereferencing a pointer.

func (Value) Elem

func (v Value) Elem() Value

Elem returns the Value that the interface i contains or that the pointer i points to.

func (Value) FuncForPC

func (v Value) FuncForPC() *runtime.Func

FuncForPC returns a *Func describing the function that contains the given program counter address, or else nil.

If pc represents multiple functions because of inlining, it returns the a *Func describing the innermost function, but with an entry of the outermost function.

NOTE: Its kind must be a reflect.Func, otherwise it returns nil

func (Value) IsNil

func (v Value) IsNil() bool

IsNil reports whether its argument i is nil.

func (Value) Kind

func (v Value) Kind() reflect.Kind

Kind gets the reflect.Kind fastly.

func (Value) Pointer

func (v Value) Pointer() uintptr

Pointer gets the pointer of i. NOTE:

*D and D, gets diffrent pointer

func (Value) RuntimeTypeID

func (v Value) RuntimeTypeID() uintptr

RuntimeTypeID gets the underlying type ID in current runtime. NOTE:

*A and A gets the different runtime type ID;
It is 10 times performance of reflect.TypeOf(i).String().

func (Value) UnderlyingElem

func (v Value) UnderlyingElem() Value

UnderlyingElem returns the underlying Value that the interface i contains or that the pointer i points to.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL