[−][src]Struct cuckoocache::cache::Cache
Methods
impl<Element, HasherInstance> Cache<Element, HasherInstance> where
HasherInstance: SaltedHasher<Element>,
[src]
HasherInstance: SaltedHasher<Element>,
pub fn allow_erase(&self, n: usize)
[src]
allow_erase marks the element at index n as discardable.
Safety
Threadsafe without any concurrent insert.
Arguments
n
the index to allow erasure of
pub fn please_keep(&self, n: usize)
[src]
please_keep marks the element at index n as an entry that should be kept.
Safety
Threadsafe without any concurrent insert.
Arguments
n
the index to prioritize keeping
pub fn empty() -> Self where
HasherInstance: Default,
[src]
HasherInstance: Default,
You must always construct a cache with some elements via a subsequent call to setup or setup_bytes, otherwise operations may segfault.
pub fn setup(&mut self, new_size: u32) -> usize
[src]
setup initializes the container to store no more than new_size elements. Returns the maximum number of elements storable
Safety
setup should only be called once.
Arguments
new_size
the desired number of elements to store. It can be any u32
pub fn setup_bytes(&mut self, new_size: usize) -> usize
[src]
pub fn insert(&mut self, e: &Element)
[src]
insert loops at most depth_limit times trying to insert a hash at various locations in the table via a variant of the Cuckoo Algorithm with eight hash locations.
It drops the last tried element if it runs out of depth before encountering an open slot.
Thus
let x = 1; let mut c = cache::Cache::empty(); c.setup(100_000); c.insert(x); c.contains(x, false);
is not guaranteed to return true.
Arguments
e
the element to insert
Posconditions
one of the following:
- All previously inserted elements and e are now in the table
- one previously inserted element is evicted from the table -the entry attempted to be inserted is evicted.
pub fn contains(&self, e: &Element, erase: bool) -> bool
[src]
contains iterates through the hash locations for a given element and checks to see if it is present. Returns true if the element is found, false otherwise
contains does not check garbage collected state (in other words, garbage is only collected when the space is needed), so:
let mut c = cache::Cache::empty(); c.setup(100_000); let x = 1; c.insert(x); if c.contains(x, true) { c.contains(x, false) } else { /// with low probability, insert failed true }
executed on a single thread will always return true!
This is a great property for re-org performance for example.
contains returns a bool set true if the element was found.
Arguments
e
the element to checkerase
Postconditions
if erase is true and the element is found, then the garbage collect flag is set
Auto Trait Implementations
impl<Element, H> Send for Cache<Element, H> where
Element: Send,
H: Send,
Element: Send,
H: Send,
impl<Element, H> Sync for Cache<Element, H> where
Element: Sync,
H: Sync,
Element: Sync,
H: Sync,
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,