• 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: -NSMutableIndexSet shiftIndexesStartingAtIndex:by: weirdness
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: -NSMutableIndexSet shiftIndexesStartingAtIndex:by: weirdness


  • Subject: Re: -NSMutableIndexSet shiftIndexesStartingAtIndex:by: weirdness
  • From: Richard Frith-Macdonald <email@hidden>
  • Date: Thu, 17 Sep 2009 15:58:44 +0100


On 17 Sep 2009, at 15:50, Tommy Nordgren wrote:


On 17 sep 2009, at 15.23, steven Hooley wrote:

- shiftIndexesStartingAtIndex:by: and
-containsIndexesInRange:NSMakeRange: don't seem to play nicely
together..
Is this expected?

NSMutableIndexSet *someIndexes = [NSMutableIndexSet indexSet];
[someIndexes addIndex:0];
[someIndexes addIndex:2];
[someIndexes shiftIndexesStartingAtIndex:2 by:-1];

BOOL result1 = [someIndexes containsIndex:0];
BOOL result2 = [someIndexes containsIndex:1];
BOOL result3 = [someIndexes containsIndexesInRange:NSMakeRange(0,2)];

	Here is the error. You are asking if the index set contains (0,1,2),
But it only contains (0, 1) after the shift
	Try using NSMakeRange (0,1) instead.

Nonsense ... NSMakeRange(0,2) produces a range starting at 0 with length 2 (ie the values 0 and 1).


NSLog(@"%@ %@ %@", (result1 ? @"YES" : @"NO"), (result2 ? @"YES" :
@"NO"), (result3 ? @"YES" : @"NO") );

-- 2009-09-17 14:21:25.789 otest[19356:10b] YES YES NO

This is a clear demonstration of a bug in NSMutableIndexSet.

I can tell you with a fair degree of confidence the cause of the bug too (because I fixed a bug with the same behavior which used to exist in GNUstep):

An index set consists of an array of ranges.
Code like -containsIndexesInRange: assumes that the ranges are non- adjacent.
The -shiftIndexesStartingAtIndex:by: method, in this instance, produces two adjacent ranges and fails to merge them into a single range as it should.



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >-NSMutableIndexSet shiftIndexesStartingAtIndex:by: weirdness (From: steven Hooley <email@hidden>)
 >Re: -NSMutableIndexSet shiftIndexesStartingAtIndex:by: weirdness (From: Tommy Nordgren <email@hidden>)

  • Prev by Date: Re: -NSMutableIndexSet shiftIndexesStartingAtIndex:by: weirdness
  • Next by Date: Re: -NSMutableIndexSet shiftIndexesStartingAtIndex:by: weirdness
  • Previous by thread: Re: -NSMutableIndexSet shiftIndexesStartingAtIndex:by: weirdness
  • Next by thread: Re: -NSMutableIndexSet shiftIndexesStartingAtIndex:by: weirdness
  • Index(es):
    • Date
    • Thread