pub fn add<T: ?Sized + Hash>(&mut self, data: &T) -> Result<(), CuckooError> {
        let fai = get_fai::<T, H>(data);
        if self.put(fai.fp, fai.i1) || self.put(fai.fp, fai.i2) {
            return Ok(());
        }
        let len = self.buckets.len();
        let mut rng = rand::thread_rng();
        let mut i = fai.random_index(&mut rng);
        let mut fp = fai.fp;
        for _ in 0..MAX_REBUCKET {
            let other_fp;
            {
                let loc = &mut self.buckets[i % len].buffer[rng.gen_range(0, BUCKET_SIZE)];
                other_fp = *loc;
                *loc = fp;
                i = get_alt_index::<H>(other_fp, i);
            }
            if self.put(other_fp, i) {
                return Ok(());
            }
            fp = other_fp;
        }
        // fp is dropped here, which means that the last item that was
        // rebucketed gets removed from the filter.
        // TODO: One could introduce a single-item cache for this element,
        // check this cache in all methods additionally to the actual filter,
        // and return NotEnoughSpace if that cache is already in use.
        // This would complicate the code, but stop random elements from
        // getting removed and result in nicer behaviour for the user.
        Err(CuckooError::NotEnoughSpace)
    }
/// Adds `data` to the filter. Returns `Ok` if the insertion was successful,
/// but could fail with a `NotEnoughSpace` error, especially when the filter
/// is nearing its capacity.
/// Note that while you can put any hashable type in the same filter, beware
/// for side effects like that the same number can have diferent hashes
/// depending on the type.
/// So for the filter, 4711i64 isn't the same as 4711u64.
///
/// **Note:** When this returns `NotEnoughSpace`, the element given was
/// actually added to the filter, but some random *other* element was
/// removed. This might improve in the future.
Adds `data` to the filter. Returns `Ok` if the insertion was successful,
but could fail with a `NotEnoughSpace` error, especially when the filter
is nearing its capacity.
Note that while you can put any hashable type in the same filter, beware
for side effects like that the same number can have diferent hashes
depending on the type.
So for the filter, 4711i64 isn't the same as 4711u64.

When this returns `NotEnoughSpace`, the element given was
actually added to the filter, but some random *other* element was
removed. This might improve in the future.
Adds ` data ` to the filter . Returns ` Ok ` if the insertion was successful but could fail with a ` NotEnoughSpace ` error especially when the filter is nearing its capacity . Note that while you can put any hashable type in the same filter beware for side effects like that the same number can have diferent hashes depending on the type . So for the filter 4711i64 isn ' t the same as 4711u64 . When this returns ` NotEnoughSpace ` the element given was actually added to the filter but some random * other * element was removed . This might improve in the future .
pub fn add<T: ?Sized + Hash>(&mut self, data: &T) -> Result<(), CuckooError> {
        let fai = get_fai::<T, H>(data);
        if self.put(fai.fp, fai.i1) || self.put(fai.fp, fai.i2) {
            return Ok(());
        }
        let len = self.buckets.len();
        let mut rng = rand::thread_rng();
        let mut i = fai.random_index(&mut rng);
        let mut fp = fai.fp;
        for _ in 0..MAX_REBUCKET {
            let other_fp;
            {
                let loc = &mut self.buckets[i % len].buffer[rng.gen_range(0, BUCKET_SIZE)];
                other_fp = *loc;
                *loc = fp;
                i = get_alt_index::<H>(other_fp, i);
            }
            if self.put(other_fp, i) {
                return Ok(());
            }
            fp = other_fp;
        }
        // fp is dropped here, which means that the last item that was
        // rebucketed gets removed from the filter.
        // TODO: One could introduce a single-item cache for this element,
        // check this cache in all methods additionally to the actual filter,
        // and return NotEnoughSpace if that cache is already in use.
        // This would complicate the code, but stop random elements from
        // getting removed and result in nicer behaviour for the user.
        Err(CuckooError::NotEnoughSpace)
    }
pub fn add < T : ? Sized + Hash > ( & mut self , data : & T ) -> Result < ( ) , CuckooError > { let fai = get_fai :: < T , H > ( data ) ; if self . put ( fai . fp , fai . i1 ) || self . put ( fai . fp , fai . i2 ) { return Ok ( ( ) ) ; } let len = self . buckets . len ( ) ; let mut rng = rand :: thread_rng ( ) ; let mut i = fai . random_index ( & mut rng ) ; let mut fp = fai . fp ; for _ in 0 .. MAX_REBUCKET { let other_fp ; { let loc = & mut self . buckets [ i % len ] . buffer [ rng . gen_range ( 0 , BUCKET_SIZE ) ] ; other_fp = * loc ; * loc = fp ; i = get_alt_index :: < H > ( other_fp , i ) ; } if self . put ( other_fp , i ) { return Ok ( ( ) ) ; } fp = other_fp ; } // fp is dropped here, which means that the last item that was // rebucketed gets removed from the filter. // TODO: One could introduce a single-item cache for this element, // check this cache in all methods additionally to the actual filter, // and return NotEnoughSpace if that cache is already in use. // This would complicate the code, but stop random elements from // getting removed and result in nicer behaviour for the user. Err ( CuckooError :: NotEnoughSpace ) }
Adds `data` to the filter.
Adds ` data ` to the filter .
&mut self
data
&T
&mut self
data
&T