map

hello
I have two vectors, a {1,4,8,3,6,9} and b{ 0,1,2,3,4,5}. For accessing the 5th element inside vector a, instead of a[4] I want to use b[4] which corresponds to a[4]. how can I do this using map.
Do you mean a[b[4]]?
imagine I have a vector of objects, coordinate, which has x,y and z component.
std::vector<coordinate>{0,1,2,3,4,5,7,8,9}. Then I divided this vector into two processors. the first and second processors receive {2, 4, 9} and {0,1,3,5,6,7,8} into Local_Vector. Now in each processor I want to create the vector of coordinate which its size will be 3 and 7 for the first and second processors. now for example in the first processor you have coordinate 9 but the size of coordinate now is 3 and you don't have access to the x,y,z component. Easily I can find the index of 9 in local_vector and then say like coordinate [index], it gives me the x,y,z of coordinate 9. but this slow down my code. my preference was to not use std:: find or map for this purpose, but it seems i don't have any other choice

in the first processor the Local_vector is {2,4,9}.
the vector of object for this processor will be {0,1,2}, but for coordinate 2 you'll need the x,y,z of node 9. I hope I could have been able to clarify my question enough.
Last edited on
Can you change the "vector object for this processor" to be this instead?
vecObj = {-1, -1, 0, -1, 1, -1, -1, -1, -1, 2}

Then you can check if (vecObj[index] >= 0) { Local_vector[vecObj[index]] }

It's a sparse array. It takes up space, but it might be faster than a map. But I would compare it with a map's speed before making the decision.


Thanks for your answer. Actually I thought about this as well, but I'm storing another vector vecobj and for this I'm taking extra memory.
Topic archived. No new replies allowed.