myahya
myahya

Reputation: 3171

Representing relations in C++

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

Any ideas for an efficient implementation, the main issue here is detecting duplicates at insertion time, it can be very costly.

Upvotes: 2

Views: 1110

Answers (2)

Björn Pollex
Björn Pollex

Reputation: 76788

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

Upvotes: 0

kennytm
kennytm

Reputation: 523214

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

Upvotes: 1

Related Questions