Skip to content

Commit 2d4e324

Browse files
authored
Add additional support files (#969)
1 parent 32cf104 commit 2d4e324

10 files changed

+383
-25
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
class Test
2+
{
3+
static void Main()
4+
{
5+
BitArray ba1 = new BitArray(100);
6+
ba1[0] = true;
7+
ba1[^98] = true;
8+
ba1[99] = true;
9+
Console.WriteLine("ba1[0] = {0}", ba1[0]); // True
10+
Console.WriteLine("ba1[98] = {0}", ba1[98]); // False
11+
Console.WriteLine("ba1[Index 0] = {0}", ba1[new Index(0)]); // True
12+
Console.WriteLine("ba1[^1] = {0}", ba1[^1]); // True
13+
}
14+
}
15+
16+
partial class BitArray
17+
{
18+
int[] bits;
19+
int length;
20+
21+
public BitArray(int length)
22+
{
23+
if (length < 0)
24+
{
25+
throw new ArgumentException();
26+
}
27+
else if (length == 0)
28+
{
29+
bits = new int[1];
30+
}
31+
else
32+
{
33+
bits = new int[((length - 1) >> 5) + 1];
34+
}
35+
this.length = length;
36+
}
37+
38+
public int Length => length;
39+
40+
public bool this[int index]
41+
{
42+
get
43+
{
44+
if (index < 0 || index >= length)
45+
{
46+
throw new IndexOutOfRangeException();
47+
}
48+
return (bits[index >> 5] & 1 << index) != 0;
49+
}
50+
set
51+
{
52+
if (index < 0 || index >= length)
53+
{
54+
throw new IndexOutOfRangeException();
55+
}
56+
if (value)
57+
{
58+
bits[index >> 5] |= 1 << index;
59+
}
60+
else
61+
{
62+
bits[index >> 5] &= ~(1 << index);
63+
}
64+
}
65+
}
66+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
class Test
2+
{
3+
static void Main()
4+
{
5+
BitArray ba = new BitArray(5);
6+
ba[0] = true;
7+
ba[3] = true;
8+
ba[^1] = true;
9+
Console.WriteLine("ba = >{0}<", ba);
10+
11+
Range[] testRange = {
12+
// all elements
13+
/*0..5,*/ 0.., ..5, //.., 0..^0, ..^0, ^5..5, ^5.., ^5..^0,
14+
15+
// trailing part
16+
// 1..5, 1.., 1..^0, ^4..5, ^4.., ^4..^0,
17+
18+
// leading part
19+
// 0..4, ..4, ^5..4, ^5..^1,
20+
21+
// middle part:
22+
// 1..4, ^4..4, ^4..^1, 1..^1,
23+
// 2..4, ^3..4, ^3..^1, 2..^1,
24+
3..4, ^2..4, //^2..^1, 3..^1,
25+
26+
// empty range
27+
0..0//, 1..1, 2..2, 3..3, 4..4, 5..5
28+
};
29+
30+
foreach (Range r in testRange)
31+
{
32+
Console.WriteLine($"BitArray is >{ba[r]}<");
33+
}
34+
}
35+
}
36+
37+
partial class BitArray
38+
{
39+
int[] bits;
40+
int length;
41+
42+
public BitArray(int length)
43+
{
44+
if (length < 0)
45+
{
46+
throw new ArgumentException();
47+
}
48+
else if (length == 0)
49+
{
50+
bits = new int[1];
51+
}
52+
else
53+
{
54+
bits = new int[((length - 1) >> 5) + 1];
55+
}
56+
this.length = length;
57+
}
58+
59+
public int Length => length;
60+
61+
public bool this[int index]
62+
{
63+
get
64+
{
65+
if (index < 0 || index >= length)
66+
{
67+
throw new IndexOutOfRangeException();
68+
}
69+
return (bits[index >> 5] & 1 << index) != 0;
70+
}
71+
set
72+
{
73+
if (index < 0 || index >= length)
74+
{
75+
throw new IndexOutOfRangeException();
76+
}
77+
if (value)
78+
{
79+
bits[index >> 5] |= 1 << index;
80+
}
81+
else
82+
{
83+
bits[index >> 5] &= ~(1 << index);
84+
}
85+
}
86+
}
87+
public override string ToString()
88+
{
89+
string retstr = "";
90+
int bitsWord;
91+
int upBound = bits.GetUpperBound(0);
92+
int bitCounter = Length;
93+
94+
if (Length == 0)
95+
{
96+
return retstr;
97+
}
98+
99+
for (int i = 0; i <= upBound; ++i)
100+
{
101+
bitsWord = bits[i];
102+
for (int j = 0; j < 32; ++j)
103+
{
104+
if (bitCounter-- == 0)
105+
{
106+
break;
107+
}
108+
retstr += ((bitsWord & 1) == 1) ? "1" : "0";
109+
bitsWord >>= 1;
110+
}
111+
}
112+
113+
return retstr;
114+
}
115+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
class Test
2+
{
3+
static void Main()
4+
{
5+
BitArray ba = new BitArray(5);
6+
ba[0] = true;
7+
ba[3] = true;
8+
ba[^1] = true;
9+
Console.WriteLine("ba = >{0}<", ba);
10+
11+
Range[] testRange = {
12+
// all elements
13+
/*0..5,*/ 0.., ..5, //.., 0..^0, ..^0, ^5..5, ^5.., ^5..^0,
14+
15+
// trailing part
16+
// 1..5, 1.., 1..^0, ^4..5, ^4.., ^4..^0,
17+
18+
// leading part
19+
// 0..4, ..4, ^5..4, ^5..^1,
20+
21+
// middle part:
22+
// 1..4, ^4..4, ^4..^1, 1..^1,
23+
// 2..4, ^3..4, ^3..^1, 2..^1,
24+
3..4, ^2..4, //^2..^1, 3..^1,
25+
26+
// empty range
27+
0..0//, 1..1, 2..2, 3..3, 4..4, 5..5
28+
};
29+
30+
foreach (Range r in testRange)
31+
{
32+
Console.WriteLine($"BitArray is >{ba[r]}<");
33+
}
34+
}
35+
}
36+
37+
partial class BitArray
38+
{
39+
int[] bits;
40+
int length;
41+
42+
public BitArray(int length)
43+
{
44+
if (length < 0)
45+
{
46+
throw new ArgumentException();
47+
}
48+
else if (length == 0)
49+
{
50+
bits = new int[1];
51+
}
52+
else
53+
{
54+
bits = new int[((length - 1) >> 5) + 1];
55+
}
56+
this.length = length;
57+
}
58+
59+
public int Length => length;
60+
61+
public override string ToString()
62+
{
63+
string retstr = "";
64+
int bitsWord;
65+
int upBound = bits.GetUpperBound(0);
66+
int bitCounter = Length;
67+
68+
if (Length == 0)
69+
{
70+
return retstr;
71+
}
72+
73+
for (int i = 0; i <= upBound; ++i)
74+
{
75+
bitsWord = bits[i];
76+
for (int j = 0; j < 32; ++j)
77+
{
78+
if (bitCounter-- == 0)
79+
{
80+
break;
81+
}
82+
retstr += ((bitsWord & 1) == 1) ? "1" : "0";
83+
bitsWord >>= 1;
84+
}
85+
}
86+
87+
return retstr;
88+
}
89+
90+
public bool this[int index]
91+
{
92+
get
93+
{
94+
if (index < 0 || index >= length)
95+
{
96+
throw new IndexOutOfRangeException();
97+
}
98+
return (bits[index >> 5] & 1 << index) != 0;
99+
}
100+
set
101+
{
102+
if (index < 0 || index >= length)
103+
{
104+
throw new IndexOutOfRangeException();
105+
}
106+
if (value)
107+
{
108+
bits[index >> 5] |= 1 << index;
109+
}
110+
else
111+
{
112+
bits[index >> 5] &= ~(1 << index);
113+
}
114+
}
115+
}
116+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#nullable enable
2+
public class Person
3+
{
4+
public string? Name { get; set; }
5+
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
public class Rectangle
2-
{
3-
}
1+
public class Rectangle
2+
{
3+
}
Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
struct Rectangle
2-
{
3-
Point a, b;
4-
5-
public Rectangle(Point a, Point b)
6-
{
7-
this.a = a;
8-
this.b = b;
9-
}
10-
11-
public Point A
12-
{
13-
get { return a; }
14-
set { a = value; }
15-
}
16-
17-
public Point B
18-
{
19-
get { return b; }
20-
set { b = value; }
21-
}
22-
}
1+
struct Rectangle
2+
{
3+
Point a, b;
4+
5+
public Rectangle(Point a, Point b)
6+
{
7+
this.a = a;
8+
this.b = b;
9+
}
10+
11+
public Point A
12+
{
13+
get { return a; }
14+
set { a = value; }
15+
}
16+
17+
public Point B
18+
{
19+
get { return b; }
20+
set { b = value; }
21+
}
22+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
partial class Class1
2+
{
3+
static async Task Main()
4+
{
5+
await M();
6+
await Task.Delay(2000);
7+
}
8+
9+
static async Task M()
10+
{
11+
await foreach (var number in GenerateSequence())
12+
{
13+
Console.WriteLine(number);
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)