-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComplexArray.cs
More file actions
87 lines (80 loc) · 2.5 KB
/
ComplexArray.cs
File metadata and controls
87 lines (80 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using System.Diagnostics;
using System.Numerics;
namespace GigaFFT
{
public class ComplexArray : IDisposable
{
private bool lightWeight;
private Complex[][] smallArray = null;
private ComplexArray2MeC largeArray = null;
public ComplexArray(ulong totalCapacityComplexStructs)
{
Debug.Assert(totalCapacityComplexStructs > 0);
this.lightWeight = totalCapacityComplexStructs <= 1024UL * 1024UL;
if (this.lightWeight)
{
ulong stripeCount = (totalCapacityComplexStructs + 4096UL - 1UL) / 4096UL;
Debug.Assert((stripeCount != 0) && ((stripeCount & (stripeCount - 1)) == 0), "stripeCount must be power of 2");
this.smallArray = new Complex[stripeCount][];
for (int stripe = 0; stripe < this.smallArray.Length; stripe++)
{
this.smallArray[stripe] = new Complex[Math.Min(totalCapacityComplexStructs, 4096UL)];
}
}
else
{
this.largeArray = new ComplexArray2MeC(totalCapacityComplexStructs);
}
}
public ulong Length
{
get
{
return lightWeight ? (smallArray.Length == 1 ? (ulong)smallArray[0].Length : (ulong)smallArray.Length * 4096UL) : largeArray.Length;
}
}
public Complex this[ulong index]
{
get
{
return lightWeight ? smallArray[index / 4096UL][index % 4096UL] : largeArray[index];
}
set
{
if (lightWeight)
{
smallArray[index / 4096UL][index % 4096UL] = value;
}
else
{
largeArray[index] = value;
}
}
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (smallArray != null || largeArray != null)
{
if (disposing)
{
if (!lightWeight)
{
largeArray.Dispose();
}
smallArray = null;
largeArray = null;
}
}
}
~ComplexArray()
{
Dispose(false);
}
}
}