Skip to content

Commit

Permalink
Represent chars in protein text with 5 bits, tests don't work yet
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonVandeVyver committed Sep 11, 2024
1 parent f15e3f8 commit fb6e77a
Show file tree
Hide file tree
Showing 11 changed files with 506 additions and 87 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions bitarray/src/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ mod tests {
#[test]
fn test_write_binary() {
let mut bitarray = BitArray::with_capacity(4, 40);
bitarray.set(0, 0x1234567890);
bitarray.set(1, 0xabcdef0123);
bitarray.set(2, 0x4567890abc);
bitarray.set(3, 0xdef0123456);
bitarray.set(0, 0x1234567890_u64);
bitarray.set(1, 0xabcdef0123_u64);
bitarray.set(2, 0x4567890abc_u64);
bitarray.set(3, 0xdef0123456_u64);

let mut buffer = Vec::new();
bitarray.write_binary(&mut buffer).unwrap();
Expand Down
18 changes: 12 additions & 6 deletions bitarray/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct BitArray {
/// The length of the bit array.
len: usize,
/// The number of bits in a single element of the data vector.
bits_per_value: usize
bits_per_value: usize,
}

impl BitArray {
Expand All @@ -39,7 +39,7 @@ impl BitArray {
data: vec![0; capacity * bits_per_value / 64 + extra],
mask: (1 << bits_per_value) - 1,
len: capacity,
bits_per_value
bits_per_value,
}
}

Expand Down Expand Up @@ -85,6 +85,7 @@ impl BitArray {
/// * `index` - The index of the value to set.
/// * `value` - The value to set at the specified index.
pub fn set(&mut self, index: usize, value: u64) {
let value: u64 = value.into();
let start_block = index * self.bits_per_value / 64;
let start_block_offset = index * self.bits_per_value % 64;

Expand Down Expand Up @@ -142,6 +143,11 @@ impl BitArray {
pub fn clear(&mut self) {
self.data.iter_mut().for_each(|x| *x = 0);
}

pub fn get_data_slice(&self, start_slice: usize, end_slice: usize) -> &[u64] {
&self.data[start_slice..end_slice]
}

}

/// Writes the data to a writer in a binary format using a bit array. This function is helpfull
Expand Down Expand Up @@ -257,10 +263,10 @@ mod tests {
fn test_bitarray_set() {
let mut bitarray = BitArray::with_capacity(4, 40);

bitarray.set(0, 0b0001110011111010110001000111111100110010);
bitarray.set(1, 0b1100001001010010011000010100110111001001);
bitarray.set(2, 0b1111001101001101101101101011101001010001);
bitarray.set(3, 0b0000100010010001010001001110101110011100);
bitarray.set(0, 0b0001110011111010110001000111111100110010_u64);
bitarray.set(1, 0b1100001001010010011000010100110111001001_u64);
bitarray.set(2, 0b1111001101001101101101101011101001010001_u64);
bitarray.set(3, 0b0000100010010001010001001110101110011100_u64);

assert_eq!(bitarray.data, vec![0x1cfac47f32c25261, 0x4dc9f34db6ba5108, 0x9144EB9C00000000]);
}
Expand Down
1 change: 1 addition & 0 deletions sa-index/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ clap = { version = "4.4.8", features = ["derive"] }
rayon = "1.8.1"
serde = { version = "1.0.197", features = ["derive"] }
sa-mappings = { path = "../sa-mappings" }
text-compression = { path = "../text-compression" }
bitarray = { path = "../bitarray" }
serde_json = "1.0.116"
10 changes: 5 additions & 5 deletions sa-index/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ mod tests {
#[test]
fn test_suffix_array_compressed() {
let mut bitarray = BitArray::with_capacity(5, 40);
bitarray.set(0, 1);
bitarray.set(1, 2);
bitarray.set(2, 3);
bitarray.set(3, 4);
bitarray.set(4, 5);
bitarray.set(0, 1 as u64);
bitarray.set(1, 2 as u64);
bitarray.set(2, 3 as u64);
bitarray.set(3, 4 as u64);
bitarray.set(4, 5 as u64);

let sa = SuffixArray::Compressed(bitarray, 1);
assert_eq!(sa.len(), 5);
Expand Down
Loading

0 comments on commit fb6e77a

Please sign in to comment.