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