From 1f0c0866a764b238f49fb875fb8302cf57db8369 Mon Sep 17 00:00:00 2001 From: Steve Dudenhoeffer Date: Sat, 15 Oct 2022 10:25:40 -0400 Subject: [PATCH] added a ForEach to priority queue to peek at contents --- priorityqueue.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/priorityqueue.go b/priorityqueue.go index bfc28ec..df99903 100644 --- a/priorityqueue.go +++ b/priorityqueue.go @@ -77,3 +77,12 @@ func (q *PriorityQueue[T]) Clear() { q.items = []*element[T]{} } + +func (q *PriorityQueue[T]) ForEach(fn func(*T)) { + q.lock.RLock() + defer q.lock.RUnlock() + + for _, v := range q.items { + fn(&v.value) + } +}