pub(crate) fn insert(&mut self, string: Cow<str>) -> NonNull<Entry> {
        let hash = Self::hash(&string);
        // Access the top-level bucket in the pool's contiguous array that
        // contains the linked list of entries that contain the string.
        let bucket_index = (hash & BUCKET_MASK) as usize;
        let mut ptr: Option<&mut Box<Entry>> = self.0[bucket_index].as_mut();

        // Iterate over the entires in the bucket.
        while let Some(entry) = ptr.take() {
            // If we find the string we're looking for, don't add anything to
            // the pool. Instead, just return the existing entry.
            // NOTE: Strings with different hash values can't possibly be equal,
            // so comparing those hash values first ought to filter out unequal
            // strings faster than comparing the strings themselves.
            if entry.hash == hash && *entry.string == *string {
                return NonNull::from(&mut **entry);
            }
            ptr = entry.next.as_mut();
        }

        // The string doesn't exist in the pool yet; insert it at the head of
        // the linked list of entries.
        let mut entry = Box::new(Entry {
            string: string.into_owned().into_boxed_str(),
            hash,
            next: self.0[bucket_index].take(),
        });
        let ptr = NonNull::from(&mut *entry);

        // The bucket in the top-level contiguous array now points to the new
        // head of the linked list.
        self.0[bucket_index] = Some(entry);

        ptr
    }
/// Given a string, returns its entry in the pool (adding it if it does not
/// yet exist in the pool).
Given a string, returns its entry in the pool (adding it if it does not
yet exist in the pool).
Given a string returns its entry in the pool ( adding it if it does not yet exist in the pool ) .
pub(crate) fn insert(&mut self, string: Cow<str>) -> NonNull<Entry> {
        let hash = Self::hash(&string);
        // Access the top-level bucket in the pool's contiguous array that
        // contains the linked list of entries that contain the string.
        let bucket_index = (hash & BUCKET_MASK) as usize;
        let mut ptr: Option<&mut Box<Entry>> = self.0[bucket_index].as_mut();
        // Iterate over the entires in the bucket.
        while let Some(entry) = ptr.take() {
            // If we find the string we're looking for, don't add anything to
            // the pool. Instead, just return the existing entry.
            // NOTE: Strings with different hash values can't possibly be equal,
            // so comparing those hash values first ought to filter out unequal
            // strings faster than comparing the strings themselves.
            if entry.hash == hash && *entry.string == *string {
                return NonNull::from(&mut **entry);
            }
            ptr = entry.next.as_mut();
        }
        // The string doesn't exist in the pool yet; insert it at the head of
        // the linked list of entries.
        let mut entry = Box::new(Entry {
            string: string.into_owned().into_boxed_str(),
            hash,
            next: self.0[bucket_index].take(),
        });
        let ptr = NonNull::from(&mut *entry);
        // The bucket in the top-level contiguous array now points to the new
        // head of the linked list.
        self.0[bucket_index] = Some(entry);
        ptr
    }
pub ( crate ) fn insert ( & mut self , string : Cow < str > ) -> NonNull < Entry > { let hash = Self :: hash ( & string ) ; // Access the top-level bucket in the pool's contiguous array that // contains the linked list of entries that contain the string. let bucket_index = ( hash & BUCKET_MASK ) as usize ; let mut ptr : Option < & mut Box < Entry > > = self . 0 [ bucket_index ] . as_mut ( ) ; // Iterate over the entires in the bucket. while let Some ( entry ) = ptr . take ( ) { // If we find the string we're looking for, don't add anything to // the pool. Instead, just return the existing entry. // NOTE: Strings with different hash values can't possibly be equal, // so comparing those hash values first ought to filter out unequal // strings faster than comparing the strings themselves. if entry . hash == hash && * entry . string == * string { return NonNull :: from ( & mut * * entry ) ; } ptr = entry . next . as_mut ( ) ; } // The string doesn't exist in the pool yet; insert it at the head of // the linked list of entries. let mut entry = Box :: new ( Entry { string : string . into_owned ( ) . into_boxed_str ( ) , hash , next : self . 0 [ bucket_index ] . take ( ) , } ) ; let ptr = NonNull :: from ( & mut * entry ) ; // The bucket in the top-level contiguous array now points to the new // head of the linked list. self . 0 [ bucket_index ] = Some ( entry ) ; ptr }
Given a string, returns its entry in the pool (adding it if it does not
yet exist in the pool).
Given a string returns its entry in the pool ( adding it if it does not yet exist in the pool ) .
&mut self
string
Cow<str>