Documentation
¶
Index ¶
- Variables
- func Equals[T any](a, b T) bool
- type Collection
- type Comparable
- type LinkedList
- func (l *LinkedList[T]) Add(elements ...T) bool
- func (l *LinkedList[T]) AddAll(c Collection[T]) bool
- func (l *LinkedList[T]) AddIndex(element T, idx int) error
- func (l *LinkedList[T]) Clear()
- func (l *LinkedList[T]) Element() (T, error)
- func (l *LinkedList[T]) Fetch() (T, error)
- func (l *LinkedList[T]) Get(idx int) (T, error)
- func (l *LinkedList[T]) Iterator() iterators.Iterator[T]
- func (al *LinkedList) MarshalJSON() ([]byte, error)
- func (l *LinkedList[T]) New() Collection[T]
- func (l *LinkedList[T]) Peek() T
- func (l *LinkedList[T]) Poll() T
- func (l *LinkedList[T]) Push(elements ...T) error
- func (l *LinkedList[T]) Remove(elements ...T) bool
- func (l *LinkedList[T]) RemoveAllOf(elements ...T) bool
- func (l *LinkedList[T]) RemoveIf(filter Predicate[T]) bool
- func (l *LinkedList[T]) RemoveIndex(idx int) error
- func (l *LinkedList[T]) Size() int
- func (l *LinkedList[T]) ToSlice() []T
- func (al *LinkedList) UnmarshalJSON(data []byte) error
- type List
- type Predicate
- type Queue
Constants ¶
This section is empty.
Variables ¶
var ErrNotImplemented = fmt.Errorf("not implemented")
Functions ¶
Types ¶
type Collection ¶
type Collection[T any] interface { iterators.Iterable[T] // Add ensures that this collection contains the specified elements. // Returns true if the collection changed as a result of the operation. // (returns false if the collection does not support duplicates and already contained all given elements). Add(elements ...T) bool // AddAll adds all elements from the given collection to this one. // Returns true if the collection changed as a result of the operation. AddAll(c Collection[T]) bool // Clear removes all of the elements from this collection. Clear() // Returns true if this collection contains the specified element. Contains(element T) bool // ContainsAll returns true if this collection contains all of the elements in the specified collection. ContainsAll(c Collection[T]) bool // Compares the specified object with this collection for equality. Equals(c Collection[T]) bool // IsEmpty returns true if this collection contains no elements. IsEmpty() bool // Removes all given elements from the collection, if they are present. // Each specified element is removed only once, even if it is contained multiple times in the collection. // Returns true if the collection changed as a result of the operation. Remove(elements ...T) bool // RemoveAllOf removes all instances of the given elements from the collection. // Returns true if the collection changed as a result of the operation. RemoveAllOf(elements ...T) bool // Removes all of this collection's elements that are also contained in the specified collection. // Returns true if the collection changed as a result of the operation. RemoveAll(c Collection[T]) bool // RetainAll removes all elements from the collection that are not contained in the specified collection. // Returns true if the collection changed as a result of the operation. RetainAll(c Collection[T]) bool // RemoveIf removes all elements from the collection that satisfy the given predicate. // Returns true if the collection changed as a result of the operation. RemoveIf(filter Predicate[T]) bool // Size returns the number of elements in this collection. Size() int // ToSlice returns a slice containing the elements in this collection. ToSlice() []T // New returns a new Collection of the same type. New() Collection[T] }
Collection represents a collection of elements. Note that T must be either comparable or implement the Comparable interface, otherwise runtime panics could occur.
type Comparable ¶
type Comparable[T any] interface { // Equals returns true if the receiver and the argument are equal. Equals(T) bool }
Comparable is an interface that can be implemented to use types as generic argument which don't satisfy the 'comparable' constraint.
type LinkedList ¶
type LinkedList[T any] struct { // contains filtered or unexported fields }
func NewLinkedList ¶
func NewLinkedList[T any](elements ...T) *LinkedList[T]
func NewLinkedListFromCollection ¶
func NewLinkedListFromCollection[T any](c Collection[T]) *LinkedList[T]
func (*LinkedList[T]) Add ¶
func (l *LinkedList[T]) Add(elements ...T) bool
Add ensures that this collection contains the specified elements. Returns true if the collection changed as a result of the operation. (returns false if the collection does not support duplicates and already contained all given elements).
func (*LinkedList[T]) AddAll ¶
func (l *LinkedList[T]) AddAll(c Collection[T]) bool
AddAll adds all elements from the given collection to this one. Returns true if the collection changed as a result of the operation.
func (*LinkedList[T]) AddIndex ¶
func (l *LinkedList[T]) AddIndex(element T, idx int) error
func (*LinkedList[T]) Clear ¶
func (l *LinkedList[T]) Clear()
Clear removes all of the elements from this collection.
func (*LinkedList[T]) Element ¶
func (l *LinkedList[T]) Element() (T, error)
func (*LinkedList[T]) Fetch ¶
func (l *LinkedList[T]) Fetch() (T, error)
func (*LinkedList[T]) Get ¶
func (l *LinkedList[T]) Get(idx int) (T, error)
func (*LinkedList[T]) Iterator ¶
func (l *LinkedList[T]) Iterator() iterators.Iterator[T]
Returns an iterator over the elements in this collection.
func (*LinkedList) MarshalJSON ¶
func (*LinkedList[T]) New ¶
func (l *LinkedList[T]) New() Collection[T]
New returns a new Collection of the same type.
func (*LinkedList[T]) Peek ¶
func (l *LinkedList[T]) Peek() T
func (*LinkedList[T]) Poll ¶
func (l *LinkedList[T]) Poll() T
func (*LinkedList[T]) Push ¶
func (l *LinkedList[T]) Push(elements ...T) error
func (*LinkedList[T]) Remove ¶
func (l *LinkedList[T]) Remove(elements ...T) bool
Removes all given elements from the collection, if they are present. Each specified element is removed only once, even if it is contained multiple times in the collection. Returns true if the collection changed as a result of the operation.
func (*LinkedList[T]) RemoveAllOf ¶
func (l *LinkedList[T]) RemoveAllOf(elements ...T) bool
RemoveAllOf removes all instances of the given elements from the collection. Returns true if the collection changed as a result of the operation.
func (*LinkedList[T]) RemoveIf ¶
func (l *LinkedList[T]) RemoveIf(filter Predicate[T]) bool
RemoveIf removes all elements from the collection that satisfy the given predicate. Returns true if the collection changed as a result of the operation.
func (*LinkedList[T]) RemoveIndex ¶
func (l *LinkedList[T]) RemoveIndex(idx int) error
func (*LinkedList[T]) Size ¶
func (l *LinkedList[T]) Size() int
Size returns the number of elements in this collection.
func (*LinkedList[T]) ToSlice ¶
func (l *LinkedList[T]) ToSlice() []T
ToSlice returns a slice containing the elements in this collection.
func (*LinkedList) UnmarshalJSON ¶
type List ¶
type List[T any] interface { Collection[T] json.Marshaler json.Unmarshaler // AddIndex adds the given element at the specified index. // Returns an IndexOutOfBoundsError if the index is not within the list's size or equal to l.Size(). AddIndex(element T, idx int) error // RemoveIndex removes the element at the specified index. // Returns an IndexOutOfBoundsError if the index is not within the list's size. RemoveIndex(idx int) error // Get returns the element at the specified index. // Returns an IndexOutOfBoundsError if the index is not within the list's size. Get(idx int) (T, error) }
type Queue ¶
type Queue[T any] interface { Collection[T] // Push adds the given elements to the queue. // Returns an error, if the queue's size restriction prevents the elements from being added. Push(elements ...T) error // Peek returns the first element without removing it. // Returns T's zero value, if the queue is empty. Peek() T // Element returns the first element without removing it. // Returns an error, if the queue is empty. Element() (T, error) // Poll returns the first element and removes it from the queue. // Returns T's zero value, if the queue is empty. Poll() T // Fetch returns the first element and removes it from the queue. // Returns an error, if the queue is empty. Fetch() (T, error) }