From 179b97636a3ce58e62c6e2d01929b6513b943cf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nojus=20Gudinavi=C4=8Dius?= Date: Sun, 7 Jan 2024 16:45:48 +0200 Subject: [PATCH] heap: clone the variadic slice in Heap.From One should use heap.FromSlice to specifify the backing slice. --- heap/heap.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/heap/heap.go b/heap/heap.go index 7bc8bc0..6e14b2c 100644 --- a/heap/heap.go +++ b/heap/heap.go @@ -4,6 +4,8 @@ package heap import ( + "slices" + g "github.com/zyedidia/generic" ) @@ -23,7 +25,7 @@ func New[T any](less g.LessFn[T]) *Heap[T] { // From returns a new heap with the given less function and initial data. func From[T any](less g.LessFn[T], t ...T) *Heap[T] { - return FromSlice(less, t) + return FromSlice(less, slices.Clone(t)) } // FromSlice returns a new heap with the given less function and initial data.