slices

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2024 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 ConcurrentSlice

type ConcurrentSlice[T any] struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

ConcurrentSlice type that can be safely shared between goroutines.

func NewConcurrentSlice

func NewConcurrentSlice[T any]() *ConcurrentSlice[T]

NewConcurrentSlice creates a new synchronized slice.

func (*ConcurrentSlice[T]) Append

func (cs *ConcurrentSlice[T]) Append(item T)

Append adds an item to the concurrent slice.

func (*ConcurrentSlice[T]) Delete

func (cs *ConcurrentSlice[T]) Delete(index int)

Delete an item from the slice

func (*ConcurrentSlice[T]) Get

func (cs *ConcurrentSlice[T]) Get(index int) (item any)

Get returns the slice item at the given index

func (*ConcurrentSlice[T]) Iter

func (cs *ConcurrentSlice[T]) Iter() <-chan Item[T]

Iter iterates the items in the concurrent slice. Each item is sent over a channel, so that we can iterate over the slice using the builtin range keyword.

func (*ConcurrentSlice[T]) Len

func (cs *ConcurrentSlice[T]) Len() int

Len returns the number of items

type Item

type Item[T any] struct {
	Index int
	Value T
}

Item represents the slice item

Jump to

Keyboard shortcuts

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