stack

package
v0.2.0-alpha.20180328 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2018 License: MIT Imports: 1 Imported by: 1

Documentation

Overview

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

Index

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

func (s *Stack) Rotate() bool

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.

func (*Stack) Size

func (s *Stack) Size() int

Size returns the number of elements that a stack contains.

func (*Stack) Sweep

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

Sweep removes and returns the element at the bottom of the stack, turning the Frame above into the new tail. If the stack was empty, it returns false.

func (*Stack) SweepPush

func (s *Stack) SweepPush(element interface{}) (interface{}, bool)

SweepPush makes a Sweep and Push operations as an atomic one, returning the swept element and the validity of the operation. If Stack was empty, it will return false.

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.

Jump to

Keyboard shortcuts

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