HerculesWS/Hercules — pull request #328 by v4Lo (2014-08-25 23:47:00+00:00)
Title: Fixes queue iteration not handling stray -1 that got created by item removal

In the current implementation the -1 created by removal of elements from the queue are not ignored by the iterator or getter. This new implementation will swap the content of the queue to the beginning retaining order but ignoring every number <= 0 (we are using -1 as magic number for deleted elements anyway). Then the end of the field is replaced by 0s so the add implementation detects them as empty.

I did this in the construction method for new iterators, as this won't add additional complexity to the add method. The tradeoff is slightly higher memory consumption in case of many removals and additions without ever iterating.