开发者

Representing relations in C++

I am trying to represent a relation (table) in C++ code:

  • The columns of the relation are integers.
  • The number of columns in the relation is fixed at runtime.
  • No duplicates should be allowed (this is the major source of cost).
  • I want to have a map from names to relations.

Any ideas for an efficient implemen开发者_如何转开发tation, the main issue here is detecting duplicates at insertion time, it can be very costly.


Make each row of the table a struct Row.

Use a std::set or std::unordered_set to store these structs. Collision (querying) can be detected in (for std::set) O(log n + d) time or (for std::unordered_set) amortized O(d) time where d is the number of columns.

To efficiently map from names to rows, create a boost::bimap<std::string, Row>.


KennyTM has a point. You could use SQLite. As described in the link, you can use it to create a temporary in-memory database.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜