• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a faction for Warcraft 3 and enter Hive's 19th Techtree Contest: Co-Op Commanders! Click here to enter!
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 21st Texturing Contest: Upgrade is now concluded, time to vote for your favourite set of icons! Click here to vote!

Unit Groups vs Linked Lists

Status
Not open for further replies.
Level 19
Joined
Mar 18, 2012
Messages
1,716
A unit group probably runs via an internal stack or linked list.

Both FirstOfGroup loops and coded linked list iterations are very fast.
Add/Remove are probably faster for group handles.
Create/Destroy are probably equal, maybe faster for your own coded linked list.
Important could be that groups automatically remove invalid ( removed ) units.

Use what fits you best.

ForGroup is definitly slower on bigger groups.

I would use linked lists.
 
Level 24
Joined
Aug 1, 2013
Messages
4,658
There is some serious difference between a vector and a linked list...
However, I do think unit groups are vectors as well.

Myself, I dont really care much and use unit groups.
But having a feature to loop over a group without removing the units on it without using a swap group would be nice.

But apart from that, you are still bound to unit groups because you cant do "LinkedListEnumUnitsInRange()" or something like that.
You still have to read from the group and while you are doing so, then you can better just do what you wanted to do.

But as long as you are not bound to such methods and you only need the "group" to store units, then a linked list is in my eyes a better option.
 
If list is good for your, then use list.
VectorT is similar, but has more logic included.

VectorT does allow functions: assign/insert/erase. But their complexity is O(n), and sadly there
is no optimized way provided to remove for example the first element without using erase.
In a list you have less functionality, but can simply connect the next to prev and alike - so is more light weight if you need this example.

Lists are good.
VectorT is also good, provides some more, but not always needed.
 
Level 24
Joined
Aug 1, 2013
Messages
4,658
Lists are faster, but not for lookups :)
That's one of the cons of a list.


Vector is a self-resizing array so no.

You forget that lists do not change the indices of their content.
If you have a uniquely filled list (one that do not fill multiple indices with the same data), you can then make a variable on that data that stores in which indice they are stored.

Then you have 100% fastest lookups.
The only problem is when your hardware device is going mental and starts loading data you are going to use in the next iterations of the loop.
In that case, linear lists are way faster... that said arrays. I dont know how vectors work behind the screen, but I assume this is the difference between arrays and (linked lists + vectors).

The only real drawback you will be facing in JASS is that you cannot for example do a binary search... cause you cant get to the middle or something like that.

@SpellBound
Unit groups arent bad.
You should start using advanced lists as soon as you want to store something else than a unit...
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
Be carefull with ghost units (units removed of the game but not from the group).
Indeed, units are not automatically removed from a group when they are removed off the game, and then FirstOfGroup can an will return null when you will try to enum this ghost unit, and then the FirstOfGroup loop will be stopped before the end.

Note that ForGroup doesn't enum ghost units, but's it's way slower and it splits the code.
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
Be carefull with ghost units (units removed of the game but not from the group).
Indeed, units are not automatically removed from a group when they are removed off the game, and then FirstOfGroup can an will return null when you will try to enum this ghost unit, and then the FirstOfGroup loop will be stopped before the end.
Is that a confirmed issue? I will test it asap, very intersting.
 
Level 7
Joined
Oct 19, 2015
Messages
286
It's 2016, there are still people who don't know about this issue?

The whole method of using an indexing system to attach data to units and then using groups to loop through those units is really suboptimal. The only reason it is used is because it's the most expedient method available in plain JASS. It's been almost 10 years though, people really need to stop being afraid of vJass and start using it.
 
Level 5
Joined
Mar 6, 2015
Messages
130
Depends the Dynamic Indexing is a very fast method but hard to create it`s to better using Dynamic Indexing while you need to run a spell too many times like Systems and templates but for a Normal Spell Using UnitGroups is better because its faster to create them and also Use UnitGroups while you using Hashtables They are Prefect matches

It's 2016, there are still people who don't know people really need to stop being afraid of vJass and start using it.

It`s not a Official Language and most of the times people encounter Compatibility issues while using vjass stuff because the original Worldedit doesn`t support it and you have to use JNGP and JNGP is one of the most horrible thing i`v ever used very buggy and incompatible with Warcraft i rather use GUI and Jass
 
Last edited by a moderator:
Level 5
Joined
Mar 6, 2015
Messages
130
When, where, how? Can you list an example?

Very radical view on something working well for a huge group of people.
1-my anti-virus constantly removes the JNGP
2-the still uses old version of worldedit this means if you create a map with regular WE and save it with JNGP your map will be gone one of my spell Packs get destroyed because I didn't know this fact

3-the JNGP skips the syntax errors and runs the map and warcraft couldn't load that map the debug window never shows up the JNGP`sntax checker is always malfunctioned getting weird errors when you fix them manually like copying the missed dlls will still have an inaccurate syntax checker constantly shows
Weird syntax errors in an approved vjass spell!


4-most important one when you copy an vjass spell in your map you can`t add a simple trigger to map andthe god blessed syntax checker finds errors in spell`s code
Besides the maps containing vjass codes won't be run in warcraft
 
1. Change antivirus? I use Nod32 and it never had any problems with JNGP.
2. Whenever I open a map that's been created with Vanilla WE in JNGP it tell me the version is off. That's it, no data loss whatsoever.
3. Have you updated JassHelper? If you don't the syntax checker will find all sorts of weird bugs that aren't there.
4. ???

PS: Not saying you don't have these problems, it's just very strange.
 
Status
Not open for further replies.
Top