Last active
March 29, 2018 03:52
-
-
Save kunigami/0523c832c678df6a5e7128c812da0d3d to your computer and use it in GitHub Desktop.
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
let m: u32 = 1 << b; | |
let mut first_non_zero_by_bucket: Vec<u32> = vec![0 as u32; m as usize]; | |
for element in elements { | |
let hash_value = hash(&element); | |
// Extracts the first b bits from hash_value to determine the bucket | |
let bucket_index: usize = (hash_value & first_b_bits_mask) as usize; | |
// Finds the position of the first 1 bit in the remaining bits | |
let mut first_non_zero: u32 = first_non_zero_bit_position(hash_value >> b); | |
first_non_zero_by_bucket[bucket_index] = cmp::max( | |
first_non_zero_by_bucket[bucket_index], | |
first_non_zero | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment