File: queue_generic.go

package info (click to toggle)
golang-github-cheekybits-genny 1.0.0-8
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 336 kB
  • sloc: makefile: 17; sh: 3
file content (33 lines) | stat: -rw-r--r-- 739 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package example

import "github.com/cheekybits/genny/generic"

type Generic generic.Type

// GenericQueue represents a queue of Generic types.
type GenericQueue struct {
	items []Generic
}

// NewGenericQueue makes a new empty Generic queue.
func NewGenericQueue() *GenericQueue {
	return &GenericQueue{items: make([]Generic, 0)}
}

// Enq adds an item to the queue.
func (q *GenericQueue) Enq(obj Generic) *GenericQueue {
	q.items = append(q.items, obj)
	return q
}

// Deq removes and returns the next item in the queue.
func (q *GenericQueue) Deq() Generic {
	obj := q.items[0]
	q.items = q.items[1:]
	return obj
}

// Len gets the current number of Generic items in the queue.
func (q *GenericQueue) Len() int {
	return len(q.items)
}