safe

package
v1.4.7 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 4 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Int added in v1.0.7

type Int struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Int ...

func NewInt

func NewInt() *Int

NewInt returns a new safe int

func (*Int) Dec added in v1.3.6

func (i *Int) Dec(step int)

Dec decrements the int by step

func (*Int) Get added in v1.0.7

func (i *Int) Get() int

Get returns the int

func (*Int) Inc added in v1.3.6

func (i *Int) Inc(step int)

Inc increments the int by step

func (*Int) MarshalJSON added in v1.4.4

func (i *Int) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of the int

func (*Int) Set added in v1.0.7

func (i *Int) Set(value int)

Set sets the int to the given value

func (*Int) String added in v1.4.4

func (i *Int) String() string

String returns the string representation of the int

func (*Int) UnmarshalJSON added in v1.4.4

func (i *Int) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes the JSON-encoded data and stores the result in the int

type Int64 added in v1.0.7

type Int64 struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Int64 ...

func NewInt64

func NewInt64() *Int64

NewInt64 returns a new safe int

func (*Int64) Dec added in v1.3.6

func (i *Int64) Dec(step int64)

Dec decrements the int by step

func (*Int64) Get added in v1.0.7

func (i *Int64) Get() int64

Get returns the int

func (*Int64) Inc added in v1.3.6

func (i *Int64) Inc(step int64)

Inc increments the int by step

func (*Int64) MarshalJSON added in v1.4.4

func (i *Int64) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of the int

func (*Int64) Set added in v1.0.7

func (i *Int64) Set(value int64)

Set sets the int to the given value

func (*Int64) String added in v1.4.4

func (i *Int64) String() string

String returns the string representation of the int

func (*Int64) UnmarshalJSON added in v1.4.4

func (i *Int64) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes the JSON-encoded data and stores the result in the int

type List added in v1.0.7

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

List ...

func NewList

func NewList[V any](opts ...ListOption) *List[V]

NewList returns a new safe list

@TODO generic type comparable interface cannot implement by struct,so we use any type for generic type

func (*List[V]) Clear added in v1.0.7

func (l *List[V]) Clear()

Clear removes all elements from the list

func (*List[V]) Contains added in v1.0.7

func (l *List[V]) Contains(value V) bool

Contains returns true if the list contains the given element

func (*List[V]) Filter added in v1.0.7

func (l *List[V]) Filter(f func(V) bool) *List[V]

Filter returns a new list with all elements that satisfy the given function

func (*List[V]) Find added in v1.0.7

func (l *List[V]) Find(f func(V) bool) V

Find returns the first element that satisfies the given function

func (*List[V]) First added in v1.0.7

func (l *List[V]) First() V

First returns the first element of the list

func (*List[V]) ForEach added in v1.0.7

func (l *List[V]) ForEach(f func(V) (stop bool))

ForEach iterates over the list and calls the given function for each element

func (*List[V]) Get added in v1.0.7

func (l *List[V]) Get(index int) V

Get returns the element at the given index

func (*List[V]) IndexOf added in v1.0.7

func (l *List[V]) IndexOf(value V) int

IndexOf returns the index of the given element

func (*List[V]) Iterator added in v1.0.8

func (l *List[V]) Iterator() []V

Iterator returns a channel that will yield successive elements of the list

func (*List[V]) LPop added in v1.4.3

func (l *List[V]) LPop() V

LPop removes and returns the first element of the list

func (*List[V]) LPush added in v1.4.3

func (l *List[V]) LPush(value V)

LPush adds an element to the beginning of the list

func (*List[V]) Last added in v1.0.7

func (l *List[V]) Last() V

Last returns the last element of the list

func (*List[V]) Length added in v1.0.7

func (l *List[V]) Length() int

Length is an alias of Size

func (*List[V]) Map added in v1.0.7

func (l *List[V]) Map(f func(V) V) *List[V]

Map returns a new list with the result of calling the given function on each element

func (*List[V]) MarshalJSON added in v1.4.2

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

MarshalJSON returns the JSON encoding of the list

func (*List[V]) Pop added in v1.0.7

func (l *List[V]) Pop() V

Pop removes and returns the last element of the list

func (*List[V]) Push added in v1.0.7

func (l *List[V]) Push(value V)

Push adds an element to the end of the list

func (*List[V]) Reduce added in v1.0.7

func (l *List[V]) Reduce(f func(V, V) V) V

Reduce returns the result of reducing the list to a single value

func (*List[V]) Reverse added in v1.0.7

func (l *List[V]) Reverse() *List[V]

Reverse reverses the list

func (*List[V]) Shift added in v1.0.7

func (l *List[V]) Shift() V

Shift removes and returns the first element of the list

like JavaScript Array.shift

func (*List[V]) Size added in v1.0.7

func (l *List[V]) Size() int

Size returns the number of elements in the list

func (*List[V]) Slice added in v1.0.7

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

Slice returns a new list with a copy of a given number of elements from the given index

func (*List[V]) Splice added in v1.0.7

func (l *List[V]) Splice(index int, count int) *List[V]

Splice removes the given number of elements from the given index

func (*List[V]) String added in v1.4.2

func (l *List[V]) String() string

String returns the string representation of the list

func (*List[V]) Swap added in v1.0.7

func (l *List[V]) Swap(index1 int, index2 int)

Swap swaps the elements at the given indices

func (*List[V]) ToSlice added in v1.0.12

func (l *List[V]) ToSlice() []V

ToSlice returns the origin map

func (*List[V]) UnmarshalJSON added in v1.4.2

func (l *List[V]) UnmarshalJSON(data []byte) error

UnmarshalJSON parses the JSON-encoded data and stores the result in the list

func (*List[V]) Unshift added in v1.0.7

func (l *List[V]) Unshift(value V)

Unshift adds an element to the beginning of the list

func (*List[V]) Unshifts added in v1.4.3

func (l *List[V]) Unshifts(values V)

Unshift adds an element to the beginning of the list

like JavaScript Array.unshift

type ListConfig added in v1.3.10

type ListConfig struct {
	Capacity int
}

ListConfig ...

type ListOption added in v1.3.10

type ListOption func(*ListConfig)

ListOption ...

type Map added in v1.0.7

type Map[K comparable, V any] struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Map ...

func NewMap

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

NewMap returns a new safe map

func (*Map[K, V]) Clear added in v1.0.7

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

Clear removes all elements from the map

func (*Map[K, V]) Del added in v1.0.7

func (m *Map[K, V]) Del(key K) error

Del deletes a key from the map

func (*Map[K, V]) Get added in v1.0.7

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

Get returns the value for a key

func (*Map[K, V]) Has added in v1.0.9

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

Has returns true if the map contains the key

func (*Map[K, V]) Iterator added in v1.0.8

func (m *Map[K, V]) Iterator() map[K]V

Iterator returns a channel that will yield all the keys and values in the map

func (*Map[K, V]) Keys added in v1.0.7

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

Keys returns all the keys in the map

func (*Map[K, V]) MarshalJSON added in v1.4.2

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

MarshalJSON returns the JSON encoding of the map

func (*Map[K, V]) Set added in v1.0.7

func (m *Map[K, V]) Set(key K, value V) error

Set sets a key = value in the map

func (*Map[K, V]) String added in v1.4.2

func (m *Map[K, V]) String() string

String returns the string representation of the map

func (*Map[K, V]) ToMap added in v1.0.12

func (m *Map[K, V]) ToMap() map[K]V

ToMap returns the origin map

func (*Map[K, V]) UnmarshalJSON added in v1.4.2

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

UnmarshalJSON decodes the JSON encoding of the map

type MapConfig added in v1.3.10

type MapConfig struct {
	Capacity int
}

MapConfig ...

type MapOption added in v1.3.10

type MapOption func(*MapConfig)

MapOption ...

type Queue added in v1.0.7

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

Queue ...

func NewQueue

func NewQueue[V any](opts ...QueueOption) *Queue[V]

NewQueue returns a new safe queue

func (*Queue[V]) Back added in v1.0.7

func (q *Queue[V]) Back() V

Back returns the last element of the queue

func (*Queue[V]) Clear added in v1.0.7

func (q *Queue[V]) Clear()

Clear removes all elements from the queue

func (*Queue[V]) Dequeue added in v1.0.7

func (q *Queue[V]) Dequeue() V

Dequeue removes and returns the first element of the queue

func (*Queue[V]) Enqueue added in v1.0.7

func (q *Queue[V]) Enqueue(value V)

Enqueue adds an element to the end of the queue

func (*Queue[V]) Front added in v1.0.7

func (q *Queue[V]) Front() V

Front returns the first element of the queue

func (*Queue[V]) IsEmpty added in v1.0.7

func (q *Queue[V]) IsEmpty() bool

IsEmpty returns true if the queue is empty

func (*Queue[V]) MarshalJSON added in v1.4.2

func (q *Queue[V]) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of the queue

func (*Queue[V]) Size added in v1.0.7

func (q *Queue[V]) Size() int

Size returns the number of elements in the queue

func (*Queue[V]) String added in v1.4.2

func (q *Queue[V]) String() string

String returns a string representation of the queue

func (*Queue[V]) UnmarshalJSON added in v1.4.2

func (q *Queue[V]) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes the JSON encoding of the queue

type QueueConfig added in v1.4.3

type QueueConfig struct {
	Capacity int
}

QueueConfig ...

type QueueOption added in v1.4.3

type QueueOption func(*QueueConfig)

QueueOption ...

type Stack added in v1.0.7

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

Stack ...

func NewStack

func NewStack[V any]() *Stack[V]

NewStack returns a new safe stack

func (*Stack[V]) Clear added in v1.0.7

func (m *Stack[V]) Clear(key string)

Clear removes all elements from the stack

func (*Stack[V]) IsEmpty added in v1.0.7

func (m *Stack[V]) IsEmpty(key string) bool

IsEmpty returns true if the stack is empty

func (*Stack[V]) MarshalJSON added in v1.4.2

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

MarshalJSON returns the JSON encoding of the stack

func (*Stack[V]) Peek added in v1.0.7

func (m *Stack[V]) Peek(key string) V

Peek returns the last element of the stack

func (*Stack[V]) Pop added in v1.0.7

func (m *Stack[V]) Pop(key string) V

Pop removes and returns the last element of the stack

func (*Stack[V]) Push added in v1.0.7

func (m *Stack[V]) Push(key string, value V)

Push adds an element to the end of the stack

func (*Stack[V]) Size added in v1.0.7

func (m *Stack[V]) Size(key string) int

Size returns the number of elements in the stack

func (*Stack[V]) String added in v1.4.2

func (m *Stack[V]) String() string

String returns a string representation of the stack

func (*Stack[V]) UnmarshalJSON added in v1.4.2

func (m *Stack[V]) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes the JSON encoding of the stack

type String added in v1.0.7

type String struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

String ...

func NewString

func NewString() *String

NewString returns a new safe string

func (*String) Get added in v1.0.7

func (i *String) Get() string

Get returns the string

func (*String) Set added in v1.0.7

func (i *String) Set(value string)

Set sets the string to the given value

Jump to

Keyboard shortcuts

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