1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-09 13:34:34 -04:00
v2fly/common/collect/sized_queue.go
2016-01-11 22:51:35 +01:00

25 lines
527 B
Go

package collect
type SizedQueue struct {
elements []interface{}
nextPos int
}
func NewSizedQueue(size int) *SizedQueue {
return &SizedQueue{
elements: make([]interface{}, size),
nextPos: 0,
}
}
// Put puts a new element into the queue and pop out the first element if queue is full.
func (this *SizedQueue) Put(element interface{}) interface{} {
res := this.elements[this.nextPos]
this.elements[this.nextPos] = element
this.nextPos++
if this.nextPos == len(this.elements) {
this.nextPos = 0
}
return res
}