CPF/CPF.ReoGrid/Data/TriangleTreeArray.cs

130 lines
2.2 KiB
C#
Raw Normal View History

2024-06-24 10:15:59 +08:00
using System;
namespace CPF.ReoGrid.Data
{
[Serializable]
public sealed class TriangleTreeArray<T>
{
public T this[int row, int col]
{
get
{
int num = row >> 12;
int num2 = col >> 8;
T[,][,] array = this.data[num, num2];
bool flag = array == null;
T result;
if (flag)
{
result = default(T);
}
else
{
int num3 = (row >> 6) % 64;
int num4 = (col >> 4) % 16;
T[,] array2 = array[num3, num4];
result = ((array2 == null) ? default(T) : array2[row % 64, col % 16]);
}
return result;
}
set
{
int num = row >> 12;
int num2 = col >> 8;
bool flag = this.data[num, num2] == null;
if (flag)
{
bool flag2 = value == null;
if (flag2)
{
return;
}
this.data[num, num2] = new T[64, 16][,];
}
int num3 = (row >> 6) % 64;
int num4 = (col >> 4) % 16;
bool flag3 = this.data[num, num2][num3, num4] == null;
if (flag3)
{
bool flag4 = value == null;
if (flag4)
{
return;
}
this.data[num, num2][num3, num4] = new T[64, 16];
}
this.data[num, num2][num3, num4][row % 64, col % 16] = value;
}
}
public bool IsPageNull(int row, int col)
{
int num = row >> 12;
int num2 = col >> 8;
T[,][,] array = this.data[num, num2];
bool flag = array == null;
bool result;
if (flag)
{
result = true;
}
else
{
int num3 = (row >> 6) % 64;
int num4 = (col >> 4) % 16;
result = (array[num3, num4] == null);
}
return result;
}
public int Rows
{
get
{
return 262144;
}
}
public int Cols
{
get
{
return 4096;
}
}
public void Iterate(int row, int col, int rows, int cols, bool ignoreNull, Func<int, int, T, bool> iterator)
{
int num = row + rows;
int num2 = col + cols;
for (int i = row; i < num; i++)
{
int j = col;
while (j < num2)
{
bool flag = this.IsPageNull(i, j);
if (flag)
{
j += 16 - j % 16;
}
else
{
bool flag2 = !iterator(i, j, this[i, j]);
if (flag2)
{
return;
}
j++;
}
}
}
}
public const int RowSize = 64;
public const int ColSize = 16;
private T[,][,][,] data = new T[64, 16][,][,];
}
}