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

Searching an NSArray


  • Subject: Searching an NSArray
  • From: Duncan Campbell <email@hidden>
  • Date: Wed, 21 Sep 2005 17:05:01 +1000

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: This email sent to email@hidden
  • Follow-Ups:
    • Re: Searching an NSArray
      • From: Steve Palmer <email@hidden>
  • Prev by Date: Conflict Resolution in Sync Services
  • Next by Date: Re: Searching an NSArray
  • Previous by thread: Re: NSView subclass bindings code?
  • Next by thread: Re: Searching an NSArray
  • Index(es):
    • Date
    • Thread