Skip to main content

OxiHashSet

Struct OxiHashSet 

Source
pub struct OxiHashSet<T>
where T: Eq + Hash + Clone,
{ /* private fields */ }
Expand description

A wrapper around std::collections::HashSet with an extended API.

OxiHashSet<T> provides functional-style operations (map, filter, fold) alongside the standard set operations (union, intersection, difference).

Implementations§

Source§

impl OxiHashSet<String>

Source

pub fn insert_str(&mut self, s: &str) -> bool

Insert a &str directly.

Source

pub fn contains_str(&self, s: &str) -> bool

Check whether the set contains the given &str.

Source

pub fn remove_str(&mut self, s: &str) -> bool

Remove by &str.

Source§

impl OxiHashSet<u64>

Source

pub fn min_elem(&self) -> Option<u64>

Return the minimum element if non-empty.

Source

pub fn max_elem(&self) -> Option<u64>

Return the maximum element if non-empty.

Source

pub fn sum(&self) -> u64

Return the sum of all elements.

Source

pub fn covers_range(&self, lo: u64, hi: u64) -> bool

Check whether the range lo..=hi is completely covered.

Source§

impl OxiHashSet<usize>

Source

pub fn covers_indices(&self, n: usize) -> bool

Check whether the indices 0..n are all present.

Source

pub fn sorted(&self) -> Vec<usize>

Return elements as a sorted vector.

Source§

impl<T: Eq + Hash + Clone> OxiHashSet<T>

Source

pub fn set_eq(&self, other: &Self) -> bool

Check structural equality with another set.

Source§

impl<T: Eq + Hash + Clone> OxiHashSet<T>

Source

pub fn all<F: Fn(&T) -> bool>(&self, predicate: F) -> bool

Check whether all elements satisfy predicate.

Source§

impl<T: Eq + Hash + Clone> OxiHashSet<T>

Source

pub fn any<F: Fn(&T) -> bool>(&self, predicate: F) -> bool

Check whether any element satisfies predicate.

Source§

impl<T: Eq + Hash + Clone> OxiHashSet<T>

Source

pub fn with_capacity(capacity: usize) -> Self

Create a set with the given capacity pre-allocated.

Source§

impl<T: Eq + Hash + Clone> OxiHashSet<T>

Source

pub fn clear(&mut self)

Clear all elements.

Source§

impl<T: Eq + Hash + Clone> OxiHashSet<T>

Source

pub fn contains(&self, elem: &T) -> bool

Check whether the set contains an element.

Source

pub fn intersect_with(&mut self, other: &Self)

Keep only elements that also appear in other (intersection in place).

Source§

impl<T: Eq + Hash + Clone> OxiHashSet<T>

Source

pub fn difference(&self, other: &Self) -> Self

Return a new set that is the difference self ∖ other.

Source§

impl<T: Eq + Hash + Clone> OxiHashSet<T>

Source

pub fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)

Extend with elements from an iterator.

Source§

impl<T: Eq + Hash + Clone> OxiHashSet<T>

Source

pub fn filter<F: Fn(&T) -> bool>(&self) -> OxiHashSet<T>

Retain only elements satisfying the predicate.

Source

pub fn retain_clone<F: Fn(&T) -> bool>(&self, predicate: F) -> Self

Return a new set containing only elements for which predicate returns true.

Source

pub fn count_where<F: Fn(&T) -> bool>(&self, predicate: F) -> usize

Count elements satisfying predicate.

Source§

impl<T: Eq + Hash + Clone> OxiHashSet<T>

Source

pub fn fold<B, F: Fn(B, &T) -> B>(&self, init: B, f: F) -> B

Fold over all elements with a given initial value.

Source§

impl<T: Eq + Hash + Clone> OxiHashSet<T>

Source

pub fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Create a set from an iterator.

Source§

impl<T: Eq + Hash + Clone> OxiHashSet<T>

Source

pub fn insert(&mut self, elem: T) -> bool

Insert an element. Returns true if the element was not already present.

Source

pub fn union_with(&mut self, other: &Self)

Extend with elements from another set (union in place).

Source§

impl<T: Eq + Hash + Clone> OxiHashSet<T>

Source

pub fn intersection(&self, other: &Self) -> Self

Return a new set that is the intersection of self and other.

Source§

impl<T: Eq + Hash + Clone> OxiHashSet<T>

Source

pub fn len(&self) -> usize

Return the number of elements.

Source

pub fn exclusive_count(&self, other: &Self) -> usize

Number of elements not shared with other.

Source

pub fn union_size(&self, other: &Self) -> usize

Total elements in union minus shared elements (Jaccard denominator).

Source

pub fn jaccard(&self, other: &Self) -> f64

Jaccard similarity coefficient (0.0–1.0).

Source§

impl<T: Eq + Hash + Clone> OxiHashSet<T>

Source

pub fn map<U, F>(&self, f: F) -> OxiHashSet<U>
where U: Eq + Hash + Clone, F: Fn(&T) -> U,

Apply a function to every element, returning a new set.

Source

pub fn iter(&self) -> impl Iterator<Item = &T>

Return an iterator over the elements.

Source§

impl<T: Eq + Hash + Clone> OxiHashSet<T>

Source

pub fn new() -> Self

Create an empty set.

Source

pub fn singleton(elem: T) -> Self

Create a singleton set containing exactly one element.

Source

pub fn flat_map<U, F>(&self, f: F) -> OxiHashSet<U>
where U: Eq + Hash + Clone, F: Fn(&T) -> OxiHashSet<U>,

Flat-map: apply f to each element and union all results.

Source

pub fn power_set(&self) -> Vec<Self>

Return the power set (set of all subsets) — only feasible for small sets.

Source§

impl<T: Eq + Hash + Clone> OxiHashSet<T>

Source

pub fn partition<F: Fn(&T) -> bool>(&self, predicate: F) -> (Self, Self)

Partition into two sets by a predicate.

Source§

impl<T: Eq + Hash + Clone> OxiHashSet<T>

Source

pub fn pick_any(&self) -> Option<&T>

Return an arbitrary element (useful for single-element sets).

Source§

impl<T: Eq + Hash + Clone> OxiHashSet<T>

Source

pub fn is_empty(&self) -> bool

Return true if the set is empty.

Source§

impl<T: Eq + Hash + Clone> OxiHashSet<T>

Source

pub fn is_subset(&self, other: &Self) -> bool

Check whether self is a subset of other.

Source§

impl<T: Eq + Hash + Clone> OxiHashSet<T>

Source

pub fn is_superset(&self, other: &Self) -> bool

Check whether self is a superset of other.

Source§

impl<T: Eq + Hash + Clone> OxiHashSet<T>

Source

pub fn is_disjoint(&self, other: &Self) -> bool

Check whether self and other are disjoint (share no elements).

Source§

impl<T: Eq + Hash + Clone> OxiHashSet<T>

Source

pub fn find<F: Fn(&T) -> bool>(&self, predicate: F) -> Option<&T>

Find an element satisfying predicate.

Source§

impl<T: Eq + Hash + Clone> OxiHashSet<T>

Source

pub fn remove(&mut self, elem: &T) -> bool

Remove an element. Returns true if it was present.

Source

pub fn subtract(&mut self, other: &Self)

Remove all elements that appear in other (difference in place).

Source§

impl<T: Eq + Hash + Clone> OxiHashSet<T>

Source

pub fn symmetric_difference(&self, other: &Self) -> Self

Return a new set that is the symmetric difference of self and other.

Source§

impl<T: Eq + Hash + Clone> OxiHashSet<T>

Source

pub fn to_vec(&self) -> Vec<T>

Collect elements into a Vec.

Source§

impl<T: Eq + Hash + Clone + Ord> OxiHashSet<T>

Source

pub fn sorted_vec(&self) -> Vec<T>

Return elements sorted in ascending order.

Source

pub fn min(&self) -> Option<&T>

Return the minimum element (requires Ord).

Source

pub fn max(&self) -> Option<&T>

Return the maximum element (requires Ord).

Source§

impl<T: Eq + Hash + Clone + Debug> OxiHashSet<T>

Source

pub fn to_sorted_vec(&self) -> Vec<T>
where T: Ord,

Return a sorted vector of elements (requires Ord on T).

Source§

impl<T: Eq + Hash + Clone> OxiHashSet<T>

Source

pub fn union(&self, other: &Self) -> Self

Return a new set that is the union of self and other.

Trait Implementations§

Source§

impl<T> Clone for OxiHashSet<T>
where T: Eq + Hash + Clone + Clone,

Source§

fn clone(&self) -> OxiHashSet<T>

Returns a duplicate 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<T> Debug for OxiHashSet<T>
where T: Eq + Hash + Clone + Debug,

Source§

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

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

impl<T: Eq + Hash + Clone> Default for OxiHashSet<T>

Source§

fn default() -> Self

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

impl<T: Eq + Hash + Clone + Display> Display for OxiHashSet<T>

Source§

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

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

impl<T: Eq + Hash + Clone> From<HashSet<T>> for OxiHashSet<T>

Source§

fn from(s: StdHashSet<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Eq + Hash + Clone> From<Vec<T>> for OxiHashSet<T>

Source§

fn from(v: Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Eq + Hash + Clone> IntoIterator for OxiHashSet<T>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T> PartialEq for OxiHashSet<T>
where T: Eq + Hash + Clone + PartialEq,

Source§

fn eq(&self, other: &OxiHashSet<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> Eq for OxiHashSet<T>
where T: Eq + Hash + Clone + Eq,

Source§

impl<T> StructuralPartialEq for OxiHashSet<T>
where T: Eq + Hash + Clone,

Auto Trait Implementations§

§

impl<T> Freeze for OxiHashSet<T>

§

impl<T> RefUnwindSafe for OxiHashSet<T>
where T: RefUnwindSafe,

§

impl<T> Send for OxiHashSet<T>
where T: Send,

§

impl<T> Sync for OxiHashSet<T>
where T: Sync,

§

impl<T> Unpin for OxiHashSet<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for OxiHashSet<T>

§

impl<T> UnwindSafe for OxiHashSet<T>
where T: 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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Setoid for T
where T: PartialEq,

Source§

fn equiv(&self, other: &T) -> bool

The equivalence relation.
Source§

fn refl(&self) -> bool

Reflexivity of the equivalence.
Source§

fn symm(&self, other: &Self) -> bool

Symmetry: if self ~ other then other ~ self.
Source§

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

Source§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.