Skip to content

Commit

Permalink
dep: deque lib update
Browse files Browse the repository at this point in the history
  • Loading branch information
vladopajic committed Nov 18, 2024
1 parent cdc774a commit aec646a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 27 deletions.
13 changes: 5 additions & 8 deletions actor/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ import (
)

func newQueue[T any](capacity int) *queue[T] {
minimum := capacity
if minimum < minQueueCapacity {
minimum = minQueueCapacity
}

return &queue[T]{
q: queueImpl.New[T](capacity, minimum),
}
q := &queueImpl.Deque[T]{}
q.SetBaseCap(max(minQueueCapacity, capacity))
q.Grow(capacity)

return &queue[T]{q}
}

type queue[T any] struct {
Expand Down
28 changes: 12 additions & 16 deletions actor/queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,31 +52,27 @@ func TestQueue_Basic(t *testing.T) {
func TestQueue_Cap(t *testing.T) {
t.Parallel()

{
q := NewQueue[any](10)
assert.Equal(t, MinQueueCapacity, q.Cap())
assert.Equal(t, 0, q.Len())
{ // push over capacity, then pop to zero
q := NewQueue[any](MinQueueCapacity / 2)
assert.Equal(t, MinQueueCapacity/2, q.Cap())

q.PushBack(`🌊`)
for range 2 * MinQueueCapacity {
q.PushBack(`🌊`)
}

assert.Equal(t, MinQueueCapacity, q.Cap())
assert.Equal(t, 1, q.Len())
}
assert.Equal(t, 2*MinQueueCapacity, q.Len())

for !q.IsEmpty() {
q.PopFront()
}

{
q := NewQueue[any](10)
assert.Equal(t, MinQueueCapacity, q.Cap())
assert.Equal(t, 0, q.Len())
}

{
{ // should used supplied capacity since value is larger then minimal
q := NewQueue[any](MinQueueCapacity * 2)
assert.Equal(t, MinQueueCapacity*2, q.Cap())
assert.Equal(t, 0, q.Len())

q.PushBack(`🌊`)

assert.Equal(t, MinQueueCapacity*2, q.Cap())
assert.Equal(t, 1, q.Len())
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/vladopajic/go-actor
go 1.23

require (
github.com/gammazero/deque v0.2.1
github.com/gammazero/deque v1.0.0
github.com/stretchr/testify v1.9.0
go.uber.org/goleak v1.3.0
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gammazero/deque v0.2.1 h1:qSdsbG6pgp6nL7A0+K/B7s12mcCY/5l5SIUpMOl+dC0=
github.com/gammazero/deque v0.2.1/go.mod h1:LFroj8x4cMYCukHJDbxFCkT+r9AndaJnFMuZDV34tuU=
github.com/gammazero/deque v1.0.0 h1:LTmimT8H7bXkkCy6gZX7zNLtkbz4NdS2z8LZuor3j34=
github.com/gammazero/deque v1.0.0/go.mod h1:iflpYvtGfM3U8S8j+sZEKIak3SAKYpA5/SQewgfXDKo=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
Expand Down

0 comments on commit aec646a

Please sign in to comment.