Unverified Commit ccf015ae authored by Clint Shryock's avatar Clint Shryock
Browse files

Make ErrItemNotFound a function so we can insert the key in the error

parent 8c483278
Showing with 8 additions and 7 deletions
+8 -7
......@@ -2,13 +2,9 @@ package queue
import (
"container/heap"
"errors"
"fmt"
)
// ErrNoItemFound is used in Pluck and Find, to indicate a matching item was not
// found
var ErrNoItemFound = errors.New("item not found in queue")
// PriorityQueue interface defines what a Queue must include, which is satisfying
// heap.Interface, and a few additional methods
// TODO: refactor to be just Queue, or add a generic Queue type that implements
......@@ -31,13 +27,18 @@ type PriorityQueue interface {
// Peek()
// Pluck removes an item from the queue by the given Key. Pluck must fix the
// queue after removal. If no item is removed, returns ErrNoItemFound
// queue after removal. If no item is removed, returns ErrItemNotFound
Pluck(string) (*Item, error)
// Find searches and returns item from the queue, if found. This does not
// remove the item. If no item is found, returns ErrNoItemFound
// remove the item. If no item is found, returns ErrItemNotFound
Find(string) (*Item, error)
// Size reports the number of items in the queue
// Size() int
}
// ErrItemNotFound creates a "not found" error for the given key
func ErrItemNotFound(key string) error {
return fmt.Errorf("queue item with key (%s) not found", key)
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment