Package list golang-gopkg-eapache-queue.v1 / ad0f934
Update docs to mention panics for bad accesses. Antoine Grondin 7 years ago
1 changed file(s) with 7 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
22 Using this instead of other, simpler, queue implementations (slice+append or linked list) provides
33 substantial memory and time benefits, and fewer GC pauses.
44
5 The queue implemented here is as fast as it is for two additional reasons: it is *not* thread-safe, and it
6 intentionally does not follow go best-practices regarding errors - if you make a mistake with this
7 queue (such as trying to remove an element from an empty queue) then who knows what will happen.
5 The queue implemented here is as fast as it is for an additional reason: it is *not* thread-safe.
86 */
97 package queue
108
5250 q.count++
5351 }
5452
55 // Peek returns the element at the head of the queue. If the queue is empty (Length == 0),
56 // Peek does not panic, it simply returns garbage.
53 // Peek returns the element at the head of the queue. This call panics
54 // if the queue is empty.
5755 func (q *Queue) Peek() interface{} {
5856 if q.Length() <= 0 {
5957 panic("queue: empty queue")
6159 return q.buf[q.head]
6260 }
6361
64 // Get returns the element at index i in the queue. If the index is invalid, the
65 // call will panic.
62 // Get returns the element at index i in the queue. If the index is
63 // invalid, the call will panic.
6664 func (q *Queue) Get(i int) interface{} {
6765 if i >= q.Length() || i < 0 {
6866 panic("queue: index out of range")
7169 return q.buf[modi]
7270 }
7371
74 // Remove removes the element from the front of the queue. If you actually want the element,
75 // call Peek first. If the queue is empty (Length == 0), Remove will put the queue in a bad
76 // state and all further operations will be undefined.
72 // Remove removes the element from the front of the queue. If you actually
73 // want the element, call Peek first. This call panics if the queue is empty.
7774 func (q *Queue) Remove() {
7875 if q.Length() <= 0 {
7976 panic("queue: empty queue")