https://github.com/vedhavyas/queue
Queue FIFO implementation in Go
https://github.com/vedhavyas/queue
fifo go queue
Last synced: about 1 year ago
JSON representation
Queue FIFO implementation in Go
- Host: GitHub
- URL: https://github.com/vedhavyas/queue
- Owner: vedhavyas
- License: apache-2.0
- Created: 2017-08-06T09:12:31.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-09-10T05:33:14.000Z (over 8 years ago)
- Last Synced: 2025-01-31T07:33:04.981Z (over 1 year ago)
- Topics: fifo, go, queue
- Language: Go
- Homepage:
- Size: 13.7 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# queue
--
import "github.com/vedhavyas/queue"
## Usage
#### type Queue
```go
type Queue struct {}
```
Queue represents the FIFO list of items
#### func (*Queue) Dequeue
```go
func (q *Queue) Dequeue() (interface{}, error)
```
Dequeue returns the first item from queue: O(1)
Returns an error if queue empty/out of bounds
#### func (*Queue) Enqueue
```go
func (q *Queue) Enqueue(item interface{})
```
Enqueue add the item to the queue: O(1)
#### func (*Queue) Get
```go
func (q *Queue) Get(i int) (interface{}, error)
```
Get returns the item at the given index from the list: O(n)
Returns an error if queue empty/out of bounds
#### func (*Queue) Len
```go
func (q *Queue) Len() int
```
Len returns the items count in the queue
#### func (*Queue) Peak
```go
func (q *Queue) Peak() (interface{}, error)
```
Peak returns the next value in queue but does not remove from queue: O(1)
Returns error if queue empty
#### func (*Queue) PeakAt
```go
func (q *Queue) PeakAt(i int) (interface{}, error)
```
PeakAt returns the item at the index i from the queue: O(n)
Returns error if queue empty/out of bounds
#### func (*Queue) String
```go
func (q *Queue) String() string
```
String dumps the queue in human readable format: O(n)