mutable

package
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package mutable provides implementations of mutable containers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Iter

type Iter[TS ~[]T, T any] struct {
	// contains filtered or unexported fields
}

Iter is the Iterator implementation for mutable containers.

func NewHead

func NewHead[TS ~[]T, T any](elements *TS, del func(int) bool) Iter[TS, T]

NewHead instantiates Iter starting at the first element of a slice.

func NewTail

func NewTail[TS ~[]T, T any](elements *TS, del func(int) bool) Iter[TS, T]

NewTail instantiates Iter starting at the last element of a slice.

func (*Iter[TS, T]) Cap

func (i *Iter[TS, T]) Cap() int

func (*Iter[TS, T]) Delete

func (i *Iter[TS, T]) Delete() bool

func (*Iter[TS, T]) DeleteNext

func (i *Iter[TS, T]) DeleteNext() bool

func (*Iter[TS, T]) DeletePrev

func (i *Iter[TS, T]) DeletePrev() bool

func (*Iter[TS, T]) Get

func (i *Iter[TS, T]) Get() (T, bool)

func (*Iter[TS, T]) GetNext

func (i *Iter[TS, T]) GetNext() T

func (*Iter[TS, T]) GetPrev

func (i *Iter[TS, T]) GetPrev() T

func (*Iter[TS, T]) HasNext

func (i *Iter[TS, T]) HasNext() bool

func (*Iter[TS, T]) HasPrev

func (i *Iter[TS, T]) HasPrev() bool

func (*Iter[TS, T]) Next

func (i *Iter[TS, T]) Next() (T, bool)

func (*Iter[TS, T]) Prev

func (i *Iter[TS, T]) Prev() (T, bool)

type Map

type Map[K comparable, V any] map[K]V

Map is the Collection implementation based on the embedded map.

func AsMap

func AsMap[K comparable, V any](elements []c.KV[K, V]) Map[K, V]

AsMap converts a slice of key/value pairs to teh Map.

func NewMap

func NewMap[K comparable, V any](capacity int) Map[K, V]

NewMap instantiates Map with a predefined capacity.

func ToMap

func ToMap[K comparable, V any](elements map[K]V) Map[K, V]

ToMap instantiates Map and copies elements to it.

func WrapMap

func WrapMap[K comparable, V any](elements map[K]V) Map[K, V]

WrapMap instantiates Map using a map as internal storage.

func (Map[K, V]) Begin

func (s Map[K, V]) Begin() c.KVIterator[K, V]

func (Map[K, V]) Collect

func (s Map[K, V]) Collect() map[K]V

func (Map[K, V]) Contains

func (s Map[K, V]) Contains(key K) bool

func (Map[K, V]) Filter

func (s Map[K, V]) Filter(filter c.BiPredicate[K, V]) c.MapPipe[K, V, map[K]V]

func (Map[K, V]) FilterKey

func (s Map[K, V]) FilterKey(fit c.Predicate[K]) c.MapPipe[K, V, map[K]V]

func (Map[K, V]) FilterValue

func (s Map[K, V]) FilterValue(fit c.Predicate[V]) c.MapPipe[K, V, map[K]V]

func (Map[K, V]) First

func (s Map[K, V]) First() (it.EmbedMapKVIter[K, V], K, V, bool)

func (Map[K, V]) For

func (s Map[K, V]) For(walker func(c.KV[K, V]) error) error

func (Map[K, V]) ForEach

func (s Map[K, V]) ForEach(walker func(c.KV[K, V]))

func (Map[K, V]) Get

func (s Map[K, V]) Get(key K) (V, bool)

func (Map[K, V]) Head

func (s Map[K, V]) Head() it.EmbedMapKVIter[K, V]

func (Map[K, V]) IsEmpty

func (s Map[K, V]) IsEmpty() bool

func (Map[K, V]) K

func (s Map[K, V]) K() immutable.MapKeys[K, V]

func (Map[K, V]) Keys

func (s Map[K, V]) Keys() c.Collection[K, []K, c.Iterator[K]]

func (Map[K, V]) Len

func (s Map[K, V]) Len() int

func (Map[K, V]) Map

func (s Map[K, V]) Map(by c.BiConverter[K, V, K, V]) c.MapPipe[K, V, map[K]V]

func (Map[K, V]) MapKey

func (s Map[K, V]) MapKey(by c.Converter[K, K]) c.MapPipe[K, V, map[K]V]

func (Map[K, V]) MapValue

func (s Map[K, V]) MapValue(by c.Converter[V, V]) c.MapPipe[K, V, map[K]V]

func (Map[K, V]) Reduce

func (s Map[K, V]) Reduce(by c.Quaternary[K, V]) (K, V)

func (Map[K, V]) Set

func (s Map[K, V]) Set(key K, value V) bool

func (Map[K, V]) String

func (s Map[K, V]) String() string

func (Map[K, V]) Track

func (s Map[K, V]) Track(tracker func(K, V) error) error

func (Map[K, V]) TrackEach

func (s Map[K, V]) TrackEach(tracker func(K, V))

func (Map[K, V]) V

func (s Map[K, V]) V() immutable.MapValues[K, V]

func (Map[K, V]) Values

func (s Map[K, V]) Values() c.Collection[V, []V, c.Iterator[V]]

type Set

type Set[K comparable] struct {
	// contains filtered or unexported fields
}

Set is the Collection implementation that provides element uniqueness. The elements must be comparable.

func NewSet

func NewSet[T comparable](capacity int) Set[T]

NewSet creates a set with a predefined capacity.

func ToSet

func ToSet[T comparable](elements []T) Set[T]

ToSet converts an elements slice to the set containing them.

func WrapSet

func WrapSet[K comparable](elements map[K]struct{}) Set[K]

WrapSet creates a set using a map as the internal storage.

func (Set[K]) Add

func (s Set[K]) Add(elements ...K) bool

func (Set[K]) AddAll

func (s Set[K]) AddAll(elements []K) bool

func (Set[K]) AddOne

func (s Set[K]) AddOne(element K) bool

func (Set[K]) Begin

func (s Set[K]) Begin() c.Iterator[K]

func (Set[K]) BeginEdit

func (s Set[K]) BeginEdit() c.DelIterator[K]

func (Set[K]) Collect

func (s Set[K]) Collect() []K

func (Set[K]) Contains

func (s Set[K]) Contains(val K) bool

func (Set[T]) Copy

func (s Set[T]) Copy() Set[T]

func (Set[K]) Delete

func (s Set[K]) Delete(elements ...K) bool

func (Set[K]) DeleteOne

func (s Set[K]) DeleteOne(element K) bool

func (Set[K]) Filter

func (s Set[K]) Filter(filter c.Predicate[K]) c.Pipe[K, []K]

func (Set[K]) For

func (s Set[K]) For(walker func(K) error) error

func (Set[K]) ForEach

func (s Set[K]) ForEach(walker func(K))

func (Set[K]) Head

func (s Set[K]) Head() *SetIter[K]

func (Set[T]) IsEmpty

func (s Set[T]) IsEmpty() bool

func (Set[K]) Len

func (s Set[K]) Len() int

func (Set[K]) Map

func (s Set[K]) Map(by c.Converter[K, K]) c.Pipe[K, []K]

func (Set[K]) Reduce

func (s Set[K]) Reduce(by c.Binary[K]) K

func (*Set[T]) Sort

func (s *Set[T]) Sort(less slice.Less[T]) *ordered.Set[T]

Sort transforms to the ordered Set contains sorted elements.

func (*Set[T]) StableSort added in v0.0.5

func (s *Set[T]) StableSort(less slice.Less[T]) *ordered.Set[T]

func (Set[K]) String

func (s Set[K]) String() string

type SetIter

type SetIter[K comparable] struct {
	it.Key[K, struct{}]
	// contains filtered or unexported fields
}

SetIter is the Set Iterator implementation.

func NewSetIter

func NewSetIter[K comparable](uniques map[K]struct{}, del func(element K) bool) *SetIter[K]

NewSetIter creates SetIter instance.

func (*SetIter[K]) Delete

func (i *SetIter[K]) Delete() bool

func (*SetIter[K]) Next

func (i *SetIter[K]) Next() (K, bool)

type Vector

type Vector[T any] []T

Vector is the Collection implementation that provides elements order and index access.

func NewVector

func NewVector[T any](capacity int) *Vector[T]

NewVector instantiates Vector with a predefined capacity.

func ToVector

func ToVector[T any](elements []T) *Vector[T]

ToVector instantiates Vector based on copy of elements slice

func WrapVector

func WrapVector[T any](elements []T) *Vector[T]

WrapVector instantiates Vector using a slise as internal storage.

func (*Vector[T]) Add

func (v *Vector[T]) Add(elements ...T) bool

Add adds elements to the end of the vector

func (*Vector[T]) AddAll

func (v *Vector[T]) AddAll(elements []T) bool

AddAll adds elements to the end of the vector

func (*Vector[T]) AddOne

func (v *Vector[T]) AddOne(element T) bool

AddOne adds a element to the end of the vector

func (*Vector[T]) Begin

func (v *Vector[T]) Begin() c.Iterator[T]

Begin creates an iterator of the vector

func (*Vector[T]) BeginEdit

func (v *Vector[T]) BeginEdit() c.DelIterator[T]

BeginEdit creates an iterator with deleting elements

func (*Vector[T]) Collect

func (v *Vector[T]) Collect() []T

Collect transforms the vector to a slice

func (*Vector[T]) Copy

func (v *Vector[T]) Copy() *Vector[T]

Copy just makes a copy of the vector instance

func (*Vector[T]) Delete

func (v *Vector[T]) Delete(indexes ...int) bool

Delete drops elements by indexes

func (*Vector[T]) DeleteOne

func (v *Vector[T]) DeleteOne(index int) bool

DeleteOne removes a element by the index

func (*Vector[T]) Filter

func (v *Vector[T]) Filter(filter c.Predicate[T]) c.Pipe[T, []T]

Filter returns a pipe consisting of vector elements matching the filter

func (*Vector[T]) First

func (v *Vector[T]) First() (Iter[Vector[T], T], T, bool)

First returns the first element of the vector, an iterator to iterate over the remaining elements, and true\false marker of availability next elements. If no more elements then returns false in the last value.

func (*Vector[T]) For

func (v *Vector[T]) For(walker func(T) error) error

For applies walker to elements. To stop walking just return the ErrBreak

func (*Vector[T]) ForEach

func (v *Vector[T]) ForEach(walker func(T))

ForEach applies walker to elements without error checking

func (*Vector[T]) Get

func (v *Vector[T]) Get(index int) (T, bool)

Get returns an element by the index, otherwise, if the provided index is ouf of the vector len, returns zero T and false in the second result

func (*Vector[T]) Head

func (v *Vector[T]) Head() Iter[Vector[T], T]

Head creates an iterator impl instace of the vector

func (*Vector[T]) IsEmpty

func (v *Vector[T]) IsEmpty() bool

IsEmpty checks if there are elements in the vector

func (*Vector[T]) Last

func (v *Vector[T]) Last() (Iter[Vector[T], T], T, bool)

Last returns the last element of the vector, an iterator to iterate over the remaining elements, and true\false marker of availability prev elements. If no more elements then returns false in the last value.

func (*Vector[T]) Len

func (v *Vector[T]) Len() int

Len returns amount of elements

func (*Vector[T]) Map

func (v *Vector[T]) Map(by c.Converter[T, T]) c.Pipe[T, []T]

Map returns a pipe of converted vector elements by the converter 'by'

func (*Vector[T]) Reduce

func (v *Vector[T]) Reduce(by c.Binary[T]) T

Reduce reduces elements to an one

func (*Vector[T]) Remove

func (v *Vector[T]) Remove(index int) (T, bool)

Remove removes and returns a element by the index

func (*Vector[T]) Set

func (v *Vector[T]) Set(index int, value T) bool

Set puts a element into the vector at the index

func (*Vector[T]) Sort

func (v *Vector[T]) Sort(less slice.Less[T]) *Vector[T]

Sort sorts the Vector in-place and returns it

func (*Vector[T]) StableSort added in v0.0.5

func (v *Vector[T]) StableSort(less slice.Less[T]) *Vector[T]

func (*Vector[T]) String

func (v *Vector[T]) String() string

String returns then string representation

func (*Vector[T]) Tail

func (v *Vector[T]) Tail() Iter[Vector[T], T]

Tail creates an iterator pointing to the end of the vector

func (*Vector[T]) Track

func (v *Vector[T]) Track(tracker func(int, T) error) error

Track applies tracker to elements with error checking. To stop traking just return the ErrBreak

func (*Vector[T]) TrackEach

func (v *Vector[T]) TrackEach(tracker func(int, T))

TrackEach applies tracker to elements without error checking

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL