暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

NativeParallelMultiHashMapTestsFixture.cs 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using Unity.Jobs;
  2. using Unity.Collections;
  3. using Unity.Burst;
  4. using Unity.Collections.Tests;
  5. internal class NativeParallelMultiHashMapTestsFixture : CollectionsTestFixture
  6. {
  7. protected const int hashMapSize = 10 * 1024;
  8. [BurstCompile(CompileSynchronously = true)]
  9. public struct MultiHashMapSimpleWriteJob : IJob
  10. {
  11. public NativeParallelMultiHashMap<int, int>.ParallelWriter hashMap;
  12. public void Execute()
  13. {
  14. hashMap.Add(0, 0);
  15. }
  16. }
  17. // Burst error BC1005: The `try` construction is not supported
  18. // [BurstCompile(CompileSynchronously = true)]
  19. public struct MultiHashMapWriteParallelForJob : IJobParallelFor
  20. {
  21. public NativeParallelMultiHashMap<int, int>.ParallelWriter hashMap;
  22. public NativeArray<int> status;
  23. public int keyMod;
  24. public void Execute(int i)
  25. {
  26. status[i] = 0;
  27. try
  28. {
  29. hashMap.Add(i % keyMod, i);
  30. }
  31. catch (System.InvalidOperationException)
  32. {
  33. status[i] = -2;
  34. }
  35. }
  36. }
  37. [BurstCompile(CompileSynchronously = true)]
  38. public struct MultiHashMapReadParallelForJob : IJobParallelFor
  39. {
  40. [ReadOnly]
  41. public NativeParallelMultiHashMap<int, int> hashMap;
  42. public NativeArray<int> values;
  43. public int keyMod;
  44. public void Execute(int i)
  45. {
  46. int iSquared;
  47. values[i] = -1;
  48. NativeParallelMultiHashMapIterator<int> it;
  49. if (hashMap.TryGetFirstValue(i % keyMod, out iSquared, out it))
  50. {
  51. int count = 0;
  52. do
  53. {
  54. if (iSquared % keyMod != i % keyMod)
  55. {
  56. values[i] = -2;
  57. return;
  58. }
  59. ++count;
  60. }
  61. while (hashMap.TryGetNextValue(out iSquared, ref it));
  62. values[i] = count;
  63. }
  64. }
  65. }
  66. }