View Full Version : is NSDictionary an objective-c's version of a hash table?
patrover
Aug 22, 2009, 06:41 AM
title...
Eraserhead
Aug 22, 2009, 06:43 AM
NSDictionary is a dictionary, though only from the developers perspective, if its more efficient to be stored as a hash table it probably is. Just like NSArray has log(n) access times - it just appears to the developer to be array-like.
patrover
Aug 22, 2009, 07:33 AM
from what i've read NSDictionary is implemented with a hash table
xsmasher
Aug 22, 2009, 12:14 PM
title...
Yes, it maps keys to objects, just like a hash table.
patrover
Aug 22, 2009, 12:52 PM
thank you both
PhoneyDeveloper
Aug 22, 2009, 12:55 PM
It's an associative array. It's most likely implemented as a hash table.
If you really care the Core Foundation code is open source and you can download it from Apple. NSDictionary sits on top of CFDictionary.
patrover
Aug 22, 2009, 01:07 PM
actually I'm less concerned about how it is implemented and more about when i should use it...
dejo
Aug 22, 2009, 01:13 PM
From the Collections Programming Topics for Cocoa (http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/Collections/Articles/Dictionaries.html#//apple_ref/doc/uid/20000134-CJBCBGII) document:
Dictionaries manage pairs of keys and values. Use a dictionary when you need a convenient and efficient way to retrieve data associated with an arbitrary key.
patrover
Aug 22, 2009, 01:20 PM
i see
http://stackoverflow.com/questions/474316/hashtables-in-cocoa
firewood
Aug 22, 2009, 02:36 PM
A hash table is one (moderately efficient) method of implementing associative arrays.
An NSDictionary is specified to behave like an associative array, but the implementation is opaque. The hidden underlying implementation could, for instance, change depending on the size of the array, phase of the moon, & etc.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.