Documentation
¶
Overview ¶
* imported from https://github.com/hayageek/threadsafe * (c) Copyright (c) 2024 Ravishanker Kusuma - MIT License * See LICENSE for more details
* imported from https://github.com/hayageek/threadsafe * (c) Copyright (c) 2024 Ravishanker Kusuma - MIT License * See LICENSE for more details
Index ¶
- type Map
- func (m *Map[K, V]) Clear()
- func (m *Map[K, V]) Contains(key K) bool
- func (m *Map[K, V]) Copy() *Map[K, V]
- func (m *Map[K, V]) Delete(key K)
- func (m *Map[K, V]) Get(key K) (V, bool)
- func (m *Map[K, V]) Keys() []K
- func (m *Map[K, V]) Length() int
- func (m *Map[K, V]) Set(key K, value V)
- func (m *Map[K, V]) Values() []V
- type Slice
- func (s *Slice[T]) Append(value T)
- func (s *Slice[T]) Clear()
- func (s *Slice[T]) Contains(value T) bool
- func (s *Slice[T]) Copy() *Slice[T]
- func (s *Slice[T]) Get(index int) (T, bool)
- func (s *Slice[T]) Insert(index int, value T) bool
- func (s *Slice[T]) Length() int
- func (s *Slice[T]) Remove(index int) bool
- func (s *Slice[T]) Set(index int, value T) bool
- func (s *Slice[T]) Values() []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Map ¶
type Map[K comparable, V any] struct { // contains filtered or unexported fields }
Map represents a thread-safe map. It uses a mutex to ensure that all operations are thread-safe.
func NewMap ¶
func NewMap[K comparable, V any]() *Map[K, V]
NewMap creates a new thread-safe map. Example:
m := threadsafe.NewMap[string, int]()
func (*Map[K, V]) Clear ¶
func (m *Map[K, V]) Clear()
Clear removes all key-value pairs from the map. Example:
m.Clear()
func (*Map[K, V]) Contains ¶
Contains checks if the map contains the specified key. Example:
contains := m.Contains("key")
func (*Map[K, V]) Copy ¶
Copy returns a new thread-safe map that is a copy of the current map. Example:
copyMap := m.Copy()
func (*Map[K, V]) Delete ¶
func (m *Map[K, V]) Delete(key K)
Delete removes the value associated with the key. Example:
m.Delete("key")
func (*Map[K, V]) Get ¶
Get retrieves the value associated with the key. It returns the value and a boolean indicating whether the key was found. Example:
value, ok := m.Get("key")
func (*Map[K, V]) Keys ¶
func (m *Map[K, V]) Keys() []K
Keys returns a slice of all keys present in the map. Example:
keys := m.Keys()
func (*Map[K, V]) Length ¶
Length returns the number of key-value pairs in the map. Example:
length := m.Length()
type Slice ¶
type Slice[T any] struct { // contains filtered or unexported fields }
Slice represents a thread-safe slice. It uses a mutex to ensure that all operations are thread-safe.
func NewSlice ¶
NewSlice creates a new thread-safe slice. Example:
slice := threadsafe.NewSlice[int]()
func (*Slice[T]) Append ¶
func (s *Slice[T]) Append(value T)
Append appends a value to the slice. Example:
slice.Append(10)
func (*Slice[T]) Clear ¶
func (s *Slice[T]) Clear()
Clear removes all elements from the slice. Example:
slice.Clear()
func (*Slice[T]) Contains ¶
Contains checks if the slice contains the specified value. Example:
contains := slice.Contains(10)
func (*Slice[T]) Copy ¶
Copy returns a new thread-safe slice that is a copy of the current slice. Example:
copySlice := slice.Copy()
func (*Slice[T]) Get ¶
Get retrieves the value at the given index. It returns the value and a boolean indicating whether the index was valid. Example:
value, ok := slice.Get(2)
func (*Slice[T]) Insert ¶
Insert inserts a value at the specified index. It returns a boolean indicating whether the operation was successful. Example:
ok := slice.Insert(2, 10)
func (*Slice[T]) Remove ¶
Remove removes the element at the given index. It returns a boolean indicating whether the operation was successful. Example:
ok := slice.Remove(2)