TLIndexPathTools icon indicating copy to clipboard operation
TLIndexPathTools copied to clipboard

Non-ideal hash calculation

Open futuretap opened this issue 8 years ago • 3 comments

I think you want to replace += by = here:

https://github.com/SwiftKickMobile/TLIndexPathTools/blob/ca47649036081ec5b1220926ae072dab908301ea/TLIndexPathTools/Data%20Model/TLIndexPathItem.m#L53-57

Right now, you're effectively calculating:

hash = 32 * hash + [self.identifier hash];

futuretap avatar Nov 21 '17 21:11 futuretap

Not sure I follow you. The initial value is hash = 0, so

hash += 31 * hash + [self.identifier hash];

is equivalent to

hash = [self.identifier hash];

and I'm not sure how that is non-ideal.

wtmoose avatar Nov 21 '17 21:11 wtmoose

You're right for line 53 which could be simplified with line 52 to:

NSInteger hash = [self.identifier hash];

The issue is in lines 54 (and 55, 57):

hash += 31 * hash + [self.sectionName hash];

is equivalent to

hash = 32 * hash + [self.sectionName hash];

futuretap avatar Nov 21 '17 22:11 futuretap

Ah, yeah. Oops

wtmoose avatar Nov 21 '17 22:11 wtmoose