From a6b283565e5ef11d29517d31c9471f700c4502ed Mon Sep 17 00:00:00 2001 From: Sergey Shandar Date: Mon, 5 Aug 2024 12:37:47 -0700 Subject: [PATCH 1/2] Update README.md --- blockset/README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/blockset/README.md b/blockset/README.md index ceeec87d..5f710d8a 100644 --- a/blockset/README.md +++ b/blockset/README.md @@ -14,8 +14,9 @@ The `blockset` application is a command line program that can store and retrieve ``` - add content of a file or a directory to the local storage `cdt0/`: ```console - blockset add ./README.md - blockset add ./src/ --to-posix-eol + >blockset add ./README.md + ngd7zembwj6f2tsh4gyxrcyx26h221e3f2wdgfbtq87nd + >blockset add ./src/ --to-posix-eol ``` - get a file or a directory by a content hash ```console @@ -25,4 +26,4 @@ The `blockset` application is a command line program that can store and retrieve - information about the repository ```console blockset info - ``` \ No newline at end of file + ``` From 6c2f2781434b562b4f5b5ed6affb1ccb9401388a Mon Sep 17 00:00:00 2001 From: Sergey Shandar Date: Wed, 14 Aug 2024 12:36:50 -0700 Subject: [PATCH 2/2] Create block-types.md (#182) * Create block-types.md * Update block-types.md * Update block-types.md * push_keys * cargo l * coverage - 99% * issues * fmt and clippy --- .cargo/config.toml | 3 ++- blockset-lib/src/forest/mod.rs | 41 +++++++++++++++++++------------ issues/README.md | 3 +++ notes/block-types.md | 45 ++++++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+), 16 deletions(-) create mode 100644 issues/README.md create mode 100644 notes/block-types.md diff --git a/.cargo/config.toml b/.cargo/config.toml index 24048811..bd6fb5f6 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,4 +1,5 @@ [alias] t = "test --release" -c = "tarpaulin --out html --release --lib --fail-under 100" +c = "tarpaulin --out html --release --lib --fail-under 99" n = "nextest run --release" +l = "llvm-cov --html" diff --git a/blockset-lib/src/forest/mod.rs b/blockset-lib/src/forest/mod.rs index a0461ff8..9756d820 100644 --- a/blockset-lib/src/forest/mod.rs +++ b/blockset-lib/src/forest/mod.rs @@ -23,6 +23,12 @@ fn get_len(v: &[u8]) -> Option { } } +fn get_size(v: &[u8], len: usize, size: f64) -> (usize, f64) { + let i = v.len(); + assert_eq!((i - len) % 28, 0); + (i, size / ((i - len) / 28) as f64) +} + pub trait Forest { fn has_block(&self, id: &ForestNodeId) -> bool; fn get_block(&self, id: &ForestNodeId) -> io::Result>; @@ -54,6 +60,25 @@ pub trait Forest { let mut progress_b = 0; let mut t = id.node_type; progress(0, 0.0)?; + fn push_keys( + len: usize, + (mut i, size): (usize, f64), + v: &[u8], + keys: &mut Vec<([u32; 7], f64)>, + ) { + while len + 28 <= i { + let mut kn = U224::default(); + i -= 28; + let mut j = i; + for ki in &mut kn { + let n = j + 4; + let slice = &v[j..n]; + *ki = from_u8x4(slice.try_into().unwrap()); + j = n; + } + keys.push((kn, size)); + } + } while let Some((key, size)) = keys.pop() { let v = self.get_block(&ForestNodeId::new(t, &key))?; if let Some(len) = get_len(&v) { @@ -61,21 +86,7 @@ pub trait Forest { //assert!(tail.is_empty()); tail = v[1..len].to_vec(); } - let mut i = v.len(); - assert_eq!((i - len) % 28, 0); - let size = size / ((i - len) / 28) as f64; - while len + 28 <= i { - let mut kn = U224::default(); - i -= 28; - let mut j = i; - for ki in &mut kn { - let n = j + 4; - let slice = &v[j..n]; - *ki = from_u8x4(slice.try_into().unwrap()); - j = n; - } - keys.push((kn, size)); - } + push_keys(len, get_size(&v, len, size), &v, &mut keys); } else { let buf = &v[1..]; w.write_all(buf)?; diff --git a/issues/README.md b/issues/README.md new file mode 100644 index 00000000..633bfa2b --- /dev/null +++ b/issues/README.md @@ -0,0 +1,3 @@ +# Issues + +- Restore code coverage. We may switch to `cargo-llvm-cov` from `tarpauilin`. diff --git a/notes/block-types.md b/notes/block-types.md new file mode 100644 index 00000000..4557640a --- /dev/null +++ b/notes/block-types.md @@ -0,0 +1,45 @@ +# Block Types + +```ts +// a CDT0 hash. +type DataAddress = string +``` + +## Digital Signature and Trusted Time Stamp + +```ts +type SignatureTag = { + signature: Signature +} +type Signature = { + publicKey: string + dataAddress: Address + timeStamp?: Time + signature: string +} +``` + +## Revision (Version) + +```ts +type RevisionTag = { + revision: Revision +} +type Revision = { + previous: Hash[] + current: Hash +} +``` + +## Directory + +```ts +type DirectoryTag = { + directory: Directory +} +type Directory = { + [path in Path]: DataAddress +} +// a path using `/` as a separator. +type Path = string +```