System Maps

Reaction score
333
Version 2.0

Huge changes. Now we can:
  • Use user-defined types in maps.
  • Create maps dynamically, at run-time. Each individual map is completely separate from the others.
  • Iterate through the contents of individual maps.
  • Map maps to other maps, creating multi-maps.

Internal changes:
  • Each map (no matter the type) shares globals.
  • As few superfluous declarations as possible.
  • Size argument removed.

Caveat Utilitor:
  • Don't create more than 8190 maps at once.
  • Don't forget to clear entries after use.
  • Don't use more than 8190 entries at once.

JASS:
//! textmacro Map takes NAME, TYPE1, TYPE2
library_once integer2i
    globals
        public integer array c
        public integer array e_id
        
        public integer array e_ids
        public integer e_n = 0
        public integer e_m = 0 
        
        public integer array e_u
        public integer array e_d
        
        public integer array e_l
        public integer array e_r
    endglobals
    
    function integer2i takes integer i returns integer
        return i
    endfunction
    
    public function H2I takes handle h returns integer
        return h
        return 0
    endfunction
    
    public function CX takes integer x returns integer
        if (x<0) then
            return x+8190
        endif
        return x
    endfunction
    
    function real2i_CX takes integer x returns integer
        return CX(x)
    endfunction
    
    function handle2i takes handle t returns integer
        return H2I(t)-0x100000
    endfunction
    
    public interface mapinstance
        integer ns
        integer ef
        integer it
    endinterface
endlibrary

library_once $TYPE1$2globs
    globals
        $TYPE1$ array $TYPE1$2i_e_k
        $TYPE1$ $TYPE1$2i_no_$TYPE1$ = $TYPE1$2i_e_k[0]
    endglobals
endlibrary

library_once handle2i
endlibrary
library_once real2CXs
endlibrary
library_once integer2CXs
endlibrary

library_once $TYPE1$2CXs
    function $TYPE1$2i_CX takes integer x returns integer
        return x
    endfunction
endlibrary

library_once $TYPE1$2i    
    function $TYPE1$2i takes $TYPE1$ t returns integer
        return t
        return 0
    endfunction
endlibrary

library_once $TYPE2$s
    globals
        public $TYPE2$ array e_v
        public $TYPE2$ no_$TYPE2$ = e_v[0]
    endglobals
endlibrary

library $NAME$ requires $TYPE1$2i, integer2i    
    struct $NAME$ extends integer2i_mapinstance
        private integer ns = 0
        private integer ef = 0
        private integer it
        
        method empty takes nothing returns boolean
            return .ns == 0
        endmethod
        
        method size takes nothing returns integer
            return .ns
        endmethod
        
        method clearValue takes $TYPE1$ tk returns nothing
            local integer i = $TYPE1$2i(tk)+this
            local integer x = $TYPE1$2i_CX(i-(i/8190)*8190)+1
            set i = integer2i_c[x]
            loop
                exitwhen i == 0
                if ($TYPE1$2i_e_k<i> == tk and integer2i_e_id<i> == this) then
                    if (integer2i_c[x] == i) then
                        set integer2i_c[x] = integer2i_e_u<i>
                    else
                        set integer2i_e_u[integer2i_e_d<i>] = integer2i_e_u<i>
                    endif
                    set integer2i_e_d[integer2i_e_u<i>] = integer2i_e_d<i>
                    
                    if (.ef == i) then
                        set .ef = integer2i_e_r<i>
                    else
                        set integer2i_e_r[integer2i_e_l<i>] = integer2i_e_r<i>
                    endif
                    set integer2i_e_l[integer2i_e_r<i>] = integer2i_e_l<i>
                    
                    set $TYPE1$2i_e_k<i> = $TYPE1$2i_no_$TYPE1$
                    set $TYPE2$s_e_v<i> = $TYPE2$s_no_$TYPE2$
                    
                    set integer2i_e_ids[integer2i_e_n] = i
                    set integer2i_e_n = integer2i_e_n+1
                    set .ns = .ns-1
                    return
                endif
                set i = integer2i_e_u<i>
            endloop
        endmethod
        
        method getValue takes $TYPE1$ tk returns $TYPE2$
            local integer i = $TYPE1$2i(tk)+this
            set i = integer2i_c[$TYPE1$2i_CX(i-(i/8190)*8190)+1]
            loop
                exitwhen i == 0
                if ($TYPE1$2i_e_k<i> == tk and integer2i_e_id<i> == this) then
                    return $TYPE2$s_e_v<i>
                endif
                set i = integer2i_e_u<i>
            endloop
            return $TYPE2$s_no_$TYPE2$
        endmethod
        
        method setValue takes $TYPE1$ tk, $TYPE2$ tv returns nothing
            local integer i = $TYPE1$2i(tk)+this
            local integer x = $TYPE1$2i_CX(i-(i/8190)*8190)+1
            set i = integer2i_c[x]
            loop
                exitwhen i == 0
                if ($TYPE1$2i_e_k<i> == tk and integer2i_e_id<i> == this) then
                    set $TYPE2$s_e_v<i> = tv
                    return
                endif
                set i = integer2i_e_u<i>
            endloop
            if (integer2i_e_n == 0) then
                set integer2i_e_m = integer2i_e_m+1
                set i = integer2i_e_m
            else
                set integer2i_e_n = integer2i_e_n-1
                set i = integer2i_e_ids[integer2i_e_n]
            endif
            set $TYPE1$2i_e_k<i> = tk
            set $TYPE2$s_e_v<i> = tv
            set integer2i_e_id<i> = this

            set integer2i_e_u<i> = integer2i_c[x]
            set integer2i_e_d<i> = 0
            set integer2i_e_d[integer2i_c[x]] = i
            set integer2i_c[x] = i
            
            set integer2i_e_r<i> = .ef
            set integer2i_e_l<i> = 0
            set integer2i_e_l[.ef] = i
            set .ef = i
            
            set .ns = .ns+1
        endmethod
        
        method operator [] takes $TYPE1$ tk returns $TYPE2$
            return .getValue(tk)
        endmethod
        
        method operator []= takes $TYPE1$ tk, $TYPE2$ tv returns nothing
            call .setValue(tk, tv)
        endmethod
        
        method begin takes nothing returns nothing
            set .it = .ef
        endmethod
        
        method next takes nothing returns nothing
            set .it = integer2i_e_r[.it]
        endmethod
        
        method getIterKey takes nothing returns $TYPE1$
            return $TYPE1$2i_e_k[.it]
        endmethod
        
        method getIterValue takes nothing returns $TYPE2$
            return $TYPE2$s_e_v[.it]
        endmethod
        
        method iterEnd takes nothing returns boolean
            return .it == 0
        endmethod
        
        private method onDestroy takes nothing returns nothing
            local integer x
            local integer it = .ef
            loop
                exitwhen it == 0
                
                set x = $TYPE1$2i($TYPE1$2i_e_k[it])+this
                set x = $TYPE1$2i_CX(x-(x/8190)*8190)+1
                
                if (integer2i_c[x] == it) then
                    set integer2i_c[x] = integer2i_e_u[it]
                else
                    set integer2i_e_u[integer2i_e_d[it]] = integer2i_e_u[it]
                endif
                set integer2i_e_d[integer2i_e_u[it]] = integer2i_e_d[it]
                    
                set integer2i_e_ids[integer2i_e_n] = it
                set integer2i_e_n = integer2i_e_n+1
                set .ns = .ns-1
                
                set it = integer2i_e_r[it]
            endloop
        endmethod
    endstruct
endlibrary
//! endtextmacro</i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i>
 

GoGo-Boy

You can change this now in User CP
Reaction score
40
Could you explain or give examples what this can be used for and what are it's advantages to structs / PUI / gamecache (in case you can compare the functionality with one of these three).
 

SerraAvenger

Cuz I can
Reaction score
234
This is an easy dictionary.
Advantage over PUI: Usable on everything and anything, not just units
Advantage over Structs: They are quite different, and not really comparable
Advantage over gamecache: Damien says it would be faster and easier to use.


Interesting, really. However I allways hate fuddling with the typecasting in JASS : D
It feels somewhat illegal ;D

Anyway, GJ!
 

Hatebreeder

So many apples
Reaction score
381
Hmmmz...
Can I like, transfer whole Structs with a simple call from one function to annother, like with ABC?
 
Reaction score
333
Could you explain or give examples what this can be used for and what are it's advantages to structs / PUI / gamecache (in case you can compare the functionality with one of these three).

Well, you might:

1. Associate values with type IDs like abilities and unit-types.
2. Create a linked list of structs, handles, etc.
3. Map strings to values.
4. Attach values to handles for use in spells.

No doubt people will think of more creative uses as they become necessary.

Hmmmz...
Can I like, transfer whole Structs with a simple call from one function to annother, like with ABC?

No. This isn't a specialized struct to handle attachment system.

This is an easy dictionary.
Advantage over PUI: Usable on everything and anything, not just units

It is more comparable to SetUnitUserData than PUI. I wouldn't recommend using this to attach data to units, though.

Advantage over gamecache: Damien says it would be faster and easier to use.

Gamecache has always been trouble, it tends to be quite slow, even when using the natives and it has been associated with some nasty bugs in the past. I would say this system has a definite speed (depending on what you use it for) and usability advantage over gamecache.
 
Reaction score
333
Bump + Update.

You can now completely control the name of a map, and it is accessed like an array. You can also control the size of the internal array through the textmacro.
 
Reaction score
333
Thanks Purge.

Another update. Removed the Size Textmacro option as it is now unnecessary. Added size() and empty() methods for retrieving the number of stored values/whether there are any. Changed how the system functions internally.
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
Its for associating values.

JASS:
//! runtextmacro Map(&quot;Ages&quot;, &quot;string&quot;, &quot;integer&quot;)


As you can see by this example that he put up, you add the "Name" "Type 1" and "type 2".

So, if you put string, the value in the brackets "[]" will be a string. Then the Type 2 is the actual variable type. My definition is kind of weird, but I suggest you read the post over and over again until you get it, because it is probably more in benefit of JASS users. :thup:
 

Vexorian

Why no custom sig?
Reaction score
187
You are typecasting from string to integer which will break when loading games.
 
Reaction score
333
Yeah, I read about that shortly after posting this.

I added "5. Stored Data in string maps will not survive a save game + load game due to a lame bug." to the original post. I'm not sure how I might work around it without using lamecache (which, now that I think about it, would only offer a solution for single player).
 
Reaction score
333
Update. Now twice as absurd. Maps can be declared dynamically, have iterators, work on almost all types (code being an exception), can be used as multi-maps.

Sample code:

JASS:
//! runtextmacro Map(&quot;data&quot;, &quot;string&quot;, &quot;integer&quot;)
//this needs to be called for each *type* of map that you want.

scope Test initializer Init
    private function Init takes nothing returns nothing
        local data foo = data.create() // creates a new map
        
        set foo[&quot;a string&quot;] = 42 // maps &quot;a string&quot; to 42
        set foo[&quot;another string&quot;] = 142 // maps &quot;another string&quot; to 142
        
        call foo.begin() // resets the iterator (must be called each time before use it).
        
        loop
            exitwhen foo.iterEnd() // returns true when there are no more pairs left.
            call BJDebugMsg(foo.getIterKey() + &quot; -&gt; &quot; + I2S(foo.getIterValue())) // prints &quot;key -&gt; value&quot;.
            call foo.next() // increments the iterator to the next pair.
        endloop
        
        call foo.destroy() // cleans up.
    endfunction
endscope


I'll try to get a demo map up at some stage.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top