Struct light_hash_set::HashSet
source · pub struct HashSet<I>where
I: Bounded + CheckedAdd + CheckedSub + Clone + Copy + Display + From<u8> + PartialEq + PartialOrd + ToBigUint + TryFrom<u64> + TryFrom<usize> + Unsigned,
usize: TryFrom<I>,
<usize as TryFrom<I>>::Error: Debug,{
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>
impl<I> HashSet<I>
sourcepub fn non_dyn_fields_size() -> usize
pub fn non_dyn_fields_size() -> usize
Size of the struct without dynamically sized fields.
sourcepub fn size_in_account(
capacity_indices: usize,
capacity_values: usize
) -> Result<usize, HashSetError>
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.
sourcepub fn capacity_indices(
capacity_elements: usize,
load_factor: f64
) -> Result<f64, HashSetError>
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.
pub fn new( capacity_indices: usize, capacity_values: usize, sequence_threshold: usize ) -> Result<Self, HashSetError>
sourcepub unsafe fn from_bytes_copy(bytes: &mut [u8]) -> Result<Self, HashSetError>
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.
sourcepub fn insert(
&mut self,
value: &BigUint,
current_sequence_number: usize
) -> Result<(), HashSetError>
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.
pub fn find_element( &self, value: &BigUint, current_sequence_number: Option<usize> ) -> Result<Option<(&mut HashSetCell, I)>, HashSetError>
sourcepub fn find_element_iter(
&self,
value: &BigUint,
current_sequence_number: usize,
start_iter: usize,
num_iterations: usize
) -> Result<Option<(usize, bool)>, HashSetError>
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.
sourcepub fn first(
&self,
current_sequence_number: usize
) -> Result<Option<&mut HashSetCell>, HashSetError>
pub fn first( &self, current_sequence_number: usize ) -> Result<Option<&mut HashSetCell>, HashSetError>
Returns a first available element.
sourcepub fn first_no_seq(&self) -> Result<Option<(HashSetCell, u16)>, HashSetError>
pub fn first_no_seq(&self) -> Result<Option<(HashSetCell, u16)>, HashSetError>
Returns a first available element that does not have a sequence number.
pub fn by_value_index( &self, value_index: usize, current_sequence_number: Option<usize> ) -> Option<&mut HashSetCell>
sourcepub fn contains(
&self,
value: &BigUint,
sequence_number: usize
) -> Result<bool, HashSetError>
pub fn contains( &self, value: &BigUint, sequence_number: usize ) -> Result<bool, HashSetError>
Checks if the hash set contains a value.
sourcepub fn mark_with_sequence_number(
&mut self,
value: &BigUint,
sequence_number: usize
) -> Result<(), HashSetError>
pub fn mark_with_sequence_number( &mut self, value: &BigUint, sequence_number: usize ) -> Result<(), HashSetError>
Marks the given element with a given sequence number.
pub fn iter(&self) -> HashSetIterator<'_, I> ⓘ
Trait Implementations§
Auto Trait Implementations§
impl<I> Freeze for HashSet<I>
impl<I> RefUnwindSafe for HashSet<I>
impl<I> !Send for HashSet<I>
impl<I> !Sync for HashSet<I>
impl<I> Unpin for HashSet<I>
impl<I> UnwindSafe for HashSet<I>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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