fn resize(&mut self, capacity: usize, hasher: impl Fn(&T) -> u64) {
        unsafe {
            debug_assert!(self.items <= capacity);

            // Allocate and initialize the new table.
            let mut new_table = RawTable::with_capacity(capacity);
            new_table.growth_left -= self.items;
            new_table.items = self.items;

            // The hash function may panic, in which case we simply free the new
            // table without dropping any elements that may have been copied into
            // it.
            let mut new_table = guard(ManuallyDrop::new(new_table), |new_table| {
                if new_table.bucket_mask != 0 {
                    new_table.free_buckets();
                }
            });

            // Copy all elements to the new table.
            for item in self.iter() {
                // This may panic.
                let hash = hasher(item.as_ref());

                // We can use a simpler version of insert() here since there are no
                // DELETED entries.
                let index = new_table.find_insert_slot(hash);
                new_table.set_ctrl(index, h2(hash));
                new_table.bucket(index).write(item.read());
            }

            // We successfully copied all elements without panicking. Now replace
            // self with the new table. The old table will have its memory freed but
            // the items will not be dropped (since they have been moved into the
            // new table).
            mem::swap(self, &mut new_table);
        }
    }
/// Allocates a new table of a different size and moves the contents of the
/// current table into it.
Allocates a new table of a different size and moves the contents of the
current table into it.
Allocates a new table of a different size and moves the contents of the current table into it .
fn resize(&mut self, capacity: usize, hasher: impl Fn(&T) -> u64) {
        unsafe {
            debug_assert!(self.items <= capacity);
            // Allocate and initialize the new table.
            let mut new_table = RawTable::with_capacity(capacity);
            new_table.growth_left -= self.items;
            new_table.items = self.items;
            // The hash function may panic, in which case we simply free the new
            // table without dropping any elements that may have been copied into
            // it.
            let mut new_table = guard(ManuallyDrop::new(new_table), |new_table| {
                if new_table.bucket_mask != 0 {
                    new_table.free_buckets();
                }
            });
            // Copy all elements to the new table.
            for item in self.iter() {
                // This may panic.
                let hash = hasher(item.as_ref());
                // We can use a simpler version of insert() here since there are no
                // DELETED entries.
                let index = new_table.find_insert_slot(hash);
                new_table.set_ctrl(index, h2(hash));
                new_table.bucket(index).write(item.read());
            }
            // We successfully copied all elements without panicking. Now replace
            // self with the new table. The old table will have its memory freed but
            // the items will not be dropped (since they have been moved into the
            // new table).
            mem::swap(self, &mut new_table);
        }
    }
fn resize ( & mut self , capacity : usize , hasher : impl Fn ( & T ) -> u64 ) { unsafe { debug_assert ! ( self items capacity ) ; // Allocate and initialize the new table. let mut new_table = RawTable :: with_capacity ( capacity ) ; new_table . growth_left -= self . items ; new_table . items = self . items ; // The hash function may panic, in which case we simply free the new // table without dropping any elements that may have been copied into // it. let mut new_table = guard ( ManuallyDrop :: new ( new_table ) , | new_table | { if new_table . bucket_mask != 0 { new_table . free_buckets ( ) ; } } ) ; // Copy all elements to the new table. for item in self . iter ( ) { // This may panic. let hash = hasher ( item . as_ref ( ) ) ; // We can use a simpler version of insert() here since there are no // DELETED entries. let index = new_table . find_insert_slot ( hash ) ; new_table . set_ctrl ( index , h2 ( hash ) ) ; new_table . bucket ( index ) . write ( item . read ( ) ) ; } // We successfully copied all elements without panicking. Now replace // self with the new table. The old table will have its memory freed but // the items will not be dropped (since they have been moved into the // new table). mem :: swap ( self , & mut new_table ) ; } }
Allocates a new table of a different size and moves the contents of the
current table into it.
Allocates a new table of a different size and moves the contents of the current table into it .
&mut self
capacity
usize
hasher
impl Fn(&T) -> u64
&mut self
capacity
usize
hasher
impl Fn(&T) -> u64