• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

[vJASS] Loop through Array vs. Hashtable Lookup

Status
Not open for further replies.
Level 39
Joined
Feb 27, 2007
Messages
5,024
I've got to check the spell being cast is in a list of spells (spells can't be removed from the list once added) and if so do yadda yadda. Since this search will run every time any spell is cast I want the check to be as lightweight as possible. Which is the better option? (or neither?)
JASS:
struct Abils extends array
    integer a
    static integer NUM_SPELLS //set elsewhere

    static method Find takes integer aid returns thistype
        local integer i = 0
        loop
            exitwhen i >= NUM_SPELLS
            if Abils[i].a == aid then
                return Abils[i]
            endif
            set i = i+1
        loop
    endmethod
endstruct

function OnSpell takes nothing returns nothing
    local Abils a = Abils.Find(GetSpellAbilityId())
    if a.a != 0 then
        call Whatever()
    endif
endfunction
or
JASS:
globals
    constant integer Spell_List
    hashtable ht = InitHashTable()
    //When spell is added to list the appropraite hashtable entry is created
ednglobals

function OnSpell takes nothing returns nothing
    if ht.LoadBoolean(ht, Spell_List, GetSpellAbilityId() then
        call Whatever()
    endif
endfunction
 
Status
Not open for further replies.
Top