From e161de188103dab9da154f9517b364290e712054 Mon Sep 17 00:00:00 2001 From: Gregory Date: Sat, 1 Jan 2022 21:24:19 +0200 Subject: [PATCH] comment about resize optimization --- sorting/priority_queue.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sorting/priority_queue.go b/sorting/priority_queue.go index 5a4ebb1..fea5b3c 100644 --- a/sorting/priority_queue.go +++ b/sorting/priority_queue.go @@ -34,7 +34,13 @@ func (pq *priorityQueue[T]) top() T { } func (pq *priorityQueue[T]) insert(item T) { - // TODO: increase by square when capacity is full + // We can ignore "resize optimization": + // append function will create new array for new slice + // with doubled capacity when needed + // https://github.com/golang/go/blob/master/src/runtime/slice.go#L188 + // https://go.dev/blog/slices-intro + // https://go.dev/play/p/OKtCFskbp2t + // https://stackoverflow.com/questions/23531737/how-the-slice-is-enlarged-by-append-is-the-capacity-always-doubled pq.heap = append(pq.heap, item) pq.n++ pq.swim(pq.n)