Rename priorityqueues to priorityqueue again

This commit is contained in:
Balint Gabor 2018-01-02 17:12:15 +01:00
parent 974536d1cf
commit b5fb850d1b

View file

@ -1,4 +1,4 @@
// package priority_queues implement a channel based priority queue
// package priority_queue implement a channel based priority queue
// over arbitrary types. It provides an
// an autopop loop applying a function to the items always respecting
// their priority. The structure is only quasi consistent ie., if a lower
@ -7,7 +7,7 @@
// that there was any point where the lower priority item was present
// but the higher was not
package priorityqueues
package priorityqueue
import (
"context"
@ -21,26 +21,26 @@ var (
wakey = struct{}{}
)
// PriorityQueues is the basic structure
type PriorityQueues struct {
// PriorityQueue is the basic structure
type PriorityQueue struct {
queues []chan interface{}
wakeup chan struct{}
}
// New is the constructor for PriorityQueues
func New(n int, l int) *PriorityQueues {
// New is the constructor for PriorityQueue
func New(n int, l int) *PriorityQueue {
var queues = make([]chan interface{}, n)
for i := range queues {
queues[i] = make(chan interface{}, l)
}
return &PriorityQueues{
return &PriorityQueue{
queues: queues,
wakeup: make(chan struct{}, 1),
}
}
// Run is a forever loop popping items from the queues
func (pq *PriorityQueues) Run(ctx context.Context, f func(interface{})) {
func (pq *PriorityQueue) Run(ctx context.Context, f func(interface{})) {
top := len(pq.queues) - 1
p := top
q := pq.queues[p]
@ -70,7 +70,7 @@ READ:
// Push pushes an item to the appropriate queue specified in the priority argument
// if context is given it waits until either the item is pushed or the Context aborts
// otherwise returns errContention if the queue is full
func (pq *PriorityQueues) Push(ctx context.Context, x interface{}, p int) error {
func (pq *PriorityQueue) Push(ctx context.Context, x interface{}, p int) error {
if p < 0 || p >= len(pq.queues) {
return errBadPriority
}