• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece!🔗 Click here to enter!

HyperTable

Level 21
Joined
Dec 9, 2007
Messages
3,096
JASS:
/*********************************************************************************\
|*                              HyperTable                                       *|
|*                          a library by    vercas                               *|
|*                                                                               *|
|*            Credit me (vercas) if you use this library in any of your projects.*|
|*********************************************************************************|
|*      How to use:                                                              *|
|*          create a new HyperTable by the following way:                        *|
|*      [argument type 1]_[argument type 2]_[argument type to store]_HyperTable  *|
|*********************************************************************************|
|*      So far, I've made                                                        *|
|*  [integer/string/handle][integer/string/handle][integer/string/real/boolean]  *|
|*      HyperTables                                                              *|
|*      So, in the 2D array you may have either integer, string or boolean       *|
|*      And you may save/load integers, reals, strings or booleans               *|
|*          Look at the footer of the library for the text macros; you may       *|
|*              understand the way it works better                               *|
|*          The way this works is pretty easy: you give it an argument, it gives *|
|*              you a helper; you give the helper an arguments or two, it loads  *|
|*                  or saves the data for you!                                   *|
|*          The helper destroys itself, so you don't have to worry about that!   *|
|*          The variables are nulled, so they won't take extra memory!           *|
|*********************************************************************************|
|*      My way of doing this isn't the most performance-wise, but, at least, it  *|
|*          works as it is supposed to!                                          *|
|*********************************************************************************|
|*      So, the syntax is like a 2D array:                                       *|
|*          yourtable[one][two] ...                                              *|
|*              "one" and "two" are the two arguments passed to the hashtables   *|
|*              "yourtable" is, of course, the name of your HyperTable variable! *|
|*            to get a value                                                     *|
|*          yourtable[one][two] = value                                          *|
|*              "value" here is the value you set in the array...                *|
|*                                                                               *|
|*          The purpose of this library is to make 2D arrays able to store more  *|
|*              than 8192 values.                                                *|
|*          These HyperTables may store up to 4294967295^2 values per table!     *|
|*              This means 18446744065119617025 values!                          *|
|*                  Who needs so many, anyway??!!                                *|
\*********************************************************************************/
library HyperTable/**************************************************************/
    
    globals
        private constant integer MAX_INSTANCES = 255
            /* The maximum number of HyperTables you may have...*\
            \* Who on earth needs so many ??!!                  */
    endglobals
    
    //! textmacro HyperTable takes one, two, ret, Load, Save
    private struct $one$_$two$_$ret$_Table_helper
        hashtable h
        $one$ i
        method operator [] takes $two$ i returns $ret$
            local $one$ s = this.i
            local hashtable h = this.h
            call this.destroy()
            return $Load$
        endmethod
        method operator []= takes $two$ i, $ret$ u returns nothing
            call $Save$
            call this.destroy()
        endmethod
        static method create takes hashtable h, $one$ i returns thistype
            local thistype this = thistype.allocate()
            set this.i = i
            set this.h = h
            return this
        endmethod
        private method OnDestroy takes nothing returns nothing
            set this.h = null
        endmethod
    endstruct
    
    struct $one$_$two$_$ret$_Table[MAX_INSTANCES]
        hashtable h = InitHashtable()
        method operator [] takes $one$ i returns $one$_$two$_$ret$_Table_helper
            return $one$_$two$_$ret$_Table_helper.create(this.h, i)
        endmethod
        private method OnDestroy takes nothing returns nothing
            set this.h = null
        endmethod
    endstruct
    //! endtextmacro
    
//! runtextmacro HyperTable("integer","integer","integer","LoadInteger(h,s             ,i             )","SaveInteger(this.h,this.i             ,i             ,u)")
//! runtextmacro HyperTable("integer","integer","string" ,"LoadStr(    h,s             ,i             )","SaveStr(    this.h,this.i             ,i             ,u)")
//! runtextmacro HyperTable("integer","integer","real"   ,"LoadReal(   h,s             ,i             )","SaveReal(   this.h,this.i             ,i             ,u)")
//! runtextmacro HyperTable("integer","integer","boolean","LoadBoolean(h,s             ,i             )","SaveBoolean(this.h,this.i             ,i             ,u)")

//! runtextmacro HyperTable("string" ,"integer","integer","LoadInteger(h,StringHash(s) ,i              )","SaveInteger(this.h,StringHash(this.i) ,i            ,u)")
//! runtextmacro HyperTable("string" ,"integer","string" ,"LoadStr(    h,StringHash(s) ,i              )","SaveStr(    this.h,StringHash(this.i) ,i            ,u)")
//! runtextmacro HyperTable("string" ,"integer","real"   ,"LoadReal(   h,StringHash(s) ,i              )","SaveReal(   this.h,StringHash(this.i) ,i            ,u)")
//! runtextmacro HyperTable("string" ,"integer","boolean","LoadBoolean(h,StringHash(s) ,i              )","SaveBoolean(this.h,StringHash(this.i) ,i            ,u)")

//! runtextmacro HyperTable("handle" ,"integer","integer","LoadInteger(h,GetHandleId(s),i              )","SaveInteger(this.h,GetHandleId(this.i),i            ,u)")
//! runtextmacro HyperTable("handle" ,"integer","string" ,"LoadStr(    h,GetHandleId(s),i              )","SaveStr(    this.h,GetHandleId(this.i),i            ,u)")
//! runtextmacro HyperTable("handle" ,"integer","real"   ,"LoadReal(   h,GetHandleId(s),i              )","SaveReal(   this.h,GetHandleId(this.i),i            ,u)")
//! runtextmacro HyperTable("handle" ,"integer","boolean","LoadBoolean(h,GetHandleId(s),i              )","SaveBoolean(this.h,GetHandleId(this.i),i            ,u)")


//! runtextmacro HyperTable("integer","string","integer","LoadInteger( h,s             ,StringHash(i) )","SaveInteger(this.h,this.i             ,StringHash(i) ,u)")
//! runtextmacro HyperTable("integer","string","string" ,"LoadStr(     h,s             ,StringHash(i) )","SaveStr(    this.h,this.i             ,StringHash(i) ,u)")
//! runtextmacro HyperTable("integer","string","real"   ,"LoadReal(    h,s             ,StringHash(i) )","SaveReal(   this.h,this.i             ,StringHash(i) ,u)")
//! runtextmacro HyperTable("integer","string","boolean","LoadBoolean( h,s             ,StringHash(i) )","SaveBoolean(this.h,this.i             ,StringHash(i) ,u)")

//! runtextmacro HyperTable("string" ,"string","integer","LoadInteger( h,StringHash(s) ,StringHash(i) )","SaveInteger(this.h,StringHash(this.i) ,StringHash(i) ,u)")
//! runtextmacro HyperTable("string" ,"string","string" ,"LoadStr(     h,StringHash(s) ,StringHash(i) )","SaveStr(    this.h,StringHash(this.i) ,StringHash(i) ,u)")
//! runtextmacro HyperTable("string" ,"string","real"   ,"LoadReal(    h,StringHash(s) ,StringHash(i) )","SaveReal(   this.h,StringHash(this.i) ,StringHash(i) ,u)")
//! runtextmacro HyperTable("string" ,"string","boolean","LoadBoolean( h,StringHash(s) ,StringHash(i) )","SaveBoolean(this.h,StringHash(this.i) ,StringHash(i) ,u)")

//! runtextmacro HyperTable("handle" ,"string","integer","LoadInteger( h,GetHandleId(s),StringHash(i) )","SaveInteger(this.h,GetHandleId(this.i),StringHash(i) ,u)")
//! runtextmacro HyperTable("handle" ,"string","string" ,"LoadStr(     h,GetHandleId(s),StringHash(i) )","SaveStr(    this.h,GetHandleId(this.i),StringHash(i) ,u)")
//! runtextmacro HyperTable("handle" ,"string","real"   ,"LoadReal(    h,GetHandleId(s),StringHash(i) )","SaveReal(   this.h,GetHandleId(this.i),StringHash(i) ,u)")
//! runtextmacro HyperTable("handle" ,"string","boolean","LoadBoolean( h,GetHandleId(s),StringHash(i) )","SaveBoolean(this.h,GetHandleId(this.i),StringHash(i) ,u)")


//! runtextmacro HyperTable("integer","handle","integer","LoadInteger( h,s             ,GetHandleId(i))","SaveInteger(this.h,this.i             ,GetHandleId(i),u)")
//! runtextmacro HyperTable("integer","handle","string" ,"LoadStr(     h,s             ,GetHandleId(i))","SaveStr(    this.h,this.i             ,GetHandleId(i),u)")
//! runtextmacro HyperTable("integer","handle","real"   ,"LoadReal(    h,s             ,GetHandleId(i))","SaveReal(   this.h,this.i             ,GetHandleId(i),u)")
//! runtextmacro HyperTable("integer","handle","boolean","LoadBoolean( h,s             ,GetHandleId(i))","SaveBoolean(this.h,this.i             ,GetHandleId(i),u)")

//! runtextmacro HyperTable("string" ,"handle","integer","LoadInteger( h,StringHash(s) ,GetHandleId(i))","SaveInteger(this.h,StringHash(this.i) ,GetHandleId(i),u)")
//! runtextmacro HyperTable("string" ,"handle","string" ,"LoadStr(     h,StringHash(s) ,GetHandleId(i))","SaveStr(    this.h,StringHash(this.i) ,GetHandleId(i),u)")
//! runtextmacro HyperTable("string" ,"handle","real"   ,"LoadReal(    h,StringHash(s) ,GetHandleId(i))","SaveReal(   this.h,StringHash(this.i) ,GetHandleId(i),u)")
//! runtextmacro HyperTable("string" ,"handle","boolean","LoadBoolean( h,StringHash(s) ,GetHandleId(i))","SaveBoolean(this.h,StringHash(this.i) ,GetHandleId(i),u)")

//! runtextmacro HyperTable("handle" ,"handle","integer","LoadInteger( h,GetHandleId(s),GetHandleId(i))","SaveInteger(this.h,GetHandleId(this.i),GetHandleId(i),u)")
//! runtextmacro HyperTable("handle" ,"handle","string" ,"LoadStr(     h,GetHandleId(s),GetHandleId(i))","SaveStr(    this.h,GetHandleId(this.i),GetHandleId(i),u)")
//! runtextmacro HyperTable("handle" ,"handle","real"   ,"LoadReal(    h,GetHandleId(s),GetHandleId(i))","SaveReal(   this.h,GetHandleId(this.i),GetHandleId(i),u)")
//! runtextmacro HyperTable("handle" ,"handle","boolean","LoadBoolean( h,GetHandleId(s),GetHandleId(i))","SaveBoolean(this.h,GetHandleId(this.i),GetHandleId(i),u)")


endlibrary/***********************************************************************/
/*********************************************************************************\
|*          God bless textmacros!                                                *|
|*              This trigger would have been 1522 lines long without them!       *|
\*********************************************************************************/

The library sais it all...

For questions, ask...

There's also a test map attached for integer testing...
 

Attachments

  • HyperTable.w3m
    48.3 KB · Views: 74
Last edited:
Level 21
Joined
Dec 9, 2007
Messages
3,096
You know that there's a limit of 256 hashtables per map? So using 1 hashtable per struct isn't really a wise idea.

But using 256 hashtables or HyperTables per map isn't a wise idea either.

This looks to me like a lame hashtable wrapper.

It is, after all a 2D version of Table, which is also a lame wrapper for hashtables.
 
Level 21
Joined
Dec 9, 2007
Messages
3,096
I would really appreciate if Vexorian would allow 2D array operators for structs. That'll make everything easier!
Hey, but who will need so many, anyway?
If you want to imitate Table, just make a string_integer_integer_HyperTable. This would allow storage of enormous numbers...
God, by the way... I'll update it. I forgot to add real numbers. (They can be converted to strings, and then hashed!)
 
Level 8
Joined
Oct 3, 2008
Messages
367
Now you're just trying to confuse me.

I am saying that this, unlike Vexorian's Table, cannot have more than 256 instances and is thus very limited and is really nothing more than a slow hashtable wrapper.
 
There is no practical use for this system, as pointed out by every post. It's also extremely limited and very easy to simulate by yourself. Hell, doesn't JassHelper even support (limited) 2D arrays?

Anyways, I don't think a hashtable wrapper will ever get approved here. This will be graveyarded unless you have some miraculous update that blows us all away.
 
Top