[][src]Struct clusterphobia::clustering::Clustering

pub struct Clustering<C: Chopped, M: Chopped, G: Iterator<Item = C>> { /* fields omitted */ }

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]

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 new Cluster if the item was not previously present in the Clustering and was able to be added to a new Cluster,
  • returns - An Err containing the category of the existing Cluster 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 the Clustering and was able to be added to the Cluster,
  • returns - An Err containing the category of the existing Cluster 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.

  1. If the items are already clustered together, no change occurs.
  2. If both items are already present in the Clustering, merge together all items from both Clusters into the Cluster holding item1.
  3. If neither item is currently in a Cluster, create a new Cluster and add each.
  4. If one item is in a Cluster and the other is not, add the unclustered item to the Cluster of the other.
  5. 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.

  1. If new_category does not exist in the Clustering, return false and do not remove the item.
  2. If the item was not previously present in the Clustering, add it to the Cluster for new_category and return true.
  3. If the item was already in new_category, do nothing and return false.
  4. 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 the Clustering.
  • returns - None, if the category is not present in the Clustering.

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 the Clustering.
  • returns - None, if the category is not present in the Clustering.

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 same Cluster.
  • returns - false, if either item is not present in the Clustering or if they are in separate Clusters.

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

impl<C: Chopped, M: Chopped, G: Iterator<Item = C>> Debug for Clustering<C, M, G>[src]

Auto Trait Implementations

impl<C, M, G> Send for Clustering<C, M, G> where
    C: Send,
    G: Send,
    M: Send

impl<C, M, G> Sync for Clustering<C, M, G> where
    C: Sync,
    G: Sync,
    M: Sync

impl<C, M, G> Unpin for Clustering<C, M, G> where
    C: Unpin,
    G: Unpin,
    M: Unpin

impl<C, M, G> UnwindSafe for Clustering<C, M, G> where
    C: UnwindSafe,
    G: UnwindSafe,
    M: UnwindSafe

impl<C, M, G> RefUnwindSafe for Clustering<C, M, G> where
    C: RefUnwindSafe,
    G: RefUnwindSafe,
    M: RefUnwindSafe

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

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