Forums > Java

How to bind elements from hashmaps with sorted structure like jitter matrices ??

June 20, 2012 | 7:14 pm

Hi there,

the context:
I have an hashmap containing all my precious objects.

For all operations on this hashmap, I’m using Iterators, one of their powerful tools!
I can remove, add elements quietly, without thinking about keys.
However each object is related to space coordinates (x,y,z) and if I’m storing them in objects, I’m especially making ALL calculations inside a global jitter matrices fed by my JAVA core when I’m creating objects.

Because of this architecture, I had to use specific keys in my hashmap.
The key of an element in the hashmap is related to the row of my triplets in the jitter matrix
example:
element in the hashmap with the key 5 got its coordinates in the 3 planes matrix at the cells (5,0) of each plane.

My totally working way but a bit strange is:
I maintain a current ID in my JAVA Core and as soon as I add an object, I increment it.
When I’m storing the whole objects in my XML, it iterates, put objects parameters in the file.
When I’m loading the XML, no prob even if it wasn’t contiguous when I created my objects,

I remove objects ONLY during composition session (= not on stage!) and this creates discontinuities in the

My problem:
if I can have non contiguous ID in my hashmap (I mean: keys like 1,4,5,6,9,10,14), because the element with key 4 is the second, it obviously is related to the second row of my matrix which isn’t good.

what would be your approach for that ?


June 20, 2012 | 8:27 pm

Why would you not just retrieve the value of the key (4 in your example) rather than the position of the key in the hashmap (1 in your example)?


June 20, 2012 | 8:34 pm

I can do that.
but I have to bind that to the matrix rows, which are obviously contiguous (I mean, it wouldn’t be cool to have irrelevant & un useful rows in my matrix)

I found and implemented a workaround a couple of minutes ago.

Here it is: I’m caching the IDs deleted.

Example:
I’m creating an object.
It has the key 0, related to the row 0 of the matrix (jitter matrix I mean)
another one key 1, related to row 1
2, related to 2.

I remove 1.
While removing, I push 1 in a vector of int.
I’m overwriting the row 1 of my matrix by values meaning there is "still" nothing at this place (999,999,999)

I recreate an object.
the Core tests if my cache is empty or not.
if it isn’t empty, it grab an int and it becomes the key of my freshly made object… binded to the correct row of the matrix.

Of course, as I wrote, it is "only" for my compositions sessions ; but I wanted to avoid to have to write & reload the XML (or the patcher) at each remove.
Now, it works.


Viewing 3 posts - 1 through 3 (of 3 total)