atom

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 12 Imported by: 0

README

atom

atom provides atomic operations for integers, floats, and strings.

Functions

new_int(value=0) -> AtomicInt

create a new AtomicInt with an optional initial value

Parameters
name type description
value int initial value, defaults to 0
Examples

basic

create a new AtomicInt with default value

load("atom", "new_int")
ai = new_int()
ai.inc()
print(ai.get())
# Output: 1

with value

create a new AtomicInt with a specific value

load("atom", "new_int")
ai = new_int(42)
ai.add(42)
print(ai.get())
# Output: 84
new_float(value=0.0) -> AtomicFloat

create a new AtomicFloat with an optional initial value

Parameters
name type description
value float initial value, defaults to 0.0
Examples

basic

create a new AtomicFloat with default value

load("atom", "new_float")
af = new_float()
print(af.get())
# Output: 0.0

with value

create a new AtomicFloat with a specific value

load("atom", "new_float")
af = new_float(3.14)
print(af.get())
# Output: 3.14
new_string(value="") -> AtomicString

create a new AtomicString with an optional initial value

Parameters
name type description
value string initial value, defaults to an empty string
Examples

basic

create a new AtomicString with default value

load("atom", "new_string")
as = new_string()
print(as.get())  # Output: ""

with value

create a new AtomicString with a specific value

load("atom", "new_string")
as = new_string("hello")
print(as.get())
# Output: "hello"

Types

AtomicInt

an atomic integer type with various atomic operations

Methods

get() -> int

returns the current value

set(value: int)

sets the value

cas(old: int, new: int) -> bool

compares and swaps the value if it matches old

add(delta: int) -> int

adds delta to the value and returns the new value

sub(delta: int) -> int

subtracts delta from the value and returns the new value

inc() -> int

increments the value by 1 and returns the new value

dec() -> int

decrements the value by 1 and returns the new value

AtomicFloat

an atomic float type with various atomic operations

Methods

get() -> float

returns the current value

set(value: float)

sets the value

cas(old: float, new: float) -> bool

compares and swaps the value if it matches old

add(delta: float) -> float

adds delta to the value and returns the new value

sub(delta: float) -> float

subtracts delta from the value and returns the new value

AtomicString

an atomic string type with various atomic operations

Methods

get() -> string

returns the current value

set(value: string)

sets the value

cas(old: string, new: string) -> bool

compares and swaps the value if it matches old

Documentation

Overview

Package atom provides atomic operations for integers, floats and strings. Inspired by the sync/atomic and go.uber.org/atomic packages from Go.

Index

Constants

View Source
const ModuleName = "atom"

ModuleName defines the expected name for this Module when used in starlark's load() function, eg: load('atom', 'new_int')

Variables

This section is empty.

Functions

func LoadModule

func LoadModule() (starlark.StringDict, error)

LoadModule loads the atom module. It is concurrency-safe and idempotent.

Types

type AtomicFloat

type AtomicFloat struct {
	// contains filtered or unexported fields
}

func (*AtomicFloat) Attr

func (a *AtomicFloat) Attr(name string) (starlark.Value, error)

func (*AtomicFloat) AttrNames

func (a *AtomicFloat) AttrNames() []string

func (*AtomicFloat) CompareSameType

func (a *AtomicFloat) CompareSameType(op syntax.Token, y_ starlark.Value, depth int) (bool, error)

func (*AtomicFloat) Freeze

func (a *AtomicFloat) Freeze()

func (*AtomicFloat) Hash

func (a *AtomicFloat) Hash() (uint32, error)

func (*AtomicFloat) String

func (a *AtomicFloat) String() string

func (*AtomicFloat) Truth

func (a *AtomicFloat) Truth() starlark.Bool

func (*AtomicFloat) Type

func (a *AtomicFloat) Type() string

type AtomicInt

type AtomicInt struct {
	// contains filtered or unexported fields
}

func (*AtomicInt) Attr

func (a *AtomicInt) Attr(name string) (starlark.Value, error)

func (*AtomicInt) AttrNames

func (a *AtomicInt) AttrNames() []string

func (*AtomicInt) CompareSameType

func (a *AtomicInt) CompareSameType(op syntax.Token, y_ starlark.Value, depth int) (bool, error)

func (*AtomicInt) Freeze

func (a *AtomicInt) Freeze()

func (*AtomicInt) Hash

func (a *AtomicInt) Hash() (uint32, error)

func (*AtomicInt) String

func (a *AtomicInt) String() string

func (*AtomicInt) Truth

func (a *AtomicInt) Truth() starlark.Bool

func (*AtomicInt) Type

func (a *AtomicInt) Type() string

type AtomicString

type AtomicString struct {
	// contains filtered or unexported fields
}

func (*AtomicString) Attr

func (a *AtomicString) Attr(name string) (starlark.Value, error)

func (*AtomicString) AttrNames

func (a *AtomicString) AttrNames() []string

func (*AtomicString) CompareSameType

func (a *AtomicString) CompareSameType(op syntax.Token, y_ starlark.Value, depth int) (bool, error)

func (*AtomicString) Freeze

func (a *AtomicString) Freeze()

func (*AtomicString) Hash

func (a *AtomicString) Hash() (uint32, error)

func (*AtomicString) String

func (a *AtomicString) String() string

func (*AtomicString) Truth

func (a *AtomicString) Truth() starlark.Bool

func (*AtomicString) Type

func (a *AtomicString) Type() string

Jump to

Keyboard shortcuts

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