rewrite id hash queue

This commit is contained in:
v2ray committed 2016-01-11 22:51:35 +01:00
1 parent 8f1c4b7f71
commit ea080b2ebf
4 files changed
+68 -190

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
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
}