Documentation
¶
Index ¶
- type Array
- func (a *Array[T]) Append(value T)
- func (a *Array[T]) Clear()
- func (a *Array[T]) Contains(value T) bool
- func (a *Array[T]) Copy() *Array[T]
- func (a *Array[T]) Get(index int) (T, bool)
- func (a *Array[T]) Insert(index int, value T) bool
- func (a *Array[T]) Length() int
- func (a *Array[T]) Remove(index int) bool
- func (a *Array[T]) Set(index int, value T) bool
- func (a *Array[T]) Values() []T
- 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 Queue
- 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
- type Stack
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Array ¶
type Array[T any] struct { // contains filtered or unexported fields }
Array represents a thread-safe array. It uses a mutex to ensure that all operations are thread-safe.
func NewArray ¶
NewArray creates a new thread-safe array with a given size. Example:
arr := threadsafe.NewArray
func (*Array[T]) Append ¶ added in v1.0.0
func (a *Array[T]) Append(value T)
Append appends a value to the array. Example:
arr.Append(10)
func (*Array[T]) Clear ¶ added in v1.0.0
func (a *Array[T]) Clear()
Clear removes all elements from the array. Example:
arr.Clear()
func (*Array[T]) Contains ¶ added in v1.0.0
Contains checks if the array contains the specified value. Example:
contains := arr.Contains(10)
func (*Array[T]) Copy ¶ added in v1.0.0
Copy returns a new thread-safe array that is a copy of the current array. Example:
copyArray := arr.Copy()
func (*Array[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 := arr.Get(2)
func (*Array[T]) Insert ¶ added in v1.0.0
Insert inserts a value at the specified index. It returns a boolean indicating whether the operation was successful. Example:
ok := arr.Insert(2, 10)
func (*Array[T]) Remove ¶ added in v1.0.0
Remove removes the element at the given index. It returns a boolean indicating whether the operation was successful. Example:
ok := arr.Remove(2)
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 ¶ added in v1.0.0
func (m *Map[K, V]) Clear()
Clear removes all key-value pairs from the map. Example:
m.Clear()
func (*Map[K, V]) Contains ¶ added in v1.0.0
Contains checks if the map contains the specified key. Example:
contains := m.Contains("key")
func (*Map[K, V]) Copy ¶ added in v1.0.0
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 Queue ¶ added in v0.0.3
type Queue struct {
// contains filtered or unexported fields
}
Queue is a thread-safe queue.
func (*Queue) Clear ¶ added in v1.0.0
func (q *Queue) Clear()
Clear removes all elements from the queue. Example:
q.Clear()
func (*Queue) Enqueue ¶ added in v0.0.3
func (q *Queue) Enqueue(value interface{})
Enqueue adds an element to the queue.
func (*Queue) IsEmpty ¶ added in v1.0.0
IsEmpty checks if the queue is empty. Example:
isEmpty := q.IsEmpty()
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 ¶ added in v1.0.0
func (s *Slice[T]) Clear()
Clear removes all elements from the slice. Example:
slice.Clear()
func (*Slice[T]) Contains ¶ added in v1.0.0
Contains checks if the slice contains the specified value. Example:
contains := slice.Contains(10)
func (*Slice[T]) Copy ¶ added in v1.0.0
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 ¶ added in v1.0.0
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 ¶ added in v1.0.0
Remove removes the element at the given index. It returns a boolean indicating whether the operation was successful. Example:
ok := slice.Remove(2)
type Stack ¶ added in v0.0.3
type Stack struct {
// contains filtered or unexported fields
}
Stack is a thread-safe stack.
func (*Stack) Clear ¶ added in v1.0.0
func (s *Stack) Clear()
Clear removes all elements from the stack. Example:
s.Clear()
func (*Stack) IsEmpty ¶ added in v1.0.0
IsEmpty checks if the stack is empty. Example:
isEmpty := s.IsEmpty()
func (*Stack) Peek ¶ added in v1.0.0
Peek returns the element at the top of the stack without removing it. Example:
value, ok := s.Peek()