System Simulated Hashtable

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
I made this to enable those who have Warcraft 3 1.23 or lower patch to edit map made by 1.23b or higher patch world editor that containing the new handle - Hashtable by doing lowest changes to it.

Readme :
JASS:
                                Simulated Hashtable v1.2
                                      by kingking

    How is it useful?

    If you are a mapper having 1.23 or older world editor and you wish to edit map
    created by 1.23b world editor that containing hashtable functions, then you can
    use this system to reduce the major changes.
    
     PROS :
        1) As an alternative for real hashtable         

     CONS :
        1) Use turtle speed gamecache as storage.

     Requires : Jass NewGen Pack 5c or later

List of functions provided :

function InitHashtable takes nothing returns hashtable
function GetHandleId takes handle h returns integer
function StringHash takes string s returns integer

function SaveInteger takes hashtable table, integer parentKey, integer childKey, integer value returns nothing
function SaveReal takes hashtable table, integer parentKey, integer childKey, real value returns nothing
function SaveBoolean takes hashtable table, integer parentKey, integer childKey, boolean value returns nothing
function SaveStr takes hashtable table, integer parentKey, integer childKey, string value returns boolean
function SavePlayerHandle takes hashtable table, integer parentKey, integer childKey, player whichPlayer returns boolean
function SaveWidgetHandle takes hashtable table, integer parentKey, integer childKey, widget whichWidget returns boolean
function SaveDestructableHandle takes hashtable table, integer parentKey, integer childKey, destructable whichDestructable returns boolean
function SaveItemHandle takes hashtable table, integer parentKey, integer childKey, item whichItem returns boolean
function SaveUnitHandle takes hashtable table, integer parentKey, integer childKey, unit whichUnit returns boolean
function SaveAbilityHandle takes hashtable table, integer parentKey, integer childKey, ability whichAbility returns boolean
function SaveTimerHandle takes hashtable table, integer parentKey, integer childKey, timer whichTimer returns boolean
function SaveTriggerHandle takes hashtable table, integer parentKey, integer childKey, trigger whichTrigger returns boolean
function SaveTriggerConditionHandle takes hashtable table, integer parentKey, integer childKey, triggercondition whichTriggercondition returns boolean
function SaveTriggerActionHandle takes hashtable table, integer parentKey, integer childKey, triggeraction whichTriggeraction returns boolean
function SaveTriggerEventHandle takes hashtable table, integer parentKey, integer childKey, event whichEvent returns boolean
function SaveForceHandle takes hashtable table, integer parentKey, integer childKey, force whichForce returns boolean
function SaveGroupHandle takes hashtable table, integer parentKey, integer childKey, group whichGroup returns boolean
function SaveLocationHandle takes hashtable table, integer parentKey, integer childKey, location whichLocation returns boolean
function SaveRectHandle takes hashtable table, integer parentKey, integer childKey, rect whichRect returns boolean
function SaveBooleanExprHandle takes hashtable table, integer parentKey, integer childKey, boolexpr whichBoolexpr returns boolean
function SaveSoundHandle takes hashtable table, integer parentKey, integer childKey, sound whichSound returns boolean
function SaveEffectHandle takes hashtable table, integer parentKey, integer childKey, effect whichEffect returns boolean
function SaveUnitPoolHandle takes hashtable table, integer parentKey, integer childKey, unitpool whichUnitpool returns boolean
function SaveItemPoolHandle takes hashtable table, integer parentKey, integer childKey, itempool whichItempool returns boolean
function SaveQuestHandle takes hashtable table, integer parentKey, integer childKey, quest whichQuest returns boolean
function SaveQuestItemHandle takes hashtable table, integer parentKey, integer childKey, questitem whichQuestitem returns boolean
function SaveDefeatConditionHandle takes hashtable table, integer parentKey, integer childKey, defeatcondition whichDefeatcondition returns boolean
function SaveTimerDialogHandle takes hashtable table, integer parentKey, integer childKey, timerdialog whichTimerdialog returns boolean
function SaveLeaderboardHandle takes hashtable table, integer parentKey, integer childKey, leaderboard whichLeaderboard returns boolean
function SaveMultiboardHandle takes hashtable table, integer parentKey, integer childKey, multiboard whichMultiboard returns boolean
function SaveMultiboardItemHandle takes hashtable table, integer parentKey, integer childKey, multiboarditem whichMultiboarditem returns boolean
function SaveTrackableHandle takes hashtable table, integer parentKey, integer childKey, trackable whichTrackable returns boolean
function SaveDialogHandle takes hashtable table, integer parentKey, integer childKey, dialog whichDialog returns boolean
function SaveButtonHandle takes hashtable table, integer parentKey, integer childKey, button whichButton returns boolean
function SaveTextTagHandle takes hashtable table, integer parentKey, integer childKey, texttag whichTexttag returns boolean
function SaveLightningHandle takes hashtable table, integer parentKey, integer childKey, lightning whichLightning returns boolean
function SaveImageHandle takes hashtable table, integer parentKey, integer childKey, image whichImage returns boolean
function SaveUbersplatHandle takes hashtable table, integer parentKey, integer childKey, ubersplat whichUbersplat returns boolean
function SaveRegionHandle takes hashtable table, integer parentKey, integer childKey, region whichRegion returns boolean
function SaveFogStateHandle takes hashtable table, integer parentKey, integer childKey, fogstate whichFogState returns boolean
function SaveFogModifierHandle takes hashtable table, integer parentKey, integer childKey, fogmodifier whichFogModifier returns boolean

function LoadInteger takes hashtable table, integer parentKey, integer childKey returns integer
function LoadReal takes hashtable table, integer parentKey, integer childKey returns real
function LoadBoolean takes hashtable table, integer parentKey, integer childKey returns boolean
function LoadStr takes hashtable table, integer parentKey, integer childKey returns string
function LoadPlayerHandle takes hashtable table, integer parentKey, integer childKey returns player
function LoadWidgetHandle takes hashtable table, integer parentKey, integer childKey returns widget
function LoadDestructableHandle takes hashtable table, integer parentKey, integer childKey returns destructable
function LoadItemHandle takes hashtable table, integer parentKey, integer childKey returns item
function LoadUnitHandle takes hashtable table, integer parentKey, integer childKey returns unit
function LoadAbilityHandle takes hashtable table, integer parentKey, integer childKey returns ability
function LoadTimerHandle takes hashtable table, integer parentKey, integer childKey returns timer
function LoadTriggerHandle takes hashtable table, integer parentKey, integer childKey returns trigger
function LoadTriggerConditionHandle takes hashtable table, integer parentKey, integer childKey returns triggercondition
function LoadTriggerActionHandle takes hashtable table, integer parentKey, integer childKey returns triggeraction
function LoadTriggerEventHandle takes hashtable table, integer parentKey, integer childKey returns event
function LoadForceHandle takes hashtable table, integer parentKey, integer childKey returns force
function LoadGroupHandle takes hashtable table, integer parentKey, integer childKey returns group
function LoadLocationHandle takes hashtable table, integer parentKey, integer childKey returns location
function LoadRectHandle takes hashtable table, integer parentKey, integer childKey returns rect
function LoadBooleanExprHandle takes hashtable table, integer parentKey, integer childKey returns boolexpr
function LoadSoundHandle takes hashtable table, integer parentKey, integer childKey returns sound
function LoadEffectHandle takes hashtable table, integer parentKey, integer childKey returns effect
function LoadUnitPoolHandle takes hashtable table, integer parentKey, integer childKey returns unitpool
function LoadItemPoolHandle takes hashtable table, integer parentKey, integer childKey returns itempool
function LoadQuestHandle takes hashtable table, integer parentKey, integer childKey returns quest
function LoadQuestItemHandle takes hashtable table, integer parentKey, integer childKey returns questitem
function LoadDefeatConditionHandle takes hashtable table, integer parentKey, integer childKey returns defeatcondition
function LoadTimerDialogHandle takes hashtable table, integer parentKey, integer childKey returns timerdialog
function LoadLeaderboardHandle takes hashtable table, integer parentKey, integer childKey returns leaderboard
function LoadMultiboardHandle takes hashtable table, integer parentKey, integer childKey returns multiboard
function LoadMultiboardItemHandle takes hashtable table, integer parentKey, integer childKey returns multiboarditem
function LoadTrackableHandle takes hashtable table, integer parentKey, integer childKey returns trackable
function LoadDialogHandle takes hashtable table, integer parentKey, integer childKey returns dialog
function LoadButtonHandle takes hashtable table, integer parentKey, integer childKey returns button
function LoadTextTagHandle takes hashtable table, integer parentKey, integer childKey returns texttag
function LoadLightningHandle takes hashtable table, integer parentKey, integer childKey returns lightning
function LoadImageHandle takes hashtable table, integer parentKey, integer childKey returns image
function LoadUbersplatHandle takes hashtable table, integer parentKey, integer childKey returns ubersplat
function LoadRegionHandle takes hashtable table, integer parentKey, integer childKey returns region
function LoadFogStateHandle takes hashtable table, integer parentKey, integer childKey returns fogstate
function LoadFogModifierHandle takes hashtable table, integer parentKey, integer childKey returns fogmodifier

function  HaveSavedInteger takes hashtable table, integer parentKey, integer childKey returns boolean
function  HaveSavedReal takes hashtable table, integer parentKey, integer childKey returns boolean
function  HaveSavedBoolean takes hashtable table, integer parentKey, integer childKey returns boolean
function  HaveSavedString takes hashtable table, integer parentKey, integer childKey returns boolean
function  HaveSavedHandle takes hashtable table, integer parentKey, integer childKey returns boolean

function  RemoveSavedInteger takes hashtable table, integer parentKey, integer childKey returns nothing
function  RemoveSavedReal takes hashtable table, integer parentKey, integer childKey returns nothing
function  RemoveSavedBoolean takes hashtable table, integer parentKey, integer childKey returns nothing
function  RemoveSavedString takes hashtable table, integer parentKey, integer childKey returns nothing
function  RemoveSavedHandle takes hashtable table, integer parentKey, integer childKey returns nothing

function  FlushParentHashtable takes hashtable table returns nothing
function  FlushChildHashtable takes hashtable table, integer parentKey returns nothing


Library here :
JASS:
library HASHTABLE initializer Init

globals
    private gamecache TABLE
endglobals
//////////////Hashtable simulator//////////////////
struct hashtable
endstruct
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////
////Blizzard made this as H2I
function GetHandleId takes handle h returns integer
    return h
    return 0
endfunction
//////////////////////////////////////////////////
/////New native : StringHash//////////////////////
function StringHash takes string s returns integer
    return s
    return 0
endfunction
///////Init hashtable//////////
function InitHashtable takes nothing returns hashtable
    return hashtable.create()
endfunction
////////////////////////////
/////Store integers/////////
function SaveInteger takes hashtable ht, integer parent, integer child, integer value returns nothing
    call StoreInteger(TABLE,I2S(ht)+"_"+I2S(parent),I2S(child),value)
endfunction

function LoadInteger takes hashtable ht, integer parent, integer child returns integer
    return GetStoredInteger(TABLE,I2S(ht)+"_"+I2S(parent),I2S(child))
endfunction

function HaveSavedInteger takes hashtable ht, integer parent, integer child returns boolean
    return HaveStoredInteger(TABLE,I2S(ht)+"_"+I2S(parent),I2S(child))
endfunction

function RemoveSavedInteger takes hashtable ht, integer parent, integer child returns nothing
    call FlushStoredInteger(TABLE,I2S(ht)+"_"+I2S(parent),I2S(child))
endfunction
///////////////////////////////

//////Store Reals////////////////
function SaveReal takes hashtable ht, integer parent, integer child, real value returns nothing
    call StoreReal(TABLE,I2S(ht)+"_"+I2S(parent),I2S(child),value)
endfunction

function LoadReal takes hashtable ht, integer parent, integer child returns real
    return GetStoredReal(TABLE,I2S(ht)+"_"+I2S(parent),I2S(child))
endfunction

function HaveSavedReal takes hashtable ht, integer parent, integer child returns boolean
    return HaveStoredReal(TABLE,I2S(ht)+"_"+I2S(parent),I2S(child))
endfunction

function RemoveSavedReal takes hashtable ht, integer parent, integer child returns nothing
    call FlushStoredReal(TABLE,I2S(ht)+"_"+I2S(parent),I2S(child))
endfunction
//////////////////////////////

////////////Store String//////
function SaveStr takes hashtable ht, integer parent, integer child, string value returns nothing
    call StoreString(TABLE,I2S(ht)+"_"+I2S(parent),I2S(child),value)
endfunction

function LoadStr takes hashtable ht, integer parent, integer child returns string
    return GetStoredString(TABLE,I2S(ht)+"_"+I2S(parent),I2S(child))
endfunction

function HaveSavedString takes hashtable ht, integer parent, integer child returns boolean
    return HaveStoredString(TABLE,I2S(ht)+"_"+I2S(parent),I2S(child))
endfunction

function RemoveSavedString takes hashtable ht, integer parent, integer child returns nothing
    call FlushStoredString(TABLE,I2S(ht)+"_"+I2S(parent),I2S(child))
endfunction
/////////////////////////////

////////Store Boolean//////
function SaveBoolean takes hashtable ht, integer parent, integer child, boolean value returns nothing
    call StoreBoolean(TABLE,I2S(ht)+"_"+I2S(parent),I2S(child),value)
endfunction

function LoadBoolean takes hashtable ht, integer parent, integer child returns boolean
     return GetStoredBoolean(TABLE,I2S(ht)+"_"+I2S(parent),I2S(child))
endfunction

function HaveSavedBoolean takes hashtable ht, integer parent, integer child returns boolean
    return HaveStoredBoolean(TABLE,I2S(ht)+"_"+I2S(parent),I2S(child))
endfunction

function RemoveSavedBoolean takes hashtable ht, integer parent, integer child returns nothing
    call FlushStoredBoolean(TABLE,I2S(ht)+"_"+I2S(parent),I2S(child))
endfunction
/////////////////////////////
private struct HandleData
    handle h
endstruct

//! textmacro HASH_HANDLES takes Type, type
function Save$Type$Handle takes hashtable ht, integer parent, integer child, handle value returns boolean
    local HandleData d = HandleData.create()
    set d.h = value
    call StoreInteger(TABLE,I2S(ht)+"_"+I2S(parent),"HandleData"+I2S(child),d)
    if GetStoredInteger(TABLE,I2S(ht)+"_"+I2S(parent),"HandleData"+I2S(child)) == d then
        return true
    endif
    return false
endfunction

function Load$Type$Handle takes hashtable ht, integer parent, integer child returns $type$
    return HandleData(GetStoredInteger(TABLE,I2S(ht)+"_"+I2S(parent),"HandleData"+I2S(child))).h
endfunction
//! endtextmacro

//! runtextmacro HASH_HANDLES ("Widget","widget")
//! runtextmacro HASH_HANDLES ("Destructable","destructable")
//! runtextmacro HASH_HANDLES ("Unit","unit")
//! runtextmacro HASH_HANDLES ("Item","item")
//! runtextmacro HASH_HANDLES ("Ability","ability")
//! runtextmacro HASH_HANDLES ("Timer","timer")
//! runtextmacro HASH_HANDLES ("Trigger","trigger"")
//! runtextmacro HASH_HANDLES ("Force","force")
//! runtextmacro HASH_HANDLES ("Group","group")
//! runtextmacro HASH_HANDLES ("Location","location")
//! runtextmacro HASH_HANDLES ("Rect","rect")
//! runtextmacro HASH_HANDLES ("Region","region")
//! runtextmacro HASH_HANDLES ("Effect","effect")
//! runtextmacro HASH_HANDLES ("Sound","sound")
//! runtextmacro HASH_HANDLES ("Lightning","lightning")
//! runtextmacro HASH_HANDLES ("Player","player")
//! runtextmacro HASH_HANDLES ("TriggerCondition","triggercondition")
//! runtextmacro HASH_HANDLES ("TriggerAction","triggeraction")
//! runtextmacro HASH_HANDLES ("TriggerEvent","event")
//! runtextmacro HASH_HANDLES ("BooleanExpr","boolexpr")
//! runtextmacro HASH_HANDLES ("UnitPool","unitpool")
//! runtextmacro HASH_HANDLES ("ItemPool","itempool")
//! runtextmacro HASH_HANDLES ("Quest","quest")
//! runtextmacro HASH_HANDLES ("QuestItem","questitem")
//! runtextmacro HASH_HANDLES ("DefeatCondition","defeatcondition")
//! runtextmacro HASH_HANDLES ("TimerDialog","timerdialog")
//! runtextmacro HASH_HANDLES ("Leaderboard","leaderboard")
//! runtextmacro HASH_HANDLES ("Multiboard","multiboard")
//! runtextmacro HASH_HANDLES ("MultiboardItem","multiboarditem")
//! runtextmacro HASH_HANDLES ("Trackable","trackable")
//! runtextmacro HASH_HANDLES ("Dialog","dialog")
//! runtextmacro HASH_HANDLES ("Button","button")
//! runtextmacro HASH_HANDLES ("TextTag","texttag")
//! runtextmacro HASH_HANDLES ("Image","image")
//! runtextmacro HASH_HANDLES ("Ubersplat","ubersplat")
//! runtextmacro HASH_HANDLES ("FogState","fogstate")
//! runtextmacro HASH_HANDLES ("FogModifier","fogmodifier")

////////native for all handle storing////
function HaveSavedHandle takes hashtable ht, integer parent, integer child returns boolean
    return HaveStoredInteger(TABLE,I2S(ht)+"_"+I2S(parent),"HandleData"+I2S(child))
endfunction

function RemoveSavedHandle takes hashtable ht, integer parent, integer child returns nothing
    call HandleData(GetStoredInteger(TABLE,I2S(ht)+"_"+I2S(parent),"HandleData"+I2S(child))).destroy()
    call FlushStoredInteger(TABLE,I2S(ht)+"_"+I2S(parent),"HandleData"+I2S(child))
endfunction
/////////////////////////////////////////

/////Cleaning functions///
function FlushParentHashtable takes hashtable ht returns nothing
    call ht.destroy()
endfunction

function FlushChildHashtable takes hashtable ht, integer parent returns nothing
    call FlushStoredMission(TABLE,I2S(ht)+"_"+I2S(parent))
endfunction
/////////////////////////

private function Init takes nothing returns nothing
    call FlushGameCache(InitGameCache("SIMULATED_HASHTABLE"))
    set TABLE = InitGameCache("SIMULATED_HASHTABLE")
endfunction
endlibrary


JASS:
v1.2 Changelog :
Fixed a bug for not clearing the handles' data when using FlushChildHashtable.
Warcraft 3 1.23b stores handles as handle type in hashtable, the version will works similar.
Added missing natives, this system have full 1.23b natives now.
 

T.s.e

Wish I was old and a little sentimental
Reaction score
133
Why would someone have an older version than 1.23b?

JASS:
//      PROS :
//      1) Works prefectly as usual

:nuts:
A submission which works isn't a pro, it's a requirement.
 

_whelp

New Member
Reaction score
54
Oh yeah, and this would hit the gamecache limit pretty fast, if used frequently.
Can't you use a static gamecache?
 
Reaction score
91
Most of the systems that are now updated have a 1.23 compatibility version so this thing here becomes useless and obsolete... Why simulate such a thing? Why would you want to return your map to 1.23 when you've just updated it to 1.23b? Which map would one want to edit? The point is to move from old to new, right?
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
My Warcraft's version is 1.23, so I decided to make it since I found the trouble when compiling script with hashtables.
 

Romek

Super Moderator
Reaction score
963
I was expecting this to have numerous coding errors and stuff like your previous code.
Though you can't really go wrong with one liners...

...Much.
You need to Init -> Flush -> Init gamecaches.

And if you're going to simulate something like hashtables, it'd be helpful if you actually included all the functions. ._.
And you could simulate StringHash too.

However, I find this quite useful. =)
 
Reaction score
86
=] Yep. good idea +rep. It's very useful for when people code in older versions then switch to the latest one for release onto battlenet. gj
 

BlackRose

Forum User
Reaction score
239
Hmmm. I have no idea what anything does now.... is this like attaching local variables?

And would I just have to re-place all current systems with the updated systems and all my spells will work fine? (ones that need H2I or whatever)?
 

Romek

Super Moderator
Reaction score
963
> You need to Init -> Flush -> Init gamecaches.
Read it.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
> You need to Init -> Flush -> Init gamecaches.
Read it.

Do you mean this?

JASS:
static method create takes nothing returns hashtable
    local hashtable ht = hashtable.allocate()
    call FlushGameCache(ht.gc)
    set ht.gc = InitGameCache("hashtable" + I2S(ht))
    return ht
endmethod


Hmmm. I have no idea what anything does now.... is this like attaching local variables?

And would I just have to re-place all current systems with the updated systems and all my spells will work fine? (ones that need H2I or whatever)?

If you have a 1.23 or older patch, then this system let you use new hashtable functions. After 1.23b released, you can remove this system and your spell will works with new hashtable natives in 1.23b.

1.23 or lower -> H2I
1.23b or newer -> GetHandleId

H2I systems do not work on 1.23b or newer patch. Older than 1.23b can use H2I. I suggest you change to GetHandleId if you are going to prepare your map for 1.23b compability.

Oh yeah, and this would hit the gamecache limit pretty fast, if used frequently.
Can't you use a static gamecache?
Nah, you can use a global hashtable, then the limit won't break.

Question : Does this
JASS:
call FlushGameCache(ht.gc)

will release 1 slot from 256 game cache limit?
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
I'm waiting for accurate speed tests of hashtables.
I know it would be definitely faster than gamecache, but i need to know how many, and also if a big hashtable is not slower than several tiny ones, and so one ...

So honestly it's fairly useless for me, i will wait the official patch and the results about the speed of a hashtable.
 

Romek

Super Moderator
Reaction score
963
> Do you mean this?
No. Read again.
Init -> Flush -> Init

> will release 1 slot from 256 game cache limit?
No.

Perhaps it'd be better if you used a single gamecache.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
v1 alpha is released. The "hashtable" is an empty thing now. Use 1 gamecache for whole system.
 

Romek

Super Moderator
Reaction score
963
Why are you going back with the versions anyway?
You started off with v1, then v1 beta, now you're on alpha... o_O

JASS:
private function InitStoreStruct takes nothing returns StorageStruct
    return StorageStruct.create()
endfunction

Why?

Also, there's a collision if I do something like this:

JASS:
//
local hashtable ht = InitHashTable()
call SaveInteger(ht, 45, 23, SomeInt)

set ht = InitHashTable()
call SaveInteger(ht, 45, 23)

// Or even:
call SaveEffectHandle(ht, 45, 23, SomeEffect)


All hashtables should be independent of one another.
And different types shouldn't collide.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top