• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[General] Hashtable

Status
Not open for further replies.
Level 13
Joined
Sep 13, 2010
Messages
550
My opinion is that to create as much hashtable as needs. Putting hundreds of data in one hashtable and to stay still overwievable is ( almost ) impossible. I think. You know you can create 255 hashtables. Of course it doesn't mean that use one hashtable for storing 10 variable...

More hashtable:
- More memory usage
- More bug free( Less chance to make a mistake eg overwrite a value )
- Less difficult code
Less hashtable
- Less memory usage
- More chance to make mistake
- Extremly difficult code with hundreds of indexing and if-es
 
Level 23
Joined
Jan 1, 2009
Messages
1,615
You should only use one, or a few hashtables for your map.
If you need to attach more Stuff to same ids and keys or different systems its better to have 2 hashtables, also for better organisation.
For every Spell would be waste, also there is a limit on how many hashtables you can create.
A Hashtable also allocates memory just on its own.
 
I could easily detect collisions with the setup I had in the Retro library. Storing millions of real values throughout the game, then firing the coordinate tracebacks - if there were collisions, the coordinates would certainly have been displaced, but they never were.

The only things that can really cause problems within hashtables are StringHashes. There are a lot of collisions there.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
Storing millions of real values throughout the game, then firing the coordinate tracebacks - if there were collisions, the coordinates would certainly have been displaced, but they never were.
And this has anything to do with hashtable collision handling?

Due to the finite size of the backing bucket arrays inside a hashtable, storing large numbers of values will result in eventually 2 items being placed at the same bucket. Inorder to still store the value without data curroption, the hashtable eithor starts a linked list for that bucket (infinite capacity) or finds the nearest free bucket and places in that (finite capacity of as many buckets the array has). In eithor case, it has to fall back to a slower algorthim (usually O(n) where n are the number of collisions that happened at that bucket) to search through the collisions. As a result, the more collisions that occur, the slower the hashtable runs when finding a piece of data but the data found will never be curropted (as bucket collisions should never damage data).

I do not know how hashtables work in WC3 due to the high level nature of the language. They eithor use a pare of hashes to map values to a single bucket array or use nested bucket arrays (a bucket array of bucket arrays) to provide better performance for large data quantities. In any case they probably use a linked list or dynamic array for collision handling.
 
Status
Not open for further replies.
Top