The rectangular array class RectArray (and by extension the Matrix and SquareMatrix classes) is one of the few remaining places in which Gambit directly handles memory allocation/deallocation via new/delete.
We want to modernise the implementation of these classes.
- The current implementation of
RectArray is a pointer-to-pointer setup, with the index into the first pointer being the row and the second being the column. This should be replaced with a single std::vector, in which the contents are "raveled" and we handle the offset arithmetic to find the appropriate element rather than relying on C-style pointer arithmetic. (Note that helpfully our RectArray is actually not resizeable at present; there was a resizeable version of this historically but it's no longer needed, which makes re-implementation a bit easier).
2.. Based on similar experience with the parallel one-dimensional Array and Vector classes, Matrix should not be derived from RectArray but instead a Matrix should just have a RectArray as a data member. This refactoring should be done.
- Classes which represent a row and a column of the
RectArray should be created and provided. These should be useful in simplifying (and making more efficient) some of the operations currently provided in getting/setting rows and columns of the RectArray. For example, there are cases in which GetRow and GetColumn is filling an Array or Vector simply so the resulting data can be used in that container, but actually the calling code could be more generic and use a class which presents a slice of the RectArray as a one-dimensional object, which would eliminate unnecessary copying. it may be beyond the scope of this issue fully to change all such uses, but the re-design of the class should set up such access.
The rectangular array class
RectArray(and by extension theMatrixandSquareMatrixclasses) is one of the few remaining places in which Gambit directly handles memory allocation/deallocation vianew/delete.We want to modernise the implementation of these classes.
RectArrayis a pointer-to-pointer setup, with the index into the first pointer being the row and the second being the column. This should be replaced with a singlestd::vector, in which the contents are "raveled" and we handle the offset arithmetic to find the appropriate element rather than relying on C-style pointer arithmetic. (Note that helpfully ourRectArrayis actually not resizeable at present; there was a resizeable version of this historically but it's no longer needed, which makes re-implementation a bit easier).2.. Based on similar experience with the parallel one-dimensional
ArrayandVectorclasses,Matrixshould not be derived fromRectArraybut instead aMatrixshould just have aRectArrayas a data member. This refactoring should be done.RectArrayshould be created and provided. These should be useful in simplifying (and making more efficient) some of the operations currently provided in getting/setting rows and columns of theRectArray. For example, there are cases in whichGetRowandGetColumnis filling anArrayorVectorsimply so the resulting data can be used in that container, but actually the calling code could be more generic and use a class which presents a slice of theRectArrayas a one-dimensional object, which would eliminate unnecessary copying. it may be beyond the scope of this issue fully to change all such uses, but the re-design of the class should set up such access.