Add npq package.
This commit is contained in:
20
mq/lib.go
20
mq/lib.go
@@ -7,8 +7,8 @@
|
||||
// For example:
|
||||
//
|
||||
// q := mq.Make[string](8)
|
||||
// mq.SendLow("world")
|
||||
// mq.SendHigh("hello")
|
||||
// q.SendLow("world")
|
||||
// q.SendHigh("hello")
|
||||
// word1, _ := mq.Recv()
|
||||
// word2, _ := mq.Recv()
|
||||
// fmt.Println(word1, word2)
|
||||
@@ -17,23 +17,27 @@
|
||||
//
|
||||
// # Implementation
|
||||
//
|
||||
// Each queue has two circular buffers, one for each priority level.
|
||||
// Currently, the capacities for these are fixed and equal. If one buffer is
|
||||
// full, attempts to send further items with its priority level will block
|
||||
// Each [Q] has two circular buffers, one for each priority level. Currently,
|
||||
// the capacities for these are fixed and equal. If one buffer is full,
|
||||
// attempts to send further items with its priority level will block
|
||||
// ([Q.Send]) or fail ([Q.TrySend]).
|
||||
//
|
||||
// Compared the pq package, the limitation on priority levels increases
|
||||
// performance, as its circular buffers are much less expensive than the heap
|
||||
// operations of a traditional priority queue.
|
||||
// Compared [pq.Q], the limitation on priority levels increases performance,
|
||||
// as its circular buffers are much less expensive than the heap operations of
|
||||
// a traditional priority queue.
|
||||
package mq
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"gogs.humancabbage.net/sam/priorityq"
|
||||
"gogs.humancabbage.net/sam/priorityq/pq"
|
||||
"gogs.humancabbage.net/sam/priorityq/queue"
|
||||
)
|
||||
|
||||
// so that godoc (kinda) works
|
||||
var _ *pq.Q[int, int]
|
||||
|
||||
// Q is a concurrent, dual-priority message queue.
|
||||
type Q[T any] struct {
|
||||
*state[T]
|
||||
|
Reference in New Issue
Block a user