use std::cmp;
use std::collections::HashMap;
use std::fs;

use parse::uca::allkeys;

fn main() {
    let allkeys = {
        let data = fs::read_to_string("data/allkeys.txt").unwrap();

        allkeys::parse(&data)
    };

    let mut l1 = 0;
    let mut l2 = 0;
    let mut l3 = 0;
    let mut l4 = 0;

    let mut count = HashMap::new();

    for entry in allkeys.entries {
        count
            .entry(entry.elements.len())
            .and_modify(|x| *x += 1)
            .or_insert(1);

        for element in entry.elements {
            l1 = cmp::max(l1, element.l1);
            l2 = cmp::max(l2, element.l2);
            l3 = cmp::max(l3, element.l3);
            l4 = cmp::max(l4, element.l4);
        }
    }

    /*
    l1       = 16 bits
    l2       =  9 bits
    l3       =  5 bits
    l4       =  0 bits
    variable =  1 bit

    total    = 31 bits
    */

    println!("l1: {} - {} bit(s)", l1, u16::BITS - l1.leading_zeros());
    println!("l2: {} - {} bit(s)", l2, u16::BITS - l2.leading_zeros());
    println!("l3: {} - {} bit(s)", l3, u8::BITS - l3.leading_zeros());
    println!("l4: {} - {} bit(s)", l4, u16::BITS - l4.leading_zeros());
    println!("variable: 1 bit(s)");
    println!();
    println!("{:#?}", count);
}
