ContentDeduplicator

Struct ContentDeduplicator 

Source
pub struct ContentDeduplicator { /* private fields */ }
Expand description

内容去重器

通过计算文件的SHA256哈希值来识别完全相同的文件, 实现内容级别的去重存储。

Implementations§

Source§

impl ContentDeduplicator

Source

pub fn new() -> Self

创建新的内容去重器

Source

pub fn calculate_hash(data: &[u8]) -> String

计算数据的SHA256哈希值

Source

pub fn check_duplicate(&mut self, hash: &str) -> Option<String>

检查文件是否重复

返回 Some(storage_id) 如果文件已存在,None 如果是新文件

Source

pub fn register_file(&mut self, hash: String, storage_id: String)

注册新文件

当存储新文件时调用,建立哈希值和存储ID的映射

Source

pub fn remove_reference(&mut self, storage_id: &str) -> bool

移除文件引用

减少引用计数,如果计数为0则完全移除 返回是否应该删除物理文件

Source

pub fn remove_hash_reference(&mut self, hash: &str) -> bool

通过哈希值移除引用

减少对应存储的引用计数,如果计数为0则完全移除 返回是否应该删除物理文件

Source

pub fn add_hash_reference(&mut self, hash: &str, storage_id: &str)

通过哈希值增加引用

增加对应存储的引用计数

Source

pub fn get_dedup_info(&self, storage_id: &str) -> Option<DedupInfo>

获取文件的去重信息

Source

pub fn get_reference_info(&self, hash: &str) -> Option<DedupInfo>

获取引用信息(用于引用文件)

Source

pub fn get_stats(&self) -> DedupStats

获取所有存储的统计信息

Source

pub fn rebuild_from_index( &mut self, entries: Vec<(String, String, u32)>, ) -> Result<()>

从索引数据重建去重器状态

Trait Implementations§

Source§

impl Debug for ContentDeduplicator

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for ContentDeduplicator

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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