Documentation ¶
Index ¶
- func CompareArray[T comparable](src, target []T, opts ...OptionFunc[T]) int64
- func CompareBaseArray[T any](src, target []T, equalFunc func(T, T) bool, opts ...OptionFunc[T]) int64
- func CompareIDArray[T comparable](src, target []IIDSection[T], opts ...OptionFunc[IIDSection[T]]) int64
- func NewUnqueFilter[T comparable]() func(T) bool
- type IIDSection
- type IItemSection
- type ISortedUniqueArray
- type IUniqueArray
- type ItemMap
- type OptionFunc
- type Options
- type UniqueAnyArray
- type UniqueArray
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompareArray ¶ added in v0.3.36
func CompareArray[T comparable](src, target []T, opts ...OptionFunc[T]) int64
CompareArray compares the elements in two arrays, returning the number of matching elements. T must be a type that supports the comparable constraint. src: The source array. target: The target array. opts: Optional functions for customizing comparison behavior. Returns the number of matching elements.
func CompareBaseArray ¶ added in v0.3.36
func CompareBaseArray[T any](src, target []T, equalFunc func(T, T) bool, opts ...OptionFunc[T]) int64
CompareBaseArray is a generic function for comparing elements in two arrays and counting the number of matching elements. T: The type of elements in the array, can be any type. src: The source array. target: The target array. equalFunc: A function for determining if two elements are equal. opts: Optional functions for customizing comparison behavior. Returns the number of matching elements.
func CompareIDArray ¶ added in v0.3.36
func CompareIDArray[T comparable](src, target []IIDSection[T], opts ...OptionFunc[IIDSection[T]]) int64
CompareIDArray compares the IDs in two arrays of IIDSection type, returning the number of matching IDs. T must be a type that supports the comparable constraint. src: The source array of IIDSection type. target: The target array of IIDSection type. opts: Optional functions for customizing comparison behavior. Returns the number of matching IDs.
func NewUnqueFilter ¶ added in v0.3.36
func NewUnqueFilter[T comparable]() func(T) bool
Types ¶
type IIDSection ¶ added in v0.3.36
type IIDSection[T comparable] interface { ID() T }
IIDSection[T comparable] id section
type IItemSection ¶
type IItemSection[T comparable] interface { IIDSection[T] Sort() int }
type ISortedUniqueArray ¶
type ISortedUniqueArray[T any] interface { IUniqueArray[T] Swap(i, j int) Less(i, j int) bool }
func NewUniqueAnyArray ¶
func NewUniqueAnyArray[T comparable]() ISortedUniqueArray[IItemSection[T]]
NewUniqueAnyArray创建一个新的可排序的唯一数组,数组元素类型为T,T必须是可比较的类型。
type IUniqueArray ¶
func NewUniqueArray ¶
func NewUniqueArray[T comparable]() IUniqueArray[T]
NewUniqueArray函数用于创建一个IUniqueArray[T]类型的实例。 该实例是一个UniqueArray[T]类型的指针,其中UniqueArray[T]是一个包含一个元素的切片和一个键为T类型值、值为空结构体的映射。 返回创建的实例。
type ItemMap ¶ added in v0.3.31
type ItemMap[T any] struct { // contains filtered or unexported fields }
ItemMap is a thread-safe key-value map for storing and retrieving items of any type T.
func NewItemMap ¶ added in v0.3.32
func (ItemMap[T]) GetItem ¶ added in v0.3.31
GetItem retrieves an item by its key. - key: The key of the item to retrieve. Returns the item pointer and a boolean indicating whether the item was successfully retrieved.
func (ItemMap[T]) GetOrSet ¶ added in v0.3.31
GetOrSet attempts to retrieve an item by the given key. If the item does not exist, it uses the provided function `f` to generate and set the item. - key: The key for the item to get or set. - f: A function that generates the item when the key is not found, taking the key as an argument and returning the item and an error if any. Returns the item corresponding to the key, or nil if retrieval or setting fails.
type OptionFunc ¶ added in v0.3.36
OptionFunc is a generic type representing functions that modify instances of the Options type. It accepts a pointer to an Options instance, enabling configurations on the Options instance.
func WithFilter ¶ added in v0.3.36
func WithFilter[T any](filter func(s T) bool) OptionFunc[T]
WithFilter src filter.
func WithIterator ¶ added in v0.3.36
func WithIterator[T any](iterator func(s, t T)) OptionFunc[T]
WithIterator sets the Iterator function of an Options instance. It returns an OptionFunc function used to configure the iteration behavior of an Options instance.
func WithMax ¶ added in v0.3.36
func WithMax[T any](max int64) OptionFunc[T]
WithMax sets the Max property of an Options instance. It returns an OptionFunc function used to configure the maximum value of an Options instance.
func WithMin ¶ added in v0.3.36
func WithMin[T any](min int64) OptionFunc[T]
WithMin sets the Min property of an Options instance. It returns an OptionFunc function used to configure the minimum value of an Options instance.
type Options ¶ added in v0.3.36
Options is a generic struct holding a set of configuration options, including maximum, minimum values, a filtering function, and an iterator function.
func NewOption ¶ added in v0.3.36
func NewOption[T any](opts ...OptionFunc[T]) *Options[T]
NewOption creates a new Options instance and applies the provided configuration functions. It takes one or more OptionFunc functions as arguments to configure the Options instance.
type UniqueAnyArray ¶
type UniqueAnyArray[T comparable] struct { // contains filtered or unexported fields }
func (*UniqueAnyArray[T]) Append ¶
func (n *UniqueAnyArray[T]) Append(vs ...IItemSection[T])
func (*UniqueAnyArray[T]) Len ¶
func (n *UniqueAnyArray[T]) Len() int
func (*UniqueAnyArray[T]) Less ¶
func (n *UniqueAnyArray[T]) Less(i, j int) bool
func (*UniqueAnyArray[T]) Swap ¶
func (n *UniqueAnyArray[T]) Swap(i, j int)
func (*UniqueAnyArray[T]) ToSlice ¶
func (n *UniqueAnyArray[T]) ToSlice() []IItemSection[T]
type UniqueArray ¶
type UniqueArray[T comparable] struct { // contains filtered or unexported fields }
func (*UniqueArray[T]) Append ¶
func (n *UniqueArray[T]) Append(vs ...T)
func (*UniqueArray[T]) Len ¶
func (n *UniqueArray[T]) Len() int
func (*UniqueArray[T]) ToSlice ¶
func (n *UniqueArray[T]) ToSlice() []T