Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create an NSRange with a given minimal and maximal value

I have a collection of int64_t values that I need to make an index set out of. I previously have used:

NSIndexSet *set = [NSIndexSet indexSetWithRange:NSMakeRange(location, length)];

to make index sets, but this time its unclear to me how I would do this based on the information I have.

Specifics: I have a collection of values. I know the highest value in the collection, the lowest value in the collection and the number of values in the collection. However, the values are not necessarily consecutive.

For example, if I have the following values: 1,3,4,6,7,9 I would like to create a set that includes all numbers in the collection between and including 1 and 9, i.e. set = 1-9.

How would I do this?

Edit

I shouldn't say I have a "collection" of integers, rather - I have objects stored in core data and each object has an int64_t attribute associated with it, so I don't have a pointer to an actual collection of the objects, and I want to avoid fetching the objects just to create a collection.

like image 226
jac300 Avatar asked Oct 17 '13 15:10

jac300


1 Answers

Edit: As it turned out in the discussion, the question was how to create a range with a given minimal and maximal value. This is done with

NSMakeRange(min, max + 1 - min)
like image 106
Martin R Avatar answered Sep 18 '22 20:09

Martin R