util

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: May 11, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeepClone

func DeepClone(v interface{}) interface{}

DeepClone deep clone

Example
package main

import (
	"fmt"
	"github.com/somethinghero/leaf/util"
)

func main() {
	src := []int{1, 2, 3}

	dst := util.DeepClone(src).([]int)

	for _, v := range dst {
		fmt.Println(v)
	}

}
Output:

1
2
3

func DeepCopy

func DeepCopy(dst, src interface{})

DeepCopy deep copy

Example
package main

import (
	"fmt"
	"github.com/somethinghero/leaf/util"
)

func main() {
	src := []int{1, 2, 3}

	var dst []int
	util.DeepCopy(&dst, &src)

	for _, v := range dst {
		fmt.Println(v)
	}

}
Output:

1
2
3

func RandGroup

func RandGroup(p ...uint32) int

RandGroup rand in group

Example
package main

import (
	"fmt"
	"github.com/somethinghero/leaf/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

RandInterval rand in [b1, b2]

Example
package main

import (
	"fmt"
	"github.com/somethinghero/leaf/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

RandIntervalN ran many in [b1, b2]

Example
package main

import (
	"fmt"
	"github.com/somethinghero/leaf/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 struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Map wrap of map

Example
package main

import (
	"fmt"
	"github.com/somethinghero/leaf/util"
)

func main() {
	m := new(util.Map)

	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) Del

func (m *Map) Del(key interface{})

Del safe delete

func (*Map) Get

func (m *Map) Get(key interface{}) interface{}

Get safe get

func (*Map) Len

func (m *Map) Len() int

Len safe get len

func (*Map) LockRange

func (m *Map) LockRange(f func(interface{}, interface{}))

LockRange safe range

func (*Map) RLockRange

func (m *Map) RLockRange(f func(interface{}, interface{}))

RLockRange read lock range

func (*Map) Set

func (m *Map) Set(key interface{}, value interface{})

Set safe set

func (*Map) TestAndSet

func (m *Map) TestAndSet(key interface{}, value interface{}) interface{}

TestAndSet try set

func (*Map) UnsafeDel

func (m *Map) UnsafeDel(key interface{})

UnsafeDel unsafe delete

func (*Map) UnsafeGet

func (m *Map) UnsafeGet(key interface{}) interface{}

UnsafeGet unsafe get

func (*Map) UnsafeLen

func (m *Map) UnsafeLen() int

UnsafeLen unsafe get len

func (*Map) UnsafeRange

func (m *Map) UnsafeRange(f func(interface{}, interface{}))

UnsafeRange unsafe range

func (*Map) UnsafeSet

func (m *Map) UnsafeSet(key interface{}, value interface{})

UnsafeSet unsafe set

type Semaphore

type Semaphore chan struct{}

Semaphore Semaphore

func MakeSemaphore

func MakeSemaphore(n int) Semaphore

MakeSemaphore MakeSemaphore

func (Semaphore) Acquire

func (s Semaphore) Acquire()

Acquire Acquire

func (Semaphore) Release

func (s Semaphore) Release()

Release Release

Jump to

Keyboard shortcuts

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