|
lord funk posted:Don't tempt me! Not only that, but NSSets are faster to reference than NSArrays.
|
# ¿ Apr 26, 2011 01:46 |
|
|
# ¿ May 5, 2024 16:02 |
|
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? 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.
|
# ¿ Apr 26, 2011 21:54 |
|
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 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 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 |
# ¿ Apr 26, 2011 23:51 |
|
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. 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.
|
# ¿ Apr 27, 2011 02:45 |