Reputation: 3171
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
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
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