slice

package
v0.0.0-...-32842ed Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2023 License: Apache-2.0 Imports: 1 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clone

func Clone[T any](sl []T) []T

func Eq

func Eq[T comparable](left, right []T) bool

func Find

func Find[T any](sl []T, predicate func(v T) bool) (v T, found bool)

func FindLast

func FindLast[T any](sl []T, predicate func(v T) bool) (v T, found bool)

func Get

func Get[T any](sl []T, index uint) (v T, ok bool)

func Has

func Has[T comparable](sl []T, target T) bool

func Insert

func Insert[T any](sl []T, index uint, ele T) []T

func Position

func Position[T any](sl []T, predicate func(v T) bool) int

func PositionLast

func PositionLast[T any](sl []T, predicate func(v T) bool) int

func Prepend

func Prepend[T any](sl []T, elements ...T) []T

func Remove

func Remove[T any](sl []T, i uint) []T

func RemoveUnordered

func RemoveUnordered[T any](sl []T, index uint) []T

Types

type Deque

type Deque[T any] []T

Doubly ended queue. This is intentionally a simple slice wrapper, so that it can be converted into a slice with no cost.

The complexity of pushing front is typically O(N) where N is length of slice. If this cost needs to be avoided, use deque implementations backed by list or ring buffer. (for example, github.com/gammazero/deque.)

func (*Deque[T]) Append

func (d *Deque[T]) Append(elements ...T)

func (*Deque[T]) Clone

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

Clone copies inner slice.

func (*Deque[T]) Get

func (d *Deque[T]) Get(index uint) (v T, ok bool)

func (*Deque[T]) Insert

func (d *Deque[T]) Insert(index uint, ele T)

func (*Deque[T]) Len

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

Len returns length of underlying slice.

func (*Deque[T]) Pop

func (d *Deque[T]) Pop() (v T, popped bool)

Pop is an alias for PopBack.

func (*Deque[T]) PopBack

func (d *Deque[T]) PopBack() (v T, popped bool)

PopBack removes an element from tail of underlying slice, and then returns removed value. If slice is empty, returns zero of T and false.

func (*Deque[T]) PopFront

func (d *Deque[T]) PopFront() (v T, popped bool)

PopFront removes an element from head of underlying slice, and then returns removed value. If slice is empty, returns zero of T and false.

func (*Deque[T]) Prepend

func (d *Deque[T]) Prepend(elements ...T)

func (*Deque[T]) Push

func (d *Deque[T]) Push(v T)

Push is an alias for PushBack.

func (*Deque[T]) PushBack

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

PushBack adds an element to tail of underlying slice.

func (*Deque[T]) PushFront

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

PushFront adds an element to head of underlying slice.

func (*Deque[T]) Remove

func (d *Deque[T]) Remove(index uint) T

type Queue

type Queue[T any] []T

FIFO queue.

func (*Queue[T]) Clone

func (q *Queue[T]) Clone() Queue[T]

Clone copies inner slice.

func (*Queue[T]) Len

func (q *Queue[T]) Len() int

Len returns length of underlying slice.

func (*Queue[T]) Pop

func (q *Queue[T]) Pop() (v T, popped bool)

Pop removes an element from head of underlying slice, and then returns removed value. If slice is empty, returns zero of T and false.

func (*Queue[T]) Prepend

func (q *Queue[T]) Prepend(elements ...T)

func (*Queue[T]) Push

func (q *Queue[T]) Push(v T)

Push adds an element to tail of underlying slice.

type Stack

type Stack[T any] []T

LIFO stack

func (*Stack[T]) Append

func (s *Stack[T]) Append(elements ...T)

func (*Stack[T]) Clone

func (s *Stack[T]) Clone() Stack[T]

func (*Stack[T]) Len

func (s *Stack[T]) Len() int

func (*Stack[T]) Pop

func (s *Stack[T]) Pop() (v T, popped bool)

Pop removes an element from tail of underlying slice, and then returns removed value. If slice is empty, returns zero of T and false.

func (*Stack[T]) Push

func (s *Stack[T]) Push(v T)

Push adds an element to tail of underlying slice.

Jump to

Keyboard shortcuts

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