Re: Searching an NSArray
Re: Searching an NSArray
- Subject: Re: Searching an NSArray
- From: Steve Palmer <email@hidden>
- Date: Wed, 21 Sep 2005 00:08:33 -0700
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