| 05-16-2009, 08:13 AM | #1 |
Just want to know your thoughts. I didn't submit it because there are already other indexing systems. I'm just going to use this one for personal use. Anyways, would like your thoughts on the code, improvments, questions ect.. If i'm going to use this for personal use, hopefully theres nothing dangerously wrong with the code. JASS:library Index globals private constant integer SUBTRACT = 0x100000 private constant integer ARRAY_SIZE = 8190 endglobals struct index private static method Handle2Integer takes handle h returns integer return h return 0 endmethod private handle indexed static method add takes handle u returns index local index i = index.Handle2Integer(u)-SUBTRACT if index.Handle2Integer(u)-SUBTRACT > ARRAY_SIZE then debug call BJDebugMsg("Index is too big (" + I2S(i) + ")") return i endif set i.indexed = u return i endmethod static method get takes handle u returns index return index.Handle2Integer(u)-SUBTRACT endmethod endstruct endlibrary JASS:scope Demo initializer InitTrig struct timerdata string name endstruct function Remove takes nothing returns nothing local index sometimer = index.get(GetExpiredTimer()) // Get the expired timer local timerdata d = sometimer // load the timers attached struct call BJDebugMsg(d.name) // display the timers stored name call sometimer.flush() // clears the index so it can be re-used. endfunction private function Actions takes nothing returns nothing local timer t = CreateTimer() // create some timer local index sometimer = index.add(t) // create the index and store the timer local timerdata d = sometimer // Some struct that will store data to the timer set d.name = "SomeTimer" // set the name of the timer call TimerStart(t, 1, false, function Remove) // Begin the timer endfunction //=========================================================================== private function InitTrig takes nothing returns nothing local trigger t = CreateTrigger() call TriggerRegisterTimerEvent(t, 0.00, false) call TriggerAddAction(t, function Actions) endfunction endscope |
| 05-16-2009, 10:04 AM | #2 |
Why repeat index.Handle2Integer(u) instead of using i? |
| 05-16-2009, 03:27 PM | #3 | |
Quote:
Integer typecasting slipped my mind, fixed. |
| 05-16-2009, 06:12 PM | #4 |
I understand it's for your personal use, but wouldn't it get tiring of typing out "Handle2Integer" over and over again, instead of simply typing "H2I." |
| 05-16-2009, 08:36 PM | #5 |
Handle2Integer is only used internally, I never have to call it. |
| 05-17-2009, 01:40 PM | #6 |
whats the use of index.indexed? ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ does setting a struct's id JASS:set myStruct = i i think JASS:set myStruct = 0 if this is true, then this method messes with your structs. |
