iterator

package
v0.0.0-...-0798a42 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FixBounds

func FixBounds(i, lower, upper int) int

FixBounds will force the index i to either its lower- or upper-bound value if out-of-bound

func MoveIndex

func MoveIndex(idx, delta int, indexer IndexProvider, cb BoundsCheckFunc) int

MoveIndex moves the index variable idx forward by delta steps and ensures that the boundary policy as defined by the CheckBoundsFunc is enforced.

If CheckBoundsFunc is nil, fix boundary checks are performed.

func WrapBounds

func WrapBounds(i, lower, upper int) int

WrapBounds will wrap the index i around its upper- or lower-bound if out-of-bound

Types

type BoundsCheckFunc

type BoundsCheckFunc func(int, int, int) int

type Factory

type Factory interface {
	NewIterator(a interface{}) Iterator
}

Factory is the interface that wraps the NewIterator method. The NewIterator() creates either UID or thread iterators and ensures that both types of iterators implement the same iteration direction.

func NewFactory

func NewFactory(reverse bool) Factory

NewFactory creates an iterator factory. When reverse is true, the iterators are reversed in the sense that the lowest UID messages are displayed at the top of the message list. Otherwise, the default order is with the highest UID message on top.

type IndexProvider

type IndexProvider interface {
	StartIndex() int
	EndIndex() int
}

IndexProvider implements a subset of the Interator interface

type Iterator

type Iterator interface {
	Next() bool
	Value() interface{}
	StartIndex() int
	EndIndex() int
}

Iterator implements an interface for iterating over UID or thread data. If Next() returns true, the current value of the iterator can be read with Value(). The return value of Value() is an interface{} type which needs to be cast to the correct type.

The iterators are implemented such that the first returned value always represents the top message in the message list. Hence, StartIndex() would return the index of the top message whereas EndIndex() returns the index of message at the bottom of the list.

Jump to

Keyboard shortcuts

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