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