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
380
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.
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/
  • The Helper The Helper:
    Here is another comfort food favorite - Million Dollar Casserole - https://www.thehelper.net/threads/recipe-million-dollar-casserole.193614/

      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