Re: NSDictionary
Re: NSDictionary
- Subject: Re: NSDictionary
- From: "John C. Randolph" <email@hidden>
- Date: Tue, 29 Jan 2002 17:15:33 -0800
On Tuesday, January 29, 2002, at 05:06 PM, Bob Savage wrote:
on 1/29/02 5:53 PM, John C. Randolph wrote:
What's the max size for NSDictionary/NSMutableDictionary? How many
rows/records and columns/fields?
Good question. I don't think there's a hard limit. I've had
NSMutableDictionaries with thousands of entries, but I've never
tried pushing it till it broke.
What are you proposing to store in this very large dictionary?
Aagh! I never thought of this. 8-O I might need something
several orders of
magnitude larger (e.g. 4,194,304 entries). I was going to use this as a
place to store spaces in a game I am working on. It is a strategy game
(based on a hexagonal grid) and I am storing the hex objects in
a dictionary
with their location (x, y) as the key. It is very common for me
to need to
look up a hex based on location, so this is quite ideal. Each hex has a
handful of properties: the location (NSPoint), elevation
(float), an array
of occupants (id), and a terrain (id).
There is no guarantee that the field of hexes is continuous
(meaning that
many to most are likely missing when the board is loaded due to
imperfect
player knowledge of the world), so saving hexes into a multidimensional
array is not an effective means of getting at the hexes by location.
If I am doing something very wrong here, please let me know
now, so I have a
chance to fix things before it becomes too late.
Storing items in a dictionary is likely to be a lot more
efficient that trying to make an array with four million
entries, especially if you have a lot less than four million
things to store. ;-)
Hashtables (dictionaries) have long been a standard technique
for storing the members of a sparse matrix.
-jcr
John C. Randolph <email@hidden> (408) 974-8819
Sr. Software Engineer, Cocoa Evangelism
Apple Worldwide Developer Relations