Artemis Map vs List

Hi, im new to game dev, just asking if what is the fastest way to get the entity? do i need to iterate over the list to get the entity or use a key to get it?

thanks!

Yeap, 50 years…

Could you explain more? I doubt anyone would understand your question…

From what I got is that you’re asking whether to use List or Hashmap.
From my experience with performance, Array > List > Hashmap (I might be really wrong :D)

To be honest, it depends on the number of entities. :point:

From my experience, iterating is always been the fastest. If you are talking about 10000000 entities, then maybe it’ll be worth it to use a hashmap. But for just finding a single object in a small list, nothing beats a simple “for” loop for speed.

Assuming that there are around 1000 entities. do you think a simple for loop is fast enough to handle it?

automatic save on the profile info? :o

When you say Artemis Map, do you mean the Bag class in Artemis ESF? If so, Bag is a list-type collection - entities are retrieved via indices, not keys, and can be iterated the same way a list is.

Yes, some more details would be nice :slight_smile:

If your entities have an id, you could use a sorted Arraylist -> Binarysearch. But I think it’s not worth it :slight_smile:

Can’t say I’ve used maps to hold entities, tbh im just starting to discover the magic of maps as of recent.

I’ve mainly used array list and the libgdx array, I’ve only ever pushed my array to around 4k or so, only about 20 of those entities were actually doing anything (collision checking, moving etc etc) so it pretty much iterated over it in milli seconds.

This is just light testing though, nothing else was going on.

The more important question is what are the frequent look-ups going to be? Do you actually need to perform a lookup? If you need to think about speed it’s going to be for the expensive/frequent lookups that are important. Find this entity out of the set of all entities is an operation that you don’t have to perform very often.

Roquen is correct, the best data structure to use (you most likely don’t need the best even, just decent) is highly variable depending on the activity the structure will see.

Lots of look-ups via indices? Use a List type.
Lots of look-ups via reference> Use a Map type, or a sorted List + binary search.

Also the frequency of insertion (at the end or in the middle is another issue) and removal/deletion matter in performance.

There are other options, even sub-options within the one I just mentioned, have a look here: http://stackoverflow.com/questions/8725387/why-there-is-no-sortedlist-in-java

Honestly though, with only ~1000 entities, you could simply loop over an unsorted List and be fine. This is all pretty much overkill, UNLESS you find that this part of your code becomes a bottleneck.