public static unsafe void Execute(ref NativeMultiHashMapVisitKeyMutableValueJobStruct <TJob, TKey, TValue> fullData, 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 buckets = (int *)fullData.HashMap.m_MultiHashMapData.m_Buffer->buckets; var nextPtrs = (int *)fullData.HashMap.m_MultiHashMapData.m_Buffer->next; var keys = fullData.HashMap.m_MultiHashMapData.m_Buffer->keys; var values = fullData.HashMap.m_MultiHashMapData.m_Buffer->values; for (int i = begin; i < end; i++) { int entryIndex = buckets[i]; while (entryIndex != -1) { var key = UnsafeUtility.ReadArrayElement <TKey>(keys, entryIndex); fullData.JobData.ExecuteNext(key, ref UnsafeUtilityEx.ArrayElementAsRef <TValue>(values, entryIndex)); entryIndex = nextPtrs[entryIndex]; } } } }
/// <summary> /// /// </summary> /// <typeparam name="TJob"></typeparam> /// <typeparam name="TKey"></typeparam> /// <typeparam name="TValue"></typeparam> /// <param name="jobData"></param> /// <param name="hashMap"></param> /// <param name="minIndicesPerJobCount"></param> /// <param name="dependsOn"></param> /// <returns></returns> public static unsafe JobHandle Schedule <TJob, TKey, TValue>(this TJob jobData, NativeMultiHashMap <TKey, TValue> hashMap, int minIndicesPerJobCount, JobHandle dependsOn = new JobHandle()) where TJob : struct, IJobNativeMultiHashMapVisitKeyMutableValue <TKey, TValue> where TKey : struct, IEquatable <TKey> where TValue : struct { var fullData = new NativeMultiHashMapVisitKeyMutableValueJobStruct <TJob, TKey, TValue> { HashMap = hashMap, JobData = jobData }; var scheduleParams = new JobsUtility.JobScheduleParameters( UnsafeUtility.AddressOf(ref fullData) , NativeMultiHashMapVisitKeyMutableValueJobStruct <TJob, TKey, TValue> .Initialize() , dependsOn , ScheduleMode.Batched ); return(JobsUtility.ScheduleParallelFor(ref scheduleParams, hashMap.m_MultiHashMapData.m_Buffer->bucketCapacityMask + 1, minIndicesPerJobCount)); }