We've got a prioritized message queue, not a priority queue.

This commit is contained in:
Sam Fredrickson 2023-03-01 13:39:19 -08:00
parent c4e92faaf7
commit 0759aaa2cd
2 changed files with 8 additions and 8 deletions

View File

@ -1,4 +1,4 @@
# priorityq - generic priority queue in Go
# priorityq - generic prioritized message queue in Go
This module was inspired by [a reddit post][reddit] wherein /u/zandery23 asked
how to implement a priority queue in Go. A fantastic solution was [provided by
@ -6,7 +6,7 @@ how to implement a priority queue in Go. A fantastic solution was [provided by
not completely precise.
Particularly, the second select block does not guarantee that an item from the
priority queue will be taken if there is also an item in the regular queue.
prioritized queue will be taken if there is also an item in the regular queue.
```go
select {
@ -26,10 +26,10 @@ From the [Go Language Specification][go_select]:
Thus, it is possible for the second case to be chosen even if the first case is
also ready.
The `precise` package in this module implements a concurrent priority queue that
guarantees receipt of a high-priority items before low-priority ones. This is
primarily a fun exercise, I cannot recommend that anyone actually use this in a
real project.
The `precise` package in this module implements a concurrent, prioritized
message queue that guarantees receipt of a high-priority items before
low-priority ones. This is primarily a fun exercise, I cannot recommend that
anyone actually use this in a real project.
[reddit]: https://www.reddit.com/r/golang/comments/11drc17/worker_pool_reading_from_two_channels_one_chan/
[sol]: https://www.reddit.com/r/golang/comments/11drc17/worker_pool_reading_from_two_channels_one_chan/jabfvkh/

View File

@ -6,7 +6,7 @@ import (
"gogs.humancabbage.net/sam/priorityq/circ"
)
// Q is a precise, concurrent priority queue.
// Q is a precise, concurrent, prioritized message queue.
//
// Each queue has two internal buffers, high and low. This implementation
// guarantees that when there are items in both buffers, consumers receive
@ -18,7 +18,7 @@ type Q[T any] struct {
*state[T]
}
// Make a new priority queue.
// Make a new queue.
func Make[T any](cap int) Q[T] {
high := circ.Make[T](cap)
low := circ.Make[T](cap)