lib/std: improve implementation of `Set.hash` and `Sequence.hash`