C ++多维数据处理 [英] C++ multi-dimensional data handling
问题描述
很多时候,我发现自己不得不为多维数据定义一个容器.
Many times, I find myself having to define a container for multi-dimensional data.
让我们举个例子:我有很多芯片,每个芯片有很多寄存器,每个寄存器有很多单元,每个单元有很多晶体管.
Let's take an example: I have many Chips, each Chip has many Registers, each Register has many Cells, and each Cell has many Transistors.
在C ++程序的某个阶段,我必须读取此数据,以后再使用它.
At some stage of my C++ program I have to read this data, and later I have to use it.
我不能将任何外部存储用于此数据:文件,数据库等.
I cannot use any external storage for this data: file, data-base, etc.
那么,我应该创建一些多维STL容器吗?向量地图或类似的地图...?
So, should I create some multi-dimensional STL container? A map of maps of vectors, or something like that... ?
还是我应该为它们每个创建类(结构)?包含晶体管矢量的Cell类,然后包含包含Cells矢量的Register类,等等?但是,如果以后我要通过晶体管而不是芯片访问数据怎么办?
Or should I create classes (structs) for each of them? Cell class that contains a vector of Transistors, and then a Register class that contains a vector of Cells, etc? But what if later I want to access my data by Transistor, and not by Chip?
还有其他方法吗?
谢谢
忘了提及:我不能使用升压.
Forgot to mention: I cannot use boost.
推荐答案
为其实施完整的类.最后,您的代码将变得更加整洁.
每当我忽略这个公理时,它就会再次困扰我.我用std :: pairs和std:pairs的std :: pairs实现了一个3层的分层字符串集合.这是快速而简单的,当我不得不用包含额外属性的类替换一层然后再替换一层时,它非常容易实现.但是最后,代码是一团糟,我不乐于对其进行记录.一遍又一遍又一遍地学到的教训...
Whenever I ignore this axiom, it comes back to haunt me. I implemented a hierarchical 3-tiered string collection in terms of std::pairs of std::strings and std:pairs. It was quick and simple, and when I had to replace one layer and then another with a class to contain extra attributes, it was surprisingly easy to do. But in the end, the code was a mess and I wasn't happy documenting it. Lesson learned again, and again, and again...
这篇关于C ++多维数据处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!