Open cher-nov opened 7 years ago
I've came up with an idea that the current implemenation of vector could be somewhat easily extended with support for multidimensional vectors by storing jump pointers to dimensions between the header and the actual storage. It may seem ineffective by memory, but actually it's just like storing vectors-of-vectors because subvectors need capacity for their headers as well.
So we need a new genarray
type, because vector-of-vectors is not the same as matrix (since subvectors can have different lengths). As opposed to this, genarray
will be pre-shaped. It means that its dimensions will be static, and to add new data row or column to it, you will have to reshape it first.
So the idea is to have something like that:
Memory structure:
[header][1st dimension jump pointers][2nd d.j.ps.]...[Nth d.j.ps.][storage]
Note that "0th dimension" have no jump pointers, as one-dimensioned array doesn't need them at all.
User type of a container will be T***...
, where number of asterisks is a number of dimensions.
User specifies shapes using varargs:
garr_reshape( some_array, 3 /* number of new dimensions */, ... /* sizes of every dimension */ );
Notes: