The `node_swap` function is slow for many swaps but can be made much faster with a dictionary mapping