Documentation
¶
Index ¶
- func BinarySearchFunc[U any, T Item](container *Container[T], target U, cmp func(T, U) int) (pos int, ok bool)
- func CompareOrdered[T Ordered](exclude ...int) func(a, b T) int
- func FindOrderedPosition[T Ordered, S ~[]T](s S, e T, exclude ...int) (int, bool)
- func FindOrderedPositionPointer[T Ordered, S ~[]*T](s S, e *T, exclude ...int) (int, bool)
- func IndexFunc[T Item](container *Container[T], f func(T) bool) (idx int)
- func InsertOrdered[T Ordered, S ~[]T](h S, element T, exclude ...int) S
- func InsertOrderedPointer[T Ordered, S ~[]*T](h S, element *T, exclude ...int) S
- func SliceAppend[T any, S ~[]T](old S, newItems ...T) S
- func SliceDelete[T Item, S ~[]T](items S, name string, deleteOne bool) S
- func SliceDeleteOne[T Item](items []T, name string) ([]T, bool)
- func SliceDeleteOnePointer[T Item](items []*T, name string) ([]*T, bool)
- func SliceInsert[T any, S ~[]T](items S, item T, position int) S
- func SlicePointerDelete[T Item, S ~[]*T](items S, name string, deleteOne bool) S
- func SortOrdered[T Ordered, S ~[]T](h S, exclude ...int)
- func SortOrderedPointer[T Ordered, S ~[]*T](h S, exclude ...int)
- func VerifySorted[T Item](container *Container[T], cmp func(T, T) int) (ok bool)
- type Container
- func (container *Container[T]) Append(items ...T)
- func (container *Container[T]) Clear()
- func (container *Container[T]) Delete(name string, deleteOne bool)
- func (container *Container[T]) Get(name string) (_ T, _ bool)
- func (container *Container[T]) InsertPosition(item T, position int)
- func (container *Container[T]) Iterate(f func(item T, index int) bool)
- func (container *Container[T]) Len() int
- type Item
- type Mapped
- func (container *Mapped[K, V]) Clear()
- func (container *Mapped[K, V]) Contains(key K) bool
- func (container *Mapped[K, V]) Delete(key K)
- func (container *Mapped[K, V]) Get(key K) (V, bool)
- func (container *Mapped[K, V]) GetWithZero(key K) V
- func (container *Mapped[K, V]) GlobalIterate(f func(key K, value V) bool)
- func (container *Mapped[K, V]) Iter() iter.Seq2[K, V]
- func (container *Mapped[K, V]) Keys() []K
- func (container *Mapped[K, V]) Len() int
- func (container *Mapped[K, V]) Set(key K, value V)
- func (container *Mapped[K, V]) Values() []V
- type MappedCollection
- func (mc *MappedCollection[K, V]) Add(key K, value *V)
- func (mc *MappedCollection[K, V]) Clear()
- func (mc *MappedCollection[K, V]) DeleteKey(key K)
- func (mc *MappedCollection[K, V]) FindOrderedPosition(key K, value *V, exclude ...int) (int, bool)
- func (mc *MappedCollection[K, V]) Get(key K) ([]*V, bool)
- func (mc *MappedCollection[K, V]) GlobalIterate(f func(key K, value *V) bool)
- func (mc *MappedCollection[K, V]) InsertOrdered(key K, value *V, exclude ...int)
- func (mc *MappedCollection[K, V]) IterateKey(key K, f func(val *V) bool)
- func (mc *MappedCollection[K, V]) KeyExists(key K) bool
- func (mc *MappedCollection[K, V]) Keys() (keys []K)
- func (mc *MappedCollection[K, V]) Len() (total int)
- func (mc *MappedCollection[K, V]) RemoveValue(key K, value *V)
- func (mc *MappedCollection[K, V]) RemoveValueByName(key K, name string, deleteOne bool)
- func (mc *MappedCollection[K, V]) Size(key K) int
- func (mc *MappedCollection[K, V]) SortKey(key K, exclude ...int)
- type MappedItem
- type Ordered
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BinarySearchFunc ¶
func BinarySearchFunc[U any, T Item](container *Container[T], target U, cmp func(T, U) int) (pos int, ok bool)
BinarySearchFunc is alias to slices.BinarySearchFunc, that uses container, instead of slice.
func CompareOrdered ¶
CompareOrdered returns a comparison function for Ordered elements. The returned function can be used with sorting and binary search algorithms.
func FindOrderedPosition ¶
FindOrderedPosition finds the position where an Ordered element should be inserted to maintain sorted order. It returns the position and a boolean, indicating if an element with the exact same order was found.
func FindOrderedPositionPointer ¶
FindOrderedPositionPointer finds the position where a pointer to an Ordered element should be inserted. It has the same behavior as FindOrderedPosition, but works with pointer slices.
func InsertOrdered ¶
InsertOrdered inserts an Ordered element into a sorted slice to the correct position. Elements with orders in the exclude list are appended to the end of the slice.
func InsertOrderedPointer ¶
InsertOrderedPointer inserts a pointer to an Ordered element into a sorted slice. It has the same behavior as InsertOrdered but works with pointer slices instead.
func SliceAppend ¶
func SliceAppend[T any, S ~[]T](old S, newItems ...T) S
func SliceDelete ¶
func SliceDeleteOne ¶
func SliceDeleteOnePointer ¶
func SliceInsert ¶
func SlicePointerDelete ¶
func SortOrdered ¶
SortOrdered sorts a slice of Ordered elements by their order. If element is excluded, it'll be inserted to the end of slice.
func SortOrderedPointer ¶
SortOrderedPointer sorts a slice of pointers to Ordered elements. It has the same behavior as SortOrdered but works with pointer slices.
Types ¶
type Container ¶
type Container[T Item] struct { // contains filtered or unexported fields }
Container represents a concurrent-safe container. It uses CAS methodic to prevent data races. It must be created via New (container.New) function. Otherwise, it can easily panic because of nil pointer dereference.
func (*Container[T]) Append ¶
func (container *Container[T]) Append(items ...T)
Append appends multiple items to the container. Nothing happens, if no items provided.
func (*Container[T]) Clear ¶
func (container *Container[T]) Clear()
Clear clears the container by storing an empty slice. Using empty slice instead of nil.
func (*Container[T]) InsertPosition ¶
InsertPosition inserts the item at the specified position in the container. If position is incorrect, it'll be inserted to the end of slice.
type Item ¶
type Item interface {
// Name returns name of the item.
// Used to easily compare two items.
Name() string
}
Item represents the container item.
type Mapped ¶
type Mapped[K comparable, V any] struct { // contains filtered or unexported fields }
Mapped represents concurrent-safe map container. It uses CAS methodic for preventing data races.
func NewMapped ¶
func NewMapped[K comparable, V any]() (m *Mapped[K, V])
NewMapped creates a new initialized mapped container.
func (*Mapped[K, V]) Contains ¶
Contains returns true, if the container can find value for this key.
func (*Mapped[K, V]) Delete ¶
func (container *Mapped[K, V]) Delete(key K)
Delete deletes a value from container by key.
func (*Mapped[K, V]) GetWithZero ¶
func (container *Mapped[K, V]) GetWithZero(key K) V
GetWithZero gets a value by key from the container. If there's no value for this key, zero V will be returned.
func (*Mapped[K, V]) GlobalIterate ¶
GlobalIterate iterates across all key-value pairs in the container.
func (*Mapped[K, V]) Keys ¶
func (container *Mapped[K, V]) Keys() []K
Keys returns all keys in the container.
type MappedCollection ¶
type MappedCollection[K comparable, V MappedItem] struct { // contains filtered or unexported fields }
MappedCollection represents container, that groups collections by keys.
func NewMappedCollection ¶
func NewMappedCollection[K comparable, V MappedItem]() (m *MappedCollection[K, V])
NewMappedCollection creates a new initialized mapped collection.
func (*MappedCollection[K, V]) Add ¶
func (mc *MappedCollection[K, V]) Add(key K, value *V)
Add adds a value to the collection under the specified key.
func (*MappedCollection[K, V]) Clear ¶
func (mc *MappedCollection[K, V]) Clear()
Clear clears the entire container.
func (*MappedCollection[K, V]) DeleteKey ¶
func (mc *MappedCollection[K, V]) DeleteKey(key K)
DeleteKey removes all values from the collection by key.
func (*MappedCollection[K, V]) FindOrderedPosition ¶
func (mc *MappedCollection[K, V]) FindOrderedPosition(key K, value *V, exclude ...int) (int, bool)
FindOrderedPosition finds ordered position for collection by value.
func (*MappedCollection[K, V]) Get ¶
func (mc *MappedCollection[K, V]) Get(key K) ([]*V, bool)
Get returns all values of the collection by key.
func (*MappedCollection[K, V]) GlobalIterate ¶
func (mc *MappedCollection[K, V]) GlobalIterate(f func(key K, value *V) bool)
GlobalIterate iterates over all collections and their values.
func (*MappedCollection[K, V]) InsertOrdered ¶
func (mc *MappedCollection[K, V]) InsertOrdered(key K, value *V, exclude ...int)
InsertOrdered inserts a value by order into the collection by key.
func (*MappedCollection[K, V]) IterateKey ¶
func (mc *MappedCollection[K, V]) IterateKey(key K, f func(val *V) bool)
IterateKey iterates over values of a collection by key.
func (*MappedCollection[K, V]) KeyExists ¶
func (mc *MappedCollection[K, V]) KeyExists(key K) bool
KeyExists returns true, if container contains a collection by entered key.
func (*MappedCollection[K, V]) Keys ¶
func (mc *MappedCollection[K, V]) Keys() (keys []K)
Keys returns all container keys.
func (*MappedCollection[K, V]) Len ¶
func (mc *MappedCollection[K, V]) Len() (total int)
Len returns total length of all collections in the container.
func (*MappedCollection[K, V]) RemoveValue ¶
func (mc *MappedCollection[K, V]) RemoveValue(key K, value *V)
RemoveValue removes a specific value from the collection by key.
func (*MappedCollection[K, V]) RemoveValueByName ¶
func (mc *MappedCollection[K, V]) RemoveValueByName(key K, name string, deleteOne bool)
RemoveValueByName removes value(s) by name from the collection by key.
func (*MappedCollection[K, V]) Size ¶
func (mc *MappedCollection[K, V]) Size(key K) int
Size returns the length of values for a collection by key.
func (*MappedCollection[K, V]) SortKey ¶
func (mc *MappedCollection[K, V]) SortKey(key K, exclude ...int)
SortKey sorts values for a specific collection using the Ordered interface.
type MappedItem ¶
MappedItem represents the mapped container item.