Skip to content

Commit

Permalink
Remove panics in queue
Browse files Browse the repository at this point in the history
Remove panics in queue
  • Loading branch information
cnderrauber committed Jul 1, 2024
1 parent 59cdb09 commit 86ae184
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 16 deletions.
11 changes: 0 additions & 11 deletions queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

package sctp

import "fmt"

type queue[T any] struct {
buf []T
head int
Expand Down Expand Up @@ -37,9 +35,6 @@ func (q *queue[T]) PushBack(ele T) {
}

func (q *queue[T]) PopFront() T {
if q.count <= 0 {
panic("PopFront() called on empty queue")
}
ele := q.buf[q.head]
var zeroVal T
q.buf[q.head] = zeroVal
Expand All @@ -49,16 +44,10 @@ func (q *queue[T]) PopFront() T {
}

func (q *queue[T]) Front() T {
if q.count <= 0 {
panic("Front() called on empty queue")
}
return q.buf[q.head]
}

func (q *queue[T]) At(i int) T {
if i < 0 || i >= q.count {
panic(fmt.Sprintf("index %d out of range %d", i, q.count))
}
return q.buf[(q.head+i)%(len(q.buf))]
}

Expand Down
5 changes: 0 additions & 5 deletions queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (

func TestQueue(t *testing.T) {
q := newQueue[int](32)
assert.Panics(t, func() { q.PopFront() })
assert.Panics(t, func() { q.Front() })
assert.Zero(t, q.Len())

// test push & pop
Expand All @@ -32,9 +30,6 @@ func TestQueue(t *testing.T) {
assert.Equal(t, 2, q.Len())
assert.Equal(t, 11, q.At(1))
assert.Equal(t, 10, q.Front())
assert.Panics(t, func() {
q.At(33)
})
assert.Equal(t, 10, q.PopFront())
assert.Equal(t, 11, q.PopFront())

Expand Down

0 comments on commit 86ae184

Please sign in to comment.