Question is the same as the title.
(“sortedArrayHint” method of NSArray class, what is the purpose of this method and how is it used)
I read documentation but the explanation is not clear.
Please explain the purpose of this method and its usage.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The idea is simple. Assume you have a large array that should always be sorted. Changing or inserting even one element means you have to resort the array. Sorting is costly.
The method
-[NSArray sortedArrayHint]can be called on an already sorted array in order to get private internal data that can be used to speed up a sort of the same array given that only a small change has been made.Usage is simple:
-[NSArray sortedArrayHint].-[NSArray sortedArrayUsingFunction:context:hint:]with the stored hint.-[NSArray sortedArrayUsingFunction:context:], and get a new hint.What is a small, or large, change is something you must measure with Instruments.
I never use this myself, since I have found it more effective to use my own categories on
NSArrayandNSMutabelArrayfor sorted inserts, that uses a binary search, on sorted array. My code is available as open source here: https://github.com/Jayway/CWFoundation