Skip to content

Instantly share code, notes, and snippets.

@Vatyx
Created December 19, 2021 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vatyx/128f066bf80c3586f031b4ece4326b7f to your computer and use it in GitHub Desktop.
Save Vatyx/128f066bf80c3586f031b4ece4326b7f to your computer and use it in GitHub Desktop.
struct FTMatrix
{
private TArray<bool> Storage;
private int N;
private int M;
FTMatrix(int N, int M)
{
this.N = N;
this.M = M;
Storage.SetNum(N * M);
}
bool& opIndex(int i, int j)
{
const int Index = (i * N) + j;
ensure(Storage.IsValidIndex(Index));
return Storage[Index];
}
const bool& opIndex(int i, int j) const
{
const int Index = (i * N) + j;
ensure(Storage.IsValidIndex(Index));
return Storage[Index];
}
int Size() const
{
return N * M;
}
};
void Test_InitializeMatrix(FUnitTest& T)
{
FTMatrix Matrix(10, 10);
T.AssertEquals(Matrix.Size(), 100);
}
void Test_IndexMatrix(FUnitTest& T)
{
FTMatrix Matrix(10, 10);
T.AssertEquals(Matrix[1, 2], false);
Matrix[1, 2] = true;
T.AssertEquals(Matrix[1, 2], true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment