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