pub struct ContentDeduplicationIndex {
pub config: ContentDedupConfig,
/* private fields */
}Expand description
Hash-based content deduplication index.
Tracks identical content blocks, reference counts, and can reclaim storage by merging duplicates.
§Example
use ipfrs_storage::content_dedup_index::{
ContentDeduplicationIndex, ContentDedupConfig, ContentDedupResult,
};
let config = ContentDedupConfig::default();
let mut idx = ContentDeduplicationIndex::new(config);
let data = b"hello, world!";
let result = idx.insert("key1".into(), data, 1000).unwrap();
assert!(matches!(result, ContentDedupResult::New { .. }));
// Insert the same content under a different key — it's a duplicate
let result2 = idx.insert("key2".into(), data, 1001).unwrap();
assert!(matches!(result2, ContentDedupResult::Duplicate { .. }));Fields§
§config: ContentDedupConfigRuntime configuration.
Implementations§
Source§impl ContentDeduplicationIndex
impl ContentDeduplicationIndex
Sourcepub fn new(config: ContentDedupConfig) -> Self
pub fn new(config: ContentDedupConfig) -> Self
Create a new index with the supplied configuration.
Sourcepub fn compute_hash(data: &[u8]) -> ContentHash
pub fn compute_hash(data: &[u8]) -> ContentHash
Compute the 32-byte approximate ContentHash for data.
Layout:
- Bytes 0– 7: FNV-1a 64-bit
- Bytes 8–15: DJB2 64-bit xorshifted
- Bytes 16–23:
data.len()as little-endian u64 - Bytes 24–31: FNV-1a 64-bit of reversed data
Sourcepub fn insert(
&mut self,
key: String,
data: &[u8],
now: u64,
) -> Result<ContentDedupResult, DedupIndexError>
pub fn insert( &mut self, key: String, data: &[u8], now: u64, ) -> Result<ContentDedupResult, DedupIndexError>
Insert data under key into the deduplication index.
Returns:
Ok(ContentDedupResult::New)when the content has not been seen before.Ok(ContentDedupResult::Duplicate)when identical content already exists.
Blocks whose size falls outside [min_block_size, max_block_size] are
returned as New without modifying the index (pass-through behaviour).
Sourcepub fn remove(&mut self, key: &str) -> bool
pub fn remove(&mut self, key: &str) -> bool
Remove the key from the index.
Decrements the reference count of the associated entry; if the count reaches zero and no other key points to the same hash, the entry is removed entirely.
Returns true if key was present, false otherwise.
Sourcepub fn lookup_by_key(&self, key: &str) -> Option<&DedupEntry>
pub fn lookup_by_key(&self, key: &str) -> Option<&DedupEntry>
Look up a dedup entry by its storage key.
Sourcepub fn lookup_by_hash(&self, hash: &ContentHash) -> Option<&DedupEntry>
pub fn lookup_by_hash(&self, hash: &ContentHash) -> Option<&DedupEntry>
Look up a dedup entry directly by its content hash.
Sourcepub fn is_duplicate(&self, data: &[u8]) -> bool
pub fn is_duplicate(&self, data: &[u8]) -> bool
Return true if data has been seen before (i.e., a matching hash
exists in the index and the block size is within range).
Sourcepub fn merge_duplicates(&mut self) -> u64
pub fn merge_duplicates(&mut self) -> u64
Scan key_to_hash and count keys whose hash is already represented by
a canonical key that differs from themselves. Returns the total number
of duplicate key→hash mappings merged (conceptually deduplicated).
This method does not remove any data; it reports how many duplicate entries currently exist and is idempotent.
Sourcepub fn deduplicated_keys(&self) -> Vec<(&str, &str)>
pub fn deduplicated_keys(&self) -> Vec<(&str, &str)>
Return all (duplicate_key, canonical_key) pairs where the duplicate
key differs from the canonical key.
Sourcepub fn stats(&self) -> ContentDedupStats
pub fn stats(&self) -> ContentDedupStats
Return a snapshot of index statistics.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ContentDeduplicationIndex
impl RefUnwindSafe for ContentDeduplicationIndex
impl Send for ContentDeduplicationIndex
impl Sync for ContentDeduplicationIndex
impl Unpin for ContentDeduplicationIndex
impl UnsafeUnpin for ContentDeduplicationIndex
impl UnwindSafe for ContentDeduplicationIndex
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more