IOSAD-92 hashBasedOnKeys IOSAD-92
authorDirk Zimmermann <dirk@pep-project.org>
Tue, 24 Apr 2018 13:29:18 +0200
branchIOSAD-92
changeset 59378a14e6e06d0
parent 592 95dde8be4786
child 594 a9cae3a6f78d
IOSAD-92 hashBasedOnKeys
pEpObjCAdapter/NSObject+Extension.h
pEpObjCAdapter/NSObject+Extension.m
pEpObjCAdapter/PEPMessage.m
     1.1 --- a/pEpObjCAdapter/NSObject+Extension.h	Tue Apr 24 13:29:17 2018 +0200
     1.2 +++ b/pEpObjCAdapter/NSObject+Extension.h	Tue Apr 24 13:29:18 2018 +0200
     1.3 @@ -18,4 +18,9 @@
     1.4  - (BOOL)isEqualToObject:(NSObject * _Nonnull)other
     1.5              basedOnKeys:(NSArray<NSString *> * _Nonnull)keys;
     1.6  
     1.7 +/**
     1.8 + Calculates a hash based on the given `keys`.
     1.9 + */
    1.10 +- (NSUInteger)hashBasedOnKeys:(NSArray<NSString *> * _Nonnull)keys;
    1.11 +
    1.12  @end
     2.1 --- a/pEpObjCAdapter/NSObject+Extension.m	Tue Apr 24 13:29:17 2018 +0200
     2.2 +++ b/pEpObjCAdapter/NSObject+Extension.m	Tue Apr 24 13:29:18 2018 +0200
     2.3 @@ -28,4 +28,17 @@
     2.4      return YES;
     2.5  }
     2.6  
     2.7 +- (NSUInteger)hashBasedOnKeys:(NSArray<NSString *> * _Nonnull)keys
     2.8 +{
     2.9 +    NSUInteger prime = 31;
    2.10 +    NSUInteger result = 1;
    2.11 +
    2.12 +    for (NSString *theKey in keys) {
    2.13 +        NSObject *objSelf = [self valueForKey:theKey];
    2.14 +        result = prime * result + objSelf.hash;
    2.15 +    }
    2.16 +
    2.17 +    return result;
    2.18 +}
    2.19 +
    2.20  @end
     3.1 --- a/pEpObjCAdapter/PEPMessage.m	Tue Apr 24 13:29:17 2018 +0200
     3.2 +++ b/pEpObjCAdapter/PEPMessage.m	Tue Apr 24 13:29:18 2018 +0200
     3.3 @@ -252,29 +252,7 @@
     3.4  
     3.5  - (NSUInteger)hash
     3.6  {
     3.7 -    NSUInteger prime = 31;
     3.8 -    NSUInteger result = 1;
     3.9 -
    3.10 -    result = prime * result + self.direction;
    3.11 -
    3.12 -    result = prime * result + self.attachments.hash;
    3.13 -    result = prime * result + self.bcc.hash;
    3.14 -    result = prime * result + self.cc.hash;
    3.15 -    result = prime * result + self.from.hash;
    3.16 -    result = prime * result + self.inReplyTo.hash;
    3.17 -    result = prime * result + self.keywords.hash;
    3.18 -    result = prime * result + self.longMessage.hash;
    3.19 -    result = prime * result + self.longMessageFormatted.hash;
    3.20 -    result = prime * result + self.messageID.hash;
    3.21 -    result = prime * result + self.optionalFields.hash;
    3.22 -    result = prime * result + self.receivedBy.hash;
    3.23 -    result = prime * result + self.receivedDate.hash;
    3.24 -    result = prime * result + self.references.hash;
    3.25 -    result = prime * result + self.replyTo.hash;
    3.26 -    result = prime * result + self.shortMessage.hash;
    3.27 -    result = prime * result + self.to.hash;
    3.28 -
    3.29 -    return result;
    3.30 +    return [self hashBasedOnKeys:s_keys];
    3.31  }
    3.32  
    3.33  - (BOOL)isEqual:(id)object