continer

package
v0.0.0-...-5771147 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

常用于管理游戏背包、技能列表的容器 适用于手游、页游等多种类型 适用于格子类BOX容器 线程安全、适用于大并发场景 version 1.0 beta by koangel email: jackliu100@gmail.com 2017/12/10

一款带锁的列表 version 1.0 beta by koangel email: jackliu100@gmail.com 2017/12/10

定时执行函数的的数据容器 version 1.0 beta by koangel email: jackliu100@gmail.com 2021/01/09

计算一个周期内数据是多少,超过这个周期会直接清理数据 主要用于统计、限制以及周期性的内存计算 version 1.0 beta by koangel email: jackliu100@gmail.com 2021/01/09

Index

Constants

View Source
const (
	Inventory = iota
	Wear
	Skill
)
View Source
const (
	EmptyGrid = "grid is empty..."
)

Variables

This section is empty.

Functions

func GetHostIndex

func GetHostIndex(key string, maxCount int) int

Types

type ExecProc

type ExecProc func(c *TickLimit)

type ItemBox

type ItemBox struct {
	// 标记属于谁,可以是任意类型
	Owner interface{}
	// 标记类型(建议自己定义),例如 Inventory,wear,skill
	Type int
	// contains filtered or unexported fields
}

func NewBox

func NewBox(column, row, itype int, owner, value, info interface{}) (box *ItemBox, err error)

////////////////////////////////////////// 创建函数

func (*ItemBox) Array

func (b *ItemBox) Array() []ItemElement

会产生数据COPY,如果需要组织数据包,请尽量避免使用该函数 仅仅打包已存在数据,空格不会打包

func (*ItemBox) EmptyGird

func (b *ItemBox) EmptyGird() (col, row int)

获得一个空格子位置信息

func (*ItemBox) EmptyGrid

func (b *ItemBox) EmptyGrid() int

空格子数量

func (*ItemBox) FromBinary

func (b *ItemBox) FromBinary(src []byte) error

func (*ItemBox) GridCount

func (b *ItemBox) GridCount() int

格子的总数

func (*ItemBox) Init

func (b *ItemBox) Init()

///////////////////////////////////////// 成员函数

func (*ItemBox) IsFull

func (b *ItemBox) IsFull() bool

是否已满

func (*ItemBox) ItemCount

func (b *ItemBox) ItemCount() int

背包操作 道具数量

func (*ItemBox) Move

func (b *ItemBox) Move(sc, sr, dc, dr int) error

移动道具 A to b,如果b or a都不为空那么交换

func (*ItemBox) Peek

func (b *ItemBox) Peek(col, row int) (item *ItemElement, err error)

取出该格子道具

func (*ItemBox) PeekInfo

func (b *ItemBox) PeekInfo(col, row int) (info interface{}, err error)

取出该格子的Ohter数值,格子为空则返回错误

func (*ItemBox) PeekValue

func (b *ItemBox) PeekValue(col, row int) (val interface{}, err error)

取出该格子的VALUE数值,格子为空则返回错误

func (*ItemBox) Push

func (b *ItemBox) Push(item, info interface{}) (err error, ri *ItemElement)

背包操作函数 暂不提供批量压入 自动压入到空格位置

func (*ItemBox) PushAndSwap

func (b *ItemBox) PushAndSwap(col, row int, item, info interface{}) error

该格子存在道具那么把该格子道具放入一个空格子,如果没有没空格子,则返回失败

func (*ItemBox) PushCell

func (b *ItemBox) PushCell(col, row int, item, info interface{}) (err error, ri *ItemElement)

格子存在则放入其他格子并返回元素,没有空格子则返回失败

func (*ItemBox) Range

func (b *ItemBox) Range(fn func(val *ItemElement) bool)

正向迭代

func (*ItemBox) Remove

func (b *ItemBox) Remove(col, row int) error

func (*ItemBox) Reverse

func (b *ItemBox) Reverse(fn func(val *ItemElement) bool)

反向迭代

func (*ItemBox) SetFormatter

func (b *ItemBox) SetFormatter(foramtter formatter.ItemFormatter)

func (*ItemBox) Sort

func (b *ItemBox) Sort(fn func(av, bv interface{}) bool)

函数返回true那么交换2个格子位置 排序会把前面空格自动填满

func (*ItemBox) SwapElement

func (b *ItemBox) SwapElement(se, de *ItemElement) error

func (*ItemBox) ToBinary

func (b *ItemBox) ToBinary() (data []byte, err error)

用于保存 保存协议,|count|len|Element Body|len|Element Body|

type ItemElement

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

func (*ItemElement) Column

func (e *ItemElement) Column() int

func (*ItemElement) IsEmpty

func (e *ItemElement) IsEmpty() bool

func (*ItemElement) Position

func (e *ItemElement) Position() int

func (*ItemElement) Remove

func (e *ItemElement) Remove()

func (*ItemElement) Row

func (e *ItemElement) Row() int

func (*ItemElement) SetValue

func (e *ItemElement) SetValue(value, info interface{})

func (*ItemElement) Value

func (e *ItemElement) Value() (value, info interface{})

type LimitAarray

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

2021/01/09 新增高性能的容器,LimitArray,采用数组切片完成计算,效率极高

func NewLA

func NewLA(lc int, key string) *LimitAarray

func (*LimitAarray) Add

func (l *LimitAarray) Add(val interface{})

func (*LimitAarray) Array

func (l *LimitAarray) Array() []interface{}

func (*LimitAarray) Clear

func (l *LimitAarray) Clear()

func (*LimitAarray) Foreach

func (l *LimitAarray) Foreach(fn func(n interface{}))

func (*LimitAarray) Len

func (l *LimitAarray) Len() int

func (*LimitAarray) Name

func (l *LimitAarray) Name() string

func (*LimitAarray) RevForeach

func (l *LimitAarray) RevForeach(fn func(n interface{}))

type SList

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

func New

func New() *SList

func (*SList) Back

func (sc *SList) Back() interface{}

func (*SList) Clear

func (sc *SList) Clear()

func (*SList) First

func (sc *SList) First() interface{}

func (*SList) Len

func (sc *SList) Len() int

func (*SList) Push

func (sc *SList) Push(item interface{})

func (*SList) Range

func (sc *SList) Range(fn func(i interface{}) bool)

func (*SList) Remove

func (sc *SList) Remove(fn func(i interface{}) bool)

func (*SList) RemoveRanges

func (sc *SList) RemoveRanges(fn func(i interface{}) bool)

func (*SList) ReverseRange

func (sc *SList) ReverseRange(fn func(i interface{}) bool)

func (*SList) Search

func (sc *SList) Search(fn func(i interface{}) bool) (interface{}, bool)

func (*SList) Sort

func (sc *SList) Sort(fn func(a, b interface{}) bool)

type SStatMap

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

func NewStatMap

func NewStatMap() *SStatMap

func (*SStatMap) Clear

func (c *SStatMap) Clear()

func (*SStatMap) Incr

func (c *SStatMap) Incr(key string, value int64)

func (*SStatMap) Len

func (c *SStatMap) Len() int

func (*SStatMap) Range

func (c *SStatMap) Range(fn func(key string, value int64) bool)

func (*SStatMap) Sub

func (c *SStatMap) Sub(key string, value int64)

func (*SStatMap) Value

func (c *SStatMap) Value(key string) int64

type TickLimit

type TickLimit struct {
	Cli        interface{}
	DebugPrint bool
	// contains filtered or unexported fields
}

func NewTickerLimit

func NewTickerLimit(name string, index int, arrCount, limit int, ticker time.Duration, fn TickWriter, start, end ExecProc) *TickLimit

func (*TickLimit) Add

func (c *TickLimit) Add(key string, data interface{})

func (*TickLimit) Data

func (c *TickLimit) Data(key string) []interface{}

func (*TickLimit) Index

func (c *TickLimit) Index() int

func (*TickLimit) Len

func (c *TickLimit) Len(key string) int

func (*TickLimit) Name

func (c *TickLimit) Name() string

func (*TickLimit) StartProc

func (c *TickLimit) StartProc()

func (*TickLimit) Stop

func (c *TickLimit) Stop()

type TickWriter

type TickWriter func(c *TickLimit, key string, data []interface{}) bool

返回true 则自动清理数据 如果返回false则不清理

type TimeGroup

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

func NewTimeGroup

func NewTimeGroup(loopTime time.Duration, clearTick time.Duration, limit int) *TimeGroup

func (*TimeGroup) AddCount

func (t *TimeGroup) AddCount(key interface{}) bool

func (*TimeGroup) AddLimitMap

func (t *TimeGroup) AddLimitMap(key interface{}) bool

func (*TimeGroup) ClearMemory

func (t *TimeGroup) ClearMemory()

func (*TimeGroup) Stop

func (t *TimeGroup) Stop()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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