Re: NSMapTable with C strings as keys
Re: NSMapTable with C strings as keys
- Subject: Re: NSMapTable with C strings as keys
- From: Kyle Sluder <email@hidden>
- Date: Tue, 28 May 2013 07:59:12 -0700
On May 28, 2013, at 12:38 AM, Oleg Krupnov <email@hidden> wrote:
> I just made the following experiment:
>
> I specified a hash method for my NSMapTable, but it always returns 0.
> This seems to force the NSMapGet to always use key comparison for
> searching for elements, as hash is always "not unique".
>
> Is this a good idea?
If you're going to do that, why bother with an NSMapTable at all? Just store your pointers in a C array.
>
> Let me think. The keys are quite short strings, like 5-10 chars.
How about making your hash function just return the first character casted to int?
>
> If we take the expense of calculating hash once for each search, then
> comparing hash values is very quick, plus a few string comparisons in
> the end if hash is not unique
It's not useful to pursue this line of thinking without benchmarks.
--Kyle Sluder
_______________________________________________
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