feat: Add equivalent trait support for flexible key lookups by liwenjieQu · Pull Request #74 · garro95/priority-queue

This PR adds support for the Equivalent trait to enable flexible key lookups in both PriorityQueue and DoublePriorityQueue.

Background

The underlying IndexMap uses the Equivalent trait as the boundary for input types in lookup operations. This PR updates the trait bounds for priority queue APIs to align with this requirement, replacing the previous Borrow<Q> pattern.

Changes

  • Updated method signatures for lookup operations (get_priority, contains, change_priority, get, get_mut, remove) to use Equivalent<I> trait bounds
  • Added comprehensive tests covering both blanket implementations and custom equivalent types

Backward Compatibility

This change maintains full backward compatibility. Existing code that satisfied the previous trait bound:

I: Borrow<Q>,
Q: Eq + Hash + ?Sized,

continues to work without modification thanks to the blanket implementation provided by the equivalent crate. Users can now implement custom Equivalent traits for flexible key lookups.