rustworkx icon indicating copy to clipboard operation
rustworkx copied to clipboard

`token_swapper` to accept generic map-and-support for target description

Open jakelishman opened this issue 6 months ago • 2 comments

What is the expected enhancement?

Currently token_swapper requires a HashMap<G::NodeId, G::NodeId> to define the partial mapping that the token swapper is meant to effect. This is fine, but token_swapper takes ownership of the allocation and all that it's used for is to build up a separate HashMap (which in turn might not be terrible as a &[Option<G::NodeId>] where the index is the index into the internal Graph object's nodes, which can be arranged to be NodeCompactIndexable).

It could be convenient to be able to provide the "mapping" and "support" information in other ways - certainly in our use in Qiskit, being able to provide an immutable closure and an iterator would let us avoid heap allocations during making the call (and #1437 would let us avoid a heap allocation in the return value too).

It could potentially be implemented in a backwards compatible manner by making it generic over a trait that's automatically implemented for HashMap.

jakelishman avatar Apr 28 '25 20:04 jakelishman