Last active
August 29, 2015 14:00
-
-
Save misterhat/5c98b7180bbc0c2ca296 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
fn encode_username(username: &str) -> u64 { | |
let mut encoded = 0; | |
for character in username.chars() { | |
let rune = character.to_lowercase() as u64; | |
encoded *= 37; | |
encoded += rune - match rune { | |
97..122 => 96, | |
48..57 => 21, | |
_ => 0 | |
}; | |
} | |
encoded | |
} | |
fn encode_username(username: &str) -> u64 { | |
username.chars().fold(0, |encoded, character| { | |
let rune = character.to_lowercase() as u64; | |
(encoded * 37) + rune - match rune { | |
97..122 => 96, | |
48..57 => 21, | |
_ => 0 | |
} | |
}) | |
} | |
fn encode_username(username: &str) -> u64 { | |
username.chars().map(|c| c.to_lowercase() as u64).fold(0, |enc, c| { | |
(enc * 37) + c - match c { | |
97..122 => 96, | |
48..57 => 21, | |
_ => 0 | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment