Re: NSUInteger hash
Re: NSUInteger hash
- Subject: Re: NSUInteger hash
- From: "Michael Ash" <email@hidden>
- Date: Sun, 17 Aug 2008 23:38:02 -0400
On Sun, Aug 17, 2008 at 12:43 PM, Steve Wart <email@hidden> wrote:
> 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 have a couple of suggestions.
First, it sounds like these walls are on a square grid. If that is
indeed the case, then I'd suggest removing the NSPoints altogether and
replacing them with integer x/y values that describe grid points
rather than pixel coordinates. Hashing then becomes trivial and
equality comparisons become reliable.
Second, maybe the wall objects *should* be shared. New walls could go
into some sort of master grid object, and that master object could
give you the existing wall object instead of a new one when you create
the second room of the shared wall. This may not actually simplify
things, I'm not sure, but it's possible.
Last, if this isn't a regular square grid (which seems unlikely, but
you never know), then creating a point class which can be shared among
all walls which have that point as an endpoint would allow you to do
comparisons based on object identity at the point level without
worrying about things like floating point imprecision.
Mike
_______________________________________________
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