Hello. I have a problem where a body state is represented by a small vector (my own implementation), and a world state is a vector comprised of all the body states concatinated.
I need to lookup values in the world vector by an index (to be a vector), which must work out which body state that index lies on, and then work out the local body vector index to find the right value.
At first things were easy becuase each body vector was the same size. So if body vectors were four elements each, and the wrold comprsed of 3 bodies, then to find element 7 of the world vector I could:-
7/4 = 1 (integer division) get the 1st body (element 0 of an array)
7%4=3 get the 3st element(element 2 of an array)
So lookup body[1] and get element[2] out of it. (this is implemented as arrays so rememeber the 0 element is a valid index for both bodies and elements)
Which is great as it is super fast, direct and no searching invloved. However, things have got more complicated and I would like variable length vectors that can be concatinated to form a world vector, and also be super fast. Any ideas?
One idea I am thinking about is that probably there will not be alot of varience in the different sizes. So perhaps I could add all vectors of the same size next to each other, then concatinate all elements of a different size netxt to them, and increase upwards like that. Then a sequential search would only take as long as there are different sizes, rather than the number of vectors.
Tom