ordered

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2023 License: MIT Imports: 22 Imported by: 2

Documentation

Overview

Package ordered provides mutable ordered collection implementations

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Map

type Map[K comparable, V any] struct {
	// contains filtered or unexported fields
}

Map is a collection implementation that provides elements access by an unique key.

func MapFromLoop

func MapFromLoop[K comparable, V any](next func() (K, V, bool)) *Map[K, V]

MapFromLoop creates a map with elements retrieved converter the 'next' function

func NewMap

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

NewMap instantiates a map using key/value pairs

func NewMapCap

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

NewMapCap instantiates Map with a predefined capacity

func NewMapOf

func NewMapOf[K comparable, V any](order []K, elements map[K]V) *Map[K, V]

NewMapOf instantiates Map populated by the 'elements' map key/values

func WrapMap

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

WrapMap instantiates an ordered Map using a map and an order slice as internal storage

func (*Map[K, V]) Contains

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

Contains checks is the map contains a key

func (*Map[K, V]) Conv

func (m *Map[K, V]) Conv(converter func(K, V) (K, V, error)) breakKvStream.Iter[K, V, map[K]V]

Conv returns a breakable stream that applies the 'converter' function to the collection elements

func (*Map[K, V]) ConvKey

func (m *Map[K, V]) ConvKey(converter func(K) (K, error)) breakKvStream.Iter[K, V, map[K]V]

ConvKey returns a stream that applies the 'converter' function to keys of the map

func (Map[K, V]) ConvValue

func (m Map[K, V]) ConvValue(converter func(V) (V, error)) breakKvStream.Iter[K, V, map[K]V]

ConvValue returns a stream that applies the 'converter' function to values of the map

func (*Map[K, V]) Convert

func (m *Map[K, V]) Convert(converter func(K, V) (K, V)) stream.Iter[K, V, map[K]V]

Convert returns a stream that applies the 'converter' function to the collection elements

func (*Map[K, V]) ConvertKey

func (m *Map[K, V]) ConvertKey(converter func(K) K) stream.Iter[K, V, map[K]V]

ConvertKey returns a stream that applies the 'converter' function to keys of the map

func (*Map[K, V]) ConvertValue

func (m *Map[K, V]) ConvertValue(converter func(V) V) stream.Iter[K, V, map[K]V]

ConvertValue returns a stream that applies the 'converter' function to values of the map

func (*Map[K, V]) Filt

func (m *Map[K, V]) Filt(predicate func(K, V) (bool, error)) breakKvStream.Iter[K, V, map[K]V]

Filt returns a breakable stream consisting of elements that satisfy the condition of the 'predicate' function

func (Map[K, V]) FiltKey

func (m Map[K, V]) FiltKey(predicate func(K) (bool, error)) breakKvStream.Iter[K, V, map[K]V]

FiltKey returns a stream consisting of key/value pairs where the key satisfies the condition of the 'predicate' function

func (*Map[K, V]) FiltValue

func (m *Map[K, V]) FiltValue(predicate func(V) (bool, error)) breakKvStream.Iter[K, V, map[K]V]

FiltValue returns a stream consisting of key/value pairs where the value satisfies the condition of the 'predicate' function

func (*Map[K, V]) Filter

func (m *Map[K, V]) Filter(predicate func(K, V) bool) stream.Iter[K, V, map[K]V]

Filter returns a stream consisting of elements that satisfy the condition of the 'predicate' function

func (*Map[K, V]) FilterKey

func (m *Map[K, V]) FilterKey(predicate func(K) bool) stream.Iter[K, V, map[K]V]

FilterKey returns a stream consisting of key/value pairs where the key satisfies the condition of the 'predicate' function

func (*Map[K, V]) FilterValue

func (m *Map[K, V]) FilterValue(predicate func(V) bool) stream.Iter[K, V, map[K]V]

FilterValue returns a stream consisting of key/value pairs where the value satisfies the condition of the 'predicate' function

func (*Map[K, V]) First

func (m *Map[K, V]) First() (ordered.MapIter[K, V], K, V, bool)

First returns the first key/value pair of the map, an iterator to iterate over the remaining pair, and true\false marker of availability next pairs. If no more then ok==false.

func (*Map[K, V]) For

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

For applies the 'walker' function for key/value pairs. Return the c.ErrBreak to stop.

func (*Map[K, V]) ForEach

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

ForEach applies the 'walker' function for every key/value pair

func (*Map[K, V]) Get

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

Get returns the value for a key. If ok==false, then the map does not contain the key.

func (*Map[K, V]) HasAny

func (m *Map[K, V]) HasAny(predicate func(K, V) bool) bool

HasAny finds the first key/value pair that satisfies the 'predicate' function condition and returns true if successful

func (*Map[K, V]) Head

func (m *Map[K, V]) Head() ordered.MapIter[K, V]

Head creates an iterator and returns as implementation type value

func (*Map[K, V]) Immutable

func (m *Map[K, V]) Immutable() ordered.Map[K, V]

Immutable converts to an immutable map instance

func (*Map[K, V]) IsEmpty

func (m *Map[K, V]) IsEmpty() bool

IsEmpty returns true if the map is empty

func (*Map[K, V]) Iter

func (m *Map[K, V]) Iter() kv.Iterator[K, V]

Iter creates an iterator and returns as interface

func (*Map[K, V]) Keys

func (m *Map[K, V]) Keys() ordered.MapKeys[K]

Keys resutrns keys collection

func (*Map[K, V]) Len

func (m *Map[K, V]) Len() int

Len returns the amount of elements contained in the map

func (*Map[K, V]) Loop

func (m *Map[K, V]) Loop() *ordered.MapIter[K, V]

Loop creates an iterator and returns as implementation type reference

func (*Map[K, V]) Map

func (m *Map[K, V]) Map() map[K]V

Map collects the key/value pairs to a map

func (*Map[K, V]) Reduce

func (m *Map[K, V]) Reduce(merge func(K, K, V, V) (K, V)) (k K, v V)

Reduce reduces the key/value pairs of the map into an one pair using the 'merge' function

func (*Map[K, V]) Set

func (m *Map[K, V]) Set(key K, value V)

Set sets the value for a key

func (*Map[K, V]) SetMap

func (m *Map[K, V]) SetMap(kvs c.TrackEachLoop[K, V])

SetMap inserts all elements from the 'other' map

func (*Map[K, V]) SetNew

func (m *Map[K, V]) SetNew(key K, value V) bool

SetNew sets the value fo a key only if the key is not exists in the map

func (*Map[K, V]) Sort

func (m *Map[K, V]) Sort(less slice.Less[K]) *Map[K, V]

Sort transforms to the ordered Map contains sorted elements

func (*Map[K, V]) StableSort

func (m *Map[K, V]) StableSort(less slice.Less[K]) *Map[K, V]

StableSort transforms to the ordered Map contains sorted elements

func (*Map[K, V]) String

func (m *Map[K, V]) String() string

String string representation on the map

func (*Map[K, V]) Tail

func (m *Map[K, V]) Tail() ordered.MapIter[K, V]

Tail creates an iterator pointing to the end of the collection

func (*Map[K, V]) Track

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

Track applies the 'tracker' function for key/value pairs. Return the c.ErrBreak to stop.

func (*Map[K, V]) TrackEach

func (m *Map[K, V]) TrackEach(tracker func(K, V))

TrackEach applies the 'tracker' function for every key/value pairs

func (*Map[K, V]) Values

func (m *Map[K, V]) Values() ordered.MapValues[K, V]

Values resutrns values collection

type Set

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

Set is a collection implementation that provides element uniqueness and access order. Elements must be comparable.

func NewSet

func NewSet[T comparable](elements ...T) *Set[T]

NewSet instantiates set and copies elements to it

func NewSetCap

func NewSetCap[T comparable](capacity int) *Set[T]

NewSetCap creates a set with a predefined capacity

func SetFromLoop

func SetFromLoop[T comparable](next func() (T, bool)) *Set[T]

SetFromLoop creates a set with elements retrieved by the 'next' function. The next returns an element with true or zero value with false if there are no more elements.

func WrapSet

func WrapSet[T comparable](elements []T, uniques map[T]int) *Set[T]

WrapSet creates a set using a map and an order slice as the internal storage.

func (*Set[T]) Add

func (s *Set[T]) Add(elements ...T)

Add adds elements in the collection

func (*Set[T]) AddAll

func (s *Set[T]) AddAll(other c.ForEachLoop[T])

AddAll inserts all elements from the "other" collection

func (*Set[T]) AddAllNew

func (s *Set[T]) AddAllNew(other c.ForEachLoop[T]) (ok bool)

AddAllNew inserts elements from the "other" collection if they are not contained in the collection

func (*Set[T]) AddNew

func (s *Set[T]) AddNew(elements ...T) bool

AddNew inserts elements if they are not contained in the collection

func (*Set[T]) AddOne

func (s *Set[T]) AddOne(element T)

AddOne adds an element in the collection

func (*Set[T]) AddOneNew

func (s *Set[T]) AddOneNew(element T) (ok bool)

AddOneNew inserts an element if it is not contained in the collection

func (*Set[T]) Append

func (s *Set[T]) Append(out []T) []T

Append collects the values to the specified 'out' slice

func (*Set[T]) Clone

func (s *Set[T]) Clone() *Set[T]

Clone returns copy of the collection

func (*Set[T]) Contains

func (s *Set[T]) Contains(element T) (ok bool)

Contains checks if the collection contains an element

func (*Set[T]) Conv

func (s *Set[T]) Conv(converter func(T) (T, error)) breakStream.Iter[T]

Conv returns a breakable stream that applies the 'converter' function to the collection elements

func (*Set[T]) Convert

func (s *Set[T]) Convert(converter func(T) T) stream.Iter[T]

Convert returns a stream that applies the 'converter' function to the collection elements

func (*Set[T]) Delete

func (s *Set[T]) Delete(elements ...T)

Delete removes elements from the collection

func (*Set[T]) DeleteActual

func (s *Set[T]) DeleteActual(elements ...T) bool

DeleteActual removes elements only if they are contained in the collection

func (*Set[T]) DeleteActualOne

func (s *Set[T]) DeleteActualOne(element T) bool

DeleteActualOne removes an element only if it is contained in the collection

func (*Set[T]) DeleteOne

func (s *Set[T]) DeleteOne(v T)

DeleteOne removes an element from the collection

func (*Set[T]) Filt

func (s *Set[T]) Filt(predicate func(T) (bool, error)) breakStream.Iter[T]

Filt returns a breakable stream consisting of elements that satisfy the condition of the 'predicate' function

func (*Set[T]) Filter

func (s *Set[T]) Filter(predicate func(T) bool) stream.Iter[T]

Filter returns a stream consisting of elements that satisfy the condition of the 'predicate' function

func (*Set[T]) First

func (s *Set[T]) First() (SetIter[T], T, bool)

First returns the first element of the collection, an iterator to iterate over the remaining elements, and true\false marker of availability next elements. If no more elements then ok==false.

func (*Set[T]) For

func (s *Set[T]) For(walker func(T) error) error

For applies the 'walker' function for the elements. Return the c.ErrBreak to stop.

func (*Set[T]) ForEach

func (s *Set[T]) ForEach(walker func(T))

ForEach applies the 'walker' function for every element

func (*Set[K]) HasAny

func (s *Set[K]) HasAny(predicate func(K) bool) bool

HasAny finds the first element that satisfies the 'predicate' function condition and returns true if successful

func (*Set[T]) Head

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

Head creates an iterator and returns as implementation type value

func (*Set[T]) IsEmpty

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

IsEmpty returns true if the collection is empty

func (*Set[T]) Iter

func (s *Set[T]) Iter() c.Iterator[T]

Iter creates an iterator and returns as interface

func (*Set[T]) IterEdit

func (s *Set[T]) IterEdit() c.DelIterator[T]

IterEdit creates iterator that can delete iterable elements

func (*Set[T]) Len

func (s *Set[T]) Len() int

Len returns amount of the elements

func (*Set[T]) Loop

func (s *Set[T]) Loop() *SetIter[T]

Loop creates an iterator and returns as implementation type reference

func (*Set[T]) Reduce

func (s *Set[T]) Reduce(merge func(T, T) T) (t T)

Reduce reduces the elements into an one using the 'merge' function

func (*Set[T]) Slice

func (s *Set[T]) Slice() (out []T)

Slice collects the elements to a slice

func (*Set[T]) Sort

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

Sort sorts the elements

func (*Set[T]) StableSort

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

StableSort sorts the elements

func (*Set[T]) String

func (s *Set[T]) String() string

type SetIter

type SetIter[T any] struct {
	// contains filtered or unexported fields
}

SetIter set iterator

func NewSetIter

func NewSetIter[T any](elements *[]T, del func(v T)) SetIter[T]

NewSetIter creates a set's iterator.

func (*SetIter[T]) Cap

func (i *SetIter[T]) Cap() (capacity int)

Cap returns the iterator capacity

func (*SetIter[T]) Delete

func (i *SetIter[T]) Delete()

Delete deletes the current element

func (*SetIter[T]) For

func (i *SetIter[T]) For(walker func(element T) error) error

For takes elements retrieved by the iterator. Can be interrupt by returning ErrBreak

func (*SetIter[T]) ForEach

func (i *SetIter[T]) ForEach(walker func(element T))

ForEach takes all elements retrieved by the iterator.

func (*SetIter[T]) Next

func (i *SetIter[T]) Next() (t T, ok bool)

Next returns the next element. The ok result indicates whether the element was returned by the iterator. If ok == false, then the iteration must be completed.

func (*SetIter[T]) Start added in v0.0.10

func (i *SetIter[T]) Start() (*SetIter[T], T, bool)

Start is used with for loop construct like 'for i, val, ok := i.Start(); ok; val, ok = i.Next() { }'

Directories

Path Synopsis
Package map_ provides mutable ordered.Map constructors
Package map_ provides mutable ordered.Map constructors
Package set provides mutable ordered.Set constructors and helpers
Package set provides mutable ordered.Set constructors and helpers

Jump to

Keyboard shortcuts

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