Skip to content

Commit

Permalink
Merge branch 'main' into mul
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-shandar committed Aug 14, 2024
2 parents 4a7db8a + 6c2f278 commit d437897
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 19 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
7 changes: 4 additions & 3 deletions blockset/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,4 +26,4 @@ The `blockset` application is a command line program that can store and retrieve
- information about the repository
```console
blockset info
```
```
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 d437897

Please sign in to comment.