Created
December 22, 2018 00:55
-
-
Save techgeek1/b5c70e76824b9adb12468d66691eef77 to your computer and use it in GitHub Desktop.
Calculator to determine the approximate memory space required for a hierarchical bitvector of a specified size
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
const COUNT: i32 = 500_000; | |
const BLOCK_SIZE: i32 = 1024; | |
fn main() { | |
let mut count = COUNT; | |
let mut block_count = 0; | |
let mut layer_count = 1; | |
while count > BLOCK_SIZE { | |
let blocks = (count as f32 / (BLOCK_SIZE as f32)).ceil() as i32; | |
block_count += blocks; | |
count = blocks; | |
layer_count += 1; | |
} | |
let size_in_kb = to_kb(block_count * BLOCK_SIZE); | |
println!("Total Capacity: {}", block_count * BLOCK_SIZE); | |
println!("Layer Count: {}", layer_count); | |
println!("Block Count: {}", block_count); | |
println!("Size: {:.2}Kb", size_in_kb); | |
} | |
fn to_kb(value: i32) -> f32 { | |
(value as f32 / 8.0) / 1024.0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment