Created
September 30, 2015 18:16
-
-
Save anonymous/0d21819b4345e2bc5aef to your computer and use it in GitHub Desktop.
Shared via Rust Playground
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 old() -> Vec<u8> { | |
let mut hash = vec![0u8; 8]; // vec of u8 representing the bits and bytes of the hash computed for the image. | |
let raw: Vec<_> = (0 .. 72).rev().collect(); // vec of u8 representing gray pixels of an 9x8 image. | |
for x in 0..8 { | |
for y in 0..8 { | |
if raw[x*8+y] > raw[x*8+y+1] { | |
hash[x] |= 0x1 << y | |
} | |
} | |
} | |
hash | |
} | |
fn new() -> Vec<u8> { | |
let mut hash = vec![0u8; 8]; // vec of u8 representing the bits and bytes of the hash computed for the image. | |
let raw: Vec<_> = (0 .. 72).rev().collect(); // vec of u8 representing gray pixels of an 9x8 image. | |
for (x, chunk) in raw.chunks(9).enumerate() { | |
chunk[1..].iter().enumerate().fold(chunk[0], |before, (y, ¤t)| -> u8 { | |
if before > current { | |
hash[x] |= 0x1 << y; | |
} | |
current | |
}); | |
} | |
hash | |
} | |
fn main(){ | |
println!("old: {:?}", old()); | |
println!("new: {:?}", new()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment