Slices

package
v0.3.17 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DoWhile

func DoWhile[T any](todo []T, accept slext.PredicateFilter[T], f uc.EvalManyFunc[T, T]) []T

DoWhile performs a do-while loop on a slice of elements.

Parameters:

  • todo: The elements to perform the do-while loop on.
  • accept: The predicate filter to accept elements.
  • f: The evaluation function to perform on the elements.

Returns:

  • []T: The elements that were accepted.

Behaviors:

  • If todo is empty, the function returns nil.
  • If accept is nil, the function returns nil.
  • If f is nil, the function returns the application of accept on todo.
  • The function performs the do-while loop on the elements in todo.

func Evaluate added in v0.3.13

func Evaluate[A, T, E, R any](elem LeafEvaluable[A, T, E, R], args []A) ([]T, error)

Evaluate performs a leaf evaluation with a loop.

Parameters:

  • le: The evaluable element.
  • args: The arguments.

Returns:

  • []T: The branches.
  • error: An error if the evaluation fails (reserved for panic-level of critical errors).

Behaviors:

  • The function performs a leaf evaluation with a loop.
  • The function returns the branches.
  • If le is nil, the function returns nil.

Types

type Accepter

type Accepter interface {
	// Accept returns true if the accepter accepts the element.
	//
	// Returns:
	//   - bool: True if the accepter accepts the element, false otherwise.
	Accept() bool
}

Accepter is an interface that represents an accepter.

type FrontierEvaluator

type FrontierEvaluator[T Accepter] struct {
	// contains filtered or unexported fields
}

FrontierEvaluator is a type that represents a frontier evaluator.

func NewFrontierEvaluator

func NewFrontierEvaluator[T Accepter](matcher uc.EvalManyFunc[T, T]) *FrontierEvaluator[T]

NewFrontierEvaluator creates a new frontier evaluator.

Parameters:

  • matcher: The matcher.

Returns:

  • *FrontierEvaluator: The new frontier evaluator.

Behaviors:

  • If matcher is nil, then the frontier evaluator will return nil for any evaluation.

func (*FrontierEvaluator[T]) Evaluate

func (fe *FrontierEvaluator[T]) Evaluate(elem T)

Evaluate evaluates the frontier evaluator given an element.

Parameters:

  • elem: The element to evaluate.

Behaviors:

  • If the element is accepted, the solutions will be set to the element.
  • If the element is not accepted, the solutions will be set to the results of the matcher.
  • If the matcher returns an error, the solutions will be set to the error.
  • The evaluations assume that, the more the element is elaborated, the more the weight increases. Thus, it is assumed to be the most likely solution as it is the most elaborated. Euristic: Depth.

func (*FrontierEvaluator[T]) GetResults

func (fe *FrontierEvaluator[T]) GetResults() ([]T, error)

GetResults gets the results of the frontier evaluator.

Returns:

  • []T: The results of the frontier evaluator.
  • error: An error if the frontier evaluator failed.

Behaviors:

  • If the solutions are empty, the function returns nil.
  • If the solutions contain errors, the function returns the first error.
  • Otherwise, the function returns the solutions.

type LeafEvaluable added in v0.3.13

type LeafEvaluable[A, T, E, R any] interface {
	// Evaluator is a function type that returns the leaf evaluator.
	//
	// Returns:
	//   - LeafEvaluater[A, T, E, R]: The leaf evaluator.
	Evaluator() LeafEvaluater[A, T, E, R]
}

LeafEvaluable is an interface that represents a leaf evaluable.

type LeafEvaluater added in v0.3.13

type LeafEvaluater[A, T, E, R any] interface {
	// Init is a function type that initializes the memory and the first branch.
	//
	// Parameters:
	//   - elems: The elements.
	//
	// Returns:
	//   - T: The first branch.
	//   - error: An error if the initialization fails.
	Init(elems []A) (T, error)

	// Core is a function type that performs the core evaluation.
	//
	// Parameters:
	//   - index: The index of the loop element.
	//   - lpe: The loop element.
	//
	// Returns:
	//   - *up.Pair[R, error]: The result and an error.
	//   - error: An error if the evaluation fails (reserved for panic-level of critical errors).
	Core(index int, lpe E) (*up.Pair[R, error], error)

	// Next is a function type that performs the next evaluation.
	//
	// Parameters:
	//   - pair: The result and an error.
	//   - branch: The current branch.
	//
	// Returns:
	//   - []T: The new branches.
	//   - error: An error if the evaluation fails (reserved for panic-level of critical errors).
	Next(pair *up.Pair[R, error], branch T) ([]T, error)

	ui.Iterable[E]
}

LeafEvaluater is an interface that represents a leaf evaluater.

Jump to

Keyboard shortcuts

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