deque

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2023 License: MIT Imports: 3 Imported by: 1

Documentation

Index

Constants

View Source
const (
	SegmentCapacity = 128
)

Constants definition

Variables

View Source
var (
	ErrOutOfRange = errors.New("out off range")
)

Define internal errors

Functions

This section is empty.

Types

type Deque

type Deque[T any] struct {
	// contains filtered or unexported fields
}

Deque is double-ended queue supports efficient data insertion from the head and tail, random access and iterator access.

func New

func New[T any]() *Deque[T]

New creates a new deque

func (*Deque[T]) At

func (d *Deque[T]) At(pos int) T

At returns the value at position pos of the deque

func (*Deque[T]) Back

func (d *Deque[T]) Back() T

Back returns the value at the last position of the deque

func (*Deque[T]) Begin

func (d *Deque[T]) Begin() *DequeIterator[T]

Begin returns an iterator of the deque with the first position

func (*Deque[T]) Clear

func (d *Deque[T]) Clear()

Clear erases all elements in the deque

func (*Deque[T]) Empty

func (d *Deque[T]) Empty() bool

Empty returns true if the deque is empty,otherwise returns false.

func (*Deque[T]) End

func (d *Deque[T]) End() *DequeIterator[T]

End returns an iterator of the deque with the position d.Size()

func (*Deque[T]) EraseAt

func (d *Deque[T]) EraseAt(pos int)

EraseAt erases the element at the position pos

func (*Deque[T]) EraseRange

func (d *Deque[T]) EraseRange(firstPos, lastPos int)

EraseRange erases elements in range [firstPos, lastPos)

func (*Deque[T]) First

func (d *Deque[T]) First() *DequeIterator[T]

First returns an iterator of the deque with the first position

func (*Deque[T]) Front

func (d *Deque[T]) Front() T

Front returns the value at the first position of the deque

func (*Deque[T]) Insert

func (d *Deque[T]) Insert(pos int, value T)

Insert inserts a value to the position pos of the deque

func (*Deque[T]) IterAt

func (d *Deque[T]) IterAt(pos int) *DequeIterator[T]

IterAt returns an iterator of the deque with the position pos

func (*Deque[T]) Last

func (d *Deque[T]) Last() *DequeIterator[T]

Last returns an iterator of the deque with the last position

func (*Deque[T]) PopBack

func (d *Deque[T]) PopBack() T

PopBack returns the value at the lase position of the deque and removes it

func (*Deque[T]) PopFront

func (d *Deque[T]) PopFront() T

PopFront returns the value at the first position of the deque and removes it

func (*Deque[T]) PushBack

func (d *Deque[T]) PushBack(value T)

PushBack pushed a value to the back of deque

func (*Deque[T]) PushFront

func (d *Deque[T]) PushFront(value T)

PushFront pushed a value to the front of the deque

func (*Deque[T]) Set

func (d *Deque[T]) Set(pos int, val T) error

Set sets the value of the deque's position pos with value val

func (*Deque[T]) Size

func (d *Deque[T]) Size() int

Size returns the amount of values in the deque

func (*Deque[T]) String

func (d *Deque[T]) String() string

String returns a string representation of the deque

type DequeIterator

type DequeIterator[T any] struct {
	// contains filtered or unexported fields
}

DequeIterator is an implementation of Deque iterator

func (*DequeIterator[T]) Clone

func (iter *DequeIterator[T]) Clone() iterator.ConstIterator[T]

Clone clones the iterator to a new iterator

func (*DequeIterator[T]) Equal

func (iter *DequeIterator[T]) Equal(other iterator.ConstIterator[T]) bool

Equal returns true if the iterator is equal to the passed iterator, otherwise returns false

func (*DequeIterator[T]) IsValid

func (iter *DequeIterator[T]) IsValid() bool

IsValid returns true if the iterator is valid, otherwise returns false

func (*DequeIterator[T]) IteratorAt

func (iter *DequeIterator[T]) IteratorAt(position int) iterator.RandomAccessIterator[T]

IteratorAt creates a new iterator with the passed position

func (*DequeIterator[T]) Next

func (iter *DequeIterator[T]) Next() iterator.ConstIterator[T]

Next moves the position of the iterator to the next position and returns itself

func (*DequeIterator[T]) Position

func (iter *DequeIterator[T]) Position() int

Position returns the position of iterator

func (*DequeIterator[T]) Prev

func (iter *DequeIterator[T]) Prev() iterator.ConstBidIterator[T]

Prev moves the position of the iterator to the previous position and returns itself

func (*DequeIterator[T]) SetValue

func (iter *DequeIterator[T]) SetValue(val T)

SetValue sets the value of the deque at the position of the iterator point to

func (*DequeIterator[T]) Value

func (iter *DequeIterator[T]) Value() T

Value returns the value of the deque at the position of the iterator point to

type Pool

type Pool[T any] struct {
	// contains filtered or unexported fields
}

Pool is a memory pool for holding Segments

type Segment

type Segment[T any] struct {
	// contains filtered or unexported fields
}

Segment is a fixed capacity ring

type T added in v1.1.0

type T any

DequeIterator is an implementation of RandomAccessIterator

Jump to

Keyboard shortcuts

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