I’d like to rethink about the idea of struct Prioritized<Content>. IMO strongly tying the content with priority will give far more flexibility and better performance.
One prior concern is that PriorityQueue<Prioritized<String>> will have an award interface like queue.insert(.init("Hello", priority: 1)). There is exactly a pitch that can solve such syntax:
The @expanded mark will automatically imply .init() in function parameters, giving a cleaner expression of queue.insert("Hello", priority: 1), which is exactly the same as the current one.
One big improvement is, when sometimes the content itself can imply its priority we can now have:
enum Task: Int, PriorityProtocol {
case pending = 0
case simple
case urgent
let priority: Int { self.rawValue }
}
var queue = PriorityQueue<Task>()
queue.insert(.urgent)
queue.insert(.pending)
queue.removeMax() // Task.urgent
The interface should get cleaner and have better robustness.