public static unsafe void Execute(ref JobNativeMultiHashMapVisitKeyValueProducer <TJob, TKey, TValue> producer, IntPtr additionalPtr, IntPtr bufferRangePatchData, ref JobRanges ranges, int jobIndex) { while (true) { int begin; int end; if (!JobsUtility.GetWorkStealingRange(ref ranges, jobIndex, out begin, out end)) { return; } var hashMapData = producer.HashMap.GetUnsafeBucketData(); var buckets = (int *)hashMapData.buckets; var nextPtrs = (int *)hashMapData.next; var keys = hashMapData.keys; var values = hashMapData.values; for (int i = begin; i < end; i++) { int entryIndex = buckets[i]; while (entryIndex != -1) { var key = UnsafeUtility.ReadArrayElement <TKey>(keys, entryIndex); var value = UnsafeUtility.ReadArrayElement <TValue>(values, entryIndex); producer.JobData.ExecuteNext(key, value); entryIndex = nextPtrs[entryIndex]; } } } }
public static unsafe JobHandle Schedule <TJob, TKey, TValue>(this TJob jobData, NativeParallelMultiHashMap <TKey, TValue> hashMap, int minIndicesPerJobCount, JobHandle dependsOn = new JobHandle()) where TJob : struct, IJobNativeMultiHashMapVisitKeyValue <TKey, TValue> where TKey : struct, IEquatable <TKey> where TValue : struct { var jobProducer = new JobNativeMultiHashMapVisitKeyValueProducer <TJob, TKey, TValue> { HashMap = hashMap, JobData = jobData }; var scheduleParams = new JobsUtility.JobScheduleParameters( UnsafeUtility.AddressOf(ref jobProducer) , JobNativeMultiHashMapVisitKeyValueProducer <TJob, TKey, TValue> .Initialize() , dependsOn #if UNITY_2020_2_OR_NEWER , ScheduleMode.Parallel #else , ScheduleMode.Batched #endif ); return(JobsUtility.ScheduleParallelFor(ref scheduleParams, hashMap.GetUnsafeBucketData().bucketCapacityMask + 1, minIndicesPerJobCount)); }