Use algorithm that doesn't allocate the memory it doesn't need.

This makes the swap usable with huge objects.