container

package
v1.1.14 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2022 License: MIT Imports: 11 Imported by: 1

README

container 容器模块

bitmap_test.go 比特位表

TestBitmapExists

bitmap := initTestData()
t.Log(bitmap)

t.Log(bitmap.Exists(122))
t.Log(bitmap.Exists(123))

//data1 := []byte{1, 2, 4, 7}
//data2 := []byte{0, 1, 5}

TestBitmapSet

bitmap := initTestData()

t.Log(bitmap.Exists(1256))

bitmap.Set(1256)

t.Log(bitmap.Exists(1256))
TestBitmapUnionOr

bitmap := initTestData()
bitmap2 := initTestData()
bitmap2.Set(256)

bitmap3 := bitmap.Union(&bitmap2)
t.Log(bitmap3.Exists(256))

bitmap3.Set(562)
t.Log(bitmap3.Exists(562))

t.Log(bitmap.Exists(562))
TestBitmapBitInverse

bitmap := initTestData()

t.Log(bitmap.Exists(66))

bitmap.Inverse()

t.Log(bitmap.Exists(66))

const_hash_test.go 一致性HASH

TestConstHash


var ringchash CHashRing

var configs []CHashNode
for i := 0; i < 10; i++ {
	configs = append(configs, TestNode("node"+strconv.Itoa(i)))
}

ringchash.Adds(configs)

fmt.Println(ringchash.Debug())

fmt.Println("==================================", configs)

fmt.Println(ringchash.Get("jjfdsljk:dfdfd:fds"))

fmt.Println(ringchash.Get("jjfdxxvsljk:dddsaf:xzcv"))
//
fmt.Println(ringchash.Get("fcds:cxc:fdsfd"))
//
fmt.Println(ringchash.Get("vdsafd:32:fdsfd"))

fmt.Println(ringchash.Get("xvd:fs:xcvd"))

var configs2 []CHashNode
for i := 0; i < 2; i++ {
	configs2 = append(configs2, TestNode("node"+strconv.Itoa(10+i)))
}
ringchash.Adds(configs2)
fmt.Println("==================================")
fmt.Println(ringchash.Debug())
fmt.Println(ringchash.Get("jjfdsljk:dfdfd:fds"))

fmt.Println(ringchash.Get("jjfdxxvsljk:dddsaf:xzcv"))
//
fmt.Println(ringchash.Get("fcds:cxc:fdsfd"))
//
fmt.Println(ringchash.Get("vdsafd:32:fdsfd"))

fmt.Println(ringchash.Get("xvd:fs:xcvd"))

ringchash.Del("node0")

fmt.Println("==================================")
fmt.Println(ringchash.Debug())
fmt.Println(ringchash.Get("jjfdsljk:dfdfd:fds"))

fmt.Println(ringchash.Get("jjfdxxvsljk:dddsaf:xzcv"))
//
fmt.Println(ringchash.Get("fcds:cxc:fdsfd"))
//
fmt.Println(ringchash.Get("vdsafd:32:fdsfd"))

fmt.Println(ringchash.Get("xvd:fs:xcvd"))

lighttimer_test.go 轻量级计时器

TestStartTicks

lt := NewLightTimer()
lt.StartTicks(time.Millisecond)

lt.AddTimer(time.Second*time.Duration(2), func(fireSeqNo uint) bool {
	fmt.Println("callback", fireSeqNo, "-")
	if fireSeqNo == 4 {
		return true
	}
	return false
})

time.Sleep(time.Hour)
TestStartTicksDeadline


//NewLightTimerPool

lt := NewLightTimer()
lt.StartTicks(time.Millisecond)

lt.AddTimerWithDeadline(time.Second*time.Duration(2), time.Now().Add(time.Second*5), func(seqNo uint) bool {
	fmt.Println("callback", seqNo, "-")
	if seqNo == 4 {
		return true
	}
	return false
}, func(seqNo uint) bool {
	fmt.Println("end callback", seqNo, "-")
	return true
})

time.Sleep(time.Hour)
TestLtPool

pool := NewLightTimerPool(10, time.Millisecond)

for i := 0; i < 100000; i++ {
	tmp := i
	pool.AddTimerWithDeadline(strconv.Itoa(tmp), time.Second*time.Duration(2), time.Now().Add(time.Second*5), func(seqNo uint) bool {
		fmt.Println("callback", tmp, "-", seqNo, "-")
		if seqNo == 4 {
			return true
		}
		return false
	}, func(seqNo uint) bool {
		fmt.Println("end callback", tmp, "-", seqNo, "-")
		return true
	})
}

time.Sleep(time.Second * 20)

fmt.Println(runtime.NumGoroutine())

time.Sleep(time.Hour)
TestStartTicks2

lt := NewLightTimer()
lt.StartTicks(time.Millisecond)

lt.AddCallback(time.Second*time.Duration(3), func() {
	fmt.Println("invoke once")
})

time.Sleep(time.Hour)

Documentation

Index

Constants

View Source
const (
	MIN_TIMER_INTERVAL = 1 * time.Millisecond
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Bitmap

type Bitmap []uint32

func (*Bitmap) Clone

func (b *Bitmap) Clone() *Bitmap

func (*Bitmap) Exists

func (b *Bitmap) Exists(item uint32) bool

func (*Bitmap) Grow

func (b *Bitmap) Grow(item uint32)

func (*Bitmap) Init

func (b *Bitmap) Init(maxNum uint32)

func (*Bitmap) Inverse

func (b *Bitmap) Inverse()

func (*Bitmap) MaxU

func (b *Bitmap) MaxU(x, y uint32) uint32

func (*Bitmap) Min

func (b *Bitmap) Min(x, y int) int

func (*Bitmap) Set

func (b *Bitmap) Set(item uint32) bool

func (*Bitmap) Sets

func (b *Bitmap) Sets(items []uint32)

func (*Bitmap) Union

func (b *Bitmap) Union(b2 *Bitmap) *Bitmap

type CHash

type CHash interface {
	Adds([]CHashNode)
	Del(id string)
	Get(key string) CHashNode
}

type CHashNode

type CHashNode interface {
	Id() string
	Health() bool
}

type CHashRing

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

func (*CHashRing) Adds

func (c *CHashRing) Adds(nodes []CHashNode)

func (*CHashRing) Debug

func (c *CHashRing) Debug() string

func (*CHashRing) Del

func (c *CHashRing) Del(nodeId string)

func (*CHashRing) Get

func (c *CHashRing) Get(key string) CHashNode

type CallbackFunc

type CallbackFunc func(uint) (done bool)

定时执行函数 入参回调执行序号(次数) 回参是否完成,true停止执行,false继续执行,在dealine的callback中无效

type DataRow

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

func (*DataRow) Data

func (r *DataRow) Data() []string

func (*DataRow) Int64 added in v1.0.16

func (r *DataRow) Int64(fieldName string) int64

func (*DataRow) String

func (r *DataRow) String(fieldName string) string

func (*DataRow) UInt64 added in v1.0.16

func (r *DataRow) UInt64(fieldName string) uint64

type DataSet

type DataSet map[string]*DataTable

func (DataSet) Table

func (s DataSet) Table(tName string) *DataTable

type DataTable

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

func NewDataTable

func NewDataTable(cols []string, pkCol string, indexes []string, initCap int) *DataTable

func (*DataTable) Cols added in v1.0.17

func (t *DataTable) Cols() []string

meta info

func (*DataTable) Indexes added in v1.0.17

func (t *DataTable) Indexes() []string

func (*DataTable) PkCol added in v1.0.17

func (t *DataTable) PkCol() string

func (*DataTable) PkInt

func (t *DataTable) PkInt(row *DataRow) int

func (*DataTable) PkString

func (t *DataTable) PkString(row *DataRow) string

func (*DataTable) Push

func (t *DataTable) Push(row []string)

func (*DataTable) PushAll

func (t *DataTable) PushAll(rows [][]string)

func (*DataTable) Row

func (t *DataTable) Row(pk string) *DataRow

data info

func (*DataTable) Rows

func (t *DataTable) Rows() (rows []*DataRow)

func (*DataTable) RowsBy

func (t *DataTable) RowsBy(indexName, indexValue string) []*DataRow

type LightTimer

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

func NewLightTimer

func NewLightTimer() *LightTimer

func (*LightTimer) AddCallback

func (lt *LightTimer) AddCallback(d time.Duration, callback func()) *Timer

Add a callback which will be called after specified duration

func (*LightTimer) AddTimer

func (lt *LightTimer) AddTimer(d time.Duration, callback CallbackFunc) *Timer

func (*LightTimer) AddTimerWithDeadline

func (lt *LightTimer) AddTimerWithDeadline(d time.Duration, deadline time.Time, callback CallbackFunc, deadlineCallback CallbackFunc) *Timer

Add a timer which calls callback periodly

func (*LightTimer) StartTicks

func (lt *LightTimer) StartTicks(tickInterval time.Duration)

Start the self-ticking routine, which ticks per tickInterval

type LightTimerPool

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

func NewLightTimerPool

func NewLightTimerPool(size int, tickInterval time.Duration) *LightTimerPool

func (*LightTimerPool) AddCallback

func (p *LightTimerPool) AddCallback(key string, d time.Duration, callback func())

func (*LightTimerPool) AddTimer

func (p *LightTimerPool) AddTimer(key string, d time.Duration, callback CallbackFunc)

func (*LightTimerPool) AddTimerWithDeadline

func (p *LightTimerPool) AddTimerWithDeadline(key string, d time.Duration, deadline time.Time,
	callback CallbackFunc, deadlineCallback CallbackFunc)

type Timer

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

func (*Timer) Cancel

func (t *Timer) Cancel()

func (*Timer) IsActive

func (t *Timer) IsActive() bool

Jump to

Keyboard shortcuts

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