diff --git a/.travis.yml b/.travis.yml index 652a7e3..235a40a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: go +sudo: false go: - - 1.2 - - 1.3 - - 1.4 + - 1.2 + - 1.3 + - 1.4 diff --git a/queue.go b/queue.go index f6126ba..1b3e168 100644 --- a/queue.go +++ b/queue.go @@ -17,7 +17,9 @@ // New constructs and returns a new Queue. func New() *Queue { - return &Queue{buf: make([]interface{}, minQueueLen)} + return &Queue{ + buf: make([]interface{}, minQueueLen), + } } // Length returns the number of elements currently stored in the queue. @@ -25,6 +27,8 @@ return q.count } +// resizes the queue to fit exactly twice its current contents +// this can result in shrinking if the queue is less than half-full func (q *Queue) resize() { newBuf := make([]interface{}, q.count*2) @@ -63,7 +67,7 @@ // Get returns the element at index i in the queue. If the index is // invalid, the call will panic. func (q *Queue) Get(i int) interface{} { - if i >= q.count || i < 0 { + if i < 0 || i >= q.count { panic("queue: Get() called with index out of range") } return q.buf[(q.head+i)%len(q.buf)] @@ -78,7 +82,7 @@ q.buf[q.head] = nil q.head = (q.head + 1) % len(q.buf) q.count-- - if len(q.buf) > minQueueLen && q.count*4 <= len(q.buf) { + if len(q.buf) > minQueueLen && q.count*4 == len(q.buf) { q.resize() } } diff --git a/queue_test.go b/queue_test.go index ccab3ee..f2765c1 100644 --- a/queue_test.go +++ b/queue_test.go @@ -119,8 +119,6 @@ defer func() { if r := recover(); r == nil { t.Errorf("%s: didn't panic as expected", name) - } else { - t.Logf("%s: got panic as expected: %v", name, r) } }()