Documentation
¶
Overview ¶
Package stackqueuebase implements core functionality fully generic stacks and queues.
Index ¶
- type Base
- func (b *Base[T]) Empty() bool
- func (b *Base[T]) Join(sep string) string
- func (b *Base[T]) Peek() (T, error)
- func (b *Base[T]) PeekN(n int) ([]T, error)
- func (b *Base[T]) Pop() (T, error)
- func (b *Base[T]) PopN(n int) ([]T, error)
- func (b *Base[T]) Push(v T)
- func (b *Base[T]) PushN(v ...T)
- func (b *Base[T]) Size() int
- type Queue
- type SQ
- type Stack
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Base ¶
type Base[T any] struct { // contains filtered or unexported fields }
Base implements stack and queue functionality, given the appropriate |impl| helper.
func NewBaseN ¶
NewBaseN creates a new Base object with |size| elements worth of preallocated memory.
func (*Base[T]) Join ¶
Join creates a string by combining each element from the stack or queue, with |sep| between each pair.
func (*Base[T]) Peek ¶
Pop returns an item from the stack or queue without removing it. If the stack or queue is empty, an error is returned instead.
func (*Base[T]) PeekN ¶
Pop returns N items from the stack or queue without removing them. If the stack or queue has fewer than N elements, an error is returned instead.
func (*Base[T]) Pop ¶
Pop pops an item from the stack or queue. If the stack or queue is empty, an error is returned instead and the stack or queue remains unmodified.
func (*Base[T]) PopN ¶
Pop pops N items from the stack or queue. If the stack or queue has fewer than N elements, an error is returned instead and the stack or queue remains unmodified.
type Queue ¶
type Queue[T any] struct{}
Queue implements SQ for a queue.
type SQ ¶
type SQ[T any] interface { // NameLower returns the name of this object ("stack" or "queue"). NameLower() string // Nth returns the Nth item from the slice. Nth([]T, int) T // Rest returns all but the first item from the slice. Rest([]T) []T }
SQ is an interface for the helper object that implements either stack-specific or queue-specific functionality.