summaryrefslogtreecommitdiff
path: root/queue/elementarypriority.go
diff options
context:
space:
mode:
Diffstat (limited to 'queue/elementarypriority.go')
-rw-r--r--queue/elementarypriority.go24
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