navigator

package
v0.0.0-...-157c9c8 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Navigator[Key any, Node Nexter[Key, Node, Context], Context any] struct {
	// Cur is current or cursor node.
	Cur Node

	// Idx of the next Key to navigate
	Idx int
	// Keys to Navigate
	Keys slice.Slice[Key]

	// TraceNodes causes Nodes to be populated during a Seek operation if true.
	TraceNodes bool
	// Nodes iterated over during a seek operation.
	Nodes slice.Slice[Node]
}

Navigator can move through graph like structures whose nodes fulfill Nexter.

func (n *Navigator[Key, Node, Context]) IdxKey() Key

IdxKey is a helper to get the key at the current index

func (n *Navigator[Key, Node, Context]) Pop() (node Node, ok bool)

Pop the last value in Nodes off and assign it to Cur. This requires that Nodes are populated. So in order to use this after a Seek operation, TraceNodes needs to be true prior to the seek operation.

func (n *Navigator[Key, Node, Context]) Seek(create bool, ctx Context) (next Node, ok bool)

Seek starts with the initial value of Cur and iterates through Keys calling Next for each key so long as the returned OK is true. If TraceNodes is true, the navigated nodes will be added to Nodes.

func (n *Navigator[Key, Node, Context]) Trace(trace bool) *Navigator[Key, Node, Context]

Trace is a chainable helper. It sets TraceNodes to trace and returns the Navigator.

type Nexter

type Nexter[Key, Node, Context any] interface {
	Next(key Key, create bool, ctx Context) (Node, bool)
}

Nexter represents a node structure that can get the next node based on the key. If "create" is true, the Next method should create the node if it does not exist. Context allows arbitrary additional information to be passed in that may be necessary to perform the Next operation.

type VoidContext

type VoidContext struct{}

VoidContext is provided as a helper for instances where Context is not necessary.

var Void VoidContext

Void is an instance of VoidContext

Jump to

Keyboard shortcuts

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