radomize a number list

  • Thread starter Thread starter William Stacey [MVP]
  • Start date Start date
William Stacey said:
Here is a Permuted Order class to find the next permutation of any ArrayList
using Lexicographic order based on HashCodes.
I would prefer to use Object Reference int as the order key as would not
have to call GetHashCode() on each object in arraylist, but can't figure out
a way to get object ref int in a safe context. Maybe not good either as GC
can move refs - right?

Indeed. I'm concerned that your algorithm is assuming that two objects
with the same hashcode are different though... if you give your
algorithm a list with two objects which are unequal but have the same
hashcode, I believe it will treat them as being the same, incorrectly.

One way of getting round that would just be to assign each object a
sequential number, making sure that you assign equal objects the same
number. You could put that number in a hash table, for instance, so you
could look it up in order to do the comparison.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top