Struct HashSet

Source
pub struct HashSet {
    pub sequence_threshold: usize,
    /* private fields */
}

Fields§

§sequence_threshold: usize

Difference of sequence numbers, after which the given element can be replaced by an another one (with a sequence number higher than the threshold).

Implementations§

Source§

impl HashSet

Source

pub fn non_dyn_fields_size() -> usize

Size of the struct without dynamically sized fields.

Source

pub fn size_in_account(capacity_values: usize) -> usize

Size which needs to be allocated on Solana account to fit the hash set.

Source

pub fn new( capacity_values: usize, sequence_threshold: usize, ) -> Result<Self, HashSetError>

Source

pub unsafe fn from_bytes_copy(bytes: &mut [u8]) -> Result<Self, HashSetError>

Creates a copy of HashSet from the given byte slice.

§Purpose

This method is meant to be used mostly in the SDK code, to convert fetched Solana accounts to actual hash sets. Creating a copy is the safest way of conversion in async Rust.

§Safety

This is highly unsafe. Ensuring the alignment and that the slice provides actual actual data of the hash set is the caller’s responsibility.

Source

pub fn get_bucket(&self, index: usize) -> Option<&Option<HashSetCell>>

Returns a reference to a bucket under the given index. Does not check the validity.

Source

pub fn get_bucket_mut( &mut self, index: usize, ) -> Option<&mut Option<HashSetCell>>

Returns a mutable reference to a bucket under the given index. Does not check the validity.

Source

pub fn get_unmarked_bucket(&self, index: usize) -> Option<&Option<HashSetCell>>

Returns a reference to an unmarked bucket under the given index. If the bucket is marked, returns None.

Source

pub fn get_capacity(&self) -> usize

Source

pub fn insert( &mut self, value: &BigUint, current_sequence_number: usize, ) -> Result<usize, HashSetError>

Inserts a value into the hash set, with self.capacity_values attempts.

Every attempt uses quadratic probing to find an empty cell or a cell which can be overwritten.

current sequence_number is used to check whether existing values can be overwritten.

Source

pub fn find_element_index( &self, value: &BigUint, current_sequence_number: Option<usize>, ) -> Result<Option<usize>, HashSetError>

Finds an index of the provided value inside buckets.

Uses the optional current_sequence_number arguments for checking the validity of the element.

Source

pub fn find_element( &self, value: &BigUint, current_sequence_number: Option<usize>, ) -> Result<Option<(&HashSetCell, usize)>, HashSetError>

Source

pub fn find_element_mut( &mut self, value: &BigUint, current_sequence_number: Option<usize>, ) -> Result<Option<(&mut HashSetCell, usize)>, HashSetError>

Source

pub fn find_element_iter( &mut self, value: &BigUint, current_sequence_number: usize, start_iter: usize, num_iterations: usize, ) -> Result<Option<(usize, bool)>, HashSetError>

find_element_iter iterates over a fixed range of elements in the hash set. We always have to iterate over the whole range to make sure that the value is not in the hash-set. Returns the position of the first free value.

Source

pub fn first( &self, current_sequence_number: usize, ) -> Result<Option<&HashSetCell>, HashSetError>

Returns a first available element.

Source

pub fn first_no_seq(&self) -> Result<Option<(HashSetCell, u16)>, HashSetError>

Returns a first available element that does not have a sequence number.

Source

pub fn contains( &self, value: &BigUint, sequence_number: Option<usize>, ) -> Result<bool, HashSetError>

Checks if the hash set contains a value.

Source

pub fn mark_with_sequence_number( &mut self, index: usize, sequence_number: usize, ) -> Result<(), HashSetError>

Marks the given element with a given sequence number.

Source

pub fn iter(&self) -> HashSetIterator<'_>

Returns an iterator over elements.

Trait Implementations§

Source§

impl Debug for HashSet

Source§

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

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

impl Drop for HashSet

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl PartialEq for HashSet

Source§

fn eq(&self, other: &Self) -> 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 Send for HashSet

Auto Trait Implementations§

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

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

Source§

fn vzip(self) -> V