ring

Structs

Ring struct #

A Ring is an element of a circular list, or ring. Rings do not have a beginning or end; a pointer to any ring element serves as reference to the entire ring. Empty rings are represented as nil Ring pointers. The zero value for a Ring is a one-element ring with a nil Value.

type Ring struct {
next *Ring
prev *Ring
Value any
}

Functions

Do method #

Do calls function f on each element of the ring, in forward order. The behavior of Do is undefined if f changes *r.

func (r *Ring) Do(f func(any))

Len method #

Len computes the number of elements in ring r. It executes in time proportional to the number of elements.

func (r *Ring) Len() int

Move method #

Move moves n % r.Len() elements backward (n < 0) or forward (n >= 0) in the ring and returns that ring element. r must not be empty.

func (r *Ring) Move(n int) *Ring

New function #

New creates a ring of n elements.

func New(n int) *Ring

Next method #

Next returns the next ring element. r must not be empty.

func (r *Ring) Next() *Ring

Prev method #

Prev returns the previous ring element. r must not be empty.

func (r *Ring) Prev() *Ring

init method #

func (r *Ring) init() *Ring

Generated with Arrow