From 965b7b35f931865a1b21a681b6f6665703857c61 Mon Sep 17 00:00:00 2001 From: bryan newbold Date: Thu, 9 Mar 2023 12:26:05 -0800 Subject: mst: Box<[u8]> for bytes, not Vec (which gives int array) --- adenosine/src/mst.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/adenosine/src/mst.rs b/adenosine/src/mst.rs index 3ec4e25..c695ac6 100644 --- a/adenosine/src/mst.rs +++ b/adenosine/src/mst.rs @@ -47,7 +47,7 @@ pub struct MetadataNode { #[derive(Debug, DagCbor, PartialEq, Eq)] struct MstEntry { p: u32, - k: Vec, + k: Box<[u8]>, v: Cid, t: Option, } @@ -60,7 +60,7 @@ struct MstNode { struct WipEntry { height: u8, - key: Vec, + key: Box<[u8]>, val: Cid, right: Option>, } @@ -218,7 +218,7 @@ pub fn generate_mst( let height = leading_zeros(key); let entry = WipEntry { height, - key: key.to_vec(), + key: key.into(), val: *val, right: None, }; @@ -351,7 +351,7 @@ fn serialize_wip_tree( }; let mut entries: Vec = vec![]; - let mut last_key: Vec = vec![]; + let mut last_key: Box<[u8]> = vec![].into(); for wip_entry in wip_node.entries { let right: Option = if let Some(right) = wip_entry.right { Some(serialize_wip_tree(db, *right)?) @@ -360,7 +360,7 @@ fn serialize_wip_tree( }; let prefix_len = common_prefix_len(&last_key, &wip_entry.key); entries.push(MstEntry { - k: wip_entry.key[prefix_len..].to_vec(), + k: wip_entry.key[prefix_len..].into(), p: prefix_len as u32, v: wip_entry.val, t: right, @@ -385,7 +385,7 @@ fn test_mst_node_cbor() { let node = MstNode { l: None, e: vec![MstEntry { - k: "asdf".as_bytes().to_vec(), + k: "com.example.record/3jqfcqzm3fo2j".as_bytes().into(), p: 0, v: cid1, t: None, @@ -397,6 +397,6 @@ fn test_mst_node_cbor() { let cid = *block.cid(); assert_eq!( cid.to_string(), - "bafyreihwovqdtuzyymasojncipiplf3xgxaqamkld7oz7ct2my3be7zxae" + "bafyreibj4lsc3aqnrvphp5xmrnfoorvru4wynt6lwidqbm2623a6tatzdu" ); } -- cgit v1.2.3