synckit

package
v0.273.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Map added in v0.261.0

type Map[K comparable, V any] struct {
	// contains filtered or unexported fields
}
Example
package main

import (
	"go.llib.dev/frameless/pkg/synckit"
)

func main() {
	var m synckit.Map[string, int]

	m.Set("foo", 42) // 42 set for "foo" key
	m.Get("foo")     // -> 42
	m.Lookup("foo")  // -> 42, true
	m.Lookup("bar")  // -> 0, false

	if ptr, release, ok := m.Borrow("foo"); ok { // the value of "foo" is borrowed
		*ptr = 24
		release()
	}

	m.Reset() // map is cleared

	m.GetOrInit("foo", func() int { // -> 42
		return 42
	})

}

func (*Map[K, V]) Borrow added in v0.261.0

func (m *Map[K, V]) Borrow(key K) (ptr *V, release func(), ok bool)

func (*Map[K, V]) BorrowWithInit added in v0.261.0

func (m *Map[K, V]) BorrowWithInit(key K, init func() V) (ptr *V, release func())

func (*Map[K, V]) Del added in v0.261.0

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

func (*Map[K, V]) Get added in v0.261.0

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

func (*Map[K, V]) GetOrInit added in v0.261.0

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

func (*Map[K, V]) Keys added in v0.261.0

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

func (*Map[K, V]) Len added in v0.261.0

func (m *Map[K, V]) Len() int

func (*Map[K, V]) Lookup added in v0.261.0

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

func (*Map[K, V]) Reset added in v0.261.0

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

func (*Map[K, V]) Set added in v0.261.0

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

type RWLocker

type RWLocker interface {
	sync.Locker
	RLock()
	RUnlock()
	RLocker() sync.Locker
}

type RWLockerFactory

type RWLockerFactory[K comparable] struct {
	// ReadOptimised will make RLocker and rsync perform much faster,
	// at the expense of having a global read locking when a read lock is made before a write locking.
	// This cause a side effect that acquiring write locks for other keys will hang until the read operation is done.
	//
	// In the end, this shortcut leads to a whopping <350% increase in read operation speed,
	// while also supporting write operations as well.
	// However, it causes only a 0.17% decrease in write speed performance.
	ReadOptimised bool
	// contains filtered or unexported fields
}

func (*RWLockerFactory[K]) RWLocker

func (l *RWLockerFactory[K]) RWLocker(key K) RWLocker

Jump to

Keyboard shortcuts

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