Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Tux Racer
Dec 24, 2005

lord funk posted:

Don't tempt me! :ohdear:

You're right, of course. Plus moving forward it would be easier to add to it. By my god. It's going to be a week of un-gluing this thing.

Not only that, but NSSets are faster to reference than NSArrays.

Adbot
ADBOT LOVES YOU

Tux Racer
Dec 24, 2005

lord funk posted:

Is this true for individual objects, or just when you iterate over the whole group? So using member: is faster than objectAtIndex:?

Well I am just getting my feet wet with iOS and Mac app development, but from what I have gathered, an NSSet is just a hash set, which means, yes this is true only for individual objects. That said, remember that since other data structures provided in the Foundations framework are just classes, so when you create an object of that class, let's say NSArray, you could actually have an NSSet of NSArrays. Also, the difference between NSArray and NSSet when finding an object is that with NSSet, you just ask the set using member: if that object exists within the set. That's an O(1) operation. With NSArray, searching for an object can either be O(n) or O(log n) depending on if you're using a sequential search or a binary search, respectively. So in this specific case, an NSSet is better than an NSArray. There are other instances where an NSArray is better than an NSSet. You'll figure out these situations through trial and error. There are trade-offs for both, so you have to make the design decision.


ZombieApostate posted:

I've got an App idea I want to develop, but don't have access to a mac. I suppose my options are to use a third party SDK (Airplay or MoSync or <insert your better idea here>) or try to set up dual boot windows/hackintosh on my computer, hopefully without having to reformat and start from scratch. I know the OP says third party SDK's tend to make garbage apps, but that sounds like it would be a lot easier than possibly destroying my windows install. What would you guys recommend?

e: if you happen to know of a tutorial that starts with "I have a windows PC" and ends with "I can dual boot windows/mac and didn't reformat", that would be swell. There's a lot of tutorials out there that I think I could adjust, but having an existing one would make life easier.

I have OSX running in a VM, and it was nearly painless to set up. There are plenty of tutorials floating around, and of course the hackintosh thread in SHSC.

Tux Racer
Dec 24, 2005

ZombieApostate posted:

A VM would be great to at least test the water and make sure it'd be worth the trouble of setting up a Mac environment to work in, but my processor doesn't support Hardware Virtualization and everything I've seen leads me to believe a Mac VM won't work without it :saddowns:

Ah, well that would cause a problem. In that case, check the hackintosh thread. The OP has a lot of great resources, particularly the tonymacx86 blog. That said, if you have an AMD CPU, you're boned.


wellwhoopdedooo posted:

Oh, average case, sure I'll buy that. But, correct me if I'm wrong, that fills a set and dictionary with

"1"
"2"
"3"
...
"99997"
"99998"
"99999"

which is more of a test of how good of a string hash function you have (and not a very good test at that) than how well your hash table does lookups--and that's fair for the stack overflow question, but not great for the question of how fast you can do lookups on any arbitrary hash--do they do so well for objects whose hash value is their memory address? Is using memory addresses as the hash value even common in Objective-C?

Anyway, I'll believe first part, for the average case anyway, but if member: is faster than objectAtIndex: for anything other than the most pathological of cases, naming it NSArray is downright deceptive.

You're really splitting hairs here. As Apple is a good software company, I think we can rest assured that their hashing algorithm is fine. Furthermore, Apple has put in a layer of abstraction so that we don't need to know what is being hashed and how quickly the algorithm performs. Obsessing over the minutiae doesn't change how quickly hashing performs relative to other lookup methods.

Yes with smaller sets of data, doing a search on an array is quicker than doing a hash lookup, but once you get to larger sets, hashing is significantly faster than any search algorithm in the worst-case scenario. And yes, hashing is an O(1) operation. Any lookup on any set of data has the same, constant complexity.

Also, none of this changes the fact that using NSSet instead of NSArray would make his code more maintainable.

And to lord funk, ZombieApostate is right. NSSet is slower than using a search on an NSArray in instances involving smaller sets of data. If you want to do the math you can find out what that threshold is, but I am assuming your app doesn't need every ounce of processing power it can squeeze out of the CPU. If that's the case, NSSet will be a good choice for the aforementioned reasons. If you add more data to your sets, you will be able to sleep soundly knowing that your app will not slow down due to less efficient search algorithms.

EDIT: I just need to clarify, I am not talking about a hash lookup vs. something like objectAtIndex:1. I am talking about a situation where you're looking for an object, but you don't know where it is in the set/array or if it exists.

Tux Racer fucked around with this message at 00:26 on Apr 27, 2011

Tux Racer
Dec 24, 2005

chimz posted:

Check out this guy's post about the cool stuff NSArray does in the background to make things faster and you'll see why reasoning about NSArray and NSSet like they're just simple implementations of arrays and hash tables doesn't always hold true.

http://ridiculousfish.com/blog/archives/2005/12/23/array/

The rest of his blog also has a bunch of interesting discussions about how Cocoa works that are worth a read.

I guess I stand corrected. That's interesting, especially since I have read elsewhere that NSSet is advantageous to NSArray for the reasons I outlined above in a couple different places.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply