ds

package module
v0.0.0-...-31dbb72 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0, BSD-2-Clause Imports: 12 Imported by: 27

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type List

type List[T any] interface {
	// Init initializes or clears the List.
	Init() List[T]

	// Front returns the first element of the List or nil if it is empty.
	Front() ListElement[T]

	// Back returns the last element of the List or nil if it is empty.
	Back() ListElement[T]

	// PushFront inserts and returns a new element with the given value at the front of the List.
	PushFront(value T) ListElement[T]

	// PushBack inserts and returns a new element with the given value at the back of the List.
	PushBack(value T) ListElement[T]

	// Remove removes the given element from the List and returns its value.
	Remove(element ListElement[T]) (removedValue T)

	// InsertBefore inserts and returns a new element with the given value immediately before the given position.
	InsertBefore(value T, position ListElement[T]) ListElement[T]

	// InsertAfter inserts and returns a new element with the given value immediately after the given position.
	InsertAfter(value T, position ListElement[T]) ListElement[T]

	// MoveToFront moves the given element to the front of the List.
	MoveToFront(element ListElement[T])

	// MoveToBack moves the given element to the back of the List.
	MoveToBack(element ListElement[T])

	// MoveBefore moves the given element before the given position.
	MoveBefore(element, position ListElement[T])

	// MoveAfter moves the given element after the given position.
	MoveAfter(element, position ListElement[T])

	// PushBackList inserts the values of the other List at the back of this List.
	PushBackList(other List[T])

	// PushFrontList inserts the values of the other List at the front of this List.
	PushFrontList(other List[T])

	// ForEach executes the given callback for the value of each element in the List. The iteration is aborted if the
	// callback returns an error.
	ForEach(callback func(value T) error) error

	// ForEachReverse executes the given callback for the value of each element in the List in reverse order. The
	// iteration is aborted if the callback returns an error.
	ForEachReverse(callback func(value T) error) error

	// Range executes the given callback for the value of each element in the List.
	Range(callback func(value T))

	// RangeReverse executes the given callback for the value of each element in the List in reverse order.
	RangeReverse(callback func(value T))

	// Values returns a slice of all values in the List.
	Values() []T

	// Len returns the number of elements in the List.
	Len() int
}

List represents an interface for a doubly linked list.

func NewList

func NewList[T any](lockFree ...bool) List[T]

NewList creates a new List (the optional lockFree parameter can be set to true to create a List that is not thread-safe).

type ListElement

type ListElement[T any] interface {
	// Prev returns the previous ListElement or nil.
	Prev() ListElement[T]

	// Next returns the next ListElement or nil.
	Next() ListElement[T]

	// Value returns the value of the ListElement.
	Value() T
}

ListElement represents an interface for a doubly linked list element.

type ReadableSet

type ReadableSet[ElementType comparable] interface {
	// Has returns true if the set contains the given element.
	Has(key ElementType) (has bool)

	// HasAll returns true if the set contains all elements of the given set.
	HasAll(other ReadableSet[ElementType]) bool

	// ForEach iterates through all elements of the set (returning an error will stop the iteration).
	ForEach(callback func(element ElementType) error) error

	// Range iterates through all elements of the set.
	Range(callback func(element ElementType))

	// Intersect returns the intersection of the set and the given set.
	Intersect(other ReadableSet[ElementType]) Set[ElementType]

	// Filter returns a new set with all elements that satisfy the given predicate.
	Filter(predicate func(element ElementType) bool) Set[ElementType]

	// Equals returns true if the set contains the same elements as the given set.
	Equals(other ReadableSet[ElementType]) bool

	// Any returns a random element from the set (and if one exists).
	Any() (element ElementType, exists bool)

	// Is returns true if the given element is the only element in the set.
	Is(element ElementType) bool

	// Iterator returns an iterator for the set.
	Iterator() *walker.Walker[ElementType]

	// Clone returns a shallow copy of the set.
	Clone() Set[ElementType]

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

	// IsEmpty returns true if the set is empty.
	IsEmpty() bool

	// Clear removes all elements from the set.
	Clear()

	// ToSlice returns a slice representation of the set.
	ToSlice() []ElementType

	// Encode encodes the set into a byte slice.
	Encode(serixAPI *serix.API) ([]byte, error)

	// String returns a string representation of the set.
	String() string
}

ReadableSet bundles the read methods of the Set interface.

func NewReadableSet

func NewReadableSet[T comparable](elements ...T) ReadableSet[T]

NewReadableSet creates a new readable Set with the given elements.

type Set

type Set[ElementType comparable] interface {
	// WriteableSet imports the write methods of the Set interface.
	WriteableSet[ElementType]

	// ReadableSet imports the read methods of the Set interface.
	ReadableSet[ElementType]
}

Set is a generic thread-safe collection of unique elements.

func NewSet

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

NewSet creates a new Set with the given elements.

type SetArithmetic

type SetArithmetic[ElementType comparable] interface {
	// Add adds the given mutations to the elements and returns the resulting net mutations for the set that are formed
	// by tracking the elements that rise above the given threshold (defaults to 1).
	Add(mutations SetMutations[ElementType], threshold ...int) SetMutations[ElementType]

	// AddedElementsCollector returns a function that adds an element to the given mutations if its occurrence count
	// reaches the given threshold (defaults to 1) after the addition.
	AddedElementsCollector(mutations SetMutations[ElementType], threshold ...int) func(addedElement ElementType)

	// Subtract subtracts the given mutations from the elements and returns the resulting net mutations for the set that
	// are formed by tracking the elements that fall below the given threshold (defaults to 1).
	Subtract(mutations SetMutations[ElementType], threshold ...int) SetMutations[ElementType]

	// SubtractedElementsCollector returns a function that deletes an element from the given mutations if its occurrence
	// count falls below the given threshold (defaults to 1) after the subtraction.
	SubtractedElementsCollector(mutations SetMutations[ElementType], threshold ...int) func(ElementType)
}

SetArithmetic is an interface that allows to perform arithmetic operations on a set of elements to return the resulting mutations of the operation.

func NewSetArithmetic

func NewSetArithmetic[ElementType comparable]() SetArithmetic[ElementType]

NewSetArithmetic creates a new SetArithmetic instance.

type SetMutations

type SetMutations[ElementType comparable] interface {
	// WithAddedElements is a setter for the added elements of the setMutations.
	WithAddedElements(elements Set[ElementType]) SetMutations[ElementType]

	// WithDeletedElements is a setter for the deleted elements of the setMutations.
	WithDeletedElements(elements Set[ElementType]) SetMutations[ElementType]

	// AddedElements returns the elements that are supposed to be added.
	AddedElements() Set[ElementType]

	// DeletedElements returns the elements that are supposed to be removed.
	DeletedElements() Set[ElementType]

	// IsEmpty returns true if the SetMutations instance is empty.
	IsEmpty() bool
}

SetMutations represents a set of mutations that can be applied to a Set atomically.

func NewSetMutations

func NewSetMutations[ElementType comparable](elements ...ElementType) SetMutations[ElementType]

NewSetMutations creates a new SetMutations instance.

type WriteableSet

type WriteableSet[ElementType comparable] interface {
	// Add adds a new element to the set and returns true if the element was not present in the set before.
	Add(element ElementType) bool

	// AddAll adds all elements to the set and returns true if any element has been added.
	AddAll(elements ReadableSet[ElementType]) (addedElements Set[ElementType])

	// Delete deletes the given element from the set.
	Delete(element ElementType) bool

	// DeleteAll deletes the given elements from the set.
	DeleteAll(other ReadableSet[ElementType]) (removedElements Set[ElementType])

	// Apply tries to apply the given mutations to the set atomically and returns the applied mutations.
	Apply(mutations SetMutations[ElementType]) (appliedMutations SetMutations[ElementType])

	// Compute tries to compute the mutations for the set atomically and returns the applied mutations.
	Compute(mutationFactory func(set ReadableSet[ElementType]) SetMutations[ElementType]) (appliedMutations SetMutations[ElementType])

	// Replace replaces the elements of the set with the given elements and returns the removed elements.
	Replace(elements ReadableSet[ElementType]) (removedElements Set[ElementType])

	// Decode decodes the set from a byte slice.
	Decode(serixAPI *serix.API, data []byte) (bytesRead int, err error)

	// ReadOnly returns a read-only version of the set.
	ReadOnly() ReadableSet[ElementType]
}

WriteableSet bundles all write methods of the Set interface.

Jump to

Keyboard shortcuts

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