github.com/songzhibin97/go-baseutils@v0.0.2-0.20240302024150-487d8ce9c082/structure/queues/queues.go (about) 1 // Package queues provides an abstract Queue interface. 2 // 3 // In computer science, a queue is a collection of entities that are maintained in a sequence and can be modified by the addition of entities at one end of the sequence and the removal of entities from the other end of the sequence. By convention, the end of the sequence at which elements are added is called the back, tail, or rear of the queue, and the end at which elements are removed is called the head or front of the queue, analogously to the words used when people line up to wait for goods or services. 4 // The operation of adding an element to the rear of the queue is known as enqueue, and the operation of removing an element from the front is known as dequeue. Other operations may also be allowed, often including a peek or front operation that returns the value of the next element to be dequeued without remove it. 5 // 6 // Reference: https://en.wikipedia.org/wiki/Queue_(abstract_data_type) 7 package queues 8 9 import "github.com/songzhibin97/go-baseutils/structure/containers" 10 11 // Queue interface that all queues implement 12 type Queue[E any] interface { 13 Enqueue(value E) 14 Dequeue() (value E, ok bool) 15 Peek() (value E, ok bool) 16 17 containers.Container[E] 18 // Empty() bool 19 // Size() int 20 // Clear() 21 // Values() []E{} 22 // String() string 23 }