count_wires/
count_wires.rs1use brdb::{Brz, IntoReader};
2use std::path::PathBuf;
3
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5 let path = PathBuf::from(
6 std::env::args()
7 .nth(1)
8 .unwrap_or_else(|| "world.brz".to_string()),
9 );
10 let db = Brz::open(path)?.into_reader();
11
12 let mut grid_ids = vec![1];
13 for index in db.entity_chunk_index()? {
14 for e in db.entity_chunk(index)? {
15 if e.is_brick_grid() || e.is_microchip_grid() {
16 if let Some(id) = e.id {
17 grid_ids.push(id);
18 }
19 }
20 }
21 }
22
23 let mut total_wires = 0u64;
24 let mut total_bricks = 0u64;
25 for &gid in &grid_ids {
26 let chunks = db.brick_chunk_index(gid)?;
27 for chunk in &chunks {
28 total_bricks += chunk.num_bricks as u64;
29 total_wires += chunk.num_wires as u64;
30 }
31 }
32
33 println!("grids: {}", grid_ids.len());
34 println!("bricks: {total_bricks}");
35 println!("wires: {total_wires}");
36 Ok(())
37}