util

package
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeepClone

func DeepClone[T any](v T) T

func DeepCopy

func DeepCopy(dst, src interface{})

func RandGroup

func RandGroup(p ...uint32) int
Example
package main

import (
	"fmt"
	"github.com/taills/leaf/v2/util"
)

func main() {
	i := util.RandGroup(0, 0, 50, 50)
	switch i {
	case 2, 3:
		fmt.Println("ok")
	}

}
Output:
ok

func RandInterval

func RandInterval(b1, b2 int32) int32
Example
package main

import (
	"fmt"
	"github.com/taills/leaf/v2/util"
)

func main() {
	v := util.RandInterval(-1, 1)
	switch v {
	case -1, 0, 1:
		fmt.Println("ok")
	}

}
Output:
ok

func RandIntervalN

func RandIntervalN(b1, b2 int32, n uint32) []int32
Example
package main

import (
	"fmt"
	"github.com/taills/leaf/v2/util"
)

func main() {
	r := util.RandIntervalN(-1, 0, 2)
	if r[0] == -1 && r[1] == 0 ||
		r[0] == 0 && r[1] == -1 {
		fmt.Println("ok")
	}

}
Output:
ok

Types

type Map

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

import (
	"fmt"
	"github.com/taills/leaf/v2/util"
)

func main() {
	m := new(util.Map[any, any])

	fmt.Println(m.Get("key"))
	m.Set("key", "value")
	fmt.Println(m.Get("key"))
	m.Del("key")
	fmt.Println(m.Get("key"))

	m.Set(1, "1")
	m.Set(2, 2)
	m.Set("3", 3)

	fmt.Println(m.Len())

}
Output:
<nil>
value
<nil>
3

func (*Map[K, V]) Del

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

func (*Map[K, V]) Get

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

func (*Map[K, V]) Len

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

func (*Map[K, V]) LockRange

func (m *Map[K, V]) LockRange(f func(K, V))

func (*Map[K, V]) RLockRange

func (m *Map[K, V]) RLockRange(f func(K, V))

func (*Map[K, V]) Set

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

func (*Map[K, V]) TestAndSet

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

func (*Map[K, V]) UnsafeDel

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

func (*Map[K, V]) UnsafeGet

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

func (*Map[K, V]) UnsafeLen

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

func (*Map[K, V]) UnsafeRange

func (m *Map[K, V]) UnsafeRange(f func(K, V))

func (*Map[K, V]) UnsafeSet

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

type Semaphore

type Semaphore chan struct{}

func MakeSemaphore

func MakeSemaphore(n int) Semaphore

func (Semaphore) Acquire

func (s Semaphore) Acquire()

func (Semaphore) Release

func (s Semaphore) Release()

Jump to

Keyboard shortcuts

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