Re: Fast NSArray compare
Re: Fast NSArray compare
- Subject: Re: Fast NSArray compare
- From: Alex Zavatone <email@hidden>
- Date: Tue, 15 Apr 2014 10:45:43 -0400
A good approach here would be to make a test case for NSArray and NSSet, a known set of files and simply test now long each takes.
On Apr 14, 2014, at 8:59 PM, Graham Cox wrote:
>
> On 15 Apr 2014, at 10:02 am, Varun Chandramohan <email@hidden> wrote:
>
>> Lets say I walkthrough 1000 files and folders, for each file/folder I need to compare against this array list. This might be slow or inefficient. Is there a faster way to do something like this?
>
>
> As a general principle, if you have to check whether one of a list of things is part of another list of things, an array is the wrong container for the job, because it amounts to a worst-case O(n^2) search. Instead, use a set or hash table for the set of things that must be detected among the first list, and it reduces to a worst-case O(n) operation. That said, if the number of items in the second list is small, the performance may be acceptable, and using a hash table might not speed it up noticeably - the time will be dominated by the iteration through the larger list.
>
> --Graham
>
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden