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
impl HashSet
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_values: usize) -> usize
pub fn size_in_account(capacity_values: usize) -> usize
Size which needs to be allocated on Solana account to fit the hash set.
pub fn new( 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 get_bucket(&self, index: usize) -> Option<&Option<HashSetCell>>
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.
Sourcepub fn get_bucket_mut(
&mut self,
index: usize,
) -> Option<&mut Option<HashSetCell>>
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.
Sourcepub fn get_unmarked_bucket(&self, index: usize) -> Option<&Option<HashSetCell>>
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
.
pub fn get_capacity(&self) -> usize
Sourcepub fn insert(
&mut self,
value: &BigUint,
current_sequence_number: usize,
) -> Result<usize, HashSetError>
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.
Sourcepub fn find_element_index(
&self,
value: &BigUint,
current_sequence_number: Option<usize>,
) -> Result<Option<usize>, HashSetError>
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.
pub fn find_element( &self, value: &BigUint, current_sequence_number: Option<usize>, ) -> Result<Option<(&HashSetCell, usize)>, HashSetError>
pub fn find_element_mut( &mut self, value: &BigUint, current_sequence_number: Option<usize>, ) -> Result<Option<(&mut HashSetCell, usize)>, HashSetError>
Sourcepub fn find_element_iter(
&mut self,
value: &BigUint,
current_sequence_number: usize,
start_iter: usize,
num_iterations: usize,
) -> Result<Option<(usize, bool)>, HashSetError>
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.
Sourcepub fn first(
&self,
current_sequence_number: usize,
) -> Result<Option<&HashSetCell>, HashSetError>
pub fn first( &self, current_sequence_number: usize, ) -> Result<Option<&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.
Sourcepub fn contains(
&self,
value: &BigUint,
sequence_number: Option<usize>,
) -> Result<bool, HashSetError>
pub fn contains( &self, value: &BigUint, sequence_number: Option<usize>, ) -> Result<bool, HashSetError>
Checks if the hash set contains a value.
Sourcepub fn mark_with_sequence_number(
&mut self,
index: usize,
sequence_number: usize,
) -> Result<(), HashSetError>
pub fn mark_with_sequence_number( &mut self, index: usize, sequence_number: usize, ) -> Result<(), HashSetError>
Marks the given element with a given sequence number.
Sourcepub fn iter(&self) -> HashSetIterator<'_> ⓘ
pub fn iter(&self) -> HashSetIterator<'_> ⓘ
Returns an iterator over elements.
Trait Implementations§
impl Send for HashSet
Auto Trait Implementations§
impl Freeze for HashSet
impl RefUnwindSafe for HashSet
impl !Sync for HashSet
impl Unpin for HashSet
impl UnwindSafe for HashSet
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