From 24996416c11942abe22b1e3c1dee29243fd55fd1 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 24 Aug 2020 14:44:34 +0100 Subject: benchmark of pq --- queue/elementarypq.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'queue/elementarypq.go') diff --git a/queue/elementarypq.go b/queue/elementarypq.go index 31cab9f..1155cb4 100644 --- a/queue/elementarypq.go +++ b/queue/elementarypq.go @@ -5,10 +5,12 @@ import "algorithms/ds" type ElementaryPQ struct { a ds.ArrayList size int + // Initial capacity + capacity int } func NewElementaryPQ(capacity int) ElementaryPQ { - return ElementaryPQ{make(ds.ArrayList, 0, capacity), 0} + return ElementaryPQ{make(ds.ArrayList, 0, capacity), 0, capacity} } func (q ElementaryPQ) Insert(a int) { @@ -43,6 +45,11 @@ func (q ElementaryPQ) Size() int { return q.size } +func (q ElementaryPQ) Clear() { + q.size = 0 + q.a = make(ds.ArrayList, 0, q.capacity) +} + func (q ElementaryPQ) max() (ind, max int) { for i, a := range q.a { if a > max { -- cgit v1.2.3