Convert to switch expression.

This commit is contained in:
2022-11-13 19:59:22 +00:00
parent 55fb8416e8
commit 18c1903d2f
2 changed files with 70 additions and 120 deletions

View File

@@ -96,17 +96,12 @@ public static class CdChecksums
subchannelStatus == false) subchannelStatus == false)
status = false; status = false;
switch(channelStatus) status = channelStatus switch
{ {
case null when subchannelStatus == true: null when subchannelStatus == true => true,
status = true; true when subchannelStatus == null => true,
_ => status
break; };
case true when subchannelStatus == null:
status = true;
break;
}
return status; return status;
} }

View File

@@ -86,115 +86,70 @@ public class ReedSolomon
/// <summary>Initializes the Reed-Solomon with RS(n,k) with GF(2^m)</summary> /// <summary>Initializes the Reed-Solomon with RS(n,k) with GF(2^m)</summary>
public void InitRs(int n, int k, int m) public void InitRs(int n, int k, int m)
{ {
switch(m) _pp = m switch
{ {
case 2: 2 => new[]
_pp = new[] {
{ 1, 1, 1
1, 1, 1 },
}; 3 => new[]
{
break; 1, 1, 0, 1
case 3: },
_pp = new[] 4 => new[]
{ {
1, 1, 0, 1 1, 1, 0, 0, 1
}; },
5 => new[]
break; {
case 4: 1, 0, 1, 0, 0, 1
_pp = new[] },
{ 6 => new[]
1, 1, 0, 0, 1 {
}; 1, 1, 0, 0, 0, 0, 1
},
break; 7 => new[]
case 5: {
_pp = new[] 1, 0, 0, 1, 0, 0, 0, 1
{ },
1, 0, 1, 0, 0, 1 8 => new[]
}; {
1, 0, 1, 1, 1, 0, 0, 0, 1
break; },
case 6: 9 => new[]
_pp = new[] {
{ 1, 0, 0, 0, 1, 0, 0, 0, 0, 1
1, 1, 0, 0, 0, 0, 1 },
}; 10 => new[]
{
break; 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1
case 7: },
_pp = new[] 11 => new[]
{ {
1, 0, 0, 1, 0, 0, 0, 1 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1
}; },
12 => new[]
break; {
case 8: 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1
_pp = new[] },
{ 13 => new[]
1, 0, 1, 1, 1, 0, 0, 0, 1 {
}; 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1
},
break; 14 => new[]
case 9: {
_pp = new[] 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1
{ },
1, 0, 0, 0, 1, 0, 0, 0, 0, 1 15 => new[]
}; {
1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
break; },
case 10: 16 => new[]
_pp = new[] {
{ 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1
1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1 },
}; _ => throw new ArgumentOutOfRangeException(nameof(m), "m must be between 2 and 16 inclusive")
};
break;
case 11:
_pp = new[]
{
1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1
};
break;
case 12:
_pp = new[]
{
1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1
};
break;
case 13:
_pp = new[]
{
1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1
};
break;
case 14:
_pp = new[]
{
1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1
};
break;
case 15:
_pp = new[]
{
1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
};
break;
case 16:
_pp = new[]
{
1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1
};
break;
default: throw new ArgumentOutOfRangeException(nameof(m), "m must be between 2 and 16 inclusive");
}
_mm = m; _mm = m;
_kk = k; _kk = k;