Is NativeMultiHashMap Enumerator guarunteed to return values with the same key together?

I don’t much care about the individual order of the keys or values, but I need values for the same key to be grouped together. Would a normal foreach() through a NativeMultiHashMap guarantee that items with the same key will be grouped together?

If not, what is the most performant way to do that? (from inside a job – i know about IJobNativeMultiHashMapVisitKeyMultipleValues, but in my case the whole map lives only within the scope of one job)

EDIT: AFAICT, they will end up in the same bucket, but if another element has the same hash (modulo bucket count), it’s possible for it to get in between. So enumerator is not properly ordered. Am I correct in that assumption?

You want to use, TryGetFirstValue, TryGetNextValue in nmhm.
You pass a key int TryGetFirstValue.
You may want get unique keys to an array first.

Yes.

Another method would be to use GetKeyValueArrays and sort them by key.