Documentation ¶
Index ¶
- func CompareQueues(n ...int)
- func Example()
- func LLQTest(m ...int) (int64, uint64)
- func SQTest(m ...int) (int64, uint64)
- type Cached
- type Squeue
- func (sq *Squeue) Each() []interface{}
- func (sq *Squeue) Empty() bool
- func (sq *Squeue) PeekBack() (interface{}, error)
- func (sq *Squeue) PeekFront() (interface{}, error)
- func (sq *Squeue) Pop() (interface{}, error)
- func (sq *Squeue) Push(elem interface{})
- func (sq *Squeue) Shift(elem interface{})
- func (sq *Squeue) Size() int
- func (sq *Squeue) String() string
- func (sq *Squeue) Unshift() (interface{}, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cached ¶
type Cached struct {
// contains filtered or unexported fields
}
Cached: underlying type for Squeue
type Squeue ¶
type Squeue struct {
// contains filtered or unexported fields
}
Squeue: main type - Slice-based, circular queue that uses a cache to cut the time of necessary reallocations
func New ¶
func New(initial ...interface{}) Squeue
New - queue constructor, convinience method Accepts initial values to be enqueued, in the order listed
func (*Squeue) Each ¶
func (sq *Squeue) Each() []interface{}
Each - returns underlying slice for iteration - convinience method Method takes values from memory in O(n) time; iteration is done most performantly using delete operations (Unshift/Pop) until the queue is empty Ex.
for !qq.Empty() { elem := qq.Pop() // do something with elem }
func (*Squeue) PeekBack ¶
PeekBack - retrieve last element from queue without removing it Checks for empty queue, if not returns last elem
func (*Squeue) PeekFront ¶
PeekFront - retrieve first element from queue without removing it Checks for empty queue, if not returns first elem
func (*Squeue) Pop ¶
Pop - remove element from back of queue Retrieves the elem, and if successful deletes its value in the slice Decrements the tail pointer to next elem in queue
func (*Squeue) Push ¶
func (sq *Squeue) Push(elem interface{})
Push - add to back of queue (enqueue) Adds element to tail, increments tail pointer
func (*Squeue) Shift ¶
func (sq *Squeue) Shift(elem interface{})
Shift - add to front of queue Add element to the head, increments head pointer
func (*Squeue) Size ¶
Size - returns number of elements in queue O(1) amortized time complexity Cached slices record their length before caching, so only the size of the head and the tail must be found, which are O(1)