
On 04/07/2011 01:22 AM, joaquin@tid.es wrote:
ppatel@archelongroup.com escribió:
Thanks for your answer Igor. Unfortunately that is out of my control. This is the type of structure we used across multiple applications. I was checking key extractors and I think that might work but haven't tried out yet.
Hello Priyank,
Please don't top-post: http://www.boost.org/community/policy.html#quoting
The rest of my answer below.
I will keep that in mind from this email and onwards.
I have a question regarding creating composite key/specifying length for arrays while using multi_index container based on following structure.
struct TestStruct {
char firstKey[50];
char secondKeyPart[3];
uint32_t thirdKeyPart;
……Some other information….
};
Do I really read to specify this lengths for character arrays? If yes, how do I do that while specifying key parts as below?
typedef multi_index_container<
TestStruct,
indexed_by<
//non-unique as some subscribers might have more than one number
hashed_unique<
composite_key<
TestStruct,
member
, member
, member
, >
>
TS;
The above keys will hash the pointer values, which is probably not what you want. If you change plain C arrays to std::string, it will work as you expect.
Leaving aside the fact that the syntax for member that you've used us incorrect (see the following example for the proper usage), Igor correctly points out that you'd be hashing pointers rather than the strings these arrays contain. The way to do this is by providing user-defined hashers and equality comparers as explained in http://www.boost.org/libs/multi_index/doc/tutorial/key_extraction.html#compo...
So, in your particular example we can have something like this:
struct CStrHasher // (C) Ion Gaztañaga { std::size_t operator()(const char *str)const { std::size_t seed = 0; for(;*str;++str)boost::hash_combine(seed,*str); return seed; } };
struct CStrEqualTo { bool operator()(const char *str1,const char *str2)const { return std::strcmp(str1,str2)==0; } };
typedef multi_index_container< TestStruct, indexed_by< hashed_unique< composite_key< TestStruct, member
, member , member >, composite_key_hash< CStrHasher, CStrHasher, boost::hash >, composite_key_equal_to< CStrEqualTo, CStrEqualTo, std::equal_to > > > TS;
Hope this helps,
Yes. For sure. I will try this out and get back to you in case of any questions. Thanks a lot for quick reply.
Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
Este mensaje se dirige exclusivamente a su destinatario. Puede consultar nuestra política de envío y recepción de correo electrónico en el enlace situado más abajo. This message is intended exclusively for its addressee. We only send and receive email on the basis of the terms set out at. http://www.tid.es/ES/PAGINAS/disclaimer.aspx _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users