Re: NSUInteger hash
Re: NSUInteger hash
- Subject: Re: NSUInteger hash
- From: "Steve Wart" <email@hidden>
- Date: Sun, 17 Aug 2008 09:43:09 -0700
Hi Aaron,
That's always a good question to ask.
I'm porting a Smalltalk/OpenGL maze application I wrote a few years ago to
Cocoa.
The maze is initialized by creating a 2D matrix of Room objects which are
separated by Wall objects. Every room has an ordered collection of walls
which I've put into an NSMutableArray. Every wall has a start point and an
end point and exists in exactly one room. So the common wall separating a
pair of rooms is actually represented by two walls.
I go through the rooms in random order, pick a wall at random, and knock it
down (also being careful to knock down the corresponding wall in any
adjacent rooms). By knocking down a wall, two rooms become merged into one.
When I have only one room left, it means that the maze is complete.
I depend on isEqualTo: to compare the walls. They are both created from the
same set of points but they are different objects, so I can't use an
identity comparison. The Smalltalk code is reasonably clean but it's
bloating unpleasantly in Objective C so I will probably need to take a
higher-level look at what I'm trying to accomplish. The original maze
algorithm was cribbed from C so it shouldn't be too hard to make it work :-)
Steve
On Sun, Aug 17, 2008 at 12:10 AM, Aaron Lees <email@hidden> wrote:
> What are you trying to do? It's usually a bad idea to compare floating
> point values for equality since you will run into subtle bugs to do with
> rounding. If you want to use your objects as dictionary keys it's often
> better to use a pointer equality rule instead of semantic equality. You can
> do this with NSMapTable without any overrides in your class.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden