diff options
author | bryan newbold <bnewbold@robocracy.org> | 2023-03-09 12:26:05 -0800 |
---|---|---|
committer | bryan newbold <bnewbold@robocracy.org> | 2023-03-09 12:26:05 -0800 |
commit | 965b7b35f931865a1b21a681b6f6665703857c61 (patch) | |
tree | 6d0879985cb51760a831d6925eb4f411ef1ff447 | |
parent | 1b28c0ee5878689304a61238f0dc3b1545794a21 (diff) | |
download | adenosine-965b7b35f931865a1b21a681b6f6665703857c61.tar.gz adenosine-965b7b35f931865a1b21a681b6f6665703857c61.zip |
mst: Box<[u8]> for bytes, not Vec<u8> (which gives int array)
-rw-r--r-- | adenosine/src/mst.rs | 14 |
1 files 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<u8>, + k: Box<[u8]>, v: Cid, t: Option<Cid>, } @@ -60,7 +60,7 @@ struct MstNode { struct WipEntry { height: u8, - key: Vec<u8>, + key: Box<[u8]>, val: Cid, right: Option<Box<WipNode>>, } @@ -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<MstEntry> = vec![]; - let mut last_key: Vec<u8> = vec![]; + let mut last_key: Box<[u8]> = vec![].into(); for wip_entry in wip_node.entries { let right: Option<Cid> = 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" ); } |