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

Struct-sized D4 table

Status
Not open for further replies.
Level 26
Joined
Aug 18, 2009
Messages
4,097
At some points in map coding, I face a situation where I have to assign a value to a combination of more than two struct instances.

var[red][green][donald duck][muzzel] = val

Since the default struct size is 8192=2^13, which is also the limit for arrays, I thought it could make sense to split up a hashtable to match this number. A hashtable has 2^64 slots, so four structs fit in and 2^12=4096 remain (multiplied by the 254 other possible hashtables). This excess space can be used as the attribute indicator, what should be assigned to the struct instance combination. The number is large enough to be used scope-overlapping like the key-function of vJass provides. You may also create a new table everywhere but unless you tailor them precisely, the 255 limit is quite reachable.

In general, it would be nice to know if the performance gain by splitting data on different hashtables compensates for the overhead.
 
Level 14
Joined
Jun 27, 2008
Messages
1,325
I presume you dont really need that much space but your keys are in big ranges. So the resulting data structure will usually be very sparse. For that purpose i think using an appriate hashing function can be more efficient.
h : (key1, key2, key3, key3) -> integer
Other than with normal indexing the resulting hashs should be very bounded so h should be non-injective. Subsequently collisions are possible and you need to handle them (with linkedlists or with multiple hashing).

Anyway i think u know how hashing works ^_°
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
You can allocate more space to a struct :
JASS:
struct MyStruct [10000]
    //Do some stuff...
endstruct

Yes, but then a single array won't do anymore and the capacity to account for becomes a problem. I am also thinking about language-supported data structures though. Like you can write "var[a][c] = val" and the compiler automatically converts it to a fitting method.

Hashing/looking for collisions sounds expensive. Then you can as well use gamecaches, only that you leak strings en mass there.
 
Status
Not open for further replies.
Top