Skip to content

Commit

Permalink
Minor changes and renames. (#11)
Browse files Browse the repository at this point in the history
* bit_vec

* quickinstall

* no dry-run

* revert back quickinstall

* try runner

* arm64

* no ARM yet

* nothing to see here

* install and uninstall
  • Loading branch information
sergey-shandar authored Oct 5, 2023
1 parent af51711 commit fe9fa10
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 29 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: cargo clippy -- -D warnings
- run: cargo clippy -- -D warnings

test:
strategy:
matrix:
# https://docs.github.com/en/actions/using-jobs/choosing-the-runner-for-a-job#choosing-github-hosted-runners
os: [windows-latest, ubuntu-latest, macos-13]
runs-on: ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- run: cargo t
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
# Data Block Set

Data Block Set

## For Developers

Installation:

```
cargo install --git https://github.com/datablockset/blockset
```

Uninstallation:

```
cargo uninstall blockset
```
16 changes: 8 additions & 8 deletions blockset/src/base32.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{ascii::to_ascii, bit_vec32::BitVec32};
use crate::{ascii::to_ascii, bit_vec::BitVec};

const fn to_base32(v: u8) -> char {
//0 1
Expand Down Expand Up @@ -32,13 +32,13 @@ pub trait ToBase32 {
}

pub trait BitsToBase32 {
fn bits_to_base32(self) -> (String, BitVec32);
fn bits_to_base32(self) -> (String, BitVec);
}

impl<T: Iterator<Item = BitVec32>> BitsToBase32 for T {
fn bits_to_base32(self) -> (String, BitVec32) {
impl<T: Iterator<Item = BitVec>> BitsToBase32 for T {
fn bits_to_base32(self) -> (String, BitVec) {
let mut result = String::default();
let mut a = BitVec32::default();
let mut a = BitVec::default();
for b in self {
a.push(&mut |v| result.push(to_base32(v as u8)), 5, b)
}
Expand All @@ -61,13 +61,13 @@ impl StrEx for str {
}
}

impl FromBase32 for (Vec<u32>, BitVec32) {
impl FromBase32 for (Vec<u32>, BitVec) {
fn from_base32(i: &str) -> Option<Self> {
let mut result = Vec::default();
let mut a = BitVec32::default();
let mut a = BitVec::default();
for b in i.chars() {
let v5 = from_base32(b)?;
a.push(&mut |v| result.push(v), 32, BitVec32::new(v5 as u32, 5));
a.push(&mut |v| result.push(v), 32, BitVec::new(v5 as u32, 5));
}
Some((result, a))
}
Expand Down
19 changes: 11 additions & 8 deletions blockset/src/bit_vec32.rs → blockset/src/bit_vec.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
#[derive(Default)]
pub struct BitVec32 {
pub v: u64,
pub struct BitVec {
pub value: u64,
pub len: u8,
}

impl BitVec32 {
impl BitVec {
pub const fn new(v: u32, len: u8) -> Self {
Self { v: v as u64, len }
Self {
value: v as u64,
len,
}
}
pub fn push(&mut self, f: &mut impl FnMut(u32), size: u8, b: BitVec32) {
pub fn push(&mut self, f: &mut impl FnMut(u32), size: u8, b: BitVec) {
assert!(size <= 32);
self.v |= b.v << self.len;
self.value |= b.value << self.len;
self.len += b.len;
let mask = (1 << size) - 1;
loop {
if self.len < size {
return;
}
f((self.v & mask) as u32);
f((self.value & mask) as u32);
self.len -= size;
self.v >>= size;
self.value >>= size;
}
}
}
20 changes: 10 additions & 10 deletions blockset/src/digest224.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::iter::once;

use crate::{
base32::{BitsToBase32, FromBase32, StrEx, ToBase32},
bit_vec32::BitVec32,
bit_vec::BitVec,
};

pub type Digest224 = [u32; 7];
Expand All @@ -19,29 +19,29 @@ impl Digest224Ex for &Digest224 {

impl ToBase32 for &Digest224 {
fn to_base32(self) -> String {
let (result, a) = self
let (result, BitVec { value, len }) = self
.iter()
.map(|x| BitVec32::new(*x, 32))
.chain(once(BitVec32::new(self.parity_bit() as u32, 1)))
.map(|x| BitVec::new(*x, 32))
.chain(once(BitVec::new(self.parity_bit() as u32, 1)))
.bits_to_base32();
assert_eq!(a.len, 0);
assert_eq!(a.v, 0);
assert_eq!(len, 0);
assert_eq!(value, 0);
assert_eq!(result.len(), 45);
result
}
}

impl FromBase32 for Digest224 {
fn from_base32(i: &str) -> Option<Self> {
let (vec, a) = i.from_base32()?;
let (vec, BitVec { value, len }) = i.from_base32()?;
if vec.len() != 7 {
return None;
}
assert_eq!(a.len, 1);
assert_eq!(a.v | 1, 1);
assert_eq!(len, 1);
assert_eq!(value | 1, 1);
let mut result = Digest224::default();
result.copy_from_slice(&vec);
if a.v as u8 != result.parity_bit() {
if value != result.parity_bit() as u64 {
return None;
}
Some(result)
Expand Down
2 changes: 1 addition & 1 deletion blockset/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod app;
mod ascii;
mod base32;
mod bit_vec32;
mod bit_vec;
mod digest224;
mod io;
mod sha224;
Expand Down

0 comments on commit fe9fa10

Please sign in to comment.