MicroTable

Scripts

13 years
edited 8 years
Description


This small library allows to attach data structs in a easy way.

Requirements:


- nothing

Actual Code


Code (jass) Select
/******************************************************************
*                         MICROTABLE V1.0                         *
*                           By moyack                             *
*                              2013                               *
*              ===================================                *
*              Exclusive resource from wc3jass.com                *
*              ===================================                *
******************************************************************/
library MicroTable
/*
the purpose of this library is to allow the attachment of data
struct by its index in an easy way.

Features:
  - One command style to get, retrieve data (GetData, StoreData)
  - Automatic flush of data when you call any Remove* or Destroy*
    function.
  - You can get the main hashtable so in you map you only need one
    hastable
  - Inline friendly :D

Functions provided:
  - GetTable: Returns the main Hashtable so you can use it in
    other parts of the code in you map.
  - StoreData: Connects the handle with a struct usind an index
    value.
  - GetData: Retrieves the struct data from the respective handle
    and index.
  - HasData: Checks if a handle has a struct stored with the
    specified index.
  - ClearData: Clears the struct info from the handle in the
    specified index.
  - FlushData: Clear ALL the information related to the handle
    (this function is called automatically when you destroy or
    remove that handle)
*/

globals
    private hashtable H = InitHashtable()
endglobals

constant function GetTable takes nothing returns hashtable
    return H
endfunction

function StoreData takes handle h, integer index, integer value returns nothing
    call SaveInteger(H, GetHandleId(h), index, value)
endfunction

function GetData takes handle h, integer index returns integer
    return LoadInteger(H, GetHandleId(h), index)
endfunction

function HasData takes handle h, integer index returns boolean
    return HaveSavedInteger(H, GetHandleId(h), index)
endfunction

function ClearData takes handle h, integer index returns nothing
    call RemoveSavedInteger(H, GetHandleId(h), index)
endfunction

function FlushData takes handle h returns nothing
    call FlushChildHashtable(H, GetHandleId(h))
endfunction

//==================================================
hook RemoveDestructable FlushData
hook RemoveItem FlushData
hook RemoveLocation FlushData
hook RemoveRect FlushData
hook RemoveRegion FlushData
hook RemoveUnit FlushData
hook RemoveWeatherEffect FlushData
hook DestroyBoolExpr FlushData
hook DestroyCondition FlushData
hook DestroyDefeatCondition FlushData
hook DestroyEffect FlushData
hook DestroyFilter FlushData
hook DestroyForce FlushData
hook DestroyGroup FlushData
hook DestroyImage FlushData
hook DestroyItemPool FlushData
hook DestroyLeaderboard FlushData
hook DestroyLightning FlushData
hook DestroyMultiboard FlushData
hook DestroyQuest FlushData
hook DestroyTextTag FlushData
hook DestroyTimer FlushData
hook DestroyTimerDialog FlushData
hook DestroyTrigger FlushData
hook DestroyUbersplat FlushData
hook DestroyUnitPool FlushData

endlibrary


Example


Check the library Hibrid TimerUtils in the related links.
13 years
Approved.

Some people would find this useful while map-making.

I don't know if GetTable should be in there though. I would discourage it.
13 years
Yay!!! thanks :)

Just for the lulz, do you think that the sample of timer utils can be as fast as Vexorian timerutils?? I dare to say that FUCK YESSS :P
13 years
I'd say that this would have approximately the same speed as TimerUtils when it stores data into a hashtable :P
The array version however, is probably faster than this at loading data and saving it only because of the speed of the hashtable.
A hashtable gets much slower as you put more data in it because of the hash collisions.
13 years
edited 13 years
Quote from: Magtheridon96 on February 14, 2013, 08:54:38 PM
I'd say that this would have approximately the same speed as TimerUtils when it stores data into a hashtable :P
The array version however, is probably faster than this at loading data and saving it only because of the speed of the hashtable.
A hashtable gets much slower as you put more data in it because of the hash collisions.
Hmmm now I'm curious... Is there a test that shows how much hashtable becomes slow?

And I forgot...
Quote from: Magtheridon96 on February 13, 2013, 10:49:27 AMI don't know if GetTable should be in there though. I would discourage it.
I did this so people just use one table, just in case they could need to store other kind of stuff different from integers.
13 years
I'm not sure that making some resources only available there is a great idea, i mean the community is more and more little, so imho it should be posted also on hiveworkshop also.
I've nothing to say about the resource by itself, even if i'm not a fan of hooks i suppose it makes sense there.
13 years
Quote from: Troll-Brain on February 20, 2013, 03:21:14 PM
I'm not sure that making some resources only available there is a great idea, i mean the community is more and more little, so imho it should be posted also on hiveworkshop also.
I want to have stuff that you can't find in other sites, besides, we're not restricting in any way. Probably later I'll post them in other sites.
QuoteI've nothing to say about the resource by itself, even if i'm not a fan of hooks i suppose it makes sense there.
In this case there's no problem unless you code horribly and destroy too often handles :P
10 years
What do you mean by "destroy too often handles"?
10 years
Quote from: sankaku on August 31, 2015, 04:08:14 AM
What do you mean by "destroy too often handles"?
I refer to the paranoic habit that some wc3 mappers have to over clean variable causing double free dealocation and making the map buggy. This happen due to lack of experience in jass coding.
10 years
Where would that usually happen? In structs? Or maybe in functions with only one return line but many ifs? The latter of course I would understand, not that I would do it, but structs are still a bit hard to understand for me even though I can use them to a lesser extent.
10 years
Quote from: sankaku on September 01, 2015, 12:25:35 PM
Where would that usually happen? In structs? Or maybe in functions with only one return line but many ifs? The latter of course I would understand, not that I would do it, but structs are still a bit hard to understand for me even though I can use them to a lesser extent.
In any part done in jass. But the trick is to have a good understanding about the memory usage in WC3.