unique keys from NativeMultiHashMap?

NativeMultiHashMap store duplicated key internally. that match keys and values in terms of their index.
So NativeMultiHashMap.GetKeyArray() give you all the keys matching all the values.
GetUniqueKeyArray simply swap duplicated key to the end.
That why we got this wired pattern.
You’d better do this if in a burst job.

NativeMultiHashMap<int,int> dic=xxxx;
var withDuplicates= dic.GetKeyArray();
withDuplicates.Sort();
int uniqueCount = withDuplicates.Unique();

Because Tuple is not supported by burst. As for my test…

This is exactly what GetUniqueKeyArray() do, just not using Tuple.

1 Like