Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-ideal hash calculation #76

Open
futuretap opened this issue Nov 21, 2017 · 3 comments
Open

Non-ideal hash calculation #76

futuretap opened this issue Nov 21, 2017 · 3 comments

Comments

@futuretap
Copy link

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];
@wtmoose
Copy link
Member

wtmoose commented Nov 21, 2017

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.

@futuretap
Copy link
Author

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

@wtmoose
Copy link
Member

wtmoose commented Nov 21, 2017

Ah, yeah. Oops

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants