lockable

package
v4.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type List

type List[T any] struct {
	Locker[[]T]
}

A lockable list that provides some list-like methods for convienence

func NewList

func NewList[T any](length int, capacity ...int) *List[T]

func (*List[T]) Append

func (l *List[T]) Append(items ...T)

Append adds the given items to the back of the list

func (*List[T]) At

func (l *List[T]) At(index int) T

At returns the item at the given index

func (*List[T]) Cap

func (l *List[T]) Cap() int

func (*List[T]) Delete

func (l *List[T]) Delete(index int)

Delete removes the given index from the list

func (*List[T]) Find

func (l *List[T]) Find(f func(index int, val T) bool) int

Find returns the first index where the given function returns true. Will return length of the list if item was not found

func (*List[T]) FindAndDelete

func (l *List[T]) FindAndDelete(f func(i int, v T) bool) (deleted bool)

FindAndDelete deletes the first item where the given function returns true.

func (*List[T]) Foreach

func (l *List[T]) Foreach(f func(index int, val T) (shouldBreak bool))

Foreach runs the given function for every item in the list

func (*List[T]) Get

func (l *List[T]) Get() []T

Get returns a copy of the internal list

func (*List[T]) Len

func (l *List[T]) Len() int

func (*List[T]) Make

func (l *List[T]) Make(length int, capacity ...int)

func (*List[T]) MarshalJSON

func (l *List[T]) MarshalJSON() ([]byte, error)

func (*List[T]) Nil

func (l *List[T]) Nil() bool

func (*List[T]) Prepend

func (l *List[T]) Prepend(items ...T)

Prepend add the given items to the front of the list

func (*List[T]) Read

func (l *List[T]) Read(f func())

func (*List[T]) Set

func (l *List[T]) Set(items []T)

Set replaces the internal list with the given list

func (*List[T]) Slice

func (l *List[T]) Slice(start, end int) []T

Slice returns a copy of the list sliced between start and end

func (*List[T]) SliceInPlace

func (l *List[T]) SliceInPlace(start, end int)

func (*List[T]) Sort

func (l *List[T]) Sort(less func(i, j T) int)

Sort sorts the list in place

func (*List[T]) UnmarshalJSON

func (l *List[T]) UnmarshalJSON(b []byte) error

func (*List[T]) UnsafeAppend

func (l *List[T]) UnsafeAppend(items ...T)

func (*List[T]) UnsafeAt

func (l *List[T]) UnsafeAt(index int) T

func (*List[T]) UnsafeCap

func (l *List[T]) UnsafeCap() int

func (*List[T]) UnsafeDelete

func (l *List[T]) UnsafeDelete(index int)

func (*List[T]) UnsafeFind

func (l *List[T]) UnsafeFind(f func(index int, val T) bool) int

func (*List[T]) UnsafeFindAndDelete

func (l *List[T]) UnsafeFindAndDelete(f func(i int, v T) bool) (deleted bool)

func (*List[T]) UnsafeForeach

func (l *List[T]) UnsafeForeach(f func(index int, val T) (shouldBreak bool))

func (*List[T]) UnsafeGet

func (l *List[T]) UnsafeGet() []T

func (*List[T]) UnsafeLen

func (l *List[T]) UnsafeLen() int

func (*List[T]) UnsafeMake

func (l *List[T]) UnsafeMake(length int, capacity ...int)

func (*List[T]) UnsafeMarshalJSON

func (l *List[T]) UnsafeMarshalJSON() ([]byte, error)

func (*List[T]) UnsafeNil

func (l *List[T]) UnsafeNil() bool

func (*List[T]) UnsafePrepend

func (l *List[T]) UnsafePrepend(items ...T)

func (*List[T]) UnsafeSet

func (l *List[T]) UnsafeSet(items []T)

func (*List[T]) UnsafeSlice

func (l *List[T]) UnsafeSlice(start, end int) []T

func (*List[T]) UnsafeSliceInPlace

func (l *List[T]) UnsafeSliceInPlace(start, end int)

func (*List[T]) UnsafeSort

func (l *List[T]) UnsafeSort(less func(i, j T) int)

func (*List[T]) UnsafeUnmarshalJSON

func (l *List[T]) UnsafeUnmarshalJSON(b []byte) error

func (*List[T]) Write

func (l *List[T]) Write(f func())

type Locker

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

func New

func New[T any](i T) *Locker[T]

func (*Locker[T]) Get

func (l *Locker[T]) Get() T

func (*Locker[T]) Safe

func (l *Locker[T]) Safe(write bool, f func())

Safe allows you to call multiple unsafe methods with only a single lock write is true if you want to obtain a write lock

func (*Locker[T]) Set

func (l *Locker[T]) Set(item T)

type Map

type Map[K comparable, V any] struct {
	Locker[map[K]V]
}

func NewMap

func NewMap[K comparable, V any]() *Map[K, V]

func (*Map[K, V]) Clear

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

func (*Map[K, V]) Clone

func (m *Map[K, V]) Clone() *Map[K, V]

func (*Map[K, V]) Copy

func (m *Map[K, V]) Copy(dst *Map[K, V])

func (*Map[K, V]) Delete

func (m *Map[K, V]) Delete(k K) (v V, has bool)

func (*Map[K, V]) DeleteFunc

func (m *Map[K, V]) DeleteFunc(del func(K, V) bool)

func (*Map[K, V]) EqualFunc

func (m *Map[K, V]) EqualFunc(m2 *Map[K, V], eq func(V, V) bool) bool

func (*Map[K, V]) Foreach

func (m *Map[K, V]) Foreach(f func(k K, v V))

func (*Map[K, V]) Get

func (m *Map[K, V]) Get(k K) (v V, has bool)

func (*Map[K, V]) Has

func (m *Map[K, V]) Has(k K) bool

func (*Map[K, V]) Keys

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

func (*Map[K, V]) Len

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

func (*Map[K, V]) Make

func (m *Map[K, V]) Make()

func (*Map[K, V]) MarshalJSON

func (m *Map[K, V]) MarshalJSON() ([]byte, error)

func (*Map[K, V]) Nil

func (m *Map[K, V]) Nil() bool

func (*Map[K, V]) Set

func (m *Map[K, V]) Set(k K, v V)

func (*Map[K, V]) UnmarshalJSON

func (m *Map[K, V]) UnmarshalJSON(b []byte) error

func (*Map[K, V]) UnsafeClear

func (m *Map[K, V]) UnsafeClear()

func (*Map[K, V]) UnsafeClone

func (m *Map[K, V]) UnsafeClone() *Map[K, V]

func (*Map[K, V]) UnsafeCopy

func (m *Map[K, V]) UnsafeCopy(dst *Map[K, V])

func (*Map[K, V]) UnsafeDelete

func (m *Map[K, V]) UnsafeDelete(k K) (v V, has bool)

func (*Map[K, V]) UnsafeDeleteFunc

func (m *Map[K, V]) UnsafeDeleteFunc(del func(K, V) bool)

func (*Map[K, V]) UnsafeEqualFunc

func (m *Map[K, V]) UnsafeEqualFunc(m2 *Map[K, V], eq func(V, V) bool) bool

func (*Map[K, V]) UnsafeForeach

func (m *Map[K, V]) UnsafeForeach(f func(k K, v V))

func (*Map[K, V]) UnsafeGet

func (m *Map[K, V]) UnsafeGet(k K) (v V, has bool)

func (*Map[K, V]) UnsafeHas

func (m *Map[K, V]) UnsafeHas(k K) bool

func (*Map[K, V]) UnsafeKeys

func (m *Map[K, V]) UnsafeKeys() []K

func (*Map[K, V]) UnsafeLen

func (m *Map[K, V]) UnsafeLen() int

func (*Map[K, V]) UnsafeMake

func (m *Map[K, V]) UnsafeMake()

func (*Map[K, V]) UnsafeMarshalJSON

func (m *Map[K, V]) UnsafeMarshalJSON() ([]byte, error)

func (*Map[K, V]) UnsafeNil

func (m *Map[K, V]) UnsafeNil() bool

func (*Map[K, V]) UnsafeSet

func (m *Map[K, V]) UnsafeSet(k K, v V)

func (*Map[K, V]) UnsafeUnmarshalJSON

func (m *Map[K, V]) UnsafeUnmarshalJSON(b []byte) error

func (*Map[K, V]) UnsafeValues

func (m *Map[K, V]) UnsafeValues() []V

func (*Map[K, V]) Values

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

Jump to

Keyboard shortcuts

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