Struct fclones::FileGroup

source ·
pub struct FileGroup<F> {
    pub file_len: FileLen,
    pub file_hash: FileHash,
    pub files: Vec<F>,
}
Expand description

A group of files that have something in common, e.g. same size or same hash

Fields§

§file_len: FileLen

Length of each file

§file_hash: FileHash

Hash of a part or the whole of the file

§files: Vec<F>

Group of files with the same length and hash

Implementations§

source§

impl<F> FileGroup<F>

source

pub fn file_count(&self) -> usize

Returns the count of all files in the group

source

pub fn total_size(&self) -> FileLen

Returns the total size of all files in the group

source

pub fn map<R>(self, f: impl Fn(F) -> R) -> FileGroup<R>

Maps the list of files in the group. Preserves the group file len and hash.

source

pub fn filter_map<R>(self, f: impl Fn(F) -> Option<R>) -> FileGroup<R>

Transforms files into different type, filtering out files that cannot be transformed

source

pub fn try_map_all<R: Debug, E: Debug>( self, f: impl Fn(F) -> Result<R, E> ) -> Result<FileGroup<R>, Vec<E>>

Tries to map each file by given fallible function. Does not stop processing on the first failure. If mapping any of the files fails, then returns a vector of errors.

source

pub fn flat_map<R, I>(self, f: impl Fn(F) -> I) -> FileGroup<R>
where I: IntoIterator<Item = R>,

Flat maps the list of files in the group. Preserves the group file len and hash.

source

pub fn partition_by_key<K: Eq + Hash>( self, key_fn: impl Fn(&F) -> K ) -> Vec<FileGroup<F>>

Splits the group into one or more groups based on the key function applied to each file. Files with the same key are placed in the same group. The key is computed only once per item. File len and file hash are preserved.

source§

impl<F: AsRef<FileId>> FileGroup<F>

source

pub fn unique_count(&self) -> usize

Returns the number of files with distinct identifiers. Files must be sorted by id.

source

pub fn unique_size(&self) -> FileLen

Returns the total size of data in files with distinct identifiers. Files must be sorted by id.

source

pub fn sort_by_id(&mut self)

Sorts the files in this group by their identifiers.

source§

impl<F: AsRef<Path> + AsRef<FileId>> FileGroup<F>

source

pub fn matches(&self, filter: &FileGroupFilter) -> bool

Returns true if the file group should be forwarded to the next grouping stage, because the number of duplicate files is higher than the maximum allowed number of replicas.

This method returns always true if the user searches for underreplicated files (filter.replication is Replication::Underreplicated). This is because even if the number of replicas is currently higher than the maximum number of allowed replicas, the group can be split in later stages and the number of replicas in the group may drop.

source

pub fn matches_strictly(&self, filter: &FileGroupFilter) -> bool

Returns true if the file group should be included in the final report. The number of replicas in the group must be appropriate for the condition specified in filter.replication.

source

pub fn missing_count(&self, filter: &FileGroupFilter) -> usize

Returns the number of missing file replicas.

This is the difference between the desired minimum number of replicas given by filter.replication and the number of files in the group.

If the number of files is greater than the minimum number of replicas, or if filter.replication is set to Replication::Overreplicated 0 is returned.

source

pub fn redundant_count(&self, filter: &FileGroupFilter) -> usize

Returns the highest number of redundant files that could be removed from the group.

If filter.roots are empty, the difference between the total number of files in the group and the desired maximum number of replicas controlled by filter.replication is returned.

If filter.roots are not empty, then files in the group are split into subgroups first, where each subgroup shares one of the roots. If the number of subgroups N is larger than the allowed number of replicas r, the last N - r subgroups are considered redundant. The total number of files in redundant subgroups is returned.

If the result would be negative in any of the above cases or if filter.replication is set to Replication::Underreplicated, 0 is returned.

source

pub fn reported_count(&self, filter: &FileGroupFilter) -> usize

Returns either the number of files redundant or missing, depending on the type of search.

source

pub fn sort_by_path(&mut self, root_paths: &[Path])

Sorts the files by their path names. If filter requires grouping by roots, then groups are kept together.

Trait Implementations§

source§

impl<T> AsRef<FileGroup<T>> for FileGroup<T>

source§

fn as_ref(&self) -> &FileGroup<T>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<F: Clone> Clone for FileGroup<F>

source§

fn clone(&self) -> FileGroup<F>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<F: Debug> Debug for FileGroup<F>

source§

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

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

impl<'de, F> Deserialize<'de> for FileGroup<F>
where F: Deserialize<'de>,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<F: PartialEq> PartialEq for FileGroup<F>

source§

fn eq(&self, other: &FileGroup<F>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<F> Serialize for FileGroup<F>
where F: Serialize,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<F: Eq> Eq for FileGroup<F>

source§

impl<F> StructuralEq for FileGroup<F>

source§

impl<F> StructuralPartialEq for FileGroup<F>

Auto Trait Implementations§

§

impl<F> RefUnwindSafe for FileGroup<F>
where F: RefUnwindSafe,

§

impl<F> Send for FileGroup<F>
where F: Send,

§

impl<F> Sync for FileGroup<F>
where F: Sync,

§

impl<F> Unpin for FileGroup<F>
where F: Unpin,

§

impl<F> UnwindSafe for FileGroup<F>
where F: UnwindSafe,

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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

§

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

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

§

fn vzip(self) -> V

source§

impl<T> BincodeSerDeBounds for T

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

source§

impl<T> KV for T