Documentation
¶
Index ¶
- type Buffer
- type Map
- type Slice
- func (s *Slice[V]) All() []V
- func (s *Slice[V]) Append(value V)
- func (s *Slice[V]) Clear()
- func (s *Slice[V]) Find(predicate func(V) bool) (V, int)
- func (s *Slice[V]) Get(index int) (V, bool)
- func (s *Slice[V]) Length() int
- func (s *Slice[V]) Range(f func(index int, value V) bool)
- func (s *Slice[V]) Set(index int, value V) bool
- func (s *Slice[V]) Update(index int, f func(V) V) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Buffer ¶ added in v1.35.0
type Buffer struct {
// contains filtered or unexported fields
}
Buffer is a concurrency-safe bytes.Buffer. It implements io.Writer so it can be used anywhere a plain buffer would, e.g. as the output target for a log handler or as subprocess stderr.
func (*Buffer) Bytes ¶ added in v1.60.0
Bytes returns a copy of the buffered content as a byte slice. The returned slice is safe to retain and modify.
func (*Buffer) Drain ¶ added in v1.35.0
Drain returns the buffered content and resets the buffer atomically.
type Map ¶
type Map[K comparable, V any] struct { // contains filtered or unexported fields }
func NewMap ¶
func NewMap[K comparable, V any]() *Map[K, V]
func (*Map[K, V]) Clear ¶ added in v1.60.0
func (m *Map[K, V]) Clear()
Clear removes all entries from the map.
func (*Map[K, V]) LoadOrStore ¶ added in v1.60.0
LoadOrStore returns the existing value for key if present; otherwise it stores and returns value. The loaded result is true if the value was loaded, false if stored.
func (*Map[K, V]) Range ¶
Range calls f for every key/value pair in the map. Iteration stops early if f returns false.
Range iterates over a snapshot of the map taken under a read lock; f is invoked without holding any lock, which means callbacks may safely call other methods on the same Map (including Store and Delete) without deadlocking. As a consequence, mutations performed during iteration are not reflected in the values seen by f.
type Slice ¶
type Slice[V any] struct { // contains filtered or unexported fields }
func (*Slice[V]) Find ¶
Find returns the first element for which predicate returns true, along with its index, or the zero value and -1 if no element matches.
predicate is invoked while a read lock is held on the slice. It must not call methods that acquire the write lock (Append, Set, Update, Clear) on the same Slice, or a deadlock will occur.
func (*Slice[V]) Range ¶
Range calls f for every element in the slice. Iteration stops early if f returns false.
f is invoked while a read lock is held on the slice. Callbacks must not call methods that acquire the write lock (Append, Set, Update, Clear) on the same Slice, or a deadlock will occur.
func (*Slice[V]) Update ¶
Update replaces the element at index with the result of f applied to the current value, returning true on success. If index is out of range, Update returns false and f is not called.
f is invoked while the write lock is held on the slice. It must not call any other method on the same Slice, or a deadlock will occur.