agent

package
v5.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package "agent" declares a set of agents that operate on values that have a generic type. They are used by the collection classes declared in this Go module.

For detailed documentation on this package refer to the wiki:

This package follows the Crater Dog Technologies™ Go Coding Conventions located here:

Additional concrete implementations of the classes declared by this package can be developed and used seamlessly since the interface declarations only depend on other interfaces and intrinsic types—and the class implementations only depend on interfaces, not on each other.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CollatorClassLike

type CollatorClassLike[V any] interface {
	// Constructor Methods
	Collator() CollatorLike[V]
	CollatorWithMaximumDepth(
		maximumDepth Size,
	) CollatorLike[V]
}

CollatorClassLike[V any] is a class interface that declares the complete set of class constructors, constants and functions that must be supported by each concrete collator-like class.

A collator-like class is capable of recursively comparing and ranking two values of any type. An optional maximum depth may be specified that limits the depth of the structures being collated to avoid possible infinite recursion.

The default maximum depth is 16.

func CollatorClass

func CollatorClass[V any]() CollatorClassLike[V]

type CollatorLike

type CollatorLike[V any] interface {
	// Principal Methods
	GetClass() CollatorClassLike[V]
	CompareValues(
		first V,
		second V,
	) bool
	RankValues(
		first V,
		second V,
	) Rank

	// Attribute Methods
	GetMaximumDepth() Size
}

CollatorLike[V any] is an instance interface that declares the complete set of principal, attribute and aspect methods that must be supported by each instance of a concrete collator-like class.

type IteratorClassLike

type IteratorClassLike[V any] interface {
	// Constructor Methods
	Iterator(
		array []V,
	) IteratorLike[V]
}

IteratorClassLike[V any] is a class interface that declares the complete set of class constructors, constants and functions that must be supported by each concrete iterator-like class.

An iterator-like class can be used to move forward and backward over the values in an array. It implements the Gang of Four (GoF) Iterator Design Pattern:

An iterator agent locks into the slots that reside between each value in the sequence:

  . [value 1] . [value 2] . [value 3] ... [value N] .
  ^           ^           ^                         ^
slot 0      slot 1      slot 2                    slot N

It moves from slot to slot and has access to the values (if they exist) on each side of the slot. At each slot an iterator has access to the previous value and next value in the array (assuming they exist). The slot at the start of the array has no PREVIOUS value, and the slot at the end of the array has no NEXT value. The size of the array is static so that its values can be modified during iteration.

func IteratorClass

func IteratorClass[V any]() IteratorClassLike[V]

type IteratorLike

type IteratorLike[V any] interface {
	// Principal Methods
	GetClass() IteratorClassLike[V]
	IsEmpty() bool
	ToStart()
	ToEnd()
	HasPrevious() bool
	GetPrevious() V
	HasNext() bool
	GetNext() V

	// Attribute Methods
	GetSize() Size
	GetSlot() Slot
	SetSlot(
		slot Slot,
	)
}

IteratorLike[V any] is an instance interface that declares the complete set of principal, attribute and aspect methods that must be supported by each instance of a concrete iterator-like class.

type Rank

type Rank uint8

Rank is a constrained type representing the possible rankings for two values.

const (
	LesserRank Rank = iota
	EqualRank
	GreaterRank
)

type RankingFunction

type RankingFunction[V any] func(
	first V,
	second V,
) Rank

RankingFunction[V any] is a functional type that declares the signature for any function that can determine the relative ranking of two values.

type Size

type Size uint

Size is a constrained type representing the size or capacity of something.

type Slot

type Slot uint

Slot is a constrained type representing a slot between values in a sequence.

type SorterClassLike

type SorterClassLike[V any] interface {
	// Constructor Methods
	Sorter() SorterLike[V]
	SorterWithRanker(
		ranker RankingFunction[V],
	) SorterLike[V]
}

SorterClassLike[V any] is a class interface that declares the complete set of class constructors, constants and functions that must be supported by each concrete sorter-like class.

A sorter-like class implements a specific sorting algorithm. It uses a ranking function to correlate the values. If no ranking function is specified the values are sorted into their "natural" ordering by type of value.

func SorterClass

func SorterClass[V any]() SorterClassLike[V]

type SorterLike

type SorterLike[V any] interface {
	// Principal Methods
	GetClass() SorterClassLike[V]
	SortValues(
		values []V,
	)
	ReverseValues(
		values []V,
	)
	ShuffleValues(
		values []V,
	)

	// Attribute Methods
	GetRanker() RankingFunction[V]
}

SorterLike[V any] is an instance interface that declares the complete set of principal, attribute and aspect methods that must be supported by each instance of a concrete sorter-like class.

Jump to

Keyboard shortcuts

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