[−][src]Struct clusterphobia::clustering::Clustering
Partitions items into one or more non-overlapping Clusters. Each item may belong to a single Cluster.
Clusters may be combined using the merge
method.
Methods
impl<C: Chopped, M: Chopped, G: Iterator<Item = C>> Clustering<C, M, G>
[src]
pub fn empty(category_generator: G) -> Self
[src]
Create an empty Clustering.
pub fn uncategorized<I: Iterator<Item = M>>(
items: &mut I,
category_generator: G
) -> Self
[src]
items: &mut I,
category_generator: G
) -> Self
Create an Clustering with many items, each a member of its own Cluster.
pub fn add_to_new_cluster(&mut self, item: M) -> Result<C, C>
[src]
Create a new Cluster
in the Clustering
and add the given item to it.
- returns - An
Ok
containing the category of the newCluster
if the item was not previously present in theClustering
and was able to be added to a newCluster
, - returns - An
Err
containing the category of the existingCluster
if the item is already clustered - panics - If unable to generate any new categories.
pub fn add_to_cluster(&mut self, item: M, category: C) -> Result<C, C>
[src]
Add the given not-yet-clustered item to the existing Cluster
for the given category.
- returns - An
Ok
containing the given category
if the item was not previously present in theClustering
and was able to be added to theCluster
, - returns - An
Err
containing the category of the existingCluster
if the item is already clustered - panics - If there is no such category in the Clustering.
pub fn merge(&mut self, item1: M, item2: M) -> bool
[src]
Merge the Cluster
holding item1 with the Cluster
holding item2.
The merge is transitive; all members affiliated with item1 will now be in the same cluster as all members affiliated with item2.
- If the items are already clustered together, no change occurs.
- If both items are already present in the
Clustering
, merge together all items from both Clusters into the Cluster holding item1. - If neither item is currently in a Cluster, create a new Cluster and add each.
- If one item is in a Cluster and the other is not, add the unclustered item to the Cluster of the other.
- Returns:
- false if the items are already clustered together
- true if the items are not already clustered together
pub fn remove_item(&mut self, item: M) -> bool
[src]
Remove an item from its Cluster
and from its place in the index for the Clustering
.
If the item is the last item in its Cluster
, that Cluster
is removed from the Clustering
.
Returns:
- true
if able to find the item and remove it
- false
if unable to find the item in Clustering
pub fn move_item(&mut self, item: M, new_category: C) -> bool
[src]
Move an item to a different (but existing) category.
Unlike merge, only the given item is moved; any items with which it had been clustered remain behind in their Cluster
.
- If
new_category
does not exist in theClustering
, return false and do not remove theitem
. - If the item was not previously present in the
Clustering
, add it to theCluster
fornew_category
and return true. - If the item was already in
new_category
, do nothing and return false. - Otherwise, remove the item from its current category and add it to
new_category
.
- Returns true if a change was made, false otherwise.
pub fn contains_item(&self, item: M) -> bool
[src]
Check if the Clustering contains the given item in any of its Clusters.
pub fn contains_category(&self, category: C) -> bool
[src]
Check if the Clustering
contains a Cluster
for the given category.
pub fn get_category(&self, item: M) -> Option<C>
[src]
Get the category for the Cluster
with which the given item is grouped.
- returns - Some(category), if the item is clustered.
- returns - None, if the item is not present in the Clustering.
pub fn get_cluster(&self, category: C) -> Option<&Cluster<C, M>>
[src]
Get the cluster for the given category.
- returns -
Some(Cluster)
, if the category is present in theClustering
. - returns -
None
, if the category is not present in theClustering
.
pub fn get_clusters<'a>(&self) -> &HashMap<C, Cluster<C, M>>
[src]
Get all the Clusters
in the Clustering
.
pub fn get_cluster_mut(&mut self, category: C) -> Option<&mut Cluster<C, M>>
[src]
Get the cluster for the given category.
- returns -
Some(Cluster)
, if the category is present in theClustering
. - returns -
None
, if the category is not present in theClustering
.
pub fn are_together(&self, item1: M, item2: M) -> bool
[src]
Check if both items are grouped into the same Cluster.
- returns -
true
, if both items are present in the Clustering and grouped into the sameCluster
. - returns -
false
, if either item is not present in theClustering
or if they are in separateClusters
.
pub fn cluster_count(&self) -> usize
[src]
Number of Clusters into which items are partitioned
pub fn member_count(&self) -> usize
[src]
Number of members in all the Clusters combined.
Trait Implementations
Auto Trait Implementations
impl<C, M, G> Send for Clustering<C, M, G> where
C: Send,
G: Send,
M: Send,
C: Send,
G: Send,
M: Send,
impl<C, M, G> Sync for Clustering<C, M, G> where
C: Sync,
G: Sync,
M: Sync,
C: Sync,
G: Sync,
M: Sync,
impl<C, M, G> Unpin for Clustering<C, M, G> where
C: Unpin,
G: Unpin,
M: Unpin,
C: Unpin,
G: Unpin,
M: Unpin,
impl<C, M, G> UnwindSafe for Clustering<C, M, G> where
C: UnwindSafe,
G: UnwindSafe,
M: UnwindSafe,
C: UnwindSafe,
G: UnwindSafe,
M: UnwindSafe,
impl<C, M, G> RefUnwindSafe for Clustering<C, M, G> where
C: RefUnwindSafe,
G: RefUnwindSafe,
M: RefUnwindSafe,
C: RefUnwindSafe,
G: RefUnwindSafe,
M: RefUnwindSafe,
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,