cyclist

package
v1.20.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2024 License: Apache-2.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 Cyclist

type Cyclist[T any] struct {
	// contains filtered or unexported fields
}

Cyclist[T] A Cyclist is an element of a circular list like container/ring in standard library but based on slice.

func New

func New[T any](n int) *Cyclist[T]

New[T] creates a cyclist of n(n>0) elements.

func (*Cyclist[T]) As

func (l *Cyclist[T]) As(reverse ...bool) (res []T)

As convert cyclist to slice. In reverse mode if reverse is true.

func (*Cyclist[T]) Capacity

func (l *Cyclist[T]) Capacity() int

Capacity computes the capacity of cyclist l.

func (*Cyclist[T]) Do

func (l *Cyclist[T]) Do(f func(T))

Do calls function f on each element of the cyclist, in forward order.

func (*Cyclist[T]) Len

func (l *Cyclist[T]) Len() int

Len computes the number of elements in cyclist l. It executes in time proportional to the number of elements.

func (*Cyclist[T]) Move

func (l *Cyclist[T]) Move(n int) (res []T)

Move moves n % l.Len() elements backward (n < 0) or forward (n >= 0) in the cyclist and returns that ring element.

func (*Cyclist[T]) Next

func (l *Cyclist[T]) Next(n int) []T

Next returns the next n cyclist element.

func (*Cyclist[T]) Prev

func (l *Cyclist[T]) Prev(n int) []T

Prev returns the previous n prev element.

func (*Cyclist[T]) Put

func (l *Cyclist[T]) Put(s ...T)

Jump to

Keyboard shortcuts

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