Re: radomize a number list
From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 06/03/04
- Next message: Kevin Yu [MSFT]: "RE: Manifest problem"
- Previous message: Jon Skeet [C# MVP]: "Re: Object initialization in C# thread - unexplained behaviour"
- In reply to: William Stacey [MVP]: "Re: radomize a number list"
- Messages sorted by: [ date ] [ thread ]
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
- Next message: Kevin Yu [MSFT]: "RE: Manifest problem"
- Previous message: Jon Skeet [C# MVP]: "Re: Object initialization in C# thread - unexplained behaviour"
- In reply to: William Stacey [MVP]: "Re: radomize a number list"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|