bug-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug #43915] Simple bug in NSCountedSet comparsons


From: Oleg
Subject: [bug #43915] Simple bug in NSCountedSet comparsons
Date: Fri, 02 Jan 2015 16:41:39 +0000
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:34.0) Gecko/20100101 Firefox/34.0

Follow-up Comment #1, bug #43915 (project gnustep):

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;
}

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?43915>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]