summaryrefslogtreecommitdiff
path: root/queue
diff options
context:
space:
mode:
authorPaul Buetow <pbuetow@mimecast.com>2020-08-24 18:15:52 +0100
committerPaul Buetow <pbuetow@mimecast.com>2020-08-24 18:15:52 +0100
commita49c86ec981becac036f590362933f183f5d1234 (patch)
tree2651b70f0ea53d4274674ffc7cf5bc0430e98147 /queue
parent44811a9f7bc84a642fd5805c964deb1ee7d134c5 (diff)
more on heapprio
Diffstat (limited to 'queue')
-rw-r--r--queue/elementarypriority.go15
-rw-r--r--queue/queue_test.go4
2 files changed, 9 insertions, 10 deletions
diff --git a/queue/elementarypriority.go b/queue/elementarypriority.go
index 508cbcb..d5b3f4a 100644
--- a/queue/elementarypriority.go
+++ b/queue/elementarypriority.go
@@ -1,21 +1,21 @@
package queue
-import "algorithms/ds"
+import (
+ "algorithms/ds"
+)
type ElementaryPriority struct {
- a ds.ArrayList
- size int
+ a ds.ArrayList
// Initial capacity
capacity int
}
func NewElementaryPriority(capacity int) *ElementaryPriority {
- return &ElementaryPriority{make(ds.ArrayList, 0, capacity), 0, capacity}
+ return &ElementaryPriority{make(ds.ArrayList, 0, capacity), capacity}
}
func (q *ElementaryPriority) Insert(a int) {
q.a = append(q.a, a)
- q.size++
}
func (q *ElementaryPriority) Max() (max int) {
@@ -32,7 +32,7 @@ func (q *ElementaryPriority) DeleteMax() int {
for i := ind + 1; i < q.Size(); i++ {
q.a[i-1] = q.a[i]
}
- q.size--
+ q.a = q.a[0 : len(q.a)-1]
return max
}
@@ -42,11 +42,10 @@ func (q *ElementaryPriority) Empty() bool {
}
func (q *ElementaryPriority) Size() int {
- return q.size
+ return len(q.a)
}
func (q *ElementaryPriority) Clear() {
- q.size = 0
q.a = make(ds.ArrayList, 0, q.capacity)
}
diff --git a/queue/queue_test.go b/queue/queue_test.go
index 25290f1..ba610e1 100644
--- a/queue/queue_test.go
+++ b/queue/queue_test.go
@@ -7,8 +7,8 @@ import (
)
const minLength int = 1
-const maxLength int = 10000
-const factor int = 100
+const maxLength int = 10
+const factor int = 10
// Store results here to avoid compiler optimizations
var benchResult ds.ArrayList