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)?