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

Group
 
 

bug #43915: Simple bug in NSCountedSet comparsons

Submitter:  Vincent Woo <akanet>
Submitted:  Fri 02 Jan 2015 03:14:06 PM UTC
   
 
Category:  Base/Foundation Severity:  3 - Normal
Item Group:  Bug Status:  Ready For Test
Privacy:  Public Assigned to:  None
Open/Closed:  In Test
* Mandatory Fields

Add a New Comment Rich Markup
   

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>
Group 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>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-05-02 thebeing StatusNone Ready For Test
        Open/ClosedOpen In Test
    2015-01-02 akanet Carbon-Copy- Added -email is unavailable-

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code