Skip to content

Token_swapper fails on graphs with edgeless nodes #994

@alexanderivrii

Description

@alexanderivrii

Information

Recently (see #971) the token swapper algorithm has been extended to support disconnected coupling maps, and in particular return an error rather than internally panic when swapping is not possible.

Here is an example where token swapper still internally panics.

let mut g = petgraph::graph::UnGraph::<(), ()>::new_undirected();
let a = g.add_node(());
let b = g.add_node(());
let c = g.add_node(());
let d = g.add_node(());
g.add_edge(c, d, ());
let mapping = HashMap::from([(a, b), (b, a)]);
let out = token_swapper(&g, mapping, Some(10), Some(4), Some(50));

Ideally this should return Err(MapNotPossible) instead of panicking:

panicked at 'index out of bounds: the len is 0 but the index is 0', rustworkx-core\src\token_swapper.rs:305:40

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions