我开始为n维向量编写一个库。
我想在此支持一些设计功能 库:
[0][0]
可能是1
字节,而[1][0]
可能是2
字节。在绘制出一些内存布局的表示之后 看起来像某些尺寸的矢量,我意识到了 布局结构有两种方法:
这是第一种方式。两种表示都是可视化的 a [2] [4] [3]数组。
---------------------------
| index | 0:0:0 |
| elementSize | |
| elementCount | |
| expansionBoundary | |
| slotCount | |
---------------------------
---------------------------
| index | 1:0:0 |
| elementSize | |
| elementCount | |
| expansionBoundary | |
| slotCount | |
---------------------------
---------------------------
| index | 0:0:0 |
| elementSize | |
| elementCount | |
| expansionBoundary | |
| slotCount | |
---------------------------
---------------------------
| index | 0:1:0 |
| elementSize | |
| elementCount | |
| expansionBoundary | |
| slotCount | |
---------------------------
---------------------------
| index | 0:2:0 |
| elementSize | |
| elementCount | |
| expansionBoundary | |
| slotCount | |
---------------------------
---------------------------
| index | 0:3:0 |
| elementSize | |
| elementCount | |
| expansionBoundary | |
| slotCount | |
---------------------------
---------------------------
| index | 1:0:0 |
| elementSize | |
| elementCount | |
| expansionBoundary | |
| slotCount | |
---------------------------
---------------------------
| index | 1:1:0 |
| elementSize | |
| elementCount | |
| expansionBoundary | |
| slotCount | |
---------------------------
---------------------------
| index | 1:2:0 |
| elementSize | |
| elementCount | |
| expansionBoundary | |
| slotCount | |
---------------------------
---------------------------
| index | 1:3:0 |
| elementSize | |
| elementCount | |
| expansionBoundary | |
| slotCount | |
---------------------------
---------------------------
| Index | 0:0:0 |
| Element | |
---------------------------
---------------------------
| Index | 0:0:1 |
| Element | |
---------------------------
---------------------------
| Index | 0:0:2 |
| Element | |
---------------------------
---------------------------
| Index | 0:1:0 |
| Element | |
---------------------------
---------------------------
| Index | 0:1:1 |
| Element | |
---------------------------
---------------------------
| Index | 0:1:2 |
| Element | |
---------------------------
---------------------------
| Index | 0:2:0 |
| Element | |
---------------------------
---------------------------
| Index | 0:2:1 |
| Element | |
---------------------------
---------------------------
| Index | 0:2:2 |
| Element | |
---------------------------
---------------------------
| Index | 0:3:0 |
| Element | |
---------------------------
---------------------------
| Index | 0:3:1 |
| Element | |
---------------------------
---------------------------
| Index | 0:3:2 |
| Element | |
---------------------------
---------------------------
| Index | 1:0:0 |
| Element | |
---------------------------
---------------------------
| Index | 1:0:1 |
| Element | |
---------------------------
---------------------------
| Index | 1:0:2 |
| Element | |
---------------------------
---------------------------
| Index | 1:1:0 |
| Element | |
---------------------------
---------------------------
| Index | 1:1:1 |
| Element | |
---------------------------
---------------------------
| Index | 1:1:2 |
| Element | |
---------------------------
---------------------------
| Index | 1:2:0 |
| Element | |
---------------------------
---------------------------
| Index | 1:2:1 |
| Element | |
---------------------------
---------------------------
| Index | 1:2:2 |
| Element | |
---------------------------
---------------------------
| Index | 1:3:0 |
| Element | |
---------------------------
---------------------------
| Index | 1:3:1 |
| Element | |
---------------------------
---------------------------
| Index | 1:3:2 |
| Element | |
---------------------------
这是第二种方式。
---------------------------
| index | 0:0:0 |
| elementSize | |
| elementCount | |
| expansionBoundary | |
| slotCount | |
---------------------------
---------------------------
| index | 0:0:0 |
| elementSize | |
| elementCount | |
| expansionBoundary | |
| slotCount | |
---------------------------
---------------------------
| Index | 0:0:0 |
| Element | |
---------------------------
---------------------------
| Index | 0:0:1 |
| Element | |
---------------------------
---------------------------
| Index | 0:0:2 |
| Element | |
---------------------------
---------------------------
| index | 0:1:0 |
| elementSize | |
| elementCount | |
| expansionBoundary | |
| slotCount | |
---------------------------
---------------------------
| Index | 0:1:0 |
| Element | |
---------------------------
---------------------------
| Index | 0:1:1 |
| Element | |
---------------------------
---------------------------
| Index | 0:1:2 |
| Element | |
---------------------------
---------------------------
| index | 0:2:0 |
| elementSize | |
| elementCount | |
| expansionBoundary | |
| slotCount | |
---------------------------
---------------------------
| Index | 0:2:0 |
| Element | |
---------------------------
---------------------------
| Index | 0:2:1 |
| Element | |
---------------------------
---------------------------
| Index | 0:2:2 |
| Element | |
---------------------------
---------------------------
| index | 0:3:0 |
| elementSize | |
| elementCount | |
| expansionBoundary | |
| slotCount | |
---------------------------
---------------------------
| Index | 0:3:0 |
| Element | |
---------------------------
---------------------------
| Index | 0:3:1 |
| Element | |
---------------------------
---------------------------
| Index | 0:3:2 |
| Element | |
---------------------------
---------------------------
| index | 1:0:0 |
| elementSize | |
| elementCount | |
| expansionBoundary | |
| slotCount | |
---------------------------
---------------------------
| index | 1:0:0 |
| elementSize | |
| elementCount | |
| expansionBoundary | |
| slotCount | |
---------------------------
---------------------------
| Index | 1:0:0 |
| Element | |
---------------------------
---------------------------
| Index | 1:0:1 |
| Element | |
---------------------------
---------------------------
| Index | 1:0:2 |
| Element | |
---------------------------
---------------------------
| index | 1:1:0 |
| elementSize | |
| elementCount | |
| expansionBoundary | |
| slotCount | |
---------------------------
---------------------------
| Index | 1:1:0 |
| Element | |
---------------------------
---------------------------
| Index | 1:1:1 |
| Element | |
---------------------------
---------------------------
| Index | 1:1:2 |
| Element | |
---------------------------
---------------------------
| index | 1:2:0 |
| elementSize | |
| elementCount | |
| expansionBoundary | |
| slotCount | |
---------------------------
---------------------------
| Index | 1:2:0 |
| Element | |
---------------------------
---------------------------
| Index | 1:2:1 |
| Element | |
---------------------------
---------------------------
| Index | 1:2:2 |
| Element | |
---------------------------
---------------------------
| index | 1:3:0 |
| elementSize | |
| elementCount | |
| expansionBoundary | |
| slotCount | |
---------------------------
---------------------------
| Index | 1:3:0 |
| Element | |
---------------------------
---------------------------
| Index | 1:3:1 |
| Element | |
---------------------------
---------------------------
| Index | 1:3:2 |
| Element | |
---------------------------
选择一种布局比另一种布局有什么优点/缺点吗?