Documentation
¶
Index ¶
- type ReturnableStack
- type SaveStack
- func (s *SaveStack[T]) ElemStringSep(encloseL, encloseR, frameSep, sep string) string
- func (stack *SaveStack[T]) Empty() bool
- func (stack *SaveStack[T]) FullEmpty() bool
- func (stack *SaveStack[T]) GetCount() uint
- func (stack *SaveStack[T]) GetFrames() uint
- func (stack *SaveStack[T]) GetFullCount() uint
- func (stack *SaveStack[T]) Peek() (elem T, stat StackStatus)
- func (stack *SaveStack[T]) Pop() (elem T, stat StackStatus)
- func (stack *SaveStack[T]) Push(elem T)
- func (stack *SaveStack[T]) Rebase() (stat StackStatus)
- func (stack *SaveStack[T]) Return() (stat StackStatus)
- func (stack *SaveStack[T]) Save()
- func (s *SaveStack[T]) Search(predicate func(T) bool) (found bool, elem T)
- func (stack *SaveStack[T]) Status() StackStatus
- type Stack
- func (s *Stack[T]) Clear(n uint)
- func (s *Stack[T]) ElemString() string
- func (s *Stack[T]) ElemStringSep(encloseL, encloseR string, sep string) string
- func (s *Stack[T]) Empty() bool
- func (s *Stack[T]) GetCapacity() uint
- func (s *Stack[T]) GetCount() uint
- func (s *Stack[T]) MultiCheck(n int) (elems []T, stat StackStatus)
- func (s *Stack[T]) MultiPop(n uint) (elems []T, stat StackStatus)
- func (s *Stack[T]) MultiPush(elems ...T)
- func (s *Stack[T]) Peek() (elem T, stat StackStatus)
- func (s *Stack[T]) Pop() (T, StackStatus)
- func (s *Stack[T]) Push(elem T)
- func (s *Stack[T]) Search(predicate func(T) bool) (found bool, elem T)
- func (s *Stack[T]) Status() StackStatus
- type StackPlus
- type StackStatus
- type StackType
- type StaticStack
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ReturnableStack ¶
type ReturnableStack[T any] interface { StackType[T] GetFullCount() uint Save() Return() StackStatus }
stacks that can create stack frames
type SaveStack ¶
func NewSaveStack ¶
only up to 2 arguments are used, one argument required; cap is the starting capacity for the stack. returnCap[0] is the starting capacity for the number of returns that can be saved. returnCap has a default value of 8
func (*SaveStack[T]) ElemStringSep ¶
func (*SaveStack[T]) GetFullCount ¶
number of elems in all frames
func (*SaveStack[T]) Peek ¶
func (stack *SaveStack[T]) Peek() (elem T, stat StackStatus)
func (*SaveStack[T]) Pop ¶
func (stack *SaveStack[T]) Pop() (elem T, stat StackStatus)
func (*SaveStack[T]) Rebase ¶
func (stack *SaveStack[T]) Rebase() (stat StackStatus)
Returns base counter to saved base counter but does NOT change the stack counter. This function effectively "merges" the top two stack frames into a single frame
func (*SaveStack[T]) Return ¶
func (stack *SaveStack[T]) Return() (stat StackStatus)
Return base counter to saved base counter and return stack counter to previous stack counter. Return fails when nothing is saved.
func (*SaveStack[T]) Save ¶
func (stack *SaveStack[T]) Save()
create return point point to return to later
func (*SaveStack[T]) Search ¶
search from top to bottom for first occurrence of element that predicate occurs for
func (*SaveStack[T]) Status ¶
func (stack *SaveStack[T]) Status() StackStatus
type Stack ¶
type Stack[T any] struct { // contains filtered or unexported fields }
func (*Stack[T]) ElemStringSep ¶
func (*Stack[T]) MultiCheck ¶
func (s *Stack[T]) MultiCheck(n int) (elems []T, stat StackStatus)
MultiCheck returns the top `n` elements of the stack (or an IllegalOperation if there are fewer than `n` elements). Elements are returned in reverse-popped order (see "IMPORTANT" below), e.g.,
[w, x, y, z].MultiCheck(3) == [x, y, z]
IMPORTANT: note that MultiCheck does NOT return a slice in the order (left-to-right) that elemnts would be popped! In fact, it does the opposite.
NOTE: elements are not removed from the stack
func (*Stack[T]) MultiPop ¶
func (s *Stack[T]) MultiPop(n uint) (elems []T, stat StackStatus)
MultiPop pops and returns the top `n` elements of the stack (or an IllegalOperation if there are fewer than `n` elements). Elements are returned in they order (left-to-right in return value) that they are popped, e.g.,
[w, x, y, z].MultiPop(3) == [z, y, x]
To return the elements in the order they appear on the stack, use
(*Stack[T]) MultiCheck(int)
func (*Stack[T]) Peek ¶
func (s *Stack[T]) Peek() (elem T, stat StackStatus)
returns the top element of the stack if it exists, else the Empty status
func (*Stack[T]) Pop ¶
func (s *Stack[T]) Pop() (T, StackStatus)
removes the top element of the stack and returns it if stack is not empty, else Empty status is returned
func (*Stack[T]) Status ¶
func (s *Stack[T]) Status() StackStatus
returns condition of stack (Ok or Empty)
type StackPlus ¶
type StackPlus[T any] interface { StackType[T] Clear(uint) MultiPush(...T) MultiPop(uint) ([]T, StackStatus) }
stacks with the ability to pop and push multiple elements
type StackStatus ¶
type StackStatus uint
const ( Ok StackStatus = iota Empty Overflow IllegalOperation IllegalReturn )
func (StackStatus) Is ¶
func (stat StackStatus) Is(stat2 StackStatus) bool
func (StackStatus) IsEmpty ¶
func (stat StackStatus) IsEmpty() bool
func (StackStatus) IsIllegalOperation ¶
func (stat StackStatus) IsIllegalOperation() bool
func (StackStatus) IsOk ¶
func (stat StackStatus) IsOk() bool
func (StackStatus) IsOverflow ¶
func (stat StackStatus) IsOverflow() bool
func (StackStatus) NotOk ¶
func (stat StackStatus) NotOk() bool
func (StackStatus) String ¶
func (stat StackStatus) String() string
type StackType ¶
type StackType[T any] interface { Push(T) Pop() (T, StackStatus) Peek() (T, StackStatus) GetCount() uint Status() StackStatus }
interface for usual stack operations (i.e., push, pop, peek, and number of elements) and an additional operation to query various states
type StaticStack ¶
stack with fixed size (i.e., stack cannot request more capacity)