syncx

package
v0.2.12 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: MIT Imports: 3 Imported by: 4

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Map

type Map[K comparable, V any] interface {
	Store(K, V)

	Clear()
	Delete(K)
	CompareAndDelete(key K, old V) (deleted bool)

	Swap(k K, new V) (previous V, loaded bool)
	CompareAndSwap(key K, old, new V) (swapped bool)

	Load(K) (V, bool)
	LoadAndDelete(K) (v V, loaded bool)
	LoadOrStore(K, V) (actual V, loaded bool)
	Range(func(K, V) bool)

	Len() int
	Keys() []K
	Values() []V
}

func AsSmap

func AsSmap[K comparable, V any, M ~map[K]V](m M) Map[K, V]

func AsXmap

func AsXmap[K comparable, V any, M ~map[K]V](m M) Map[K, V]

func NewSmap

func NewSmap[K comparable, V any]() Map[K, V]

func NewXmap

func NewXmap[K comparable, V any]() Map[K, V]

type OnceOverride added in v0.2.1

type OnceOverride[T any] struct {
	// contains filtered or unexported fields
}

OnceOverride holds a value that has an initial default and can be overridden once. After the first successful Set, further modifications are not allowed.

Example
package main

import (
	"fmt"

	"github.com/xoctopus/x/syncx"
)

func main() {
	v := syncx.NewOnceOverride("default")
	fmt.Println(v.Value())
	v.Set("override")
	fmt.Println(v.Value())
	v.Set("override2")
	fmt.Println(v.Value())

}
Output:

default
override
override

func NewOnceOverride added in v0.2.1

func NewOnceOverride[T any](defaultValue T) *OnceOverride[T]

func (*OnceOverride[T]) Set added in v0.2.1

func (o *OnceOverride[T]) Set(x T) bool

func (*OnceOverride[T]) Value added in v0.2.1

func (o *OnceOverride[T]) Value() T

type Pool

type Pool[T any] struct {
	// contains filtered or unexported fields
}

func NewPool

func NewPool[T any](newer func() T) Pool[T]

func (*Pool[T]) Get

func (p *Pool[T]) Get() T

func (*Pool[T]) Put

func (p *Pool[T]) Put(v T)

type Set

type Set[K comparable] struct {
	// contains filtered or unexported fields
}

func NewSet

func NewSet[K comparable](keys ...K) *Set[K]

func (*Set[K]) Clear

func (s *Set[K]) Clear()

func (*Set[K]) Delete

func (s *Set[K]) Delete(k K)

func (*Set[K]) Exists

func (s *Set[K]) Exists(k K) bool

func (*Set[K]) Keys

func (s *Set[K]) Keys() []K

func (*Set[K]) Len

func (s *Set[K]) Len() int

func (*Set[K]) Range

func (s *Set[K]) Range(f func(k K) bool)

func (*Set[K]) Store

func (s *Set[K]) Store(k K)

Jump to

Keyboard shortcuts

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