gpt4 book ai didi

c++ - 表示具有 "multiple-combined"键的查找表的数据结构

转载 作者:太空狗 更新时间:2023-10-29 20:05:18 24 4
gpt4 key购买 nike

您将如何设计用于查找的表数据结构?

我基本上要代表下表

Country             Activity        Legal_Age
European Drink 18
European Drive 21
American Drink 21
American Drive 18

这里我的 Key 是(Country & Activity),值是 Legal_age。

我想到使用 std::map 来分解这个问题(分解成单独的映射),如下所示。

national_Activity_age_map

European            European_Activity_age_map
American American_Activity_age_map

European_Activity_age_map

Drink           18
Drive 21

American_Activity_age_map

Drink           21
Drive 18

但这里的问题是,随着原始表的列数不断增加,要添加和维护的 map 数量也在不断增加。

假设美国选择为美国公民和非公民规定不同的饮酒年龄。然后我将不得不添加新的映射并修改现有的映射。

是否有一种简单明了的方法来在 DataStructure 中表示此数据,该 DataStructure 接受一个多因子分解键并产生一个值?

下面有一些类似的问题,但没有回答我的具体问题。 What datastructure would you use to represent this format of data?

更新:我不能在工作中使用 Boost 功能,因为它必须被移植(或类似的东西)。是否有我可以使用的 C++ (gcc 4.1.2) 功能。

最佳答案

尝试 Boost Multi-Index .

The Boost Multi-index Containers Library provides a class template named multi_index_container which enables the construction of containers maintaining one or more indices with different sorting and access semantics. Indices provide interfaces similar to those of STL containers, making using them familiar. The concept of multi-indexing over the same collection of elements is borrowed from relational database terminology and allows for the specification of complex data structures in the spirit of multiply indexed relational tables where simple sets and maps are not enough.

关于c++ - 表示具有 "multiple-combined"键的查找表的数据结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14249803/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com