bugGNUstep - Bugs: bug #43915, Simple bug in NSCountedSet...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #43915: Simple bug in NSCountedSet comparsons

Submitted by:  Vincent Woo <akanet>
Submitted on:  Fri 02 Jan 2015 03:14:06 PM UTC  
 
Category: Base/FoundationSeverity: 3 - Normal
Item Group: BugStatus: Ready For Test
Privacy: PublicAssigned to: None
Open/Closed: In Test

Tue 10 Nov 2015 11:27:03 PM UTC, comment #3:

Niels,

Thank you for that fix. I think everything landed in trunk alright. Can this bug be closed?

Cheers,
Vincent

Vincent Woo <akanet>
Sat 02 May 2015 08:08:25 AM UTC, comment #2:

Thanks Vincent for the bug report and Oleg for the suggested fix! Unfortunately, things are slightly more complicated since some subclasses implemented optimisations for the equality checking, so I decided to do things a bit differently (among other things to avoid having to check which subclass we're dealing with). This should now be fixed in trunk (r38470)

Niels Grewe <thebeing>
Project Member
Fri 02 Jan 2015 04:41:39 PM UTC, comment #1:

My solution for NSSet isEqualToSet: method. It looks ugly with introspection, because countForObject: methods is private for NSSet (or NSMutableSet) and is public for NSCountedSet in Apple implementation. It is possible to compare NSCountedSet and NSSet, the second one has count number equal 1 for all members. I have not tested it very carefully.

- (BOOL)isEqualToSet:(id)other
{
if ([self count] != [other count]) {
return NO;
} else {
id object, enumerator = [self objectEnumerator];
BOOL isOtherCountedSet = [other isKindOfClass:[NSCountedSet class]];
BOOL isSelfCountedSet = [self isKindOfClass:[NSCountedSet class]];

while ((object = [enumerator nextObject])) {
if (![other member: object]) {
return NO;
}

NSUInteger countForObjectInOther = isOtherCountedSet ? [other countForObject:object] : 1;
NSUInteger countForObjectInSelf = isSelfCountedSet ? [self countForObject:object] : 1;
if (countForObjectInOther != countForObjectInSelf) {
return NO;
}
}
}

return YES;
}

Oleg <olegivanov>
Fri 02 Jan 2015 03:14:06 PM UTC, original submission:

Hey all, this is my first bug report to gnustep-base so please let me know if I've misstepped in any way.

I've got a very simple and reproducible bug for you today. The following code should print "false" (as it does in XCode), but prints "true" instead:

NSCountedSet *set1 = [NSCountedSet setWithArray:@[@1, @1]];
NSCountedSet *set2 = [NSCountedSet setWithArray:@[@1]];
BOOL isEqual = [set1 isEqualToSet:set2];
NSLog(@"%@", isEqual ? @"true" : @"false");

This is because NSCountedSet in GNUStep falls back to the NSSet implementation of isEqualToSet:

https://github.com/gnustep/base/blob/master/Source/NSSet.m#L596

Which is obviously not using the counts of the number of items in the set.

I am on Ubuntu 14.04 and using the very latest version (HEAD) of GNUStep.

I don't know Objective-C very well, but I imagine isEqualToSet could be implemented on NSCountedSet that could be count-aware (and cast regular sets to counted sets with count=1).

Vincent Woo <akanet>

 

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by thebeing (Posted a comment)
  • -unavailable- added by olegivanov (Posted a comment)
  • -unavailable- added by akanet (Submitted the item)
  • -unavailable- added by akanet
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 3 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Sat 02 May 2015 08:08:25 AM UTCthebeingStatusNone=>Ready For Test
      Open/ClosedOpen=>In Test
    Fri 02 Jan 2015 03:14:06 PM UTCakanetCarbon-Copy-=>Added -unavailable-

    Back to the top


    Powered by Savane 3.1-cleanup1