Created
December 15, 2016 10:45
-
-
Save antonfirsov/6c11a2f0a1048e8bcca455c072d14810 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public struct Fast2DArray<T> | |
{ | |
public T[] Data; | |
public int Width; | |
public int Height; | |
public Fast2DArray(T[,] data) | |
{ | |
this.Height = data.GetLength(0); | |
this.Width = data.GetLength(1); | |
this.Data = new T[this.Width*this.Height]; | |
// TODO: Flatten data into Data | |
} | |
public T this[int i, int j] | |
{ | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
get | |
{ | |
return this.Data[i * this.Width + j]; | |
} | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
set | |
{ | |
this.Data[i * this.Width + j] = value; | |
} | |
} | |
} | |
public class ArrayUser | |
{ | |
public static readonly Fast2DArray<bool> Pattern = new Fast2DArray<bool>( | |
new bool[,] | |
{ | |
{true, false, true }, | |
{false, true, false} | |
} | |
); | |
public void Foo() | |
{ | |
var blah = Pattern[1, 0]; | |
Console.WriteLine(blah); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment