v0.1.5 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2018 License: MIT Imports: 1 Imported by: 1



Package stack provides a basic implementation of a stack using a linked list.



This section is empty.


This section is empty.


This section is empty.


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 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) Flush

func (s *Stack) Flush()

Flush flushes the content of the stack.

func (*Stack) Peek

func (s *Stack) Peek() interface{}

Peek returns the element on top of the stack.

func (*Stack) Pop

func (s *Stack) Pop() (interface{}, bool)

Pop removes and returns the element on top of the stack, updating its head to the next Frame. 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 to the previous stack's head.

func (*Stack) Size

func (s *Stack) Size() int

Size returns the number of elements that a stack contains.

type Stacker

type Stacker interface {
	// Push an element into a Stack
	Push(element interface{})
	// Pop the topmost element of a stack
	Pop() (interface{}, bool)
	// Size returns the size of the Stack
	Size() int
	// Peek returns the topmost element of the Stack
	Peek() interface{}
	// Flush flushes a Stack

Stacker represents an interface that contains all the required methods to implement a Stack that can be used in piladb.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL