Get returns the element at index i in the queue. If the index is invalid, the call will panic. This method accepts both positive and negative index values. Index 0 refers to the first element, and index -1 refers to the last.
(i int)
| 72 | // negative index values. Index 0 refers to the first element, and |
| 73 | // index -1 refers to the last. |
| 74 | func (q *Queue) Get(i int) interface{} { |
| 75 | // If indexing backwards, convert to positive index. |
| 76 | if i < 0 { |
| 77 | i += q.count |
| 78 | } |
| 79 | if i < 0 || i >= q.count { |
| 80 | panic("queue: Get() called with index out of range") |
| 81 | } |
| 82 | // bitwise modulus |
| 83 | return q.buf[(q.head+i)&(len(q.buf)-1)] |
| 84 | } |
| 85 | |
| 86 | // Remove removes and returns the element from the front of the queue. If the |
| 87 | // queue is empty, the call will panic. |
no outgoing calls