Documentation
¶
Overview ¶
Package for generic LIFO stack data structure
Index ¶
- Constants
- func DefaultConversion[T any](val *T) string
- type Format
- type Stack
- func (s *Stack[T]) Cap() int
- func (s *Stack[T]) Clear()
- func (s *Stack[T]) ClearWithCap(c int)
- func (s *Stack[T]) Empty() bool
- func (s *Stack[T]) Format(f *Format[T]) string
- func (s *Stack[T]) HasItems() bool
- func (s *Stack[T]) Len() int
- func (s *Stack[T]) Pop()
- func (s *Stack[T]) PopAndReturn() T
- func (s *Stack[T]) Push(item T)
- func (s *Stack[T]) PushItems(items ...T)
- func (s *Stack[T]) PushSlice(items []T)
- func (s Stack[T]) String() string
- func (s *Stack[T]) Top() T
- func (s *Stack[T]) TopPointer() *T
Constants ¶
Variables ¶
This section is empty.
Functions ¶
func DefaultConversion ¶ added in v1.0.4
Default conversion function converts each item to its default Go format
Types ¶
type Format ¶ added in v1.0.4
type Format[T any] struct { // Function that converts each item of the stack to a string Conversion func(*T) string // Symbol to write after the last item End string // Symbol to write between two items Sep string // Symbol to write before the first item Start string // If true, items are written from top to bottom, // if false, the direction is reversed TopFirst bool }
Formatting options for a Stack[T]
type Stack ¶
type Stack[T any] struct { // contains filtered or unexported fields }
Generic LIFO stack, Last In, First Out
func (*Stack[T]) ClearWithCap ¶ added in v1.0.4
Removes all items and sets capacity to c
func (*Stack[T]) HasItems ¶
Returns a flag indicating whether there is at least one item in the stack
func (*Stack[T]) PopAndReturn ¶ added in v1.0.4
func (s *Stack[T]) PopAndReturn() T
Removes the top item and returns a shallow copy of it. Panics if the stack is empty.
func (*Stack[T]) PushItems ¶ added in v1.0.4
func (s *Stack[T]) PushItems(items ...T)
Adds items on the stack in order. Last item becomes the new top.
func (*Stack[T]) PushSlice ¶
func (s *Stack[T]) PushSlice(items []T)
Adds a slice of items on the stack in order. Last item becomes the new top.
func (*Stack[T]) Top ¶
func (s *Stack[T]) Top() T
Returns a shallow copy of the top item without removing it from the stack. Panics if the stack is empty.
func (*Stack[T]) TopPointer ¶ added in v1.0.4
func (s *Stack[T]) TopPointer() *T
Returns a pointer to the top item without removing it from the stack. Panics if the stack is empty.