NSArray vs. NSSet

  • Anyone know if NSSets are faster than NSArrays? Why wouldn't I always
    just use an NSArray?

    Mike
  • On Mar 10, 2005, at 11:29 AM, Mike R. Manzano wrote:

    > Anyone know if NSSets are faster than NSArrays?

    Faster "than" when doing what?

    > Why wouldn't I always just use an NSArray?

    This a trick question? ;-) The answer is when NSSet is a better fit for
    what you are doing then NSArray.

    Review the docs for both classes and think about the difference on what
    they do, for example one allows you to access items primarily by index
    the other by object comparison, one is ordered the other isn't, one
    allows duplicate objects in the collection the other doesn't, etc.

    You may want to review the following...
    <http://developer.apple.com/documentation/Cocoa/Conceptual/Collections/
    index.html
    >

    Anyway we can't help much other then guess at what type of comparison
    you want between these two collection classes... we need to know more
    about what you want to use them for.

    -Shawn
  • On 10 Mar 2005, at 19:29, Mike R. Manzano wrote:
    > Anyone know if NSSets are faster than NSArrays? Why wouldn't I always
    > just use an NSArray?

    Well they're different things - one is not just a more efficient
    version of the other. Normally you'd tend to use the one that's the
    right fit for your problem and assume that they're well enough
    implemented that performance isn't going to be too much of an issue.

    --
    Andy Armstrong, hexten.net
  • Aha, I tricked you into answering my question :)  Just kidding.

    The question came up when I discovered there was an NSSet class,
    coupled with the fact that I've gotten away with using nothing but
    arrays and dictionaries in my code so far.

    Anyway, back to your regularly scheduled programming.

    Mike

    On Mar 10, 2005, at 11:45 AM, Shawn Erickson wrote:

    >
    > This a trick question? ;-) The answer is when NSSet is a better fit
    > for what you are doing then NSArray.
    >
    > Review the docs for both classes and think about the difference on
    > what they do, for example one allows you to access items primarily by
    > index the other by object comparison, one is ordered the other isn't,
    > one allows duplicate objects in the collection the other doesn't, etc.
  • On Thursday, March 10, 2005, at 01:53PM, Mike R. Manzano <alephx01...> wrote:

    > Aha, I tricked you into answering my question :)  Just kidding.
    >
    > The question came up when I discovered there was an NSSet class,
    > coupled with the fact that I've gotten away with using nothing but
    > arrays and dictionaries in my code so far.

    I wouldn't be to worried about that. NSSet *is* useful, and I'm glad it's in Foundation, but its applications are a bit more specific than NSArray and NSDictionary. On average NSArray and NSDictionary are much more likely to be the right solution that NSSet.

    > Anyway, back to your regularly scheduled programming.
    >
    > Mike

    <groans and returns to screens full of Java and C#... :( >
  • On Mar 10, 2005, at 12:48 PM, Tim Hart wrote:

    > I wouldn't be to worried about that. NSSet *is* useful, and I'm glad
    > it's in Foundation, but its applications are a bit more specific than
    > NSArray and NSDictionary. On average NSArray and NSDictionary are much
    > more likely to be the right solution that NSSet.

    The main reason to use an NSSet right now is that it's faster at
    checking for existence of an object. It's common to see an NSSet used
    as a cache for the contents of an NSArray or NSDictionary.

    Also, an idividual object can only appear once in an NSSet, whereas it
    can appear multiple times in a dictionary or array.

        - Scott

    --
    http://treehouseideas.com/
    http://theocacao.com/ [blog]
previous month march 2005 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Go to today