The doc string should specify that any pair with distance > limit will be set to distance = infinity.

Also, in the code we should enforce limit >= 0, otherwise this claim won't be true!