[Snippet] Catalog

JASS:
            set w = w + 1
            set catalog = w
            set l[w] = w
            set p[w] = w
            set i[w] = Table.create()
            set r[w] = Table.create()
            set f[w] = Table.create()

That should just be "set catalog = CatalogCreate()" - needless duplicate text :p

readonly module attributes can still be set by the struct, operators are needed to achieve a truly-readonly value.

The components look good, but I still have to figure out how it interfaces with the save/load portion.
 
100% fixed.

There was a bug with retrieving ids and counts of added catalogs, but it all works now ;D.

This can still get a very minor improvement (using a delegate and moving all of the functions into a struct) ;o. The improvement would change the API.

I'll probably implement it tomorrow (would lower the code generated by the module to 4 lines ^_^).

edit
nvm, I realized that the only way to do the stuff like method operator id is to write out the methods for the module
 
Last edited:
Added destroy catalog as well as a struct API.


Maximized instance count for catalogs by using tables rather than arrays (catalogs don't need to be fast).



Destruction is 100% proper ; P. For example, if catalog B is added to catalog A and catalog B is destroyed, it is removed from catalog A. If catalog A is destroyed, A is removed from B's added to list.
 
Upgraded CatalogAdd so that you can do crazy stuff like this

JASS:
struct tester extends array
    private static method onInit takes nothing returns nothing
        local integer c1 = CatalogCreate()
        local integer c2 = CatalogCreate()
        local integer c3 = CatalogCreate()
        local integer c4 = CatalogCreate()
        
        call CatalogAddCatalog(c4,c3)
        call CatalogAddCatalog(c3,c2)
        call CatalogAddCatalog(c2,c1)
        
        call CatalogAdd(c1, 'hrif')
        call CatalogAdd(c2, 'Hpal')
        call CatalogAdd(c1, 'hpea')
        call CatalogAdd(c3, 'hfoo')
        call CatalogAdd(c4, 'hsor')
        
        //hsor: 1
        //hpea: 2
        //hfoo: 3
        //Hpal: 4
        //hrif: 5
        
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,I2S(CatalogId(c4, 'hsor')))
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,I2S(CatalogId(c4, 'hpea')))
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,I2S(CatalogId(c4, 'hfoo')))
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,I2S(CatalogId(c4, 'Hpal')))
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,I2S(CatalogId(c4, 'hrif')))
    endmethod
endstruct

But be warned that if you add the same thing to multiple catalogs along a chain, you will run into problems ; )

JASS:
struct tester extends array
    private static method onInit takes nothing returns nothing
        local integer c1 = CatalogCreate()
        local integer c2 = CatalogCreate()
        local integer c3 = CatalogCreate()
        local integer c4 = CatalogCreate()
        
        call CatalogAddCatalog(c4,c3)
        call CatalogAddCatalog(c3,c2)
        call CatalogAddCatalog(c2,c1)
        
        call CatalogAdd(c1, 'hrif')
        call CatalogAdd(c1, 'hpea')
        call CatalogAdd(c2, 'Hpal')
        call CatalogAdd(c2, 'hpea')
        call CatalogAdd(c3, 'hpea')
        call CatalogAdd(c3, 'hfoo')
        call CatalogAdd(c4, 'hsor')
        
        //hsor: 1
        //hpea: 2
        //hfoo: 3
        //Hpal: 4
        //hrif: 6
        
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,I2S(CatalogId(c4, 'hsor')))
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,I2S(CatalogId(c4, 'hpea')))
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,I2S(CatalogId(c4, 'hfoo')))
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,I2S(CatalogId(c4, 'Hpal')))
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,I2S(CatalogId(c4, 'hrif')))
    endmethod
endstruct

I could make it so that the problems don't occur, but it's better to do good catalog design than have an insane overhead to deal with the problem ;o (and by insane, I really do mean insane o-o, I implemented it and removed it because of how insane it was o-o).
 
Oh my god.

This is JASS what we're talking about, you probably have heard this in a classroom that teaches pro-grade programming. JASS hashtables might work quite differently when you use InitHashtable.

Hashtable just returns 0 if there was no integer, null if no handle or string, 0.00 if no real, false if no boolean.

Is this something I should add to the "Table" library, initializing 0,0 to 0? Is that all it needs to be sped up? I don't get what you're really trying to do with this.
 
Not even that would make sense because the Path library creates the hashtable dynamically meaning that you can't initialize it during the map init phase.

Even if it is 10x slower in-game there won't be more than 256 hashtables and 256x(hashtable lookup)x10 is still not enough to cause any noticable performance difference because it only happens ONE time.
 
Eh, they're the same speed, initialized and un-initialized.

Forgive me, I had heard that from someone else ; P.


Also, you can't have 2 returns.


Finally, LoadInteger doesn't initialize the value : )

JASS:
struct testers extends array
    private static hashtable table = InitHashtable()
    
    private static method onInit takes nothing returns nothing
        call LoadInteger(table, 0, 0)
        
        if (HaveSavedInteger(table, 0, 0)) then
            call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"Saved")
        else
            call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"Not Saved")
        endif
    endmethod
endstruct

edit
Made it so that catalogs are properly nested ; )

JASS:
struct testers extends array
    private static method onInit takes nothing returns nothing
        local integer c1 = CatalogCreate()
        local integer c2 = CatalogCreate()
        local integer c3 = CatalogCreate()
        local integer c4 = CatalogCreate()
        
        call CatalogAddCatalog(c4,c3)
        call CatalogAddCatalog(c3,c2)
        call CatalogAddCatalog(c2,c1)
        
        call CatalogAdd(c1, 'hrif')
        call CatalogAdd(c2, 'Hpal')
        call CatalogAdd(c3, 'hpea')
        call CatalogAdd(c3, 'hfoo')
        call CatalogAdd(c4, 'hsor')
        
        //hsor: 1
        //hpea: 2
        //hfoo: 3
        //Hpal: 4
        //hrif: 5
        
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,I2S(CatalogRaw(c4, 1))+"=="+I2S('hsor'))
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,I2S(CatalogRaw(c4, 2))+"=="+I2S( 'hpea'))
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,I2S(CatalogRaw(c4, 3))+"=="+I2S( 'hfoo'))
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,I2S(CatalogRaw(c4, 4))+"=="+I2S( 'Hpal'))
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,I2S(CatalogRaw(c4, 5))+"=="+I2S( 'hrif'))
        
        /*call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,I2S(CatalogId(c4, 'hsor')))
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,I2S(CatalogId(c4, 'hpea')))
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,I2S(CatalogId(c4, 'hfoo')))
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,I2S(CatalogId(c4, 'Hpal')))
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,I2S(CatalogId(c4, 'hrif')))*/
        
        call CatalogDestroy(c2)
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,I2S(CatalogCount(c4)))
    endmethod
endstruct
 
Fixed 3 bugs that were introduced to the last version and improved the speed of Count, Id, and Raw functions =).


The bug had to do with multiple catalogs added to a single catalog, like adding 4 and 5 to 6. I had only tested 1 catalog added to each catalog, hahahahaha... did I ever encounter the bug? No... I just saw in the code what would happen while improving the speed ; P.

JASS:
struct testers extends array
    private static method Count takes integer n returns integer
        return n*(n+1)/2
    endmethod
    private static method init takes nothing returns nothing
        local Catalog c1 = Catalog.create()
        local Catalog c2 = Catalog.create()
        local Catalog c3 = Catalog.create()
        local Catalog c4 = Catalog.create()
        local Catalog c5 = Catalog.create()
        local Catalog c6 = Catalog.create()
        local Catalog c7 = Catalog.create()
        local Catalog c8 = Catalog.create()
        
        call c8.addCatalog(c7)
        call c8.addCatalog(c6)
        call c7.addCatalog(c6)
        call c7.addCatalog(c6)
        call c6.addCatalog(c5)
        call c6.addCatalog(c4)
        call c5.addCatalog(c4)
        call c5.addCatalog(c3)
        call c4.addCatalog(c3)
        call c4.addCatalog(c2)
        call c2.addCatalog(c1)
        call c1.addCatalog(c8)
        
        call c1.add(-1)
        
        call c2.add(-2)
        call c2.add(-3)
        
        call c3.add(-4)
        call c3.add(-5)
        call c3.add(-6)
        
        call c4.add(-7)
        call c4.add(-8)
        call c4.add(-9)
        call c4.add(-10)
        
        call c5.add(-11)
        call c5.add(-12)
        call c5.add(-13)
        call c5.add(-14)
        call c5.add(-15)
        
        call c6.add(-16)
        call c6.add(-17)
        call c6.add(-18)
        call c6.add(-19)
        call c6.add(-20)
        call c6.add(-21)
        
        call c7.add(-22)
        call c7.add(-23)
        call c7.add(-24)
        call c7.add(-25)
        call c7.add(-26)
        call c7.add(-27)
        call c7.add(-28)
        
        call c8.add(-29)
        call c8.add(-30)
        call c8.add(-31)
        call c8.add(-32)
        call c8.add(-33)
        call c8.add(-34)
        call c8.add(-35)
        call c8.add(-36)
        
        /*
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,6000,I2S(c8.raw(36))+"=="+I2S(-1))
        
        call c7.destroy()
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,6000,I2S(c8.raw(36-7))+"=="+I2S(-1))
        */
        
        /*
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,6000,I2S(c8.id(-1))+"=="+I2S(36-7))
        
        call c7.destroy()
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,6000,I2S(c8.id(-1))+"=="+I2S(36-7))
        */
        
        /*
        call c4.destroy()
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,6000,I2S(c8.count)+"=="+I2S(Count(8)-4-2-1))
        
        call c5.destroy()
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,6000,I2S(c8.count)+"=="+I2S(Count(8)-5-4-3-2-1))
        */
        
        call DestroyTimer(GetExpiredTimer())
    endmethod
    
    private static method onInit takes nothing returns nothing
        call TimerStart(CreateTimer(),0,false,function thistype.init)
    endmethod
endstruct
 
Added the all new Catalog Loop struct ;D

JASS:
struct Tester extends array
    private static method onInit takes nothing returns nothing
        local Catalog c = Catalog.create()
        local Catalog c2 = Catalog.create()
        local Catalog c3 = Catalog.create()
        local Catalog c4 = Catalog.create()
        local Catalog c5 = Catalog.create()
        
        local CatalogLoop catalogLoop
        local integer value
        
        call c.addCatalog(c2)
        call c.addCatalog(c3)
        call c3.addCatalog(c4)
        call c4.addCatalog(c5)
        
        call c.add(1)
        call c.add(2)
        call c2.add(3)
        call c2.add(4)
        call c5.add(7)
        
        set catalogLoop = CatalogLoop.create(c, 1)
        
        loop
            set value = catalogLoop.next
            exitwhen 0 == value
            call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"Found "+I2S(value))
        endloop
    endmethod
endstruct


Brilliant? Yes : P.
 
Top