• 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: Searching an NSArray
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Searching an NSArray


  • Subject: Re: Searching an NSArray
  • From: Zameer Andani <email@hidden>
  • Date: Wed, 21 Sep 2005 09:10:18 -0700

>From my experience for NSArray predicate matching, it seems like it performs
the matching linearly, which would be no different from what you're doing
now...  Perhaps as steve said, a binary search would be more effective.


On 9/21/05 12:08 AM, "Steve Palmer" <email@hidden> wrote:

> Off the top of my head and since the array looks sorted, why not use
> a binary search?
>
> - Steve
>
>
> On Sep 21, 2005, at 12:05am, Duncan Campbell wrote:
>
>> Hey folks,
>>
>> I have an NSArray full of NSRange objects - the results of
>> peforming a regex query against a large document (each result is
>> stored as an NSRange object in the array). My array looks something
>> like this:
>>
>> {0,10)
>> {23,33)
>> {51,61)
>> {100,110}
>> ...etc
>>
>> (assuming a 10-character range - this is just an example)
>>
>> What i want to do is to find the location in the array of the first
>> NSRange object with a location greater than some arbitrary value.
>> (note, not an EXACT match - otherwise I could just create a dummy
>> NSRange and do an objectAtIndex: ).
>>
>> For example, if in the above the value I was looking for was "11",
>> then the 2nd object - {23,33) - would be the one i am looking for.
>> Likewise, if I was looking for "75" then the last object -
>> {100,110} - would the correct object.
>>
>> Currently l am enumerating thru the array, looking at each object's
>> location, and checking it's location - this is obviously very
>> inefficient, and since my array can be very large and queried very
>> many times I'm not a happy camper..
>>
>> Does anyone have any suggestions (other than "don't store your
>> array this way") - can I perhaps use predicates?
>>
>> Cheers for any suggestions.
>>
>> Duncan.
>>
>>
>> _______________________________________________
>> Do not post admin requests to the list. They will be ignored.
>> Cocoa-dev mailing list      (email@hidden)
>> Help/Unsubscribe/Update your Subscription:
>> 40opencommunity.co.uk
>>
>> This email sent to email@hidden
>>
>
>  _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Re: Searching an NSArray (From: Steve Palmer <email@hidden>)

  • Prev by Date: NSPopUpButton Bindings question
  • Next by Date: Printing multiple Views in one print job
  • Previous by thread: Re: Searching an NSArray
  • Next by thread: NSPanel, DO & applications vs. bundles
  • Index(es):
    • Date
    • Thread