![]() |
#1 |
requires vJass
Code Moderator
|
![]() 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.
![]() Last edited by grim001 : 02-05-2010 at 06:19 PM. |
![]() |
![]() |
Sponsored Links - Login to hide this ad! |
|
![]() |
#2 |
In Flames
Join Date: Jan 2006
Posts: 1,154
![]() |
![]() looks much better than DataTable ;)
__________________however in your first example the "LoopThroughAllYourStructs" method most probably should be static ;) |
![]() |
![]() |
![]() |
#3 |
Corkscrew Chainsaw!!!
|
![]() StackModule too plx.
__________________ |
![]() |
![]() |
![]() |
#4 |
requires vJass
Code Moderator
|
![]() Updated, it regained the ability to destroy structs attached to units leaving the game.
|
![]() |
![]() |
![]() |
#5 | |
In Flames
Join Date: Jan 2006
Posts: 1,154
![]() |
![]() Quote:
|
|
![]() |
![]() |
![]() |
#6 |
requires vJass
Code Moderator
|
![]() You mean give the user the option to leak?
|
![]() |
![]() |
![]() |
#7 | |
User
Join Date: Jun 2008
Posts: 72
![]() |
![]() 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:
|
|
![]() |
![]() |
![]() |
#8 |
requires vJass
Code Moderator
|
![]() 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.
|
![]() |
![]() |
![]() |
#9 |
Overdoses result in death
Join Date: Jan 2007
Posts: 2,365
![]() ![]() ![]() |
![]() Grim, change your user title to "Requires vJass" so you don't have to type it for everything you do at WC3C.
__________________ |
![]() |
![]() |
![]() |
#10 | |
requires vJass
Code Moderator
|
![]() Quote:
Do you actually need fast random access? Otherwise linked list is superior. |
|
![]() |
![]() |
![]() |
#11 |
Moderator
Code Moderator
Join Date: Feb 2006
Posts: 1,405
![]() ![]() ![]() ![]() |
![]() 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. |
![]() |
![]() |
![]() |
#12 |
requires vJass
Code Moderator
|
![]() Let's compare array iteration and linked list iteration:
Array style: ![]() 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 1 comparison, 1 global array read, 3 local read, 2 local sets, 1 subtraction per loop Linked list style: ![]() 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 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. |
![]() |
![]() |
![]() |
#13 |
Moderator
Code Moderator
Join Date: Feb 2006
Posts: 1,405
![]() ![]() ![]() ![]() |
![]() 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. |
![]() |
![]() |
![]() |
#14 |
requires vJass
Code Moderator
|
![]() I'm going to split this into two libraries since UnitList has become much bigger.
|
![]() |
![]() |
![]() |
#15 |
Free Software Terrorist
Technical Director
|
![]() 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. |
![]() |
![]() |
![]() |
Thread Tools | Search this Thread |
|
|