
hi, i am new using the multiindex library, and I need to do the following. I have a set of d-dimensional points (e.g (3,5,8,9,5) is a 5-dimensional point), and I need to sort the points on each of the coordinates. I want to store the points in a vector, and use multiindex to have all the points (vectors in this case) sorted in each of the coordinates. E.g. sorted by x: x y z w ----------- 0 0 0 0 1 2 7 4 2 3 1 1 3 1 3 3 4 5 2 9 sorted by y: 0 0 0 0 3 1 3 3 1 2 7 4 2 3 1 1 4 5 2 9 etc... would you mind pointing me in the right direction with an example of how to do it with multiindex library? thanks

Hello Adán,
Adán Cosgaya
hi,i am new using the multiindex library, and I need to do the following.I have a set of d-dimensional points (e.g (3,5,8,9,5) is a 5-dimensional point), and I need to sort the points on each of the coordinates. I want to store the points in a vector,
Do you mean that the points *are* vectors or that, moreover, they are stored in a vector (thus, a vector of vectors)? If the latter, why do you want to have them in a vector? Does not having them stored in the multi_index_container suffice? In the following I assume that the points are stored only in a multi_index_container whose first index is of type sequenced (std::list-like), which gives you the free-positioning interface you seem to need. If this is not what you're after please tell me so.
and use multiindex to have all the points (vectors in this case) sorted in each of the coordinates [...] would you mind pointing me in the right direction with an example of how to do it with multiindex library? thanks
You only need to define an appropriate key extractor
for the N-th element of a vector:
template<int N>
struct nth_coordinate
{
typedef int result_type;
int operator()(const std::vector<int>& x)const
{
return x[N]; // or .at(N) for greater safety
}
};
so that the multi_index_container definition becomes:
typedef multi_index_container<
std::vector<int>,
indexed_by<
sequenced<>,
ordered_non_unique
multi_index_t;
Does this help? If for some reason the sequenced index at position #0 does not suffice, in Boost 1.34 there will be random access indices which are more similar to a vector, see http://tinyurl.com/psr6o . Good luck with your project, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

Hi,
tks for the answer,
and yes, my original idea was something along the lines of a vector of
vector, but what you described seem to be the right way to go.
would you mind giving me an example of how to insert some points (e.g. 4-d
or 5-d points), and iterate over them, I will need to access each point
during the next stage of my problem
Thanks
Adan
On 7/4/06, Joaquin M Lopez Munoz
Hello Adán,
Adán Cosgaya
writes: hi,i am new using the multiindex library, and I need to do the following.I have a set of d-dimensional points (e.g (3,5,8,9,5) is a 5-dimensional point), and I need to sort the points on each of the coordinates. I want to store the points in a vector,
Do you mean that the points *are* vectors or that, moreover, they are stored in a vector (thus, a vector of vectors)? If the latter, why do you want to have them in a vector? Does not having them stored in the multi_index_container suffice? In the following I assume that the points are stored only in a multi_index_container whose first index is of type sequenced (std::list-like), which gives you the free-positioning interface you seem to need. If this is not what you're after please tell me so.
and use multiindex to have all the points (vectors in this case) sorted in each of the coordinates [...] would you mind pointing me in the right direction with an example of how to do it with multiindex library? thanks
You only need to define an appropriate key extractor for the N-th element of a vector:
template<int N> struct nth_coordinate { typedef int result_type;
int operator()(const std::vector<int>& x)const { return x[N]; // or .at(N) for greater safety } };
so that the multi_index_container definition becomes:
typedef multi_index_container< std::vector<int>, indexed_by< sequenced<>, ordered_non_unique
>, ordered_non_unique >, ordered_non_unique >, ordered_non_unique >, ordered_non_unique > > multi_index_t;
Does this help? If for some reason the sequenced index at position #0 does not suffice, in Boost 1.34 there will be random access indices which are more similar to a vector, see http://tinyurl.com/psr6o .
Good luck with your project,
Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Adán Cosgaya ha escrito:
Hi, tks for the answer, and yes, my original idea was something along the lines of a vector of vector, but what you described seem to be the right way to go. would you mind giving me an example of how to insert some points ( e.g. 4-d or 5-d points), and iterate over them, I will need to access each point during the next stage of my problem
Inserting and traversing with different indices is meant to be exhaustively covered in the documentation. I strongly recommend you devote some time to read it, at least the tutorial part, if after this you are still in need of help I'll be happy to try to answer any particular questions you might have.
Thanks
Adan
Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
participants (3)
-
Adán Cosgaya
-
Joaquin M Lopez Munoz
-
Joaquín Mª López Muñoz