I have an array (NSArray or NSMutableArray doesn’t matter): SpecID of specific files IDs (109234, etc.). And I have a large array of all files IDs : FilesID.
I need to check whether FilesID contains all the elements of SpecID.
So the question what is the fastest and most efficient way of doing this except simple comparing all the elements to each other in a loop. May be there are some standard method or efficient algorithm?
You could use sets:
For this to work efficiently, the objects should ideally be
NSNumberobjects, or if they are custom objects, they should override bothhashandisEqual:. The efficiency of sets depends mostly on having a goodhash. The Foundation classes, e.g.NSNumber,NSStringetc have good hashes.Also, if you can, load your IDs directly into sets rather than converting them from arrays as this will be slightly more efficient, but otherwise the above is probably as simple as it would get. There may be specialised algorithms which would perform better but only explore those options if the above is too slow.