Struct light_hash_set::HashSet

source ·
pub struct HashSet<I>{
    pub capacity_indices: usize,
    pub capacity_values: usize,
    pub sequence_threshold: usize,
    pub next_value_index: *mut usize,
    /* private fields */
}

Fields§

§capacity_indices: usize

Capacity of indices, which is a prime number larger than the expected number of elements and an included load factor.

§capacity_values: usize

Capacity of values, which is equal to the expected number of elements.

§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).

§next_value_index: *mut usize

Index of the next vacant cell in the value array.

Implementations§

source§

impl<I> HashSet<I>

source

pub fn non_dyn_fields_size() -> usize

Size of the struct without dynamically sized fields.

source

pub fn size_in_account( capacity_indices: usize, capacity_values: usize ) -> Result<usize, HashSetError>

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

source

pub fn capacity_indices( capacity_elements: usize, load_factor: f64 ) -> Result<f64, HashSetError>

Returns the capacity of buckets for the desired capacity, while taking the load factor in account.

source

pub fn new( capacity_indices: usize, 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 insert( &mut self, value: &BigUint, current_sequence_number: usize ) -> Result<(), 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( &self, value: &BigUint, current_sequence_number: Option<usize> ) -> Result<Option<(&mut HashSetCell, I)>, HashSetError>

source

pub fn find_element_iter( &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<&mut 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 by_value_index( &self, value_index: usize, current_sequence_number: Option<usize> ) -> Option<&mut HashSetCell>

source

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

Checks if the hash set contains a value.

source

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

Marks the given element with a given sequence number.

source

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

Trait Implementations§

source§

impl<I> Debug for HashSet<I>

source§

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

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

impl<I> Drop for HashSet<I>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<I> Freeze for HashSet<I>
where usize: Sized,

§

impl<I> RefUnwindSafe for HashSet<I>

§

impl<I> !Send for HashSet<I>

§

impl<I> !Sync for HashSet<I>

§

impl<I> Unpin for HashSet<I>
where usize: Sized,

§

impl<I> UnwindSafe for HashSet<I>

Blanket Implementations§

source§

impl<T> AbiExample for T

source§

default fn example() -> T

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

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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