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
1
/******************************************************************
2
*                         MICROTABLE V1.0                         *
3
*                           By moyack                             *
4
*                              2013                               *
5
*              ===================================                *
6
*              Exclusive resource from wc3jass.com                *
7
*              ===================================                *
8
******************************************************************/
9
library MicroTable
10
/*
11
 the purpose of this library is to allow the attachment of data
12
 struct by its index in an easy way.
13
 
14
 Features:
15
  - One command style to get, retrieve data (GetData, StoreData)
16
  - Automatic flush of data when you call any Remove* or Destroy*
17
    function.
18
  - You can get the main hashtable so in you map you only need one 
19
    hastable
20
  - Inline friendly :D
21
 
22
 Functions provided:
23
  - GetTable: Returns the main Hashtable so you can use it in
24
    other parts of the code in you map.
25
  - StoreData: Connects the handle with a struct usind an index
26
    value.
27
  - GetData: Retrieves the struct data from the respective handle
28
    and index.
29
  - HasData: Checks if a handle has a struct stored with the
30
    specified index.
31
  - ClearData: Clears the struct info from the handle in the 
32
    specified index.
33
  - FlushData: Clear ALL the information related to the handle
34
    (this function is called automatically when you destroy or
35
    remove that handle)
36
*/
37
38
globals
39
    private hashtable H = InitHashtable()
40
endglobals
41
42
constant function GetTable takes nothing returns hashtable
43
    return H
44
endfunction
45
46
function StoreData takes handle h, integer index, integer value returns nothing
47
    call SaveInteger(H, GetHandleId(h), index, value)
48
endfunction
49
50
function GetData takes handle h, integer index returns integer 
51
    return LoadInteger(H, GetHandleId(h), index)
52
endfunction
53
54
function HasData takes handle h, integer index returns boolean
55
    return HaveSavedInteger(H, GetHandleId(h), index)
56
endfunction
57
58
function ClearData takes handle h, integer index returns nothing 
59
    call RemoveSavedInteger(H, GetHandleId(h), index)
60
endfunction
61
62
function FlushData takes handle h returns nothing
63
    call FlushChildHashtable(H, GetHandleId(h))
64
endfunction
65
66
//==================================================
67
hook RemoveDestructable FlushData
68
hook RemoveItem FlushData
69
hook RemoveLocation FlushData
70
hook RemoveRect FlushData
71
hook RemoveRegion FlushData
72
hook RemoveUnit FlushData
73
hook RemoveWeatherEffect FlushData
74
hook DestroyBoolExpr FlushData
75
hook DestroyCondition FlushData
76
hook DestroyDefeatCondition FlushData
77
hook DestroyEffect FlushData
78
hook DestroyFilter FlushData
79
hook DestroyForce FlushData
80
hook DestroyGroup FlushData
81
hook DestroyImage FlushData
82
hook DestroyItemPool FlushData
83
hook DestroyLeaderboard FlushData
84
hook DestroyLightning FlushData
85
hook DestroyMultiboard FlushData
86
hook DestroyQuest FlushData
87
hook DestroyTextTag FlushData
88
hook DestroyTimer FlushData
89
hook DestroyTimerDialog FlushData
90
hook DestroyTrigger FlushData
91
hook DestroyUbersplat FlushData
92
hook DestroyUnitPool FlushData
93
94
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.