Be less destructive to any input array ref to set_by_frequency.
Fail if root frequency zero (to avoid /0).