
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