Map with key as vector<any>

I

itt ium

Hi Group,
I have a situation where I have a database with key as vector of boost::any(or handle classes).Size of key vector is fixed and order of value type invector is also fixed. I want to match the map at run time with some input pattern vector of boost::any. some of the values in input pattern may be NIL that will be defined by some special value of data type.

A match will be found when all non NIL values in the vector matches.
Matching will be assumed to be failed in following cases

1. Size of input pattern (vector) is not same as size of keys (vector) in the container
2. Non NIL key does not matches

I am interested to know the **fastest** container for this case. If solution involves map or hash, I will appreciate some hint on writing less_than orhash function for this situation.
I am open to any dea.
thanks
Ittium
 
K

Kai-Uwe Bux

itt said:
Hi Group,
I have a situation where I have a database with key as vector of
boost::any (or handle classes).Size of key vector is fixed and order of
value type in vector is also fixed.

Uhm, why vector<any> when the size and the order of types is fixed. To me
something like

struc key_type {
type_1 value_1;
type_2 value_2;
type_3 value_3;
...
};

looks simpler.
I want to match the map at run time
with some input pattern vector of boost::any. some of the values in input
pattern may be NIL that will be defined by some special value of data
type.

A match will be found when all non NIL values in the vector matches.
Matching will be assumed to be failed in following cases

1. Size of input pattern (vector) is not same as size of keys (vector) in
the container 2. Non NIL key does not matches

My understanding of your problem is a little fuzzy, but you might want to
look into the multy_index library from Boost.


Best,

Kai-Uwe Bux
 
N

Narinder

Hi Group,
I have a situation where I have a database with key as vector of boost::any (or handle classes).Size of key vector is fixed and order of value type in vector is also fixed. I want to match the map at run time with some input pattern vector of boost::any. some of the values in input pattern may be NIL that will be defined by some special value of data type.

A match will be found when all non NIL values in the vector matches.
Matching will be assumed to be failed in following cases

1. Size of input pattern (vector) is not same as size of keys (vector) inthe container
2. Non NIL key does not matches

I am interested to know the **fastest** container for this case. If solution involves map or hash, I will appreciate some hint on writing less_than or hash function for this situation.
I am open to any dea.
thanks
Ittium


Given your types :
type_1
type_2
type_3

Then you could simply use boost::variant:

struct empty{};

typedef variant<empty,type_1> type_1_or_empty;
typedef variant<empty,type_2> type_2_or_empty;
typedef variant<empty,type_3> type_3_or_empty;

It'd be much safer than using Any, and you could write static_visitors
for operator<
and define :

template<class T>
bool operator==(const empty&,const T&){return false;}

template<class T>
bool operator==(const T&,const empty&){return false;}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top