wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Resources > Code Resources > Scripts
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 04-15-2009, 12:46 AM   #1
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default ListModule

This library provides the List module, which allows you to easily create a linked list of all of the allocated instances of a struct-type. Iterating through a linked list is about 12% faster than iteratating through an array in JASS. There is no faster method to iterate through a list of structs than the method used by this module. Aside from the marginal speed gain, the best use of this library is to hide some ugly low-level code from your structs. Rather than manually building and maintaining a list of struct instances, just implement the List module, and your code will become much prettier.

Expand JASS:

Last edited by grim001 : 02-05-2010 at 06:19 PM.
grim001 is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 04-15-2009, 05:13 AM   #2
akolyt0r
In Flames
 
akolyt0r's Avatar
 
Join Date: Jan 2006
Posts: 1,154

Submissions (3)

akolyt0r has a spectacular aura about (120)

Default

looks much better than DataTable ;)

however in your first example the "LoopThroughAllYourStructs" method most probably should be static ;)
__________________
akolyt0r is offline   Reply With Quote
Old 04-15-2009, 05:46 AM   #3
Here-b-Trollz
Corkscrew Chainsaw!!!
 
Join Date: Jun 2006
Posts: 711

Here-b-Trollz has a spectacular aura about (149)

Hero Contest #2 - 2nd Place

Default

StackModule too plx.
__________________
By reading this signature, you agree that I cannot be held accountable for anything that I might say or do.
Here-b-Trollz is offline   Reply With Quote
Old 04-15-2009, 06:51 AM   #4
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default

Updated, it regained the ability to destroy structs attached to units leaving the game.
grim001 is offline   Reply With Quote
Old 04-15-2009, 08:05 AM   #5
akolyt0r
In Flames
 
akolyt0r's Avatar
 
Join Date: Jan 2006
Posts: 1,154

Submissions (3)

akolyt0r has a spectacular aura about (120)

Default

Quote:
Originally Posted by grim001
Updated, it regained the ability to destroy structs attached to units leaving the game.
that should be optional .. add a boolean to UnitList...
__________________
akolyt0r is offline   Reply With Quote
Old 04-15-2009, 08:15 AM   #6
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default

You mean give the user the option to leak?
grim001 is offline   Reply With Quote
Old 04-15-2009, 11:55 AM   #7
dead_or_alivex
User
 
Join Date: Jun 2008
Posts: 72

dead_or_alivex has little to show at this moment (3)

Default

Great, I was just thinking of something like this. I was toying with the idea of making structs extend a linked list struct, then thought to use the new modules, and then came across this topic.

Quote:
Originally Posted by Documentation
The "List" module allows you to create a linked list containing all of the allocated instances of a struct.
This is slightly misleading. You can choose which structs go into the list, right? When I first read it I got the impression that you couldn't.
dead_or_alivex is offline   Reply With Quote
Old 04-15-2009, 12:21 PM   #8
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default

You can leave structs out of the list, but I can't think of any application where it makes sense to do so. Documentation gets long enough without describing unintended ways of using it. If Vex adds module-specific onCreate, onDestroy, etc., I could make the adding/removing automatic.
grim001 is offline   Reply With Quote
Old 04-15-2009, 12:54 PM   #9
Tide-Arc Ephemera
Overdoses result in death
 
Tide-Arc Ephemera's Avatar
 
Join Date: Jan 2007
Posts: 2,365

Submissions (3)

Tide-Arc Ephemera is a jewel in the rough (206)Tide-Arc Ephemera is a jewel in the rough (206)Tide-Arc Ephemera is a jewel in the rough (206)

Default

Grim, change your user title to "Requires vJass" so you don't have to type it for everything you do at WC3C.
__________________
Before asking for help with triggers... read this and check your trigger!

If you're having troubles getting help on WC3C or anywhere at all, please have a look at...
The WRONG way to ask for help and The CORRECT way to ask for help.

Quote:
Originally Posted by Alevice
You may never stop our bioweapon! We mexicans shall rule the third world! Mwahahahahahahaha!
Please acknowledge that I use Mac and avoid suggesting vJass and other tools that don't work on it. Thank you.
Tide-Arc Ephemera is offline   Reply With Quote
Old 04-16-2009, 06:24 AM   #10
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default

Quote:
Originally Posted by Here-b-Trollz
StackModule too plx.

Do you actually need fast random access? Otherwise linked list is superior.
grim001 is offline   Reply With Quote
Old 04-16-2009, 04:36 PM   #11
PipeDream
Moderator
 
PipeDream's Avatar


Code Moderator
 
Join Date: Feb 2006
Posts: 1,405

Submissions (6)

PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)

Default

It doesn't exactly implement what we usually call lists, since there's two extra invariants: uniqueness of entries and it's static in the single instance sense. Because of the uniqueness the base name should be Set. I'm uncertain what to do about the single instantiability - consider SingletonSet, StaticSet.

I'm skeptical of the claim that it's faster than iterating over an array, but I like the style.
__________________
PipeDream is offline   Reply With Quote
Old 04-17-2009, 03:27 AM   #12
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default

Let's compare array iteration and linked list iteration:

Array style:
Collapse JASS:
function DoLoop takes nothing returns nothing
    local integer n = MyStruct.stack_n //global read
    local MyStruct ms
        loop
            exitwhen n < 0 //var read and comparison
            set ms = MyStruct[n] //var set, var read, array read
            //do stuff
            set n = n - 1 //var read, subtraction, var set
        endloop
endfunction
Requires 2 local integer declarations, 1 global read
Requires 1 comparison, 1 global array read, 3 local read, 2 local sets, 1 subtraction per loop

Linked list style:
Collapse JASS:
function DoLoop takes nothing returns nothing
    local MyStruct ms = MyStruct.first //global read
        loop
            exitwhen ms == 0 //var read and comparison
            //do stuff
            set ms = ms.next //var set, var read, array read
        endloop
endfunction
Requires 1 local integer declaration, 1 global read
Requires 1 comparison, 1 global array read, 2 local read, 1 local set

The difference comes out to 1 fewer local declaration in the function, and 1 less local read/local set/subtraction per loop (all from getting rid of the n = n - 1 line). It's not that big of a deal but it should please the "speed wanker" group as they have been referred to lately.

Last edited by grim001 : 04-17-2009 at 03:28 AM.
grim001 is offline   Reply With Quote
Old 04-17-2009, 06:26 AM   #13
PipeDream
Moderator
 
PipeDream's Avatar


Code Moderator
 
Join Date: Feb 2006
Posts: 1,405

Submissions (6)

PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)

Default

Count literal values as well in ops

The subtlety I missed is the extra layer of indirection required by an array implementation which is absorbed naturally by linked lists.

Not a criticism:
You don't have to have indirection at the cost of copying the entire struct contents. Since iteration is more frequent than modification, some structs are small, etc, it's not nonsensical. It could even happen in a system like this w vjass support for automatic struct assignment by value, or a requirement that people write a copy or move by value method.
__________________
PipeDream is offline   Reply With Quote
Old 04-17-2009, 05:49 PM   #14
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default

I'm going to split this into two libraries since UnitList has become much bigger.
grim001 is offline   Reply With Quote
Old 04-20-2009, 03:39 PM   #15
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default

Could you move UnitListModule to another thread? I'll review ListModule:
...
Ok, ListModule has been approved, but I'd rather you move UnitListModule to another thread, so I can just approve this one and review that other one later instead of having to wait till reviewing UnitListModule before approving this one.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 08:47 AM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2019, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services