Created
July 1, 2014 10:01
-
-
Save daschl/88f15e41685e7b0a68e5 to your computer and use it in GitHub Desktop.
run with cargo test
This file contains 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
<std macros>:8:12: 35:21 error: mismatched types: expected `bool` but found `<generic integer #0>` (expected bool but found integral variable) | |
<std macros>:8 if !$cond { | |
<std macros>:9 fail!($($arg),+) | |
<std macros>:10 } | |
<std macros>:11 ); | |
<std macros>:12 ) | |
error: internal compiler error: unexpected failure | |
note: the compiler hit an unexpected failure path. this is a bug. | |
note: we would appreciate a bug report: http://doc.rust-lang.org/complement-bugreport.html | |
note: run with `RUST_BACKTRACE=1` for a backtrace | |
task 'rustc' failed at 'index out of bounds: the len is 12 but the index is 12', /Users/rustbuild/src/rust-buildbot/slave/nightly-mac/build/src/libsyntax/lib.rs:1 |
This file contains 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
extern crate crypto = "rust-crypto"; | |
use std::io::stdio::println; | |
use crypto::md5::Md5; | |
use crypto::digest::Digest; | |
fn main() { | |
println!("{}", ketama("Hello World!")); | |
} | |
fn ketama(key: &str) -> u8 { | |
// 2: Create MD5 digset | |
let mut sh = Md5::new(); | |
sh.input_str(key); | |
let mut digest = Vec::from_elem((sh.output_bits()+7)/8, 0u8); | |
sh.result(digest.as_mut_slice()); | |
// 3: Construct the ketama hash | |
let result = | |
((digest.get(3) & 0xFF) << 24) | | |
((digest.get(2) & 0xFF) << 16) | | |
((digest.get(1) & 0xFF) << 8) | | |
(digest.get(0) & 0xFF); | |
result | |
} | |
#[cfg(test)] | |
mod tests { | |
use ketama; | |
fn test_ketama() { | |
assert!(3979113294, ketama("26")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment