mirror of
https://github.com/v2ray/v2ray-core.git
synced 2026-11-24 15:18:44 +00:00
rewrite id hash queue
This commit is contained in:
1 parent
8f1c4b7f71
commit
ea080b2ebf
4 files changed
+68
-190
No files matched your search
@@ -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
|
||||
}
|
||||
Reference in new issue
Block a user