github.com/songzhibin97/go-baseutils@v0.0.2-0.20240302024150-487d8ce9c082/base/bslice/slice.go (about)

     1  package bslice
     2  
     3  import (
     4  	"github.com/songzhibin97/go-baseutils/base/bcomparator"
     5  	"github.com/songzhibin97/go-baseutils/base/btype"
     6  )
     7  
     8  type CalculableBSlice[E btype.Integer | btype.Float] interface {
     9  	OrderedBSlice[E]
    10  
    11  	Sum() E
    12  	Avg() E
    13  	Max() E
    14  	Min() E
    15  }
    16  
    17  type OrderedBSlice[E btype.Ordered] interface {
    18  	ComparableBSlice[E]
    19  
    20  	Compare([]E) int
    21  
    22  	Sort()
    23  	IsSorted() bool
    24  	BinarySearch(E) (int, bool)
    25  }
    26  
    27  type ComparableBSlice[E comparable] interface {
    28  	AnyBSlice[E]
    29  
    30  	Contains(E) bool
    31  	Equal([]E) bool
    32  	Compact()
    33  }
    34  
    35  type AnyBSlice[E any] interface {
    36  	EqualFunc([]E, func(E, E) bool) bool
    37  	CompareFunc([]E, func(E, E) int) int
    38  	IndexFunc(func(E) bool) int
    39  
    40  	Insert(int, ...E)
    41  	InsertE(int, ...E) error
    42  
    43  	Delete(int, int)
    44  	DeleteE(int, int) error
    45  	DeleteToSlice(int, int) []E
    46  	DeleteToSliceE(int, int) ([]E, error)
    47  	DeleteToBSlice(int, int) AnyBSlice[E]
    48  	DeleteToBSliceE(int, int) (AnyBSlice[E], error)
    49  
    50  	Replace(int, int, ...E)
    51  	ReplaceE(int, int, ...E) error
    52  
    53  	CloneToSlice() []E
    54  	CloneToBSlice() AnyBSlice[E]
    55  
    56  	CompactFunc(func(E, E) bool)
    57  
    58  	Grow(int)
    59  	GrowE(int) error
    60  
    61  	Clip()
    62  
    63  	ForEach(func(int, E))
    64  
    65  	SortFunc(func(i, j E) bool)
    66  	SortFuncToSlice(func(i, j E) bool) []E
    67  	SortFuncToBSlice(func(i, j E) bool) AnyBSlice[E]
    68  
    69  	SortComparator(comparator bcomparator.Comparator[E])
    70  	SortComparatorToSlice(comparator bcomparator.Comparator[E]) []E
    71  	SortComparatorToBSlice(comparator bcomparator.Comparator[E]) AnyBSlice[E]
    72  
    73  	SortStableFunc(func(i, j E) bool)
    74  	SortStableFuncToSlice(func(i, j E) bool) []E
    75  	SortStableFuncToBSlice(func(i, j E) bool) AnyBSlice[E]
    76  
    77  	IsSortedFunc(func(i, j E) bool) bool
    78  	BinarySearchFunc(E, func(E, E) int) (int, bool)
    79  
    80  	Filter(func(E) bool)
    81  	FilterToSlice(func(E) bool) []E
    82  	FilterToBSlice(func(E) bool) AnyBSlice[E]
    83  
    84  	Reverse()
    85  	ReverseToSlice() []E
    86  	ReverseToBSlice() AnyBSlice[E]
    87  
    88  	Marshal() ([]byte, error)
    89  	Unmarshal(data []byte) error
    90  
    91  	Len() int
    92  	Cap() int
    93  	ToInterfaceSlice() []interface{}
    94  	ToMetaSlice() []E // no concurrency safe!
    95  
    96  	Swap(i, j int)
    97  	Clear()
    98  
    99  	Append(...E)
   100  	AppendToSlice(...E) []E
   101  	AppendToBSlice(...E) AnyBSlice[E]
   102  
   103  	CopyToSlice() []E
   104  	CopyToBSlice() AnyBSlice[E]
   105  
   106  	GetByIndex(int) E
   107  	GetByIndexE(int) (E, error)
   108  	GetByIndexOrDefault(int, E) E
   109  
   110  	GetByRange(int, int) []E           // no concurrency safe!
   111  	GetByRangeE(int, int) ([]E, error) // no concurrency safe!
   112  
   113  	SetByIndex(int, E)
   114  	SetByIndexE(int, E) error
   115  
   116  	SetByRange(int, []E)
   117  	SetByRangeE(int, []E) error
   118  }