Skip to content

Commit

Permalink
queue: add constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
creachadair committed Jan 19, 2024
1 parent 01b8ae1 commit 760ce9a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions queue/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ type Queue[T any] struct {
n int
}

// New constructs a new empty queue.
func New[T any]() *Queue[T] { return new(Queue[T]) }

// NewSize constructs a new empty queue with storage pre-allocated for n items.
// The queue will automatically grow beyond the initial size as needed.
func NewSize[T any](n int) *Queue[T] { return &Queue[T]{vs: make([]T, n)} }

// Add adds v to the end of q.
func (q *Queue[T]) Add(v T) {
if q.n < len(q.vs) {
Expand Down

0 comments on commit 760ce9a

Please sign in to comment.