次のコードを c# で記述し、2 次元ポイントのスネーク インデックスを計算します。
    public static uint SnakeCurveIndex(uint bits, uint x, uint y )
    {
        uint index = 0;
        //The dimension of the array
        uint dim = (uint)Math.Pow( 2.0 , (double)bits);
        if(y % (uint)2 == 0 )
        {
            index = x + y * dim;
        }
        else
        {
            index = (dim - 1 - x) + y * dim;
        }
        if (index >= dim*dim)
        {
            //Debug console 
            throw new Exception("The index is out of bounds");
        }
        return index;
    }
変数ビットは、曲線の順序を担当します。次の図は、1 ~ 3 の曲線の順序を表しています。

私の質問は、このコードを n 次元の点に拡張するのは誰ですか? 多次元配列またはその他の手法が必要ですか?
お時間をいただきありがとうございます。
