Click here to Skip to main content
15,887,350 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi!
there are times when you need an ordered sequence like a vector, but also a quick way of finding an item (like a map, or set).
Is there a dual contruct a sort of MAP_SEQUENCE ...

I quess really I am looking at is data with 2 keys:
1 is the sequence order
2 the other order like say name

SCENARIO:

Say you are implement a database object class that represents a table.
You have the concept that the table has a set of keys.
Each key has an ordered set of fields.
A field has:
a name
a value ( variant perhaps)

In the Key class, the field order matters, and also there is a need to look up the field by name in the key to get/set its value.

this is what I have so far: i.e 2 containers, a vector of the data
and a map mapping field name to field index in the the seq container.
But it seems to have redundancy.


class Key
{
public:
...
// access operators to the field data by name or index
_variant_t&; operator [] ( short field);
_variant_t&; operator [] ( int field);
const _variant_t &; operator [] ( const char* field) const;
const _variant_t &; operator [] ( short field) const;
...

protected:
// Fields in key sequence
std::vector<_variant_t> data;

// case insensitve map of field name to index in the data vector sequence to data item
std::map< CString, short, CompareNoCase> field_map;

// key information - gleaned from the database schema
const Key_Info* key_info;

CString key_name; // key name
...
};



Is there 1 container that would do both jobs -
provide a quick lookup for either key ( field name or index)?
Posted
Updated 28-Feb-10 4:08am
v3

I haven't used it, but you might want to take a look at Boost MultiIndex[^]
 
Share this answer
 
You can always use the sort function to sort[^] on any field whenever needed.
Here is another reference - STL Function objects[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900