[API Review] PriorityQueue APIs

Making a comparison to OperationQueue (which is a kind-of priority queue of operations to be done) this type seems to to not preserve the order of insert of like prioritized items whereas OperationQueue does.


struct Prioritized<Content>: Comparable {
  var content: Content
  var priority: Int = 0
  
  static func == (_ lhs: Prioritized, _ rhs: Prioritized) -> Bool {
    return lhs.priority == rhs.priority
  }
  
  static func < (_ lhs: Prioritized, _ rhs: Prioritized) -> Bool {
    return lhs.priority < rhs.priority
  }
}

var queue = PriorityQueue<Prioritized<String>>()
queue.insert(contentsOf: [
  .init(content: "foo 0"),
  .init(content: "foo 1", priority: 1),
  .init(content: "bar 0"),
  .init(content: "bar 1", priority: 1),
  .init(content: "baz 0"),
  .init(content: "baz 1", priority: 1),
])

while let item = queue.popMax() {
  print(item.content)
}

I would expect to produce printing:

foo 1
bar 1
baz 1
foo 0
bar 0
baz 0

It does not seem to preserve that order of insertion.