Skip to content

Commit

Permalink
Create block-types.md (#182)
Browse files Browse the repository at this point in the history
* Create block-types.md

* Update block-types.md

* Update block-types.md

* push_keys

* cargo l

* coverage - 99%

* issues

* fmt and clippy
  • Loading branch information
sergey-shandar authored Aug 14, 2024
1 parent a6b2835 commit 6c2f278
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -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"
41 changes: 26 additions & 15 deletions blockset-lib/src/forest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ fn get_len(v: &[u8]) -> Option<usize> {
}
}

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<Vec<u8>>;
Expand Down Expand Up @@ -54,28 +60,33 @@ 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) {
if len > 1 {
//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)?;
Expand Down
3 changes: 3 additions & 0 deletions issues/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Issues

- Restore code coverage. We may switch to `cargo-llvm-cov` from `tarpauilin`.
45 changes: 45 additions & 0 deletions notes/block-types.md
Original file line number Diff line number Diff line change
@@ -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
```

0 comments on commit 6c2f278

Please sign in to comment.