(
&mut self,
x: Self::T,
hasher: impl Fn(&Self::T) -> u64,
accounting: &mut usize,
)
| 156 | type T = T; |
| 157 | |
| 158 | fn insert_accounted( |
| 159 | &mut self, |
| 160 | x: Self::T, |
| 161 | hasher: impl Fn(&Self::T) -> u64, |
| 162 | accounting: &mut usize, |
| 163 | ) { |
| 164 | let hash = hasher(&x); |
| 165 | |
| 166 | if cfg!(debug_assertions) { |
| 167 | // In debug mode, check that the element is not already present |
| 168 | debug_assert!( |
| 169 | self.find_entry(hash, |y| y == &x).is_err(), |
| 170 | "attempted to insert duplicate element into HashTableAllocExt::insert_accounted" |
| 171 | ); |
| 172 | } |
| 173 | |
| 174 | if self.len() == self.capacity() { |
| 175 | // need to request more memory |
| 176 | let bump_elements = self.capacity().max(16); |
| 177 | let bump_size = bump_elements * size_of::<T>(); |
| 178 | *accounting = (*accounting).checked_add(bump_size).expect("overflow"); |
| 179 | |
| 180 | self.reserve(bump_elements, &hasher); |
| 181 | } |
| 182 | |
| 183 | // We assume the element is not already present |
| 184 | self.insert_unique(hash, x, hasher); |
| 185 | } |
| 186 | } |
no test coverage detected