Skip to content

Instantly share code, notes, and snippets.

@damirstuhec
Created June 4, 2014 13:12
Show Gist options
  • Save damirstuhec/00749c1ff006667d0e16 to your computer and use it in GitHub Desktop.
Save damirstuhec/00749c1ff006667d0e16 to your computer and use it in GitHub Desktop.
NSString category for computing hash with modulo operation
- (NSInteger)hashWithModulo:(NSInteger)modulo
{
int i, sum = 0;
for (i = 0; i < self.length; i++)
{
sum += [self characterAtIndex:i];
}
return (sum % modulo);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment