No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

NativeParallelHashMapTestsFixture.cs 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using Unity.Jobs;
  2. using Unity.Burst;
  3. using Unity.Collections;
  4. using Unity.Collections.Tests;
  5. internal class NativeParallelHashMapTestsFixture : CollectionsTestFixture
  6. {
  7. protected const int hashMapSize = 10 * 1024;
  8. // Burst error BC1005: The `try` construction is not supported
  9. // [BurstCompile(CompileSynchronously = true)]
  10. internal struct HashMapWriteJob : IJob
  11. {
  12. public NativeParallelHashMap<int, int>.ParallelWriter hashMap;
  13. public NativeArray<int> status;
  14. public int keyMod;
  15. public void Execute()
  16. {
  17. for (int i = 0; i < status.Length; i++)
  18. {
  19. status[i] = 0;
  20. try
  21. {
  22. if (!hashMap.TryAdd(i % keyMod, i))
  23. {
  24. status[i] = -1;
  25. }
  26. }
  27. catch (System.InvalidOperationException)
  28. {
  29. status[i] = -2;
  30. }
  31. }
  32. }
  33. }
  34. [BurstCompile(CompileSynchronously = true)]
  35. internal struct HashMapReadParallelForJob : IJobParallelFor
  36. {
  37. [ReadOnly]
  38. public NativeParallelHashMap<int, int> hashMap;
  39. public NativeArray<int> values;
  40. public int keyMod;
  41. public void Execute(int i)
  42. {
  43. int iSquared;
  44. values[i] = -1;
  45. if (hashMap.TryGetValue(i % keyMod, out iSquared))
  46. {
  47. values[i] = iSquared;
  48. }
  49. }
  50. }
  51. }