Is there a way to iterate over keys of a StorageMap?

Can I get a vector of keys stored in a storage map? Or should a separate storage vec be used for that?

This is not possible, as the storage keys are not actually stored on-chain (only the values).

If you need to iterate over storage keys (which is often not suggested), you can do so with a separate vector of keys.

Got it, thanks.

But if the storage keys are not stored on-chain, how do you handle hash collisions? The cases when the hash function returns the same result for two different storage keys