ds

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2022 License: BSD-2-Clause, ISC Imports: 0 Imported by: 4

Documentation

Overview

Package containers provides core interfaces and functions for data structures.

Container is the base interface for all data structures to implement.

Iterators provide stateful iterators.

Enumerable provides Ruby inspired (each, select, map, find, any?, etc.) container functions.

Serialization provides serializers (marshalers) and deserializers (unmarshalers).

Index

Constants

View Source
const (
	CanOnlyCompareEqualIteratorTypes = "Can only compare iterators of equal concrete type"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BackwardIterator

type BackwardIterator interface {
	// *********************    Inherited methods    ********************//
	Iterator

	// Next moves the iterator backward  by one position.
	Previous()

	// NextN moves the iterator backward by n positions.
	PreviousN(n int)
}

BackwardIterator defines an Iterator, which can be moved backward according to the indexes ordering.

type BidirectionalIterator

type BidirectionalIterator interface {
	// *********************    Inherited methods    ********************//
	ForwardIterator
	BackwardIterator

	// Next moves the iterator forward/backward by n positions.
	MoveBy(n int)
}

BidirectionalIterator defines a ForwardIterator and BackwardIterator, which can be moved forward and backward according to the underlying data structure's ordering.

type CollectionIterator

type CollectionIterator[TIndex any] interface {
	// *********************    Inherited methods    ********************//
	SizedIterator

	// Index returns the index of the iterator's position in the collection.
	Index() TIndex
}

CollectionIterator defines a SizedIterator, which can be said to reference a collection of elements.

type ComparableIterator

type ComparableIterator interface {
	// *********************    Inherited methods    ********************//
	Iterator

	// IsEqualTo checks if the iterator's position is said to be equal to other's position.
	IsEqual(other ComparableIterator) bool
}

ComparableIterator defines an Iterator, which can be said to be in a position equal to other's position.

type Container

type Container interface {
	IsEmpty() bool
	Size() int
	Clear()
	ToString() string
}

Container defines the minimum functionality required for all other containers.

type ForwardIterator

type ForwardIterator interface {
	// *********************    Inherited methods    ********************//
	Iterator

	// Next moves the iterator forward by one position.
	Next()

	// NextN moves the iterator forward by n positions.
	NextN(i int)
}

ForwardIterator defines an ordered Iterator, which can be moved forward according to the indexes ordering.

type Iterator

type Iterator interface {
	// IsBegin checks if the iterator is pointing to one element before it's first element, unless Next() is called, the iterator is in an invalid state.
	IsBegin() bool
	// IsEnd checks if the iterator is pointing to one element past it's last element, unless Previous() is called, the iterator is in an invalid state.
	IsEnd() bool

	// IsFirst checks if the iterator is pointing to it's first element, when Next() is called, the iterator is in an invalid state.
	IsFirst() bool
	// IsBegin checks if the iterator is pointing to it's last element, when Previous() is called, the iterator is in an invalid state.
	IsLast() bool

	// IsValid checks if the iterator is in a valid position and not e.g. out of bounds.
	IsValid() bool
}

Iterator defines the minimum functionality required for all other iterators.

type JSONDeserializer

type JSONDeserializer interface {
	// FromJSON populates containers's elements from the input JSON representation.
	FromJSON([]byte) error
	// UnmarshalJSON @implements json.Unmarshaler
	UnmarshalJSON([]byte) error
}

JSONDeserializer provides JSON deserialization

type JSONSerializer

type JSONSerializer interface {
	// ToJSON outputs the JSON representation of containers's elements.
	ToJSON() ([]byte, error)
	// MarshalJSON @implements json.Marshaler
	MarshalJSON() ([]byte, error)
}

JSONSerializer provides JSON serialization

type OrderedIterator

type OrderedIterator interface {
	// *********************    Inherited methods    ********************//
	Iterator

	// IsBefore checks if the iterator's position is said to come before other's position.
	IsBefore(other OrderedIterator) bool
	// IsBefore checks if the iterator's position is said to come after other's position.
	IsAfter(other OrderedIterator) bool

	// DistanceTo returns the signed distance of the iterator's position to other's position.
	DistanceTo(other OrderedIterator) int
}

OrderedIterator defines an Iterator, which can be said to be in a position before or after others's position.

type RandomAccessIterator

type RandomAccessIterator[TIndex any] interface {
	// *********************    Inherited methods    ********************//
	CollectionIterator[TIndex]

	// MoveTo moves the iterator to the given index.
	MoveTo(i TIndex)
}

RandomAccessIterator defines a BidirectionalIterator and CollectionIterator, which can be moved to every position in the iterator.

type RandomAccessReadableIterator

type RandomAccessReadableIterator[TIndex any, TValue any] interface {
	// *********************    Inherited methods    ********************//
	RandomAccessIterator[TIndex]
	ReadableIterator[TValue]

	// GetAt returns the value at the given index of the iterator.
	GetAt(i TIndex) (value TValue, found bool)
}

RandomAccessReadableIterator defines a RandomAccessIterator and ReadableIterator, which can read from every index in the iterator.

type RandomAccessWriteableIterator

type RandomAccessWriteableIterator[TIndex any, TValue any] interface {
	// *********************    Inherited methods    ********************//
	RandomAccessIterator[TIndex]
	WritableIterator[TValue]

	// GetAt sets the value at the given index of the iterator.
	SetAt(i TIndex, value TValue) bool
}

RandomAccessWriteableIterator defines a RandomAccessIterator and WritableIterator, which can write from every index in the iterator.

type ReadWriteCompForRandCollIterator added in v0.4.0

type ReadWriteCompForRandCollIterator[TIndex any, TValue any] interface {
	ComparableIterator
	CollectionIterator[TIndex]
	ForwardIterator
	RandomAccessReadableIterator[TIndex, TValue]
	RandomAccessWriteableIterator[TIndex, TValue]
}

type ReadWriteOrdCompBidRandCollIterator added in v0.4.0

type ReadWriteOrdCompBidRandCollIterator[TIndex any, TValue any] interface {
	OrderedIterator
	ComparableIterator

	BidirectionalIterator

	RandomAccessReadableIterator[TIndex, TValue]
	RandomAccessWriteableIterator[TIndex, TValue]
}

type ReadWriteOrdCompBidRevRandCollIterator added in v0.4.0

type ReadWriteOrdCompBidRevRandCollIterator[TIndex any, TValue any] interface {
	OrderedIterator
	ComparableIterator

	ReversedIterator
	BackwardIterator

	RandomAccessReadableIterator[TIndex, TValue]
	RandomAccessWriteableIterator[TIndex, TValue]
}

type ReadWriteUnordCompBidRandCollIterator added in v0.5.0

type ReadWriteUnordCompBidRandCollIterator[TIndex any, TValue any] interface {
	ComparableIterator
	OrderedIterator
	CollectionIterator[TIndex]
	UnorderedBidirectionalIterator
	UnorderedRandomAccessReadableIterator[TIndex, TValue]
	UnorderedRandomAccessWriteableIterator[TIndex, TValue]
}

type ReadableIterator

type ReadableIterator[TValue any] interface {
	// *********************    Inherited methods    ********************//
	Iterator

	// Get returns the value at the iterator's position.
	// found will be false if the iterator is in an invalid state or the collection is empty.
	Get() (value TValue, found bool)
}

ReadableIterator defines an Iterator, which can be used to read the underlying values.

type ReversedIterator

type ReversedIterator interface {
	// *********************    Inherited methods    ********************//
	ForwardIterator
}

ReversedIterator defines a a ForwardIterator, whose iteration direction is reversed. This allows using ForwardIterator and ReversedIterator with the same API.

type SizedIterator

type SizedIterator interface {
	// *********************    Inherited methods    ********************//
	Iterator

	// Size returns the number of elements in the iterator.
	Size() int
}

SizedIterator defines an Iterator, which can be said to have a fixed size.

type UnorderedBackwardIterator

type UnorderedBackwardIterator interface {
	// *********************    Inherited methods    ********************//
	BackwardIterator
}

UnorderedBackwardIterator defines an unordered BackwardIterator, which can be moved backward according to the indexes ordering. This iterator would allow you to e.g. iterate over a builtin map in the reverse lexographical order of the keys.

type UnorderedBidirectionalIterator added in v0.4.0

type UnorderedBidirectionalIterator interface {
	// *********************    Inherited methods    ********************//
	UnorderedForwardIterator
	UnorderedBackwardIterator

	// Next moves the iterator forward/backward by n positions.
	MoveBy(n int)
}

UnorderedBidirectionalIterator defines an UnorderedForwardIterator and UnorderedBackwardIterator, which can be moved forward and backward according to the indexes ordering.

type UnorderedForwardIterator

type UnorderedForwardIterator interface {
	// *********************    Inherited methods    ********************//
	ForwardIterator
}

UnorderedForwardIterator defines an unordered ForwardIterator, which can be moved forward according to the indexes ordering. This iterator would allow you to e.g. iterate over a builtin map in the lexographical order of the keys.

type UnorderedRandomAccessIterator added in v0.4.0

type UnorderedRandomAccessIterator[TIndex any] interface {
	// *********************    Inherited methods    ********************//
	UnorderedBidirectionalIterator
	CollectionIterator[TIndex]

	// MoveTo moves the iterator to the given index.
	MoveTo(i TIndex)
}

UnorderedRandomAccessIterator defines an UnorderedBidirectionalIterator and CollectionIterator, which can be moved to every position in the iterator.

type UnorderedRandomAccessReadableIterator added in v0.4.0

type UnorderedRandomAccessReadableIterator[TIndex any, TValue any] interface {
	// *********************    Inherited methods    ********************//
	UnorderedRandomAccessIterator[TIndex]
	ReadableIterator[TValue]

	// GetAt returns the value at the given index of the iterator.
	GetAt(i TIndex) (value TValue, found bool)
}

UnorderedRandomAccessReadableIterator defines a RandomAccessIterator and ReadableIterator, which can read from every index in the iterator.

type UnorderedRandomAccessWriteableIterator added in v0.4.0

type UnorderedRandomAccessWriteableIterator[TIndex any, TValue any] interface {
	// *********************    Inherited methods    ********************//
	UnorderedRandomAccessIterator[TIndex]
	WritableIterator[TValue]

	// GetAt sets the value at the given index of the iterator.
	SetAt(i TIndex, value TValue) bool
}

UnorderedRandomAccessWriteableIterator defines a RandomAccessIterator and WritableIterator, which can write from every index in the iterator.

type UnorderedReversedIterator added in v0.4.0

type UnorderedReversedIterator interface {
	// *********************    Inherited methods    ********************//
	UnorderedForwardIterator
}

UnorderedReversedIterator defines an UnorderedForwardIterator, whose iteration direction is reversed. This allows using UnorderedForwardIterator and UnorderedReversedIterator with the same API.

type WritableIterator

type WritableIterator[TValue any] interface {
	// *********************    Inherited methods    ********************//
	Iterator

	// Set sets the value at the iterator's position.
	Set(value TValue) bool
}

WritableIterator defines an Iterator, which can be used to write to the underlying values.

Jump to

Keyboard shortcuts

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