Reputation: 2438
Ok so i reformated the post to make it a little easier to understand (sorry about all the pastebins but stack overflow was being dumb with code formatting)
Please note that I do not intend to have the ridiculous amount of data stored as I state below. The main reason I use the amount I said is to squeeze out as much efficiency as possible.
Lets say I have the following code(s)
the method that will be adding to the DropItemQueue (starts at floodFill(with depth 0) the other paramaters do not matter)
this is the same class and it will then call the dropItem method in Utils
My Utils.dropItem method is as follows
This is the ServerTickHandler.addDropItemQueue method and its variable storage
Here is the DropItemQueue class
If I was to say add 100000000 elements to this hashset I have noticed that it takes around 2 seconds to
iterate over everything in the hashset using This iterator is called every 1/20th of a seccond
2 seconds per iteration doesn't seem like much but with that amount of elements to get rid of every single element stored in the hash set it would take around 50 days
every time an element is parsed to the hashset the maxTicks is 1 more than the previous added element so basically every 1 second an item is dropped but due to the 2 seconds to iterate over everything its actually taking 3 seconds to drop an item which would make it take around 150 days to complete the iteration and flush every element out and complete
my question is would it be quicker to have multiple hash sets with less maximum elements lets say 1000 elements.
yes this would give me 100000 hashsets but due to them each being smaller would the iterations times be slower (all be it a very small increase in efficiency) or is there something better I can use other than a hashsets or are hashsets the best thing to use?
do note that if I did use multiple iterations of smaller iterations I could not use threads due to cross thread data redundancy
Upvotes: 0
Views: 1612
Reputation: 4999
The HashSet
data structure is designed for really only one purpose, which is to answer the question "Does this set contain this item". For any other use it not necessarily the most efficient.
For your use, it seems like a Queue would be a better choice.
Upvotes: 1