get all the elements with a certain value with multi_index
Hello I'm trying to use multi_index with an ordered_non_unique index. My question is how can I perform a search like with "find(key)" and get all the elements that match that key. Since find only returns one element that match, and there can be several in the container. I've tried to iterate "count(key)" times with the iterator returned by find but doesn't seem to work. Is there a way to do this? Regards -- Pedro Larroy Tovar, pedro at larroy dot com | http://pedro.larroy.com/ * Las patentes de programación son nocivas para la innovación * http://proinnova.hispalinux.es/
On 6/29/07, boost@larroy.com
Hello
I'm trying to use multi_index with an ordered_non_unique index. My question is how can I perform a search like with "find(key)" and get all the elements that match that key. Since find only returns one element that match, and there can be several in the container.
Use equal_range. It returns a pair of iterators to begin and end of the equal range.
I've tried to iterate "count(key)" times with the iterator returned by find but doesn't seem to work. Is there a way to do this?
Regards
-- Pedro Larroy Tovar, pedro at larroy dot com | http://pedro.larroy.com/ * Las patentes de programación son nocivas para la innovación * http://proinnova.hispalinux.es/
Best regards, -- Felipe Magno de Almeida
On Fri, Jun 29, 2007 at 07:05:56AM -0300, Felipe Magno de Almeida wrote:
On 6/29/07, boost@larroy.com
wrote: Hello
I'm trying to use multi_index with an ordered_non_unique index. My question is how can I perform a search like with "find(key)" and get all the elements that match that key. Since find only returns one element that match, and there can be several in the container.
Use equal_range. It returns a pair of iterators to begin and end of the equal range.
I've tried to iterate "count(key)" times with the iterator returned by find but doesn't seem to work. Is there a way to do this?
Regards
-- Pedro Larroy Tovar, pedro at larroy dot com | http://pedro.larroy.com/ * Las patentes de programación son nocivas para la innovación * http://proinnova.hispalinux.es/
Best regards, -- Felipe Magno de Almeida _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Thanks! I didn't noticed that function. -- Pedro Larroy Tovar, pedro at larroy dot com | http://pedro.larroy.com/ * Las patentes de programación son nocivas para la innovación * http://proinnova.hispalinux.es/
On 6/29/07, Felipe Magno de Almeida
Use equal_range. It returns a pair of iterators to begin and end of the equal range.
Similar question - once I have the equal_range, how do I iterate
through them via a different index?
ie ordered_non_unique
Hello Tony,
Gottlob Frege
On 6/29/07, Felipe Magno de Almeida
wrote: Use equal_range. It returns a pair of iterators to begin and end of the equal range.
Similar question - once I have the equal_range, how do I iterate through them via a different index?
ie ordered_non_unique
+ ordered_unique how do I display a list of the items sorted by category, then by item name within each category?
If what you want to do is traverse a range obtained from index #n following the order imposed by index #m, then you can't do that efficiently, sorry. However, the particular case you're posing does not boil down to that, but to something different: ordering elements by lexicographical order according to two keys, here category and ItenName. You can do this by making the category use a composite key on category+itenname. Not sure whether this is what you're after. Does it help? Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
On 7/4/07, Joaquin M Lopez Munoz
Hello Tony,
Gottlob Frege
writes: On 6/29/07, Felipe Magno de Almeida
wrote: Use equal_range. It returns a pair of iterators to begin and end of the equal range.
Similar question - once I have the equal_range, how do I iterate through them via a different index?
ie ordered_non_unique
+ ordered_unique how do I display a list of the items sorted by category, then by item name within each category?
If what you want to do is traverse a range obtained from index #n following the order imposed by index #m, then you can't do that efficiently, sorry. However, the particular case you're posing does not boil down to that, but to something different: ordering elements by lexicographical order according to two keys, here category and ItenName. You can do this by making the category use a composite key on category+itenname.
Not sure whether this is what you're after. Does it help?
Yeah that works, and is pretty much what I already have (without multi_index) but I was hoping that it would be one more problem solved with multi_index. (In my case, I still have other reasons for multi_index - there are actually more keys than just the 2 I used in the example.) Thanks - at least I know I'm not missing something! Tony
participants (4)
-
boost@larroy.com
-
Felipe Magno de Almeida
-
Gottlob Frege
-
Joaquin M Lopez Munoz