cher-nov / Gena

Generic pseudo-templated containers for C. Written entirely in C89 with design inspired by the C++ STL. /// DOCS ARE SLIGHTLY OUTDATED, PROJECT IS STABLE AND STILL BEING DEVELOPED
https://habr.com/ru/post/324210/
Do What The F*ck You Want To Public License
89 stars 6 forks source link

`genarray` #1

Open cher-nov opened 7 years ago

cher-nov commented 7 years ago

Notes:

cher-nov commented 2 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:

  1. 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.

  2. User type of a container will be T***..., where number of asterisks is a number of dimensions.

  3. User specifies shapes using varargs:

    garr_reshape( some_array, 3 /* number of new dimensions */, ... /* sizes of every dimension */ );