mirror of
https://github.com/cloudflare/cloudflared.git
synced 2025-07-28 11:19:58 +00:00
TUN-528: Move cloudflared into a separate repo
This commit is contained in:
55
vendor/github.com/golang-collections/collections/queue/queue.go
generated
vendored
Normal file
55
vendor/github.com/golang-collections/collections/queue/queue.go
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
package queue
|
||||
|
||||
type (
|
||||
Queue struct {
|
||||
start, end *node
|
||||
length int
|
||||
}
|
||||
node struct {
|
||||
value interface{}
|
||||
next *node
|
||||
}
|
||||
)
|
||||
|
||||
// Create a new queue
|
||||
func New() *Queue {
|
||||
return &Queue{nil,nil,0}
|
||||
}
|
||||
// Take the next item off the front of the queue
|
||||
func (this *Queue) Dequeue() interface{} {
|
||||
if this.length == 0 {
|
||||
return nil
|
||||
}
|
||||
n := this.start
|
||||
if this.length == 1 {
|
||||
this.start = nil
|
||||
this.end = nil
|
||||
} else {
|
||||
this.start = this.start.next
|
||||
}
|
||||
this.length--
|
||||
return n.value
|
||||
}
|
||||
// Put an item on the end of a queue
|
||||
func (this *Queue) Enqueue(value interface{}) {
|
||||
n := &node{value,nil}
|
||||
if this.length == 0 {
|
||||
this.start = n
|
||||
this.end = n
|
||||
} else {
|
||||
this.end.next = n
|
||||
this.end = n
|
||||
}
|
||||
this.length++
|
||||
}
|
||||
// Return the number of items in the queue
|
||||
func (this *Queue) Len() int {
|
||||
return this.length
|
||||
}
|
||||
// Return the first item in the queue without removing it
|
||||
func (this *Queue) Peek() interface{} {
|
||||
if this.length == 0 {
|
||||
return nil
|
||||
}
|
||||
return this.start.value
|
||||
}
|
Reference in New Issue
Block a user