• 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.

what does "hashtable" mean?

Status
Not open for further replies.
Level 5
Joined
Jan 30, 2013
Messages
124
like "system", I don't know what a hastable (in WE) means and what it is used for:vw_wtf:
I have used "google translate" to translate the word "hashtable" into my language but the mean which is given out is very silly:grin: hahaha...
could you please to explain me clearly about it?
I have tried some but I don't still know what it is:thumbs_up:
thanks!
 
a Hash Table or Hash Map is a data structure. It allows you to save data with key for easier searching.

In Warcraft III, Hashtable is a type that is basically or theoritically a 2D array which has an array size of 2^31 per key(child and parent). This allows you to save/load data like variable array.

You can only have 255 hashtable, and 1 hashtable is enough for a map.
 
Level 5
Joined
May 6, 2013
Messages
125
A Hashfunction maps a bigger range of numbers to a smaller range of numbers (eg: 10214->1, 12489->2, 19057->3 etc). This smaller range of numbers is called the "hash". A Hashtable is a table (usually an array) that uses those hashes as an index to store data, therefor the name Hashtable. Im not aware of the term "hash" having any translation into other languages (well, some asian one maybe, i guess), which is probably why your translator failed.
Strictly speaking, a Jass Array acts like a hashtable too; otherwise, it would not be possible to access array[4000] of a newly created array without creating 4000 empty handle variables when doing so. WC probably internally maps the value 4000 to a smaller hash (like, 44, cause i like the 44, it looks kinda awesome. Of course, we cant tell what the hash really looks like) and uses this hash to store your value.
And if you are now thinking "that's impossible, there gotta be two different numbers that have the same hash": you're right. Its called hash collision, its the main problem of hashtables, its why hashtables tend to get slower and slower the more data you put into them, and it usually has a simple and inefficient solution.
Arrays in jass are indeed way faster than jass hashtables as they are one-dimensional and only have to map numbers from 0 to 8192. Its easier to get a hashfunction with less collisions with those restrictions taking place.
Then again, what warcraft calls hashtables is actually a hashtable without restrictions (its index is called parent key), holding another hashtable without restrictions (its index is called child key), holding the actual data. Mindblowing, and obviously way slower.
Because its hashfunction works for every number you give to it, it can be used to safe data without having to keep the index small (like you have to in arrays). Therefor, you can simply use Key(Unit handle) as an index, which is usually a number too big to be used as an array index.
Many people don't know what an actual hashtable is and therefor derive from that fact that people tend to use it with the Key(Unit) function that it can ONLY be used with the Key(Unit) function, but that is not the case. It does not necessarily have to be used to bind data to a unit, item or anything. It just rarely makes sense to use it for other things.
 
Status
Not open for further replies.
Top