TUN-528: Move cloudflared into a separate repo

This commit is contained in:
Areg Harutyunyan
2018-05-01 18:45:06 -05:00
parent e8c621a648
commit d06fc520c7
4726 changed files with 1763680 additions and 0 deletions

View 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
}

View File

@@ -0,0 +1,50 @@
package queue
import (
"testing"
)
func Test(t *testing.T) {
q := New()
if q.Len() != 0 {
t.Errorf("Length should be 0")
}
q.Enqueue(1)
if q.Len() != 1 {
t.Errorf("Length should be 1")
}
if q.Peek().(int) != 1 {
t.Errorf("Enqueued value should be 1")
}
v := q.Dequeue()
if v.(int) != 1 {
t.Errorf("Dequeued value should be 1")
}
if q.Peek() != nil || q.Dequeue() != nil {
t.Errorf("Empty queue should have no values")
}
q.Enqueue(1)
q.Enqueue(2)
if q.Len() != 2 {
t.Errorf("Length should be 2")
}
if q.Peek().(int) != 1 {
t.Errorf("First value should be 1")
}
q.Dequeue()
if q.Peek().(int) != 2 {
t.Errorf("Next value should be 2")
}
}