iterator

package
v0.0.0-...-ab5ba7d Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BidirectionalIterator

type BidirectionalIterator[Index comparable, Value any] interface {
	UnidirectionalIterator[Index, Value]

	// Moves the iterator to the previous element in the collection
	// if it is not at the start.
	//
	// Return true if moving successfully, otherwise return false.
	Prev() bool
}

Represents a iterator that can move in both directions.

type Direction

type Direction int
const (
	ToLowerBound Direction = -1
	ToUpperBound Direction = 1
)

type Iterator

type Iterator[Index comparable, Value any] interface {
	// Return a shallow copy of the iterator.
	Clone() Iterator[Index, Value]

	// Return the current index of the iterator.
	//
	// Return a negative number if the iterator access invalid index.
	Index() Index

	// Return the current value of the iterator.
	//
	// Return the zero value of `Value` if the iterator access invalid element.
	Value() Value

	// Return the metadata of the iterator.
	Metadata() Metadata
}

Represents a object that can iterate over a collection.

type Metadata

type Metadata = map[string]any

type RandomAccessIterator

type RandomAccessIterator[Index comparable, Value any] interface {
	BidirectionalIterator[Index, Value]

	// Return the n-th index of the iterator.
	//
	// Return a negative number if the iterator access invalid index.
	IndexN(n typedef.Quantity) Index

	// Return the n-th value of the iterator.
	//
	// Return the zero value of `Value` if the iterator access invalid element.
	ValueN(n typedef.Quantity) Value

	// Move the iterator to the next n-th element in the collection.
	//
	// Return true if moving successfully, otherwise return false.
	NextN(n typedef.Quantity) bool

	// Move the iterator to the previous n-th element in the collection.
	//
	// Return true if moving successfully, otherwise return false.
	PrevN(n typedef.Quantity) bool

	// If `to` is the lower bound, then count the remaining number of times
	// the Prev method can be called until it returns false.
	//
	// If `to` is the upper bound, then count the remaining number of times
	// the Next method can be called until it returns false.
	//
	// Return a negative number
	// if the number of times the method can be called is infinite,
	// or any exception occurs.
	Distance(to Direction) typedef.Quantity
}

Represents a iterator that can move to any element in the collection.

type UnidirectionalIterator

type UnidirectionalIterator[Index comparable, Value any] interface {
	Iterator[Index, Value]

	// Moves the iterator to the next element in the collection
	// if it is not at the end.
	//
	// Return true if moving successfully, otherwise return false.
	Next() bool
}

Represents a iterator that can only move in one direction.

Jump to

Keyboard shortcuts

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