NewCircularQueue creates a new CircularQueue with the given size. Returns an error if the size is less than or equal to 0.
(size int)
| 27 | // NewCircularQueue creates a new CircularQueue with the given size. |
| 28 | // Returns an error if the size is less than or equal to 0. |
| 29 | func NewCircularQueue[T any](size int) (*CircularQueue[T], error) { |
| 30 | if size <= 0 { |
| 31 | return nil, errors.New("size must be greater than 0") |
| 32 | } |
| 33 | return &CircularQueue[T]{ |
| 34 | items: make([]T, size), |
| 35 | front: -1, |
| 36 | rear: -1, |
| 37 | size: size, |
| 38 | }, nil |
| 39 | } |
| 40 | |
| 41 | // Enqueue adds an item to the rear of the queue. |
| 42 | // Returns an error if the queue is full. |
nothing calls this directly
no outgoing calls
no test coverage detected