Does the set size change - does it grow and shrink once created?
What is most important to you - speed? memory utilization?
Does the list need to be sorted? members inserted in the middle? members deleted from the middle?
Will you 'use' consecutive integers? I.e. can you keep track of the first and last you used (or a list of ranges you've used)?
I would like it to be fast since this is being used in an algorithm that runs through equations and it eventually starts to loop. I am trying to find the first time it starts to repeat.
I have limited knowledge in Java, just trying to convert some code for fun. There will be a bunch more questions in the future!
Ernest Friedman-Hill wrote:The Java equivalent would be to use a HashSet; it would work pretty much the same way:
HashSet is what I been using. I was not sure if that was the best tool for the job. I originally started with an ArrayList and found out that was not the best idea.
As stated, BitSet could be useful if you want to move into extraordinarily large numbers.
I once wrote a bitwise operation that was an array of ints where each bit represented a boolean state for a couple of billion numbers.
As DOM points out, BitSet implements this for you.
Ernest Friedman-Hill wrote:...but it uses just one huge 500M block of memory.
Yeah I've been there, but it isn't as much as a problem as it once was.
Ernest Friedman-Hill wrote:As DOM points out, BitSet implements this for you.
Mr Newton went there first (mostly), straight out of the blocks, even.
I am attacking the problem 100% wrong. Brute force will not win over some fancy algorithm that Math Geeks can whip out.
I just wanted to play around with it as an excuse to write code in a different language.