-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBitArray.cs
More file actions
96 lines (86 loc) · 2.3 KB
/
Copy pathBitArray.cs
File metadata and controls
96 lines (86 loc) · 2.3 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
88
89
90
91
92
93
94
95
96
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
namespace Stl2Blueprint
{
/// <summary>
/// An array of bool values stored using bits.
/// Useful for when memory usage is important.
/// </summary>
public class BitArray
{
private readonly System.Collections.BitArray data;
private readonly int [] size;
public int Count { get; private set; }
public BitArray(int size)
{
size = Math.Max(size, 0);
this.size = new [] { size, 1, 1 };
data = new System.Collections.BitArray(size);
}
public BitArray(int sizeX, int sizeY)
{
sizeX = Math.Max(sizeX, 0);
sizeY = Math.Max(sizeY, 0);
this.size = new [] { sizeX, sizeY, 1 };
data = new System.Collections.BitArray(sizeX * sizeY);
}
public BitArray (int sizeX, int sizeY, int sizeZ)
{
sizeX = Math.Max(sizeX, 0);
sizeY = Math.Max(sizeY, 0);
sizeZ = Math.Max(sizeZ, 0);
this.size = new [] { sizeX, sizeY, sizeZ };
data = new System.Collections.BitArray(sizeX * sizeY * sizeZ);
}
public int Length(int dim = 0)
{
return size [dim];
}
public int GetIndex(int x, int y)
{
return x + y * size [0];
}
public int GetIndex(int x, int y, int z)
{
return x + size [0] * (y + size [1] * z);
}
public bool this [int index]
{
get
{
return data [index];
}
set
{
data [index] = value;
}
}
public bool this [int x, int y]
{
get
{
return this [GetIndex(x, y)];
}
set
{
this [GetIndex(x, y)] = value;
}
}
public bool this [int x, int y, int z]
{
get
{
return this [GetIndex(x, y, z)];
}
set
{
this [GetIndex(x, y, z)] = value;
}
}
}
}