/// <summary> /// applies the operation <paramref name="op"/> to all entries of this array /// </summary> public void ApplyAll(ApplyAllOperation op) { if (m_LockedForever) { throw new ApplicationException("illegal call - object is locked."); } // special treatment for empty arrays for (int i = this.Dimension - 1; i >= 0; i--) { if (this.GetLength(i) <= 0) { return; } } // do all... unsafe { int[] _index = new int[m_Dimension]; int index_lin = this.Index(_index); fixed(int *index = _index) { fixed(double *pStorage = this.m_Storage) { ApplyAllRec(0, index, _index, index_lin, pStorage, op); } } } }
/// <summary> /// applies the operation <paramref name="op"/> to all entries of this /// array /// </summary> unsafe private void ApplyAllRec(int dim, int *index, int[] _index, int index_lin, double *pStorage, ApplyAllOperation op) { Debug.Assert(!m_LockedForever, "illegal call - object is locked."); int L = this.GetLength(dim); int C = this.GetCycle(dim); if (dim == m_Dimension - 1) { // end of recursion for (index[dim] = 0; index[dim] < L; index[dim]++) { op(_index, ref pStorage[index_lin]); index_lin += C; } } else { for (index[dim] = 0; index[dim] < L; index[dim]++) { ApplyAllRec(dim + 1, index, _index, index_lin, pStorage, op); index_lin += C; } } }