diff options
| author | Paul Buetow <paul@buetow.org> | 2023-04-02 20:22:13 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2023-04-02 20:22:13 +0300 |
| commit | 0c6d4ed2e499e3e17165e43803d0d1c6dd0956d9 (patch) | |
| tree | 6d6a5df53d1dd3e655d24f0423f24bc52ad9784c /queue/elementarypriority.go | |
| parent | f78ba2cdc6840dbc52a27a2f9fac28f3b61e8b7b (diff) | |
initial generics
Diffstat (limited to 'queue/elementarypriority.go')
| -rw-r--r-- | queue/elementarypriority.go | 24 |
1 files changed, 12 insertions, 12 deletions
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 |
