containers

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SafeMap

type SafeMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

SafeMap is a thread-safe map.

func NewSafeMap

func NewSafeMap[K comparable, V any](items ...Tuple[K, V]) *SafeMap[K, V]

NewSafeMap creates a new SafeMap.

func (*SafeMap[K, V]) AppendElem

func (m *SafeMap[K, V]) AppendElem(elem Tuple[K, V])

AppendElem appends an element to the map.

func (*SafeMap[K, V]) AsCollection

func (m *SafeMap[K, V]) AsCollection() generics.Collection[K, V, Tuple[K, V]]

func (*SafeMap[K, V]) AsIterable

func (m *SafeMap[K, V]) AsIterable() generics.Iterable[Tuple[K, V]]

func (*SafeMap[K, V]) Cap

func (m *SafeMap[K, V]) Cap() int

Cap returns the capacity of the map, which is equal to the length.

func (*SafeMap[K, V]) Clear

func (m *SafeMap[K, V]) Clear()

Clear clears the map.

func (*SafeMap[K, V]) Clone

func (m *SafeMap[K, V]) Clone() generics.Collection[K, V, Tuple[K, V]]

Clone returns a copy of the map.

func (*SafeMap[K, V]) Delete

func (m *SafeMap[K, V]) Delete(key K)

Delete deletes a value from the map.

func (*SafeMap[K, V]) Factory

func (m *SafeMap[K, V]) Factory() generics.Collection[K, V, Tuple[K, V]]

Factory returns a new instance of the map.

func (*SafeMap[K, V]) Get

func (m *SafeMap[K, V]) Get(key K) V

Get gets a value from the map. Panics if the key does not exist.

func (*SafeMap[K, V]) GetE

func (m *SafeMap[K, V]) GetE(key K) (V, bool)

GetE gets a value from the map.

func (*SafeMap[K, V]) HasKey

func (m *SafeMap[K, V]) HasKey(key K) bool

HasKey checks if the map has the key.

func (*SafeMap[K, V]) IsEmpty

func (m *SafeMap[K, V]) IsEmpty() bool

IsEmpty checks if the map is empty.

func (*SafeMap[K, V]) Iter

func (m *SafeMap[K, V]) Iter() *generics.Iterator[Tuple[K, V]]

func (*SafeMap[K, V]) IterHandler

func (m *SafeMap[K, V]) IterHandler(iter *generics.Iterator[Tuple[K, V]])

func (*SafeMap[K, V]) Keys

func (m *SafeMap[K, V]) Keys() []K

Keys returns all keys in the map.

func (*SafeMap[K, V]) Len

func (m *SafeMap[K, V]) Len() int

Len returns the length of the map.

func (*SafeMap[K, V]) Set

func (m *SafeMap[K, V]) Set(key K, val V)

Set sets a value in the map.

func (*SafeMap[K, V]) SetElem

func (m *SafeMap[K, V]) SetElem(elem Tuple[K, V])

SetElem sets a value in the map.

func (*SafeMap[K, V]) Values

func (m *SafeMap[K, V]) Values() []V

Values returns all values in the map.

type SafeSlice

type SafeSlice[V any] struct {
	// contains filtered or unexported fields
}

SafeSlice is a thread-safe slice.

It doesn't check out of bounds access.

func NewSafeSlice

func NewSafeSlice[V any](items ...V) *SafeSlice[V]

NewSafeSlice creates a new SafeSlice.

func NewSafeSliceN

func NewSafeSliceN[V any](s, n int) *SafeSlice[V]

NewSafeSliceN creates a new SafeSlice with size and capacity of n.

func (*SafeSlice[V]) Append

func (s *SafeSlice[V]) Append(item V)

Append appends a value to the slice.

func (*SafeSlice[V]) AppendElem

func (s *SafeSlice[V]) AppendElem(elem Tuple[int, V])

AppendElem appends a value to the slice.

func (*SafeSlice[V]) AppendSafeSlice

func (s *SafeSlice[V]) AppendSafeSlice(other *SafeSlice[V])

AppendSafeSlice appends a SafeSlice to the slice.

func (*SafeSlice[V]) AppendSlice

func (s *SafeSlice[V]) AppendSlice(slice []V)

AppendSlice appends a slice to the slice.

func (*SafeSlice[V]) AsCollection

func (s *SafeSlice[V]) AsCollection() generics.Collection[int, V, Tuple[int, V]]

func (*SafeSlice[V]) AsIterable

func (s *SafeSlice[V]) AsIterable() generics.Iterable[Tuple[int, V]]

func (*SafeSlice[V]) Cap

func (s *SafeSlice[V]) Cap() int

Cap returns the capacity of the slice.

func (*SafeSlice[V]) Clear

func (s *SafeSlice[V]) Clear()

Clear clears the slice.

func (*SafeSlice[V]) Clone

func (s *SafeSlice[V]) Clone() generics.Collection[int, V, Tuple[int, V]]

Clone returns a clone of the slice. Same as Values.

func (*SafeSlice[V]) Compare

func (s *SafeSlice[V]) Compare(i, j Tuple[int, V], comp func(V, V) generics.CompareResult) generics.CompareResult

Compare compares two slice items.

func (*SafeSlice[V]) Delete

func (s *SafeSlice[V]) Delete(i int)

Delete deletes a value at given index from the slice.

func (*SafeSlice[V]) Factory

func (s *SafeSlice[V]) Factory() generics.Collection[int, V, Tuple[int, V]]

Factory returns a new SafeSlice.

func (*SafeSlice[V]) Get

func (s *SafeSlice[V]) Get(i int) V

Get gets a value from the slice.

func (*SafeSlice[V]) IsEmpty

func (s *SafeSlice[V]) IsEmpty() bool

IsEmpty returns true if the slice is empty.

func (*SafeSlice[V]) Iter

func (s *SafeSlice[V]) Iter() *generics.Iterator[Tuple[int, V]]

func (*SafeSlice[V]) IterHandler

func (s *SafeSlice[V]) IterHandler(iter *generics.Iterator[Tuple[int, V]])

func (*SafeSlice[V]) Len

func (s *SafeSlice[V]) Len() int

Len returns the length of the slice.

func (*SafeSlice[V]) Set

func (s *SafeSlice[V]) Set(i int, item V)

Set sets a value in the slice.

func (*SafeSlice[V]) SetElem

func (s *SafeSlice[V]) SetElem(item Tuple[int, V])

SetElem sets a value in the slice.

func (*SafeSlice[V]) Slice

func (s *SafeSlice[V]) Slice(start, end int) *SafeSlice[V]

Slice returns a new SafeSlice with the elements from start to end-1.

func (*SafeSlice[V]) Values

func (s *SafeSlice[V]) Values() []V

Values returns all values in the slice. This function is not thread-safe, use with caution.

type Tuple

type Tuple[T any, U any] struct {
	First  T
	Second U
}

func NewTuple

func NewTuple[T any, U any](first T, second U) Tuple[T, U]

NewTuple creates a new Tuple.

func (Tuple[T, U]) Index

func (t Tuple[T, U]) Index() T

Index is same as Key().

func (Tuple[T, U]) Key

func (t Tuple[T, U]) Key() T

Key returns the first value of the tuple.

func (Tuple[T, U]) Value

func (t Tuple[T, U]) Value() U

Value returns the second value of the tuple.

Jump to

Keyboard shortcuts

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