ragc_common/
lib.rs

1//! Common data structures and utilities for AGC genome compression.
2//!
3//! This crate provides the foundational types and utilities used across the ragc project:
4//!
5//! - **Archive I/O** - Reading and writing AGC archive format
6//! - **Collection metadata** - Managing samples, contigs, and segment descriptors
7//! - **Variable-length integers** - Space-efficient encoding/decoding
8//! - **Hash functions** - MurmurHash implementations for k-mer hashing
9//! - **Stream naming** - Archive version-aware stream identification
10//!
11//! # Examples
12//!
13//! ## Creating and reading an archive
14//!
15//! ```no_run
16//! use ragc_common::Archive;
17//!
18//! // Create a new archive for writing
19//! let mut archive = Archive::new_writer();
20//! archive.open("output.agc").expect("Failed to create archive");
21//!
22//! // Register a stream and add data
23//! let stream_id = archive.register_stream("my_stream");
24//! let data = b"Hello, AGC!";
25//! archive.add_part(stream_id, data, data.len() as u64).expect("Failed to add data");
26//!
27//! archive.close().expect("Failed to close archive");
28//!
29//! // Read it back
30//! let mut archive = Archive::new_reader();
31//! archive.open("output.agc").expect("Failed to open archive");
32//!
33//! let stream_id = archive.get_stream_id("my_stream").expect("Stream not found");
34//! let (data, _) = archive.get_part_by_id(stream_id, 0).expect("Failed to read data");
35//!
36//! assert_eq!(&data, b"Hello, AGC!");
37//! ```
38//!
39//! ## Variable-length integer encoding
40//!
41//! ```
42//! use ragc_common::{write_varint, read_varint};
43//! use std::io::Cursor;
44//!
45//! let mut buffer = Vec::new();
46//! write_varint(&mut buffer, 12345).expect("Failed to encode");
47//!
48//! let mut cursor = Cursor::new(&buffer);
49//! let (value, bytes_read) = read_varint(&mut cursor).expect("Failed to decode");
50//!
51//! assert_eq!(value, 12345);
52//! ```
53//!
54//! ## Using hash functions
55//!
56//! ```
57//! use ragc_common::MurMur64Hash;
58//!
59//! let kmer_value = 0x12345678u64;
60//! let hash = MurMur64Hash::hash(kmer_value);
61//! ```
62
63pub mod archive;
64pub mod collection;
65pub mod hash;
66pub mod stream_naming;
67pub mod types;
68pub mod varint;
69
70// Re-export commonly used types
71pub use types::{Base, Contig, PackedBlock};
72pub use types::{
73    AGC_FILE_MAJOR, AGC_FILE_MINOR, AGC_VER_BUGFIX, AGC_VER_MAJOR, AGC_VER_MINOR, CONTIG_SEPARATOR,
74};
75
76// Re-export hash functions
77pub use hash::{MurMur32Hash, MurMur64Hash, MurMurPair64Hash, MurMurStringsHash};
78
79// Re-export varint functions
80pub use varint::{
81    decode_varint, encode_varint, read_fixed_u64, read_varint, write_fixed_u64, write_varint,
82};
83
84// Re-export archive
85pub use archive::Archive;
86
87// Re-export collection
88pub use collection::{zigzag_decode, zigzag_decode_i64, zigzag_encode, zigzag_encode_i64};
89pub use collection::{CollectionV3, CollectionVarInt, ContigDesc, SampleDesc, SegmentDesc};
90
91// Re-export stream naming
92pub use stream_naming::{
93    int_to_base64, stream_base, stream_delta_ext, stream_delta_name, stream_prefix, stream_ref_ext,
94    stream_ref_name,
95};