Skip to main content

ContentDeduplicationIndex

Struct ContentDeduplicationIndex 

Source
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: ContentDedupConfig

Runtime configuration.

Implementations§

Source§

impl ContentDeduplicationIndex

Source

pub fn new(config: ContentDedupConfig) -> Self

Create a new index with the supplied configuration.

Source

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
Source

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).

Source

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.

Source

pub fn lookup_by_key(&self, key: &str) -> Option<&DedupEntry>

Look up a dedup entry by its storage key.

Source

pub fn lookup_by_hash(&self, hash: &ContentHash) -> Option<&DedupEntry>

Look up a dedup entry directly by its content hash.

Source

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).

Source

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.

Source

pub fn deduplicated_keys(&self) -> Vec<(&str, &str)>

Return all (duplicate_key, canonical_key) pairs where the duplicate key differs from the canonical key.

Source

pub fn stats(&self) -> ContentDedupStats

Return a snapshot of index statistics.

Source

pub fn len(&self) -> usize

Return the number of unique content hashes in the index.

Source

pub fn is_empty(&self) -> bool

Return true when the index contains no entries.

Source

pub fn key_count(&self) -> usize

Return the number of key→hash mappings (including duplicates).

Trait Implementations§

Source§

impl Debug for ContentDeduplicationIndex

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more