Suggestion for Data Structure

Suggestion for Data Structure

Post by bWlsa21hb » Tue, 03 Aug 2004 21:09:01


What do you think its the best way to implement SQL table (i.e. a table in which each column is in a different type - int, string, float etc.) in C++ language using STL?
I know there are also RELATIONS between the tables but I'm asking only on the table itself.
 
 
 

Suggestion for Data Structure

Post by Mateusz sk » Tue, 03 Aug 2004 23:46:31


It is too general question.
You don't consider any indices and key->value mapping.

In simple solution std::vector of std::vector of your structures
may be used.

Greets

--

Mateusz skot
mateusz at loskot dot net

 
 
 

Suggestion for Data Structure

Post by tom_usene » Wed, 04 Aug 2004 01:49:39

On Mon, 2 Aug 2004 05:09:01 -0700, "milkman"



The simplest version would be to write a discriminated union type that
could take on any one of the types in question, and then use a
vector<vector<yourdiscriminateduniontype> >. Another name for a
discriminated union type is a "variant". You can find articles on
writing them via google.

Actually, thinking about it you'd do:
vector<vector<yourdiscriminateduniontype>*>
since that would make insertions somewhat cheaper. But maybe what
you'd really do is use a linked list of rows (i.e. stable in memory)
and then have multiple indices (which would be either vectors, sparse
vectors or maps I think).

Tom
 
 
 

Suggestion for Data Structure

Post by Mateusz sk » Wed, 04 Aug 2004 02:18:24


Right, that's the solution.
Union may be similar to the VARIANT definition in COM (see ATL sources).


You can take a look at ATL sources I think.

Greets

--

Mateusz skot
mateusz at loskot dot net
 
 
 

Suggestion for Data Structure

Post by bWlsa21hb » Wed, 04 Aug 2004 07:25:04

Thank you very much, it was very helpful.