• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[April Fools Day 2013] SequentialIntegralDataUnitStorageStructure

Gentlemen, I present, the SequentialIntegralDataUnitStorageStructure!
This structure will actually allow you to store data in memory pseudo-sequentially! The memory addresses are not contiguous at the level of the RAM, but this resource emulates it!

It's innovative, and it just works.

JASS:
/*****************************
*
*   SequentialIntegralDataUnitStorageStructure
*   v1.0.0.0
*   By Magtheridon96
*
*   - Allows the storage of integral data in memory 
*     sequentially all with O(1) complexity!
*
*   API:
*   ----
*
*       struct SequentialIntegralDataUnitStorageStructure extends array
*
*           static method create takes nothing returns thistype
*               - This function initializes an instance of the struct
*           
*           method cache takes integer index, integer memory returns nothing
*               - This function caches memory in the given index
*
*           method lookup takes integer index returns integer
*               - This function lookups the memory stored at a given index
*
*           method destroy takes nothing returns nothing
*               - This will free all memory used by the array           
*
*****************************/
library SequentialIntegralDataUnitStorageStructure

    globals
        private hashtable h = InitHashtable()
    endglobals

    struct SequentialIntegralDataUnitStorageStructure extends array
        private static thistype array rn
        private static integer ic = 0
        
        static method create takes nothing returns thistype
            local thistype this = rn[0]
            if this == 0 then
                set ic = ic + 1
                set this = ic
            else
                set rn[0] = rn[this]
            endif
            call FlushChildHashtable(h, this)
            return this
        endmethod
        
        method cache takes integer index, integer memory returns nothing
            call SaveInteger(h, this, index, memory)
        endmethod
        
        method lookup takes integer index returns integer
            return LoadInteger(h, this, index)
        endmethod
        
        method destroy takes nothing returns nothing
            call FlushChildHashtable(h, this)
            set rn[this] = rn[0]
            set rn[0] = this
        endmethod
    endstruct

endlibrary

Feel free to comment.
 
Last edited:
Top