C++ 多维数据处理

C++ multi-dimensional data handling(C++ 多维数据处理)
本文介绍了C++ 多维数据处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很多时候,我发现自己不得不为多维数据定义一个容器.

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

或者我应该为它们中的每一个创建类(结构)?包含晶体管向量的单元类,然后是包含单元向量的寄存器类,等等?但是,如果以后我想通过晶体管而不是芯片访问我的数据怎么办?

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?

还有其他方法吗?

谢谢

忘了提:我不能使用 boost.

Forgot to mention: I cannot use boost.

推荐答案

为他们实现完整的类.你的代码最终会更干净.

每当我忽略这个公理时,它就会再次困扰我.我根据 std::strings 和 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++ 多维数据处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

What is the proper function for comparing two C-style strings?(比较两个 C 风格字符串的正确函数是什么?)
Image Capture with OpenCV - Select Timeout Error(使用 OpenCV 捕获图像 - 选择超时错误)
SHA256 HMAC using OpenSSL 1.1 not compiling(使用 OpenSSL 1.1 的 SHA256 HMAC 未编译)
How to make a Debian package depend on multiple versions of libboost(如何制作一个Debian包依赖于多个版本的libboost)
Why does strcpy_s not exist anywhere on my system?(为什么我系统上的任何地方都不存在 strcpy_s?)
Simplest way to get current time in current timezone using boost::date_time?(使用 boost::date_time 在当前时区获取当前时间的最简单方法?)