Re: NSMapTable with C strings as keys
Re: NSMapTable with C strings as keys
- Subject: Re: NSMapTable with C strings as keys
- From: Michael Crawford <email@hidden>
- Date: Mon, 27 May 2013 23:42:55 -0700
Cryptographic hashes such as md5 are intensive to calculate because
they are meant to make it difficult for an attacker to come up with
different inputs that output identical hashes.
For purposes of looking up strings in a hash table, a 32 bit CRC
(Cyclic Redundancy Check) would be quick to calculate with few
collisions. It also doesn't require multiprecision arithmetic.
Mike Crawford
email@hidden
On Mon, May 27, 2013 at 11:25 PM, Oleg Krupnov <email@hidden> wrote:
> Hi Jens,
>
> I guess you may be right. But… two questions in this regard:
>
> 1. I thought that "isEqual" method is alternative to "hash" method,
> because searching by key and searching by hash are two mutually
> exclusive methods of looking up values, aren't they?
>
> 2. What hash function you'd suggest in my case, that would calculate
> unsigned int on output, for C strings? Because calculating hash
> functions (such as md5) may be computationally expensive, which could
> undermine my entire idea of sparing extra few calls on creating
> NSStrings :)
>
> Thanks!
>
> On Tue, May 28, 2013 at 9:08 AM, Jens Alfke <email@hidden> wrote:
>>
>> On May 27, 2013, at 10:46 PM, Oleg Krupnov <email@hidden> wrote:
>>
>> Now, the problem is that sometimes when I try to get a value from the
>> table, the MapTableKeyComparator function is not called at all, and
>> NSMapGet returns NULL, thought immediate dump of the table shows that
>> all previous records are perfectly present in the table.
>>
>>
>> Probably because you haven’t implemented a hash function, only an equals
>> function. I’m guessing NSMapTable’s default hash function merely hashes the
>> key pointer itself, which means that if you pass it a different pointer to
>> an equal C string, it won’t find anything.
>>
>> —Jens
>>
>
> _______________________________________________
>
> 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
--
Michael David Crawford
mdcrawford at gmail dot com
Custom Software Development for the iPhone and Mac OS X
http://www.dulcineatech.com/custom-software-development/
_______________________________________________
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