-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1886 from smartdevicelink/feature/issue-1024-sdl-…
…0180-broaden-choiceCell-uniqueness SDL 0180 - Fix to support broaden choice cell uniqueness
- Loading branch information
Showing
25 changed files
with
523 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// NSArray+Extensions.h | ||
// SmartDeviceLink | ||
// | ||
// Created by Frank Elias on 2/18/21. | ||
// Copyright © 2021 smartdevicelink. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "SDLMacros.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface NSArray (Extensions) | ||
|
||
-(NSUInteger)dynamicHash; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// NSArray+Extensions.m | ||
// SmartDeviceLink | ||
// | ||
// Created by Frank Elias on 2/18/21. | ||
// Copyright © 2021 smartdevicelink. All rights reserved. | ||
// | ||
|
||
#import "NSArray+Extensions.h" | ||
|
||
@implementation NSArray (Extensions) | ||
|
||
/// A dynamic version of the NSArray `hash` method. The default `hash` method returns the number of objects in the array as its hash and this leads to clashes between arrays with the same number of objects. | ||
/// Instead, this method calls hash on each of it's sub-objects, XOR and rotates them, then returns this as the hash. This is much slower than the default hash method, but sometimes necessary to properly compare arrays. | ||
/// @returns A hash based on the hashes of all of the contained objects | ||
- (NSUInteger)dynamicHash { | ||
NSUInteger retVal = 0; | ||
for (NSUInteger i = 0; i < self.count; i++) { | ||
retVal ^= NSUIntRotateCell(((NSObject *)self[i]).hash, (NSUIntBitCell / (i + 2))); | ||
} | ||
|
||
return retVal; | ||
} | ||
|
||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// SDLMacros.h | ||
// SmartDeviceLink | ||
// | ||
// Created by Joel Fischer on 2/8/21. | ||
// Copyright © 2021 smartdevicelink. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
extern NSUInteger const NSUIntBitCell; | ||
extern NSUInteger NSUIntRotateCell(NSUInteger val, NSUInteger howMuch); | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// SDLMacros.m | ||
// SmartDeviceLink | ||
// | ||
// Created by Joel Fischer on 2/8/21. | ||
// Copyright © 2021 smartdevicelink. All rights reserved. | ||
// | ||
|
||
#import "SDLMacros.h" | ||
|
||
NSUInteger const NSUIntBitCell = (CHAR_BIT * sizeof(NSUInteger)); | ||
NSUInteger NSUIntRotateCell(NSUInteger val, NSUInteger howMuch) { | ||
return ((((NSUInteger)val) << howMuch) | (((NSUInteger)val) >> (NSUIntBitCell - howMuch))); | ||
} |
Oops, something went wrong.