Skip to content

Merkleize byte-identical node allocation #90

Description

@adamv-symbolica
use pathmap::PathMap;
use pathmap::viz::{viz_maps, DrawConfig, VizMode};

fn main() {
    // Every bitstring over {0,1} of length 1..=4 ending in 1, plus the empty path (16 paths)
    let mut paths: Vec<Vec<u8>> = vec![vec![]];
    for len in 1..=4usize {
        for bits in 0..(1u32 << len) {
            let p: Vec<u8> = (0..len).map(|i| ((bits >> (len - 1 - i)) & 1) as u8).collect();
            if *p.last().unwrap() == 1 { paths.push(p); }
        }
    }
    let mut map = PathMap::from_iter(paths.iter().map(|p| (p.as_slice(), ())));

    let count = |m: &PathMap<()>| {
        let dc = DrawConfig { mode: VizMode::Mermaid, ascii_path: false, hide_value_paths: true,
                              minimize_values: true, logical: false, color: false };
        let mut out = Vec::new();
        viz_maps(std::slice::from_ref(m), &dc, &mut out).unwrap();
        String::from_utf8(out).unwrap().lines().filter(|l| l.contains("shape: rect")).count()
    };

    println!("before: {}", count(&map));   // 15
    let r = map.merkleize();
    println!("after: {} ({r:?})", count(&map)); // 7, expected 4
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions