| 01-19-2010, 08:32 AM | #1 |
Sup dudes! I was working around with tables, and I know thought why not create different tables for whatever you need? Now you can store units with units, integers with integers, units with integers, integers with units etc! :D Just make your own table you need to have. JASS:library AdvancedTable //: CnP from Vexorians Table. //: Sorry dude, there is no other way. //============================================================= globals private constant integer MAX_INSTANCES=8100 //400000 //Feel free to change max instances if necessary, it will only affect allocation //speed which shouldn't matter that much. private hashtable ht // Actually this is the data holder endglobals //========================================================= private struct GTable[MAX_INSTANCES] method reset takes nothing returns nothing call FlushChildHashtable(ht, integer(this) ) endmethod private method onDestroy takes nothing returns nothing call this.reset() endmethod //============================================================= // initialize it all. // private static method onInit takes nothing returns nothing set ht = InitHashtable() endmethod endstruct //: Setup textmacros for table creation. //! textmacro AdvancedTable_make takes name, valType, func, funcPref, hashType, paraType, keyType, key, value struct $name$Table extends GTable method operator [] takes $keyType$ key returns $valType$ return Load$func$$funcPref$(ht, integer(this), $key$) endmethod method operator []= takes $keyType$ key, $paraType$ value returns nothing call Save$func$$funcPref$(ht, integer(this) ,$key$, $value$) endmethod method flush takes $keyType$ key returns nothing call RemoveSaved$hashType$(ht, integer(this), $key$) endmethod static method flush2D takes string firstkey returns nothing call $name$Table(- StringHash(firstkey)).reset() endmethod static method operator [] takes string firstkey returns $name$Table return $name$Table(- StringHash(firstkey) ) endmethod endstruct //! endtextmacro //: Finally create our crazy tables. // TableName DataType Func Prefix hashID paraType keyType key value //! runtextmacro AdvancedTable_make("Integer", "integer", "Integer", "", "Integer", "integer", "integer", "key", "value") //! runtextmacro AdvancedTable_make("Boolean", "boolean", "Boolean", "", "Boolean", "boolean", "integer", "key", "value") //! runtextmacro AdvancedTable_make("Unit", "unit", "Unit", "Handle", "Handle", "unit", "integer", "key", "value") //! runtextmacro AdvancedTable_make("Item", "item", "Item", "Handle", "Handle", "item", "integer", "key", "value") endlibrary JASS:local UnitTable ut = UnitTable.create() set ut[0] = CreateUnit('hpea', Player(0), 0., 0., 0.) It has all features of Table and even more! What do you think? |
| 01-19-2010, 03:03 PM | #2 |
remove $value$, $key$ (useless) and merge $Func$ and $Prefix$ (can be easyliy combined) |
| 01-20-2010, 12:12 AM | #3 |
all values stored in same keyspace you dont need multiple functions for removal. |
| 01-20-2010, 08:13 AM | #4 | |
Quote:
and merge $Func$ and $Prefix$ (can be easily combined) I could, but its differencing two things. |
