Documentation ¶
Index ¶
- func AsSlice[T any](data ...T) []T
- func Contains[T comparable](list []T, value T) bool
- func ContainsFunc[T any](list []T, check func(T) bool) bool
- func Convert[T any, U any](converter func(T) U, data ...T) []U
- func ConvertDictionary[T any, U comparable, V any](data []T, converter func(T) (U, V)) map[U]V
- func Index[T comparable](list []T) map[T]int
- func IndexWithFunction[T any, U comparable](list []T, converter func(T) U) map[U]int
- func Keys[T comparable, U any](mapping map[T]U) []T
- func ToDictionary[T any, U comparable](mapping map[U]T, list []T, keyer func(int, T) U, overwrite bool)
- func ToDictionaryKeys[T comparable, U any](mapping map[T]U, list []T, valuer func(int, T) U, overwrite bool)
- func Values[T comparable, U any](mapping map[T]U) []U
- type ConcurrentList
- func (list *ConcurrentList[T]) Append(items ...T)
- func (list *ConcurrentList[T]) At(index uint) T
- func (list *ConcurrentList[T]) Clear() []T
- func (list *ConcurrentList[T]) From(index uint) []T
- func (list *ConcurrentList[T]) Length() uint
- func (list *ConcurrentList[T]) PopFront(n uint) []T
- func (list *ConcurrentList[T]) RemoveAt(index uint) T
- func (list *ConcurrentList[T]) Slice(start uint, end uint) []T
- func (list *ConcurrentList[T]) To(index uint) []T
- func (list *ConcurrentList[T]) WithResize() *ConcurrentList[T]
- type IndexedMap
- func (m *IndexedMap[U, T]) Add(key U, value T, overwrite bool)
- func (m *IndexedMap[U, T]) AddIf(key U, value T, onCollision func(T, T) bool)
- func (m *IndexedMap[U, T]) Data() []T
- func (m *IndexedMap[U, T]) Exists(key U) bool
- func (m *IndexedMap[U, T]) ForEach(loopFunc func(U, T) bool)
- func (m *IndexedMap[U, T]) Get(key U) (T, bool)
- func (m *IndexedMap[U, T]) Keys() []U
- func (m *IndexedMap[U, T]) Length() int
- func (m *IndexedMap[U, T]) Remove(key U) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AsSlice ¶
func AsSlice[T any](data ...T) []T
AsSlice converts a parameterized list of items to a slice
func Contains ¶
func Contains[T comparable](list []T, value T) bool
Contains checks whether or not the value provided exists in list. This function will return true if it does, or false if it doesn't
func ContainsFunc ¶
ContainsFunc checkes whether or not any item in the
func Convert ¶
Convert converts all the items in a list from a first type to a second type, using the function provided
func ConvertDictionary ¶
func ConvertDictionary[T any, U comparable, V any](data []T, converter func(T) (U, V)) map[U]V
ConvertDictionary creates a dictionary from a list using the converter function provided
func Index ¶
func Index[T comparable](list []T) map[T]int
Index creates an index between the values in a list and their indices
func IndexWithFunction ¶
func IndexWithFunction[T any, U comparable](list []T, converter func(T) U) map[U]int
IndexWithFunction creates an index on a slice of data, where the key is generated by the converter function provided, and the value is the index of the value that produced the key in the slice
func Keys ¶
func Keys[T comparable, U any](mapping map[T]U) []T
Keys extracts all the keys from a map and returns them as a slice. This function makes no guarantees on ordering
func ToDictionary ¶
func ToDictionary[T any, U comparable](mapping map[U]T, list []T, keyer func(int, T) U, overwrite bool)
ToDictionary converts a list of items to a map of items based on the output of a function that gets a key from each item and a Boolean value that determines whether conflicts should be overwritten
func ToDictionaryKeys ¶
func ToDictionaryKeys[T comparable, U any](mapping map[T]U, list []T, valuer func(int, T) U, overwrite bool)
ToDictionaryKeys works similarly to the ToDictionary function except that, the list provided will be used as the keys and the valuer function will be used to generate a value for the map associated with the key. This can be useful when trying to index on a struct property
func Values ¶
func Values[T comparable, U any](mapping map[T]U) []U
Values extracts all the values from a map and returns them as a slice. This function makes no guarantees on ordering
Types ¶
type ConcurrentList ¶
type ConcurrentList[T any] struct { // contains filtered or unexported fields }
ConcurrentList is a list structure that is thread-safe
func NewConcurrentList ¶
func NewConcurrentList[T any](items ...T) *ConcurrentList[T]
NewConcurrentList creates a new concurrent list from an existing varadabatic list
func (*ConcurrentList[T]) Append ¶
func (list *ConcurrentList[T]) Append(items ...T)
Append adds one or more items to the end of the list
func (*ConcurrentList[T]) At ¶
func (list *ConcurrentList[T]) At(index uint) T
At returns the item at the given index
func (*ConcurrentList[T]) Clear ¶
func (list *ConcurrentList[T]) Clear() []T
Clear removes all data from the list and returns it
func (*ConcurrentList[T]) From ¶
func (list *ConcurrentList[T]) From(index uint) []T
From returns the tail of the list from the given index
func (*ConcurrentList[T]) Length ¶
func (list *ConcurrentList[T]) Length() uint
Length returns the number of items in the list
func (*ConcurrentList[T]) PopFront ¶
func (list *ConcurrentList[T]) PopFront(n uint) []T
PopFront removes the first N items from the front of the list and returns them
func (*ConcurrentList[T]) RemoveAt ¶
func (list *ConcurrentList[T]) RemoveAt(index uint) T
RemoveAt removes the item at the given index from the list and returns it
func (*ConcurrentList[T]) Slice ¶
func (list *ConcurrentList[T]) Slice(start uint, end uint) []T
Slice returns the part of the list from the start index to the end index
func (*ConcurrentList[T]) To ¶
func (list *ConcurrentList[T]) To(index uint) []T
To returns the head of the list to the given index
func (*ConcurrentList[T]) WithResize ¶
func (list *ConcurrentList[T]) WithResize() *ConcurrentList[T]
WithResize modifies the list, allowing it to dynamically resize in cases where the capacity is larger than the length (this will likely only be useful in cases of extremely large datasets). This function returns the modified list object so that it can be chained with other modifiers
type IndexedMap ¶
type IndexedMap[U comparable, T any] struct { // contains filtered or unexported fields }
IndexedMap is a list structure with O(1) lookup for a field that is indexed based on a key value
func NewIndexedMap ¶
func NewIndexedMap[U comparable, T any]() *IndexedMap[U, T]
NewIndexedMap creates a new, empty IndexedMap
func (*IndexedMap[U, T]) Add ¶
func (m *IndexedMap[U, T]) Add(key U, value T, overwrite bool)
Add adds a new key and value to the indexed map. If the overwrite function is true then, if a collision occurs, the item being added will take precedence over the existing item. Otherwise, the existing item will take precedence. This operation may be O(1) unless the underlying list needs to be resized, in which case it will be O(N)
func (*IndexedMap[U, T]) AddIf ¶
func (m *IndexedMap[U, T]) AddIf(key U, value T, onCollision func(T, T) bool)
AddIf adds a new key and value to the indexed map. If a collision occurs, then the onCollision function will be called with the existing item and item to be added. If it returns true then the existing item will be overwritten and otherwise it will be ignored.
func (*IndexedMap[U, T]) Data ¶
func (m *IndexedMap[U, T]) Data() []T
Data returns the data associated with the indexed map as a slice, allowing for users to access the data that was being stored. This operation is guaranteed O(1).
func (*IndexedMap[U, T]) Exists ¶
func (m *IndexedMap[U, T]) Exists(key U) bool
Exists determines whether or not the key exists in the indexed map. This operation is guaranteed to be O(1).
func (*IndexedMap[U, T]) ForEach ¶
func (m *IndexedMap[U, T]) ForEach(loopFunc func(U, T) bool)
ForEach iterates over the entire indexed map and calls a function for each key and associated value. If the function returns true, the iteration will continue; otherwise, it will not. This operation will be O(N) if the inner function does not return false.
func (*IndexedMap[U, T]) Get ¶
func (m *IndexedMap[U, T]) Get(key U) (T, bool)
Get retrieves the item from the indexed list associated with the key. True will be returned if the value was found, otherwise false will be returned. This operation is guaranteed O(1).
func (*IndexedMap[U, T]) Keys ¶
func (m *IndexedMap[U, T]) Keys() []U
Keys returns the collection of keys associated with the indexed map as a slice, allowing for users to access the entire search space of the collection. This operation is guaranteed O(1).
func (*IndexedMap[U, T]) Length ¶
func (m *IndexedMap[U, T]) Length() int
Length returns the number of elements in the indexed map. This operation is guaranteed O(1).
func (*IndexedMap[U, T]) Remove ¶
func (m *IndexedMap[U, T]) Remove(key U) bool
Remove deletes the object associated with the key from the indexed map, if the key exists. A value of true will be returned if the key was actually associated with an item; otherwise false will be returned. This operation requires a resize of the array so it will run in O(M) where M is the number of elements from the index of the deleted entry to the end of the list.