Tux pointed out the patch still has O(n^2) time complexity since the sublist class in arraylist does not override clear() from AbstractList, which uses a forward moving iterator to clear the list. Resolved by using a peek and poll from ArrayDeque. This patch also removes the useless WeakHashMap which holds the list (it mapped world->list) and replaces it with a field on World.
1.8 KiB
1.8 KiB