is NSDictionary an objective-c's version of a hash table?

Discussion in 'iOS Programming' started by patrover, Aug 22, 2009.

  1. Eraserhead macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #2
    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.
     
  2. patrover thread starter macrumors newbie

    Joined:
    Aug 15, 2009
    #3
    from what i've read NSDictionary is implemented with a hash table
     
  3. xsmasher macrumors regular

    xsmasher

    Joined:
    Jul 18, 2008
    #4
    Yes, it maps keys to objects, just like a hash table.
     
  4. patrover thread starter macrumors newbie

    Joined:
    Aug 15, 2009
  5. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #6
    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.
     
  6. patrover thread starter macrumors newbie

    Joined:
    Aug 15, 2009
    #7
    actually I'm less concerned about how it is implemented and more about when i should use it...
     
  7. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #8
    From the Collections Programming Topics for Cocoa document:

     
  8. firewood macrumors 604

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #10
    definition vs. implementation

    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.
     

Share This Page