Algorithms for doing stuff with maps