Re: [Boost-users] [multi_index].[composite_key] Index creation at run-time.

But, how are you planning to actually implement this? Certainly you can't do the following: struct element {
Hi,
Guess, I should have given a code snippet :(
public:
boost::tuple
1. If the maxium number of keys of the composite_key is bounded then you can use that maximum and later on, at run-time, take advantage of only the first N key slots. struct element { //Assumption: no more than 10 elements, a reasonable limit I guess. // boost::tuple
tp; const std::string & tuple_element(const int ind) const { return tp.get<ind>; } //... };
As per this suggestion:
2. You can have std::vector<> as the key, the comparison semantics of this container in some ways resembles that of an infinite-length composite key. struct element { std::vector<const std::string > tp; const std::string & tuple_element(const int ind) const { return tp[ind]; } //... };
template < std::size_t hash_table_size> struct element_hash { int operator() ( const std::string & hash_string ) const { std::string::const_iterator hash_iter = hash_string.begin(); register int hash_value = 0; //... return hash_value; } }; typedef multi_index_container< element, indexed_by< hashed_unique < // indexed by elements of tuple/vector composite_key< element, const_mem_fun< element, const std::string &, &element::tuple_element(0) > >, // end of composite key def composite_key_hash < element_hash< 8191 > > // end of key hash > // end of hash
// end of inedexed_by
element_collection;
regards, Prashant Thakre
----- Mensaje original ----- De: Prashant Thakre
Fecha: Martes, Junio 6, 2006 9:06 pm Asunto: Re: [Boost-users] [multi_index].[composite_key] Index creation atrun-time. Hi, Thanks for the reply.
You're welcome. I'm afraid I'll have to ask for some more info before I can try to answer your original question, though :(
This is what I am trying to achieve: a) Each entry in the container will have tuple containing n-elements tuple < t0, t1 ..., tn >, where n is known at run-time. This entry will also have other elements.
But, how are you planning to actually implement this? Certainly you can't do the following:
class element { public: boost::tuple
tp; ... }; because you don't know n at compile time. This question is important, since how you actually implement the run-time knowledge of n will surely determine the way you can plug a composite_key into the scheme. If you can provide some actual code, no matter how sketchy, showing how you implement your element type, so much the better.
Looking fwd to your feedback,
Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

Prashant Thakre
Hi, Guess, I should have given a code snippet :(
But, how are you planning to actually implement this? Certainly you can't do the following: struct element { public: boost::tuple
tp; // ... }; As per your first suggestion:
1. If the maxium number of keys of the composite_key is bounded then you can use that maximum and later on, at run-time, take advantage of only the first N key slots. struct element { //Assumption: no more than 10 elements, a reasonable limit I guess. // boost::tuple
tp; const std::string & tuple_element(const int ind) const { return tp.get<ind>; } //... };
Well, this can't work as is, cause tp.get<ind> requires that ind be a compile-time constant, which is not (it is an argument to tuple_element). Actually, I think it would be hard (though not impossible) to treat tuples, whose dimension is compile-time, as run-time sized objects. Let's turn to the second approach:
As per this suggestion:
2. You can have std::vector<> as the key, the comparison semantics of this container in some ways resembles that of an infinite-length composite key. struct element { std::vector<const std::string > tp; const std::string & tuple_element(const int ind) const { return tp[ind]; } //... };
OK, here, instead of a composite_key instantiation,
you can take advantage directly of std::vector comparison
semantics (you don't really need tuple_element):
typedef multi_index_container<
element,
indexed_by<
hashed_unique<
member
element_collection;
Now, you can use n-sized vectors everywhere, where n is determined at run-time. Does this suit your needs? Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

Hi,
OK, here, instead of a composite_key instantiation, you can take advantage directly of std::vector comparison semantics (you don't really need tuple_element):
typedef multi_index_container< element, indexed_by< hashed_unique< member
> // other indices, maybe element_collection;
Is this equivalent to having a member std::string tp which is constructed at
run-time from all the elements of std::vector< const std::string > ? Also, how
does the hash function generate the key ?
Thanks a lot.
regards,
Prashant Thakre
Joaquin M Lopez Munoz
Prashant Thakre
writes: Now, you can use n-sized vectors everywhere, where n is determined at run-time. Does this suit your needs?
Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
_______________________________________________ Boost-users mailing list Boost-users <at> lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Prashant Thakre ha escrito:
Hi,
OK, here, instead of a composite_key instantiation, you can take advantage directly of std::vector comparison semantics (you don't really need tuple_element):
typedef multi_index_container< element, indexed_by< hashed_unique< member
> // other indices, maybe element_collection;
Is this equivalent to having a member std::string tp which is constructed at run-time from all the elements of std::vector< const std::string > ?
Depends on how you construct that string: if you just concatenate the vector elements, then no, it's not equivalent. For instance, the following two vectors {"mast","err","apparent"} {"master","rap","parent"} both map to "masterrapparent".
Also, how does the hash function generate the key ?
Boost.Hash combines the vector element's hash values as described at http://boost.org/doc/html/id2490467.html B.MI also lets you specify your own hashing mechanism if you need it: http://boost.org/libs/multi_index/doc/advanced_topics.html#hash_spec
Thanks a lot.
regards, Prashant Thakre
Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
participants (3)
-
Joaquin M Lopez Munoz
-
Joaquín Mª López Muñoz
-
Prashant Thakre