From 693f0a174a8b062529a7334796c5c21487ed39c2 Mon Sep 17 00:00:00 2001 From: jinwoo1225 Date: Sat, 26 Aug 2023 21:25:46 +0900 Subject: [PATCH] deep copy in range --- priority_queue.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/priority_queue.go b/priority_queue.go index 6b58e43..eb9a501 100644 --- a/priority_queue.go +++ b/priority_queue.go @@ -76,9 +76,13 @@ func (h *PriorityQueue[T]) Range() []Item[T] { h.mu.RLock() defer h.mu.RUnlock() - var items []Item[T] + items := make([]Item[T], 0, h.internalHeap.Len()) for _, item := range h.internalHeap.items { - items = append(items, item) + items = append(items, Item[T]{ + Value: item.Value, + Priority: item.Priority, + index: item.index, + }) } return items