diff options
| author | Paul Buetow <pbuetow@mimecast.com> | 2020-08-24 14:44:34 +0100 |
|---|---|---|
| committer | Paul Buetow <pbuetow@mimecast.com> | 2020-08-24 14:44:34 +0100 |
| commit | 24996416c11942abe22b1e3c1dee29243fd55fd1 (patch) | |
| tree | b090eb27d9aabe9ff7e61cc3caf79ef6c778d3f0 /queue/elementarypq.go | |
| parent | 4098a882ca0dfa1f785ecf5800cb1efcbcfe44a4 (diff) | |
benchmark of pq
Diffstat (limited to 'queue/elementarypq.go')
| -rw-r--r-- | queue/elementarypq.go | 9 |
1 files changed, 8 insertions, 1 deletions
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 { |
