queue

package
v0.0.0-...-a1d7b1b Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2018 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Deque

type Deque struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Deque is a head-tail linked list data structure implementation. It is based on a doubly linked list container, so that every operations time complexity is O(1).

every operations over an instiated Deque are synchronized and safe for concurrent usage.

func NewCappedDeque

func NewCappedDeque(capacity int) *Deque

NewCappedDeque creates a Deque with the specified capacity limit.

func NewDeque

func NewDeque() *Deque

NewDeque creates a Deque.

func (*Deque) Append

func (s *Deque) Append(item interface{}) bool

Append inserts element at the back of the Deque in a O(1) time complexity, returning true if successful or false if the deque is at capacity.

func (*Deque) Capacity

func (s *Deque) Capacity() int

Capacity returns the capacity of the deque, or -1 if unlimited

func (*Deque) Empty

func (s *Deque) Empty() bool

Empty checks if the deque is empty

func (*Deque) First

func (s *Deque) First() interface{}

First returns the first value stored in the deque in a O(1) time complexity

func (*Deque) Full

func (s *Deque) Full() bool

Full checks if the deque is full

func (*Deque) Last

func (s *Deque) Last() interface{}

Last returns the last value stored in the deque in a O(1) time complexity

func (*Deque) Pop

func (s *Deque) Pop() interface{}

Pop removes the last element of the deque in a O(1) time complexity

func (*Deque) Prepend

func (s *Deque) Prepend(item interface{}) bool

Prepend inserts element at the Deques front in a O(1) time complexity, returning true if successful or false if the deque is at capacity.

func (*Deque) Shift

func (s *Deque) Shift() interface{}

Shift removes the first element of the deque in a O(1) time complexity

func (*Deque) Size

func (s *Deque) Size() int

Size returns the actual deque size

type Queue

type Queue struct {
	*Deque
}

Queue is a FIFO (First in first out) data structure implementation. It is based on a deque container and focuses its API on core functionalities: Enqueue, Dequeue, Head, Size, Empty. Every operations time complexity is O(1).

As it is implemented using a Deque container, every operations over an instiated Queue are synchronized and safe for concurrent usage.

func NewCappedQueue

func NewCappedQueue(capacity int) *Queue

func NewQueue

func NewQueue() *Queue

func (*Queue) Dequeue

func (q *Queue) Dequeue() interface{}

Dequeue removes and returns the front queue item

func (*Queue) Enqueue

func (q *Queue) Enqueue(item interface{})

Enqueue adds an item at the back of the queue, but remove the first element when queue is full

func (*Queue) Head

func (q *Queue) Head() interface{}

Head returns the front queue item

Jump to

Keyboard shortcuts

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