PDA

View Full Version : Hashtable in a Hashtable

Starquizer
08-10-2012, 07:44 PM
Can I save a hashtable in another one ?

Tank-Commander
08-10-2012, 07:46 PM
Try it and find out? Though I think it's important to note there is never any situation where you -need- to be doing that, if you're doing whatever "correctly" anyway, don't think you can anyway though

Starquizer
08-10-2012, 07:52 PM
That's strange, I think I saw something like that written in one of the patch notes.

Anyway, I think it can't be done because I can't find any function that can do that.

claptomanic
08-10-2012, 08:31 PM
what youre trying to do? maybe we can think of another solution^^

Starquizer
08-10-2012, 08:44 PM
I know it sounds crazy and absolute insane, it is well known that most people use hashtable as a 2D array variable but can it be extended to 3D ?

PurgeandFire
08-10-2012, 10:08 PM
You don't need a hashtable in a hashtable for that. You can simulate multi-dimensional arrays with n-dimension to 1-dimension algorithms.

Assuming a normal hashtable save is [x][y] 2D, you can simulate [x][y][z] 3D by doing [x][y + z*width], where 'width' is the max array size for y. (or rather, the max array # that y can reach plus 1, to avoid collisions) So if you want [0][5][1], where the width of y is 10, then it would end up being [0][5 + 1*10] which is [0][15], a unique index.

For 4D, you can continue the algorithm with [x][y + width * (z + depth * a)]. And so on. You can look up a lot of these algorithms with google.

Dr Super Good
08-10-2012, 10:54 PM
Yes but this seems impractical seeing as you are only allowed 256 hashtables and game caches and there is no way to destroy them.

Only if you were mapping 2 indices to a hashtable reference would this be used but I do not know of such a situation off the top of my head.

Nestharus
08-10-2012, 11:38 PM
Yes but this seems impractical seeing as you are only allowed 256 hashtables and game caches and there is no way to destroy them.

Only if you were mapping 2 indices to a hashtable reference would this be used but I do not know of such a situation off the top of my head.

Flushing a hashtable destroys it.

SaveHashtableHandle(hashtable, integer, integer, hashtable)

So to answer your question very shortly and simply, you can save hashtables in hashtables.

edit
Also, I know how frustrating it is when people don't answer your question and instead say something like, why, or you can do it another way.

Dr Super Good
08-11-2012, 12:13 AM
Flushing a hashtable destroys it.
When I last tried, it only cleaned the hashtable completly. It did not free an allocation slot nor the object.

mckill2009
08-11-2012, 02:00 AM
sit can but it's completely pointless...

Starquizer
08-11-2012, 11:28 AM
Yes but this seems impractical seeing as you are only allowed 256 hashtables and game caches and there is no way to destroy them.

Only if you were mapping 2 indices to a hashtable reference would this be used but I do not know of such a situation off the top of my head.

I guess PurgeAndFire's algorithm doesn't involve using more than 1 hashtable.

Dr Super Good
08-11-2012, 11:46 AM
Generally you use multiple hashtables in parallel as that can help keep them opperating efficiently. In this case you would purly map references to parallel hashtables in series. If you ran hashtables in series you would quickly hit the 256 hashtable/game cache limit.

Luorax
08-11-2012, 01:11 PM
I guess PurgeAndFire's algorithm doesn't involve using more than 1 hashtable.

Surely not, but saving a hashtable in another one does, and that's what you were willing to do. He responded to the main post, not to PurgeandFire's method.

I'd recommend using PurgeandFire's method, vJASS' struct arrays use the very same method to handle arrays. Keys may go up to 2^32, so you won't really run out of space even if you make a 10D array with a size of 80000 each.