Originally Posted by
Andys1814
And how would using an ArrayList solve this?
The size of the ArrayList is exactly the number of players online and not MAX_PLAYERS.
Yes you can have an IF statement to skip the null entries in an array but that still an extra O( n ) steps.
So over 30+ loops this adds up.
Unless I'm wrong. Then please correct me.
Originally Posted by
Kris
List only loops from 0 til size(amount of objects in the list, not the length of the backing array).
A bit less looping, yes. However if you're looking to find players by name, go with my suggestion above. Use a map of <string(username), player(the player object)>; always stick to one format and you have no problems whatsoever; o(1) lookup time, no looping or anything.
We are not looking for anything specific. We just want to improve the overall efficiency of PI code. So wherever we can we are.
Also in PI (in my cleaned source anyway): It was initialised like this
Code:
public static Player players[] = new Player[Settings.MAX_PLAYERS];
static {
for (int i = 0; i < Settings.MAX_PLAYERS; i++)
players[i] = null;
}
So looping through size would in-fact be O( n ) steps