Re: radomize a number list

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 06/03/04


Date: Thu, 3 Jun 2004 06:20:22 +0100

William Stacey [MVP] <staceywREMOVE@mvps.org> wrote:
> 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.
 

-- 
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Relevant Pages

  • Re: Hashtables
    ... with some digging I found this tidbit: ... A jobject could be something else I guess. ... It seems as if the default algorithm is to use the address at the first attempt to read hashCode. ... I'd be tempted to always store the initial address>> 3, or change the header when hashCode is first used and first copy after use. ...
    (comp.lang.java.help)
  • Re: Problem: GetHashCode for string is different in 1.1 and 2.
    ... or even across calls to GetHashCode across different ... counter to the object reference. ... and use the MD5 or SHA1 algorithm for hashing your data. ... This is creating a big problem, because we relied on this hashcode as ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Match GetHashCode between .NET 1.1 app and non-.NET app
    ... Hash algorithm should be tuned to your specific data to get the most rage of data distribution ... that you *should not* rely on a hashcode being valid outside the ... Michael Nemtsev:: blog: http://spaces.msn.com/laflour ...
    (microsoft.public.dotnet.framework.clr)
  • Re: Hashtables
    ... toStringand hashCode on an array of objects and keep doing it to see if they ever change. ... I expect toString() will eventually change after a GC but surely hashCode will not. ... although they have changed their algorithm as well. ...
    (comp.lang.java.help)