代码拉取完成,页面将自动刷新
package manager
type Queue struct {
PoolSize int
PoolChan chan interface{}
}
func NewQueue(size int) *Queue {
return &Queue{
PoolSize: size,
PoolChan: make(chan interface{}, size),
}
}
func (this *Queue) Init(size int) *Queue {
this.PoolSize = size
this.PoolChan = make(chan interface{}, size)
return this
}
func (this *Queue) Push(i interface{}) bool {
if len(this.PoolChan) == this.PoolSize {
return false
}
this.PoolChan <- i
return true
}
func (this *Queue) PushSlice(s []interface{}) {
for _, i := range s {
this.Push(i)
}
}
func (this *Queue) Pull() interface{} {
return <-this.PoolChan
}
// 二次使用Queue实例时,根据容量需求进行高效转换
func (this *Queue) Exchange(num int) (add int) {
last := len(this.PoolChan)
if last >= num {
add = int(0)
return
}
if this.PoolSize < num {
pool := []interface{}{}
for i := 0; i < last; i++ {
pool = append(pool, <-this.PoolChan)
}
// 重新定义、赋值
this.Init(num).PushSlice(pool)
}
add = num - last
return
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。