Package list golang-gopkg-eapache-queue.v1 / c0c762f
Merge pull request #4 from eapache/cleanup Cleanup Evan Huus 6 years ago
3 changed file(s) with 11 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
00 language: go
1 sudo: false
12
23 go:
3 - 1.2
4 - 1.3
5 - 1.4
4 - 1.2
5 - 1.3
6 - 1.4
1616
1717 // New constructs and returns a new Queue.
1818 func New() *Queue {
19 return &Queue{buf: make([]interface{}, minQueueLen)}
19 return &Queue{
20 buf: make([]interface{}, minQueueLen),
21 }
2022 }
2123
2224 // Length returns the number of elements currently stored in the queue.
2426 return q.count
2527 }
2628
29 // resizes the queue to fit exactly twice its current contents
30 // this can result in shrinking if the queue is less than half-full
2731 func (q *Queue) resize() {
2832 newBuf := make([]interface{}, q.count*2)
2933
6266 // Get returns the element at index i in the queue. If the index is
6367 // invalid, the call will panic.
6468 func (q *Queue) Get(i int) interface{} {
65 if i >= q.count || i < 0 {
69 if i < 0 || i >= q.count {
6670 panic("queue: Get() called with index out of range")
6771 }
6872 return q.buf[(q.head+i)%len(q.buf)]
7781 q.buf[q.head] = nil
7882 q.head = (q.head + 1) % len(q.buf)
7983 q.count--
80 if len(q.buf) > minQueueLen && q.count*4 <= len(q.buf) {
84 if len(q.buf) > minQueueLen && q.count*4 == len(q.buf) {
8185 q.resize()
8286 }
8387 }
118118 defer func() {
119119 if r := recover(); r == nil {
120120 t.Errorf("%s: didn't panic as expected", name)
121 } else {
122 t.Logf("%s: got panic as expected: %v", name, r)
123121 }
124122 }()
125123