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) + } +}