• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSSet Inefficiency
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSSet Inefficiency


  • Subject: Re: NSSet Inefficiency
  • From: Ondra Cada <email@hidden>
  • Date: Sun, 24 Mar 2002 15:23:05 +0100

On Saturday, March 23, 2002, at 03:11 , Gerriet M. Denkmann wrote:

I have an app which creates about 2 million objects, halve of these are different. And I want to keep only these different objects.

1. strategy: NSMutableSet
set = [ NSMutableSet initWithCapacity: 0]

Can't work at all. You wanted [[NSMutableSet alloc] init] (or initWithCapacity:2000000, the zero's nonsense)

for( ii = 1 to 2000000)
create newThing[ii]

This is C++, can't work in ObjC. Even in ObjC++ you can't (AFAIK) mix the C++ pseuod-object things with real ObjC ones.

oldThing = [ set member: newThing ]
if ( oldThing == nil )
[ set addObject: newThing ]
else
[ newThing release ]
use oldThing

This pseudo code (can't be real one, compiler would never swallow this) I don't even understand. Working with sets, you want something like

NSMutableSet *s=[NSMutableSet set];
for (.....) {
id o=GenerateAnObjectWhichCanOrMightNotBeUnique();

if (![s containsObject:o]) {
// well o _is_ unique, do with it what you want to
[s addObject:o];
} // else o is not unique
}

This seemed somehow slow, so I tried:

first of all, what you shown use here could not be even compiled, not even worked. Therefore I can't be sure why it did not work, but I *GUESS* that the problem is that you haven't implemented -hash properly for objects which you store in an NSSet.

1. Is NSSet really that inefficient, of did I commit any grave mistakes?

It is as efficient as a nicely implemented hash table can ever be. As such though it heavily depends on the quality of the hash, though.
---
Ondra Cada
OCSoftware: email@hidden http://www.ocs.cz
2K Development: email@hidden http://www.2kdevelopment.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
  • Follow-Ups:
    • Re: NSSet Inefficiency
      • From: "Gerriet M. Denkmann" <email@hidden>
References: 
 >NSSet Inefficiency (From: "Gerriet M. Denkmann" <email@hidden>)

  • Prev by Date: Re: Cocoa and UNIX txt files ??
  • Next by Date: Re: Service hotkeys on login
  • Previous by thread: NSSet Inefficiency
  • Next by thread: Re: NSSet Inefficiency
  • Index(es):
    • Date
    • Thread