docs

您正在閱讀 v0.1.2 的文件。Nabi 0.1.2 已停止支援。 最新版本:v0.1.3 →

core::collections::set

本頁內容

API 參考只有英文版,由標準函式庫原始碼中的英文文件註解產生。

Set<T, S>, a hash set over Dict<T, bool, S>, so it iterates in insertion order.

Structs

SetSource

pub struct Set<T, S = RandomState>

S builds the hashers (RandomState: the process key).

  • pub fn freeze(self) -> FrozenSet<T, S>§

    Source

    The set as a FrozenSet, which threads share without a lock or a copy. O(1): the frozen set takes the members over, and using self after is a compile error (to_set() gives a set to change again; freeze a clone() to keep this one).

  • pub const fn new() -> Set<T>§

    Source

    An empty set.

  • pub const fn with_hasher(state: S) -> Set<T, S>§

    Source

    An empty set hashing with state's hashers.

  • pub const fn with_capacity_and_hasher(cap: usize, state: S) -> Set<T, S>§

    Source

    Room for cap members, hashing with state's hashers.

  • pub const fn hasher(self) -> S§

    Source

    What builds the set's hashers.

  • pub const fn len(self) -> usize§

    Source

    The number of members.

  • pub const fn is_empty(self) -> bool§

    Source

    true when the set has no member.

  • pub const fn insert(self, x: T) -> bool§

    Source

    true when x was not there yet.

  • pub const fn remove(self, x: T) -> bool§

    Source

    true when x was there.

  • pub const fn contains(self, x: T) -> bool§

    Source

    true when x is a member.

  • pub const fn clear(self)§

    Source

    Drop every member.

  • pub const fn retain(self, keep: fn(T) -> bool)§

    Source

    Keep only the members keep accepts, in place; O(n).

  • pub const fn extend<I: IntoIterator<Item = T>>(self, items: I)§

    Source

    Insert every item of items.

  • pub const fn union(self, other: Set<T, S>) -> Set<T, S>§

    Source

    The members of either set: those of self in its order, then those only in other in its order.

  • pub const fn intersection(self, other: Set<T, S>) -> Set<T, S>§

    Source

    The members of both sets, in self's order.

  • pub const fn difference(self, other: Set<T, S>) -> Set<T, S>§

    Source

    The members of self not in other, in self's order.

  • pub const fn symmetric_difference(self, other: Set<T, S>) -> Set<T, S>§

    Source

    The members of exactly one set: those only in self in its order, then those only in other in its order.

  • pub const fn is_subset(self, other: Set<T, S>) -> bool§

    Source

    true when every member of self is in other.

  • pub const fn is_superset(self, other: Set<T, S>) -> bool§

    Source

    true when every member of other is in self.

  • pub const fn is_disjoint(self, other: Set<T, S>) -> bool§

    Source

    true when no member is in both sets.

  • pub const fn pop(self) -> T | none§

    Source

    Remove and return the member inserted last, or none when the set is empty. Python: s.pop() (which takes any member).

    nabi
    let s = {1, 2, 3};
    assert((s.pop() ?? 0) == 3 && s.len() == 2);
    assert(s.drain() == [1, 2] && s.is_empty());
    
  • pub const fn drain(self) -> List<T>§

    Source

    Remove every member and return them, in insertion order.

  • pub const fn to_list(self) -> List<T>§

    Source

    The members in a new list, in iteration order.

  • pub const fn iter(self) -> SetIter<T, S>§

    Source

    The members, lazily (insertion order).

Trait implementations 11

SetIterSource

pub struct SetIter<T, S = RandomState>

The members of a set, in insertion order.

Trait implementations 2