|
Boost Users : |
From: Prashant Thakre (prashant.thakre_at_[hidden])
Date: 2006-06-07 07:08:05
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<t0,t1,...tn> 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<t0,t1,...t9> 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 <prashant.thakre_at_[hidden]>
> 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<t0,t1,...tn> 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
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net