Documentation
¶
Index ¶
- type Option
- type Stack
- func New[E any](ops ...Option[E]) (s *Stack[E], err error)
- func NewFromMapKeys[K comparable, V any](m map[K]V, ops ...Option[K]) (*Stack[K], error)
- func NewFromMapValues[K comparable, V any](cmp func(V, V) int, m map[K]V, ops ...Option[V]) (*Stack[V], error)
- func NewFromSlice[E any](slice []E, ops ...Option[E]) (*Stack[E], error)
- func (s *Stack[E]) Clear()
- func (s *Stack[E]) Clone() *Stack[E]
- func (s *Stack[E]) IsEmpty() bool
- func (s *Stack[E]) Len() int
- func (s *Stack[E]) MarshalJSON() ([]byte, error)
- func (s *Stack[E]) Peek() (E, bool)
- func (s *Stack[E]) Pop() (E, bool)
- func (s *Stack[E]) Push(e E)
- func (s *Stack[E]) String() string
- func (s *Stack[E]) UnmarshalJSON(data []byte) (err error)
- func (s *Stack[E]) Values() []E
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Stack ¶
type Stack[E any] struct { // contains filtered or unexported fields }
Stack represents a stack based on linkedlist.. The stack provides typical LIFO(last-in, first-out) behavior.
func New ¶
New creates and initializes a empty stack. Options can be provided to customize the stack's properties (e.g., thread safety).
func NewFromMapKeys ¶
func NewFromMapKeys[K comparable, V any](m map[K]V, ops ...Option[K]) (*Stack[K], error)
NewFromMapKeys creates and initializes a stack from the provided map keys. Options can be provided to customize the stack's properties (e.g., thread safety). Returns an empty stack if the provided map is nil or empty.
func NewFromMapValues ¶
func NewFromMapValues[K comparable, V any](cmp func(V, V) int, m map[K]V, ops ...Option[V]) (*Stack[V], error)
NewFromMapValues creates a stack from the provided map values. Options can be provided to customize the stack's properties (e.g., thread safety). Returns an empty stack if the provided map is nil or empty.
func NewFromSlice ¶
NewFromSlice creates and initializes a stack from the provided slice. Options can be provided to customize the stack's properties (e.g., thread safety).
func (*Stack[E]) MarshalJSON ¶
MarshalJSON will marshal the stack into a JSON-based representation.
func (*Stack[E]) Peek ¶
Peek returns the top element of the stack without removing it. Returns the zero value of E and false if the stack is empty.
func (*Stack[E]) Pop ¶
Pop removes and returns the top element of the stack. Returns the zero value of E and false if the stack is empty.
func (*Stack[E]) Push ¶
func (s *Stack[E]) Push(e E)
Push adds an element to the top of the stack. The stack's size increases by one.
func (*Stack[E]) UnmarshalJSON ¶
UnmarshalJSON will unmarshal a JSON-based representation byte slice into the stack.