Skip to content

Instantly share code, notes, and snippets.

@aarohmankad
Last active December 7, 2017 00:52
Show Gist options
  • Save aarohmankad/194ea6e5e98cd845443aa011a8a6269e to your computer and use it in GitHub Desktop.
Save aarohmankad/194ea6e5e98cd845443aa011a8a6269e to your computer and use it in GitHub Desktop.
A good example showing why to leave comments in your code
int hash(string input) {
int output = 5381;
// Less collisions than simply adding ASCII characters of value
// simple method: hash("tab") = hash("bat")
// this method: hash("tab") != hash("bat")
for (char c : input) {
output += (output << 5) + c;
}
return output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment