Documentation ¶
Overview ¶
Package stack provides a basic implementation of a stack using a linked list.
Index ¶
- type Stack
- func (s *Stack) Base(element interface{})
- func (s *Stack) Flush()
- func (s *Stack) Peek() interface{}
- func (s *Stack) Pop() (interface{}, bool)
- func (s *Stack) Push(element interface{})
- func (s *Stack) Rotate() bool
- func (s *Stack) Size() int
- func (s *Stack) Sweep() (interface{}, bool)
- func (s *Stack) SweepPush(element interface{}) (interface{}, bool)
- type Stacker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
Stack implements the Stacker interface, and represents the stack data structure as a linked list, containing a pointer to the first Frame as a head, the last one as a base, and the size of the stack. It also contain a mutex to lock and unlock the access to the stack at I/O operations.
func NewStack ¶
func NewStack() *Stack
NewStack returns a blank stack, where head is nil and size is 0.
func (*Stack) Base ¶
func (s *Stack) Base(element interface{})
Base bases the stack on top of a new element, so this element becomes the bottommost element of the stack.
func (*Stack) Peek ¶
func (s *Stack) Peek() interface{}
Peek returns the element on top of the stack.
func (*Stack) Pop ¶
Pop removes and returns the element on top of the stack, updating its head to the Frame underneath. If the stack was empty, it returns false.
func (*Stack) Push ¶
func (s *Stack) Push(element interface{})
Push adds a new element on top of the stack, creating a new head holding this data and updating its head on top of the stack's head. It will update the tail only if the stack was empty.
func (*Stack) Rotate ¶
Rotate puts the bottommost element of the Stack into the top, as an action of rotating the contents. Return false if the Stack is empty.
type Stacker ¶
type Stacker interface { // Push an element into a Stack Push(element interface{}) // Pop the topmost element of a Stack Pop() (interface{}, bool) // Base bases a new element at the bottom of the Stack Base(element interface{}) // Sweep the bottommost element of a Stack Sweep() (interface{}, bool) // SweepPush sweeps the bottommost element of a Stack // and pushes another on top SweepPush(element interface{}) (interface{}, bool) // Rotate the bottommost element of a Stack to the top Rotate() bool // Size returns the size of the Stack Size() int // Peek returns the topmost element of the Stack Peek() interface{} // Flush flushes a Stack Flush() }
Stacker represents an interface that contains all the required methods to implement a Stack that can be used in piladb.