deque

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2025 License: MIT Imports: 1 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[T any] interface {
	// PushBack inserts v at the end.
	PushBack(v T)
	// PushFront inserts v at the front.
	PushFront(v T)
	// PopBack removes and returns the last element, or false if empty.
	PopBack() (T, bool)
	// PopFront removes and returns the first element, or false if empty.
	PopFront() (T, bool)
	// Begin returns a sequence of elements from the beginning to the end.
	Begin() iter.Seq[T]
	// End returns a sequence of elements from the end to the beginning.
	End() iter.Seq[T]
}

A Deque is a double-ended queue interface. It allows for efficient insertion and removal of elements from both ends.

type SegmentedSlice

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

A SegmentedSlice (double-ended queue) implemented as a segmented slice (map-of-blocks), inspired by the SGI C++ STL deque design. This gives O(1) push/pop at both ends, true O(1) random access, and good cache locality.

func NewSegmentedSlice

func NewSegmentedSlice[T any]() *SegmentedSlice[T]

NewSegmentedSlice creates an empty SegmentedSlice.

func (*SegmentedSlice[T]) At

func (d *SegmentedSlice[T]) At(i int) (T, bool)

At returns element at index i (0 <= i < Len()), or false if out of range.

func (*SegmentedSlice[T]) Begin

func (d *SegmentedSlice[T]) Begin() iter.Seq[T]

Begin returns a sequence of elements from the beginning to the end.

func (*SegmentedSlice[T]) End

func (d *SegmentedSlice[T]) End() iter.Seq[T]

End returns a sequence of elements from the end to the beginning.

func (*SegmentedSlice[T]) Len

func (d *SegmentedSlice[T]) Len() int

Len returns the number of elements.

func (*SegmentedSlice[T]) PopBack

func (d *SegmentedSlice[T]) PopBack() (T, bool)

PopBack removes and returns the last element, or false if empty.

func (*SegmentedSlice[T]) PopFront

func (d *SegmentedSlice[T]) PopFront() (T, bool)

PopFront removes and returns the first element, or false if empty.

func (*SegmentedSlice[T]) PushBack

func (d *SegmentedSlice[T]) PushBack(v T)

PushBack inserts v at the end.

func (*SegmentedSlice[T]) PushFront

func (d *SegmentedSlice[T]) PushFront(v T)

PushFront inserts v at the front.

Jump to

Keyboard shortcuts

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