Skip to content

Commit

Permalink
deep copy in range
Browse files Browse the repository at this point in the history
  • Loading branch information
jinwoo1225 committed Aug 26, 2023
1 parent 3c5bae0 commit 693f0a1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions priority_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 693f0a1

Please sign in to comment.