util

package
v0.0.0-...-1e7f4ca Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	B  DataSize = 1
	KB          = B << 10
	MB          = KB << 10
	GB          = MB << 10
	TB          = GB << 10
	PB          = TB << 10
	EB          = PB << 10
)
View Source
const (
	BYTE_BYTES = 1

	INT8_BYTES   = 1
	INT16_BYTES  = 2
	INT32_BYTES  = 4
	INT64_BYTES  = 8
	INT128_BYTES = 16

	FLOAT32_BYTES = 4
	FLOAT64_BYTES = 8

	INT64_SIZE = 64
)
View Source
const (
	// SizeUint8 is the byte size of a uint8.
	SizeUint8 = 1
	// SizeUint16 is the byte size of a uint16.
	SizeUint16 = 2
	// SizeUint32 is the byte size of a uint32.
	SizeUint32 = 4
	// SizeUint64 is the byte size of a uint64.
	SizeUint64 = 8

	// SizeInt8 is the byte size of a int8.
	SizeInt8 = 1
	// SizeInt16 is the byte size of a int16.
	SizeInt16 = 2
	// SizeInt32 is the byte size of a int32.
	SizeInt32 = 4
	// SizeInt64 is the byte size of a int64.
	SizeInt64 = 8

	// SizeFloat32 is the byte size of a float32.
	SizeFloat32 = 4
	// SizeFloat64 is the byte size of a float64.
	SizeFloat64 = 8

	// SizeByte is the byte size of a byte.
	// The `byte` type is aliased (by Go definition) to uint8.
	SizeByte = 1

	// SizeBool is the byte size of a bool.
	// The `bool` type is aliased (by flatbuffers convention) to uint8.
	SizeBool = 1

	// SizeSOffsetT is the byte size of an SOffsetT.
	// The `SOffsetT` type is aliased (by flatbuffers convention) to int32.
	SizeSOffsetT = 4
	// SizeUOffsetT is the byte size of an UOffsetT.
	// The `UOffsetT` type is aliased (by flatbuffers convention) to uint32.
	SizeUOffsetT = 4
	// SizeVOffsetT is the byte size of an VOffsetT.
	// The `VOffsetT` type is aliased (by flatbuffers convention) to uint16.
	SizeVOffsetT = 2
)
View Source
const (
	SET_ThreadSafe = iota
	SET_NonThreadSafe
)
View Source
const (
	// VtableMetadataFields is the count of metadata fields in each vtable.
	VtableMetadataFields = 2
)

Variables

View Source
var (
	INT16_ZERO   int16   = 0
	INT32_ZERO   int32   = 0
	INT64_ZERO   int64   = 0
	FLOAT64_ZERO float64 = 0
)
View Source
var (
	EMPTY = []byte{}
)
View Source
var EMPTY_MAP map[string]string = make(map[string]string)

basic map

View Source
var ErrBits = errors.New("unit with capital unit prefix and lower case unit (b) - bits, not bytes ")
View Source
var QUICKSORT_MEDIAN_OF_9 int32 = 128
View Source
var QUICKSORT_NO_REC int32 = 16

Functions

func AddExactInt64

func AddExactInt64(x, y int64) int64

func BoolArraySame

func BoolArraySame(array1 []bool, array2 []bool) bool

func BoolsLenInt32

func BoolsLenInt32(b []bool) int32

*

*

func ByteSliceToString

func ByteSliceToString(b []byte) string

byteSliceToString converts a []byte to string without a heap allocation.

func BytesLenInt32

func BytesLenInt32(b []byte) int32

*

*

func BytesToInt64

func BytesToInt64(buf []byte, i int) int64

func CheckArgument

func CheckArgument(expression bool)

func CheckArgument2

func CheckArgument2(expression bool, msg string)

func CheckNotNull

func CheckNotNull[T basic.Object](reference T) T

func CheckState

func CheckState(expression bool)

func CheckState2

func CheckState2(expression bool, msg string)

func CopyArrays

func CopyArrays[T basic.Object](from []T, srcPos int32, dest []T, destPos int32, length int32)

func CopyBools

func CopyBools(from []bool, srcPos int32, dest []bool, destPos int, length int32)

func CopyBoolsOfRange

func CopyBoolsOfRange(original []bool, from int32, to int32) []bool

func CopyBytes

func CopyBytes(from []byte, srcPos int32, dest []byte, destPos int32, length int32)

func CopyFloat64s

func CopyFloat64s(from []float64, srcPos int32, dest []float64, destPos int32, length int32)

func CopyInt16s

func CopyInt16s(from []int16, srcPos int32, dest []int16, destPos int32, length int32)

func CopyInt16sOfRange

func CopyInt16sOfRange(original []int16, from int32, to int32) []int16

func CopyInt32s

func CopyInt32s(from []int32, srcPos int32, dest []int32, destPos int32, length int32)

func CopyInt32sOfRange

func CopyInt32sOfRange(original []int32, from int32, to int32) []int32

func CopyInt64s

func CopyInt64s(from []int64, srcPos int32, dest []int64, destPos int32, length int32)

func CopyOfBools

func CopyOfBools(original []bool, newLength int32) []bool

func CopyOfBytes

func CopyOfBytes(original []byte, newLength int32) []byte

func CopyOfFloat64s

func CopyOfFloat64s(original []float64, newLength int32) []float64

func CopyOfInt16s

func CopyOfInt16s(original []int16, newLength int32) []int16

func CopyOfInt32

func CopyOfInt32(original []int32, newLength int32) []int32

func CopyOfInt64s

func CopyOfInt64s(original []int64, newLength int32) []int64

func EmptyMap

func EmptyMap[K basic.ComObj, V basic.Object]() map[K]V

func FillArrays

func FillArrays[T basic.Object](array []T, index int32, length int32, value T)

func FillInt32Range

func FillInt32Range(a []int32, start int32, end int32, value int32)

func FillInt32s

func FillInt32s(array []int32, value int32)

func FillInt64s

func FillInt64s(array []int64, value int64)

func FilterKeys

func FilterKeys[K basic.ComObj, V basic.Object](src map[K]V, f func(K) bool) map[K]V

func GetBool

func GetBool(buf []byte) bool

GetBool decodes a little-endian bool from a byte slice.

func GetByte

func GetByte(buf []byte) byte

GetByte decodes a little-endian byte from a byte slice.

func GetFloat32

func GetFloat32(buf []byte) float32

GetFloat32 decodes a little-endian float32 from a byte slice.

func GetFloat64

func GetFloat64(buf []byte) float64

GetFloat64 decodes a little-endian float64 from a byte slice.

func GetInt16

func GetInt16(buf []byte) (n int16)

GetInt16 decodes a little-endian int16 from a byte slice.

func GetInt32

func GetInt32(buf []byte) (n int32)

GetInt32 decodes a little-endian int32 from a byte slice.

func GetInt64

func GetInt64(buf []byte) (n int64)

GetInt64 decodes a little-endian int64 from a byte slice.

func GetInt8

func GetInt8(buf []byte) (n int8)

GetInt8 decodes a little-endian int8 from a byte slice.

func GetUint16

func GetUint16(buf []byte) (n uint16)

GetUint16 decodes a little-endian uint16 from a byte slice.

func GetUint32

func GetUint32(buf []byte) (n uint32)

GetUint32 decodes a little-endian uint32 from a byte slice.

func GetUint64

func GetUint64(buf []byte) (n uint64)

GetUint64 decodes a little-endian uint64 from a byte slice.

func GetUint8

func GetUint8(buf []byte) (n uint8)

GetUint8 decodes a little-endian uint8 from a byte slice.

func If

func If(cond bool, a, b interface{}) interface{}

func Int16sLenInt32

func Int16sLenInt32(b []int16) int32

func Int32Exact

func Int32Exact(value int64) int32

func Int32ExactU

func Int32ExactU(value uint64) int32

func Int32sLenInt32

func Int32sLenInt32(b []int32) int32

*

*

func Int64sLenInt32

func Int64sLenInt32(b []int64) int32

func IntSlice

func IntSlice(s SetInterface[int]) []int

IntSlice is a helper function that returns a slice of ints of s. If the set contains mixed types of items only items of type int are returned.

func JoinNums

func JoinNums[T basic.Numbers](elems []T, sep string) string

func Lens

func Lens[T basic.Object](a []T) int32

*

  • 计算指定数组的长度

func LensInt64

func LensInt64[T basic.Object](a []T) int64

func Md5Hash

func Md5Hash(data []byte) string

func Md5HashBytes

func Md5HashBytes(data []byte) []byte

func NewMap

func NewMap[K basic.ComObj, V basic.Object](k K, v V) map[K]V

*

  • 给k,v 返回map

func ParseInt

func ParseInt(str string, offset int32, length int32, base int32) int32

func ParseInt64

func ParseInt64(str string, offset int32, length int32, base int32) int64

func PutAll

func PutAll[K basic.ComObj, V basic.Object](dest map[K]V, src map[K]V)

func QuickSortIndirect

func QuickSortIndirect(perm []int32, x []float64, from int32, to int32)

*

  • Sorts the specified range of elements according to the natural ascending
  • order using indirect quicksort. *
  • <p>
  • The sorting algorithm is a tuned quicksort adapted from Jon L. Bentley and M.
  • Douglas McIlroy, &ldquo;Engineering a Sort Function&rdquo;, <i>Software:
  • Practice and Experience</i>, 23(11), pages 1249&minus;1265, 1993. *
  • <p>
  • This method implement an <em>indirect</em> sort. The elements of {@code perm}
  • (which must be exactly the numbers in the interval {@code [0..perm.length)})
  • will be permuted so that {@code x[perm[i]] &le; x[perm[i + 1]]}. *
  • <p>
  • Note that this implementation does not allocate any object, contrarily to the
  • implementation used to sort primitive types in {@link java.util.Arrays},
  • which switches to mergesort on large inputs. *
  • @param perm a permutation array indexing {@code x}.
  • @param x the array to be sorted.
  • @param from the index of the first element (inclusive) to be sorted.
  • @param to the index of the last element (exclusive) to be sorted.

func ReverseNums

func ReverseNums[T basic.Object](array []T, fromIndex int32, toIndex int32)

func Sha1Hash

func Sha1Hash(data []byte) string

func Sha1HashBytes

func Sha1HashBytes(data []byte) []byte

func SizeOf

func SizeOf(t basic.Object) int32

func SizeOfInt64

func SizeOfInt64(t basic.Object) int64

func StringSlice

func StringSlice(s SetInterface[string]) []string

StringSlice is a helper function that returns a slice of strings of s. If the set contains mixed types of items only items of type string are returned.

func Strval

func Strval(value interface{}) string

Strval 获取变量的字符串值 浮点型 3.0将会转换成字符串3, "3" 非数值或字符类型的变量将会被转换成JSON格式字符串

func SubStrNoEnd

func SubStrNoEnd(source string, start int) string

func Substring

func Substring(source string, start int, end int) string

获取source的子串,如果start小于0或者end大于source长度则返回"" start:开始index,从0开始,包括0 end:结束index,以end结束,但不包括end

func Ternary

func Ternary[T basic.Object](cond bool, a, b T) T

func ToArrayT

func ToArrayT[S basic.Object, T basic.Object](list *ArrayList[S]) []T

func ToByteExact

func ToByteExact(value int64) (byte, error)

func ToInt16Exact

func ToInt16Exact(value int64) (int16, error)

func ToInt32Exact

func ToInt32Exact(value int64) (int32, error)

func ToInt8Exact

func ToInt8Exact(value int64) (int8, error)

func ToIntExact

func ToIntExact(value int64) (int, error)

func Try

func Try(f func(), catch func(interface{}), finally func())

func UniqueIndex

func UniqueIndex[K basic.ComObj, V basic.Object](values *ArrayList[V], keyFunction func(v V) K) map[K]V

func Verify

func Verify(expression bool)

func Verify2

func Verify2(expression bool, msg string)

func WriteBool

func WriteBool(buf []byte, b bool)

WriteBool encodes a little-endian bool into a byte slice.

func WriteByte

func WriteByte(buf []byte, n byte)

WriteByte encodes a little-endian uint8 into a byte slice.

func WriteFloat32

func WriteFloat32(buf []byte, n float32)

WriteFloat32 encodes a little-endian float32 into a byte slice.

func WriteFloat64

func WriteFloat64(buf []byte, n float64)

WriteFloat64 encodes a little-endian float64 into a byte slice.

func WriteInt16

func WriteInt16(buf []byte, n int16)

WriteInt16 encodes a little-endian int16 into a byte slice.

func WriteInt32

func WriteInt32(buf []byte, n int32)

WriteInt32 encodes a little-endian int32 into a byte slice.

func WriteInt64

func WriteInt64(buf []byte, n int64)

WriteInt64 encodes a little-endian int64 into a byte slice.

func WriteInt8

func WriteInt8(buf []byte, n int8)

WriteInt8 encodes a little-endian int8 into a byte slice.

func WriteSOffsetT

func WriteSOffsetT(buf []byte, n SOffsetT)

WriteSOffsetT encodes a little-endian SOffsetT into a byte slice.

func WriteUOffsetT

func WriteUOffsetT(buf []byte, n UOffsetT)

WriteUOffsetT encodes a little-endian UOffsetT into a byte slice.

func WriteUint16

func WriteUint16(buf []byte, n uint16)

WriteUint16 encodes a little-endian uint16 into a byte slice.

func WriteUint32

func WriteUint32(buf []byte, n uint32)

WriteUint32 encodes a little-endian uint32 into a byte slice.

func WriteUint64

func WriteUint64(buf []byte, n uint64)

WriteUint64 encodes a little-endian uint64 into a byte slice.

func WriteUint8

func WriteUint8(buf []byte, n uint8)

WriteUint8 encodes a little-endian uint8 into a byte slice.

func WriteVOffsetT

func WriteVOffsetT(buf []byte, n VOffsetT)

WriteVOffsetT encodes a little-endian VOffsetT into a byte slice.

Types

type ArrayList

type ArrayList[T basic.Object] struct {
	// 继承
	List[T]

	// 继承
	sort.Interface
	// contains filtered or unexported fields
}

func EMPTY_LIST

func EMPTY_LIST[T basic.Object]() *ArrayList[T]

func MapKeys

func MapKeys[K basic.ComObj, V basic.Object](src map[K]V) *ArrayList[K]

func MapValues

func MapValues[K basic.ComObj, V basic.Object](src map[K]V) *ArrayList[V]

func NewArrayList

func NewArrayList[T basic.Object](values ...T) *ArrayList[T]

func NewCmpList

func NewCmpList[T basic.Object](cmp Compare[T]) *ArrayList[T]

func NewCmpListWithValues

func NewCmpListWithValues[T basic.Object](cmp Compare[T], values ...T) *ArrayList[T]

func (*ArrayList[T]) Add

func (list *ArrayList[T]) Add(values ...T) List[T]

func (*ArrayList[T]) AddAll

func (list *ArrayList[T]) AddAll(values List[T]) List[T]

func (*ArrayList[T]) AddAllIndex

func (list *ArrayList[T]) AddAllIndex(index int32, values List[T]) List[T]

func (*ArrayList[T]) AddIndex

func (list *ArrayList[T]) AddIndex(index int32, values ...T) List[T]

func (*ArrayList[T]) Clear

func (list *ArrayList[T]) Clear()

func (*ArrayList[T]) Contains

func (list *ArrayList[T]) Contains(value T) bool

func (*ArrayList[T]) ForEach

func (list *ArrayList[T]) ForEach(f func(T))

func (*ArrayList[T]) Get

func (list *ArrayList[T]) Get(index int) T

func (*ArrayList[T]) GetByInt32

func (list *ArrayList[T]) GetByInt32(index int32) T

func (*ArrayList[T]) IsEmpty

func (list *ArrayList[T]) IsEmpty() bool

func (*ArrayList[T]) Iter

func (list *ArrayList[T]) Iter() Iterator[T]

func (*ArrayList[T]) Len

func (list *ArrayList[T]) Len() int

@Override for sort.Interface

func (*ArrayList[T]) Less

func (list *ArrayList[T]) Less(i, j int) bool

@Override for sort.Interface

func (*ArrayList[T]) Remove

func (list *ArrayList[T]) Remove(index int) T

func (*ArrayList[T]) Size

func (list *ArrayList[T]) Size() int

func (*ArrayList[T]) SizeInt32

func (list *ArrayList[T]) SizeInt32() int32

func (*ArrayList[T]) Stream

func (list *ArrayList[T]) Stream() *Stream[T]

func (*ArrayList[T]) SubList

func (list *ArrayList[T]) SubList(start int, end int) *ArrayList[T]

func (*ArrayList[T]) Swap

func (list *ArrayList[T]) Swap(i, j int)

@Override for sort.Interface

func (*ArrayList[T]) ToArray

func (list *ArrayList[T]) ToArray() []T

type Compare

type Compare[T basic.Object] interface {
	Cmp(i, j T) int
}

type CopiesList

type CopiesList[T basic.Object] struct {
	// 继承
	List[T]
	// contains filtered or unexported fields
}

func (*CopiesList[T]) Add

func (ct *CopiesList[T]) Add(values ...T) List[T]

func (*CopiesList[T]) AddAll

func (ct *CopiesList[T]) AddAll(values List[T]) List[T]

func (*CopiesList[T]) AddAllIndex

func (ct *CopiesList[T]) AddAllIndex(index int32, values List[T]) List[T]

func (*CopiesList[T]) AddIndex

func (ct *CopiesList[T]) AddIndex(index int32, values ...T) List[T]

func (*CopiesList[T]) Clear

func (ct *CopiesList[T]) Clear()

func (*CopiesList[T]) Contains

func (ct *CopiesList[T]) Contains(value T) bool

func (*CopiesList[T]) ForEach

func (ct *CopiesList[T]) ForEach(f func(T))

func (*CopiesList[T]) Get

func (ct *CopiesList[T]) Get(index int) T

func (*CopiesList[T]) IsEmpty

func (ct *CopiesList[T]) IsEmpty() bool

func (*CopiesList[T]) Iter

func (ct *CopiesList[T]) Iter() Iterator[T]

func (*CopiesList[T]) Remove

func (ct *CopiesList[T]) Remove(index int) T

func (*CopiesList[T]) Size

func (ct *CopiesList[T]) Size() int

func (*CopiesList[T]) Stream

func (ct *CopiesList[T]) Stream() *Stream[T]

func (*CopiesList[T]) ToArray

func (ct *CopiesList[T]) ToArray() []T

type DataSize

type DataSize uint64

func MustParse

func MustParse(t []byte) DataSize

func MustParseString

func MustParseString(s string) DataSize

func Ofds

func Ofds(i uint64, base DataSize) DataSize

func Parse

func Parse(t []byte) (DataSize, error)

func ParseString

func ParseString(s string) (DataSize, error)

func (DataSize) Bytes

func (b DataSize) Bytes() uint64

func (DataSize) EBytes

func (b DataSize) EBytes() float64

func (DataSize) GBytes

func (b DataSize) GBytes() float64

func (DataSize) HR

func (b DataSize) HR() string

func (DataSize) HumanReadable

func (b DataSize) HumanReadable() string

func (DataSize) KBytes

func (b DataSize) KBytes() float64

func (DataSize) MBytes

func (b DataSize) MBytes() float64

func (DataSize) MarshalText

func (b DataSize) MarshalText() ([]byte, error)

func (DataSize) PBytes

func (b DataSize) PBytes() float64

func (DataSize) String

func (b DataSize) String() string

func (DataSize) TBytes

func (b DataSize) TBytes() float64

func (*DataSize) UnmarshalText

func (b *DataSize) UnmarshalText(t []byte) error

type Int32Stream

type Int32Stream struct {
	Head     int32
	Tail     *Int32Stream
	Length   int
	NotEmpty bool
}

func GenInt32Stream

func GenInt32Stream(r *Int32Stream, f func(*Int32Stream) int32, m int) *Int32Stream

func NewInt32Stream

func NewInt32Stream(head int32, tail *Int32Stream) *Int32Stream

func NullInt32

func NullInt32() *Int32Stream

func (*Int32Stream) Add

func (s *Int32Stream) Add(i int32) *Int32Stream

func (*Int32Stream) Addall

func (s *Int32Stream) Addall(i ...int32) *Int32Stream

func (*Int32Stream) Filter

func (s *Int32Stream) Filter(f func(int32) bool) *Int32Stream

func (*Int32Stream) FoldLeft

func (s *Int32Stream) FoldLeft(i *Int32Stream, f func(*Int32Stream, int32) *Int32Stream) *Int32Stream

左折叠 用于实现 reduce 的功能

func (*Int32Stream) FoldRight

func (s *Int32Stream) FoldRight(i *Int32Stream, f func(*Int32Stream, int32) *Int32Stream) *Int32Stream

右折叠

func (*Int32Stream) Merge

func (s *Int32Stream) Merge(t *Int32Stream) *Int32Stream

合并两个 Int32Stream

func (*Int32Stream) Reduce

func (s *Int32Stream) Reduce(i int32, f func(int32, int32) int32) int32

func (*Int32Stream) Reverse

func (s *Int32Stream) Reverse() *Int32Stream

倒序

func (*Int32Stream) Sort

func (s *Int32Stream) Sort(c func(int32, int32) bool) *Int32Stream

func (*Int32Stream) Sum

func (s *Int32Stream) Sum() int32

type Iterable

type Iterable[T basic.Object] interface {
	Iter() Iterator[T]

	ForEach(func(T))
}

type Iterator

type Iterator[T basic.Object] interface {
	HasNext() bool
	Next() T
	ForEach(func(T))
}

type List

type List[T basic.Object] interface {
	// 继承
	Iterable[T]

	Remove(index int) T
	Get(index int) T
	IsEmpty() bool
	Size() int

	AddIndex(index int32, values ...T) List[T]
	Add(values ...T) List[T]

	AddAll(values List[T]) List[T]
	AddAllIndex(index int32, values List[T]) List[T]

	Contains(value T) bool
	Clear()
	ForEach(f func(T))
	ToArray() []T

	Stream() *Stream[T]
	Iter() Iterator[T]
}

func NCopysList

func NCopysList[T basic.Object](n int, element T) List[T]

type LongStream

type LongStream struct {
	Head     int64
	Tail     *LongStream
	Length   int
	NotEmpty bool
}

func GenLongStream

func GenLongStream(r *LongStream, f func(*LongStream) int64, m int) *LongStream

func NewLongStream

func NewLongStream(head int64, tail *LongStream) *LongStream

func NullLong

func NullLong() *LongStream

func (*LongStream) Add

func (s *LongStream) Add(i int64) *LongStream

func (*LongStream) Addall

func (s *LongStream) Addall(i ...int64) *LongStream

func (*LongStream) Filter

func (s *LongStream) Filter(f func(int64) bool) *LongStream

func (*LongStream) FoldLeft

func (s *LongStream) FoldLeft(i *LongStream, f func(*LongStream, int64) *LongStream) *LongStream

左折叠 用于实现 reduce 的功能

func (*LongStream) FoldRight

func (s *LongStream) FoldRight(i *LongStream, f func(*LongStream, int64) *LongStream) *LongStream

右折叠

func (*LongStream) Merge

func (s *LongStream) Merge(t *LongStream) *LongStream

合并两个 LongStream

func (*LongStream) Reduce

func (s *LongStream) Reduce(i int64, f func(int64, int64) int64) int64

func (*LongStream) Reverse

func (s *LongStream) Reverse() *LongStream

倒序

func (*LongStream) Sort

func (s *LongStream) Sort(c func(int64, int64) bool) *LongStream

func (*LongStream) Sum

func (s *LongStream) Sum() int64

type MothMap

type MothMap[K basic.ComObj, V basic.Object] map[K]V

MothMap

func (MothMap[K, V]) Put

func (m MothMap[K, V]) Put(k K, v V)

type Predicate

type Predicate[T basic.Object] interface {
	Test(t T) bool
}

校验

type SOffsetT

type SOffsetT int32

A SOffsetT stores a signed offset into arbitrary data.

func GetSOffsetT

func GetSOffsetT(buf []byte) SOffsetT

GetSOffsetT decodes a little-endian SOffsetT from a byte slice.

type Set

type Set[T basic.ComObj] struct {
	// contains filtered or unexported fields
}

Set defines a thread safe set data structure.

func (*Set[T]) Add

func (s *Set[T]) Add(items ...T)

Add includes the specified items (one or more) to the set. The underlying Set s is modified. If passed nothing it silently returns.

func (*Set[T]) Clear

func (s *Set[T]) Clear()

Clear removes all items from the set.

func (*Set[T]) Copy

func (s *Set[T]) Copy() SetInterface[T]

Copy returns a new Set with a copy of s.

func (*Set[T]) Each

func (s *Set[T]) Each(f func(item T) bool)

Each traverses the items in the Set, calling the provided function for each set member. Traversal will continue until all items in the Set have been visited, or if the closure returns false.

func (*Set[T]) ForEach

func (s *Set[T]) ForEach(f func(T))

func (*Set[T]) Has

func (s *Set[T]) Has(items ...T) bool

Has looks for the existence of items passed. It returns false if nothing is passed. For multiple items it returns true only if all of the items exist.

func (*Set) IsEmpty

func (s *Set) IsEmpty() bool

IsEmpty reports whether the Set is empty.

func (*Set[T]) IsEqual

func (s *Set[T]) IsEqual(t SetInterface[T]) bool

IsEqual test whether s and t are the same in size and have the same items.

func (*Set[T]) IsSubset

func (s *Set[T]) IsSubset(t SetInterface[T]) (subset bool)

IsSubset tests whether t is a subset of s.

func (*Set) IsSuperset

func (s *Set) IsSuperset(t SetInterface[T]) bool

IsSuperset tests whether t is a superset of s.

func (*Set[T]) List

func (s *Set[T]) List() []T

List returns a slice of all items. There is also StringSlice() and IntSlice() methods for returning slices of type string or int.

func (*Set[T]) Merge

func (s *Set[T]) Merge(t SetInterface[T])

Merge is like Union, however it modifies the current set it's applied on with the given t set.

func (*Set[T]) Pop

func (s *Set[T]) Pop() T

Pop deletes and return an item from the set. The underlying Set s is modified. If set is empty, nil is returned.

func (*Set[T]) Remove

func (s *Set[T]) Remove(items ...T)

Remove deletes the specified items from the set. The underlying Set s is modified. If passed nothing it silently returns.

func (*Set) Separate

func (s *Set) Separate(t SetInterface[T])

it's not the opposite of Merge. Separate removes the set items containing in t from set s. Please aware that

func (*Set[T]) Size

func (s *Set[T]) Size() int

Size returns the number of items in a set.

func (*Set[T]) Stream

func (s *Set[T]) Stream() *Stream[T]

func (*Set) String

func (s *Set) String() string

String returns a string representation of s

type SetInterface

type SetInterface[T basic.ComObj] interface {
	Add(items ...T)
	Remove(items ...T)
	Pop() T
	Has(items ...T) bool
	Size() int
	Clear()
	IsEmpty() bool
	IsEqual(s SetInterface[T]) bool
	IsSubset(s SetInterface[T]) bool
	IsSuperset(s SetInterface[T]) bool
	Each(func(T) bool)
	String() string
	List() []T
	Copy() SetInterface[T]
	Merge(s SetInterface[T])
	Separate(s SetInterface[T])
	ForEach(f func(T))
	Stream() *Stream[T]
}

SetInterface is describing a Set. Sets are an unordered, unique list of values.

func Difference

func Difference[T basic.ComObj](set1, set2 SetInterface[T], sets ...SetInterface[T]) SetInterface[T]

Difference returns a new set which contains items which are in in the first set but not in the others. Unlike the Difference() method you can use this function separately with multiple sets.

func EmptySet

func EmptySet[T basic.ComObj]() SetInterface[T]

func Intersection

func Intersection[T basic.ComObj](set1, set2 SetInterface[T], sets ...SetInterface[T]) SetInterface[T]

Intersection returns a new set which contains items that only exist in all given sets.

func NewSet

func NewSet[T basic.ComObj](settype SetType) SetInterface[T]

New creates and initalizes a new Set interface. Its single parameter denotes the type of set to create. Either ThreadSafe or NonThreadSafe. The default is ThreadSafe.

func NewSetWithItems

func NewSetWithItems[T basic.ComObj](settype SetType, items ...T) SetInterface[T]

func SymmetricDifference

func SymmetricDifference[T basic.ComObj](s SetInterface[T], t SetInterface[T]) SetInterface[T]

SymmetricDifference returns a new set which s is the difference of items which are in one of either, but not in both.

func Union

func Union[T basic.ComObj](set1, set2 SetInterface[T], sets ...SetInterface[T]) SetInterface[T]

Union is the merger of multiple sets. It returns a new set with all the elements present in all the sets that are passed.

The dynamic type of the returned set is determined by the first passed set's implementation of the New() method.

type SetMap

type SetMap[K basic.ComObj, V basic.ComObj] struct {
	// contains filtered or unexported fields
}

SetMap

func NewSetMap

func NewSetMap[K basic.ComObj, V basic.ComObj]() *SetMap[K, V]

func (*SetMap[K, V]) Get

func (sm *SetMap[K, V]) Get(k K) SetInterface[V]

*

*

func (*SetMap[K, V]) Put

func (sm *SetMap[K, V]) Put(k K, v V)

*

*

type SetNonTS

type SetNonTS[T basic.ComObj] struct {
	// contains filtered or unexported fields
}

SetNonTS defines a non-thread safe set data structure.

func (*SetNonTS) Add

func (s *SetNonTS) Add(items ...T)

Add includes the specified items (one or more) to the set. The underlying Set s is modified. If passed nothing it silently returns.

func (*SetNonTS) Clear

func (s *SetNonTS) Clear()

Clear removes all items from the set.

func (*SetNonTS) Copy

func (s *SetNonTS) Copy() SetInterface[T]

Copy returns a new Set with a copy of s.

func (*SetNonTS) Each

func (s *SetNonTS) Each(f func(item T) bool)

Each traverses the items in the Set, calling the provided function for each set member. Traversal will continue until all items in the Set have been visited, or if the closure returns false.

func (*SetNonTS) ForEach

func (s *SetNonTS) ForEach(f func(item T))

func (*SetNonTS) Has

func (s *SetNonTS) Has(items ...T) bool

Has looks for the existence of items passed. It returns false if nothing is passed. For multiple items it returns true only if all of the items exist.

func (*SetNonTS) IsEmpty

func (s *SetNonTS) IsEmpty() bool

IsEmpty reports whether the Set is empty.

func (*SetNonTS) IsEqual

func (s *SetNonTS) IsEqual(t SetInterface[T]) bool

IsEqual test whether s and t are the same in size and have the same items.

func (*SetNonTS) IsSubset

func (s *SetNonTS) IsSubset(t SetInterface[T]) (subset bool)

IsSubset tests whether t is a subset of s.

func (*SetNonTS) IsSuperset

func (s *SetNonTS) IsSuperset(t SetInterface[T]) bool

IsSuperset tests whether t is a superset of s.

func (*SetNonTS) List

func (s *SetNonTS) List() []T

List returns a slice of all items. There is also StringSlice() and IntSlice() methods for returning slices of type string or int.

func (*SetNonTS) Merge

func (s *SetNonTS) Merge(t SetInterface[T])

Merge is like Union, however it modifies the current set it's applied on with the given t set.

func (*SetNonTS) Pop

func (s *SetNonTS) Pop() T

Pop deletes and return an item from the set. The underlying Set s is modified. If set is empty, nil is returned.

func (*SetNonTS) Remove

func (s *SetNonTS) Remove(items ...T)

Remove deletes the specified items from the set. The underlying Set s is modified. If passed nothing it silently returns.

func (*SetNonTS) Separate

func (s *SetNonTS) Separate(t SetInterface[T])

it's not the opposite of Merge. Separate removes the set items containing in t from set s. Please aware that

func (*SetNonTS) Size

func (s *SetNonTS) Size() int

Size returns the number of items in a set.

func (*SetNonTS) Stream

func (s *SetNonTS) Stream() *Stream[T]

func (*SetNonTS) String

func (s *SetNonTS) String() string

String returns a string representation of s

type SetType

type SetType int

SetType denotes which type of set is created. ThreadSafe or NonThreadSafe

func (SetType) String

func (s SetType) String() string

type Stream

type Stream[T basic.Object] struct {
	Head     T
	Tail     *Stream[T]
	Length   int
	NotEmpty bool
}

func GenStream

func GenStream[T basic.Object](r *Stream[T], f func(*Stream[T]) T, m int) *Stream[T]

func MapInt32

func MapInt32[R basic.Object](s *Int32Stream, f func(t int32) R) *Stream[R]

Map

func MapLong

func MapLong[R basic.Object](s *LongStream, f func(t int64) R) *Stream[R]

Map

func MapStream

func MapStream[T basic.Object, R basic.Object](s *Stream[T], f func(t T) R) *Stream[R]

MapStream

func NewStream

func NewStream[T basic.Object](head T, tail *Stream[T]) *Stream[T]

func NullStream

func NullStream[T basic.Object]() *Stream[T]

func (*Stream[T]) Add

func (s *Stream[T]) Add(i T) *Stream[T]

func (*Stream[T]) Addall

func (s *Stream[T]) Addall(i ...T) *Stream[T]

func (*Stream[T]) AnyMatch

func (s *Stream[T]) AnyMatch(f func(T) bool) bool

func (*Stream[T]) Filter

func (s *Stream[T]) Filter(f func(T) bool) *Stream[T]

func (*Stream[T]) FoldLeft

func (s *Stream[T]) FoldLeft(i *Stream[T], f func(*Stream[T], T) *Stream[T]) *Stream[T]

左折叠 用于实现 reduce 的功能

func (*Stream[T]) FoldRight

func (s *Stream[T]) FoldRight(i *Stream[T], f func(*Stream[T], T) *Stream[T]) *Stream[T]

右折叠

func (*Stream[T]) ForEach

func (s *Stream[T]) ForEach(f func(T))

func (*Stream[T]) MapToInt32

func (s *Stream[T]) MapToInt32(f func(t T) int32) *Int32Stream

func (*Stream[T]) MapToLong

func (s *Stream[T]) MapToLong(f func(t T) int64) *LongStream

func (*Stream[T]) Merge

func (s *Stream[T]) Merge(t *Stream[T]) *Stream[T]

合并两个 Stream

func (*Stream[T]) Reduce

func (s *Stream[T]) Reduce(i T, f func(T, T) T) T

Reduce

func (*Stream[T]) Reverse

func (s *Stream[T]) Reverse() *Stream[T]

倒序

func (*Stream[T]) Sort

func (s *Stream[T]) Sort(c func(T, T) bool) *Stream[T]

func (*Stream[T]) ToList

func (s *Stream[T]) ToList() *ArrayList[T]

To List

type StringBuilder

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

func NewSB

func NewSB() *StringBuilder

func (*StringBuilder) AddBool

func (b *StringBuilder) AddBool(key string, value bool) *StringBuilder

func (*StringBuilder) AddFloat32

func (b *StringBuilder) AddFloat32(key string, value float32) *StringBuilder

func (*StringBuilder) AddFloat64

func (b *StringBuilder) AddFloat64(key string, value float64) *StringBuilder

func (*StringBuilder) AddInt

func (b *StringBuilder) AddInt(key string, value int) *StringBuilder

func (*StringBuilder) AddInt16

func (b *StringBuilder) AddInt16(key string, value int16) *StringBuilder

func (*StringBuilder) AddInt32

func (b *StringBuilder) AddInt32(key string, value int32) *StringBuilder

func (*StringBuilder) AddInt64

func (b *StringBuilder) AddInt64(key string, value int64) *StringBuilder

func (*StringBuilder) AddInt8

func (b *StringBuilder) AddInt8(key string, value int8) *StringBuilder

func (*StringBuilder) AddString

func (b *StringBuilder) AddString(key string, value string) *StringBuilder

func (*StringBuilder) AddUInt64

func (b *StringBuilder) AddUInt64(key string, value uint64) *StringBuilder

func (*StringBuilder) AppendBool

func (b *StringBuilder) AppendBool(i bool) *StringBuilder

func (*StringBuilder) AppendChar

func (b *StringBuilder) AppendChar(i byte) *StringBuilder

func (*StringBuilder) AppendFloat32

func (b *StringBuilder) AppendFloat32(i float32) *StringBuilder

func (*StringBuilder) AppendFloat64

func (b *StringBuilder) AppendFloat64(i float64) *StringBuilder

func (*StringBuilder) AppendInt

func (b *StringBuilder) AppendInt(i int) *StringBuilder

func (*StringBuilder) AppendInt16

func (b *StringBuilder) AppendInt16(i int16) *StringBuilder

func (*StringBuilder) AppendInt32

func (b *StringBuilder) AppendInt32(i int32) *StringBuilder

func (*StringBuilder) AppendInt64

func (b *StringBuilder) AppendInt64(i int64) *StringBuilder

func (*StringBuilder) AppendInt8

func (b *StringBuilder) AppendInt8(i int8) *StringBuilder

func (*StringBuilder) AppendString

func (b *StringBuilder) AppendString(i string) *StringBuilder

func (*StringBuilder) AppendUInt32

func (b *StringBuilder) AppendUInt32(i uint32) *StringBuilder

func (*StringBuilder) AppendUInt64

func (b *StringBuilder) AppendUInt64(i uint64) *StringBuilder

func (*StringBuilder) Length

func (b *StringBuilder) Length() int

func (*StringBuilder) SetLength

func (b *StringBuilder) SetLength(len int) *StringBuilder

func (*StringBuilder) String

func (b *StringBuilder) String() string

func (*StringBuilder) ToStringHelper

func (b *StringBuilder) ToStringHelper() string

type UOffsetT

type UOffsetT uint32

A UOffsetT stores an unsigned offset into vector data.

func GetUOffsetT

func GetUOffsetT(buf []byte) UOffsetT

GetUOffsetT decodes a little-endian UOffsetT from a byte slice.

type VOffsetT

type VOffsetT uint16

A VOffsetT stores an unsigned offset in a vtable.

func GetVOffsetT

func GetVOffsetT(buf []byte) VOffsetT

GetVOffsetT decodes a little-endian VOffsetT from a byte slice.

Jump to

Keyboard shortcuts

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