From 0c6d4ed2e499e3e17165e43803d0d1c6dd0956d9 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 2 Apr 2023 20:22:13 +0300 Subject: initial generics --- queue/elementarypriority.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'queue/elementarypriority.go') diff --git a/queue/elementarypriority.go b/queue/elementarypriority.go index a0bbfba..391d948 100644 --- a/queue/elementarypriority.go +++ b/queue/elementarypriority.go @@ -4,26 +4,26 @@ import ( "codeberg.org/snonux/algorithms/ds" ) -type ElementaryPriority struct { - a ds.ArrayList +type ElementaryPriority[T ds.Number] struct { + a ds.ArrayList[T] // Initial capacity capacity int } -func NewElementaryPriority(capacity int) *ElementaryPriority { - return &ElementaryPriority{make(ds.ArrayList, 0, capacity), capacity} +func NewElementaryPriority[T ds.Number](capacity int) *ElementaryPriority[T] { + return &ElementaryPriority[T]{make(ds.ArrayList[T], 0, capacity), capacity} } -func (q *ElementaryPriority) Insert(a int) { +func (q *ElementaryPriority[T]) Insert(a T) { q.a = append(q.a, a) } -func (q *ElementaryPriority) Max() (max int) { +func (q *ElementaryPriority[T]) Max() (max T) { _, max = q.max() return } -func (q *ElementaryPriority) DeleteMax() int { +func (q *ElementaryPriority[T]) DeleteMax() T { if q.Empty() { return 0 } @@ -37,19 +37,19 @@ func (q *ElementaryPriority) DeleteMax() int { return max } -func (q *ElementaryPriority) Empty() bool { +func (q *ElementaryPriority[T]) Empty() bool { return q.Size() == 0 } -func (q *ElementaryPriority) Size() int { +func (q *ElementaryPriority[T]) Size() int { return len(q.a) } -func (q *ElementaryPriority) Clear() { - q.a = make(ds.ArrayList, 0, q.capacity) +func (q *ElementaryPriority[T]) Clear() { + q.a = make(ds.ArrayList[T], 0, q.capacity) } -func (q *ElementaryPriority) max() (ind, max int) { +func (q *ElementaryPriority[T]) max() (ind int, max T) { for i, a := range q.a { if a > max { ind, max = i, a -- cgit v1.2.3