Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
tibvdm committed Apr 8, 2024
1 parent 2a88733 commit 64277d0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion fa-compression/src/algorithm2/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use super::CompressionTable;
/// let mut compression_table = CompressionTable::new();
/// compression_table.add_entry("IPR:IPR000001".to_string());
/// compression_table.add_entry("IPR:IPR000002".to_string());
///
///
/// let decoded_string = decode(input, compression_table);
/// assert_eq!(decoded_string, "IPR:IPR000001;IPR:IPR000002");
/// ```
Expand Down
6 changes: 3 additions & 3 deletions fa-compression/src/algorithm2/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use super::CompressionTable;
/// * `compression_table` - The compression table used for encoding.
///
/// # Returns
///
///
/// A compressed byte vector representing the encoded annotations.
///
///
/// # Examples
///
/// ```
Expand All @@ -22,7 +22,7 @@ use super::CompressionTable;
/// let mut compression_table = CompressionTable::new();
/// compression_table.add_entry("IPR:IPR000001".to_string());
/// compression_table.add_entry("IPR:IPR000002".to_string());
///
///
/// let encoded = encode("IPR:IPR000001;IPR:IPR000002", compression_table);
/// assert_eq!(encoded, vec![0, 0, 0, 1, 0, 0]);
/// ```
Expand Down
34 changes: 19 additions & 15 deletions fa-compression/src/algorithm2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,57 +12,61 @@ pub use encode::encode;
/// Represents an entry in the compression table.
#[doc(hidden)]
pub struct CompressionTableEntry {
annotation: String,
annotation: String
}

/// Represents a compression table.
pub struct CompressionTable {
/// List of annotations in the compression table.
entries: Vec<CompressionTableEntry>,
entries: Vec<CompressionTableEntry>
}

impl CompressionTable {
/// Creates a new compression table.
///
///
/// # Returns
///
///
/// An empty compression table.
///
///
/// # Examples
///
///
/// ```
/// use fa_compression::algorithm2::CompressionTable;
///
///
/// let table = CompressionTable::new();
/// ```
pub fn new() -> CompressionTable {
CompressionTable {
entries: Vec::new(),
entries: Vec::new()
}
}

/// Adds a new entry to the compression table.
///
///
/// # Arguments
///
///
/// * `annotation` - The annotation to add to the compression table.
///
///
/// # Examples
///
///
/// ```
/// use fa_compression::algorithm2::CompressionTable;
///
///
/// let mut table = CompressionTable::new();
/// table.add_entry("IPR:IPR000001".to_string());
/// table.add_entry("IPR:IPR000002".to_string());
/// ```
pub fn add_entry(&mut self, annotation: String) {
self.entries.push(CompressionTableEntry { annotation });
self.entries.push(CompressionTableEntry {
annotation
});
}

/// Returns the index of the given annotation in the compression table, if it exists.
fn index_of(&self, annotation: &str) -> Option<usize> {
self.entries.iter().position(|entry| entry.annotation == annotation)
self.entries
.iter()
.position(|entry| entry.annotation == annotation)
}
}

Expand Down

0 comments on commit 64277d0

Please sign in to comment.