Debian Codegraph @

src/lib.rs

raw symbols SCIP
1 //! An unordered multiset/bag implementation backed by `HashMap`.
2 //!
3 //! A bag, unlike a set, allows duplicate values, and keeps track of how many
4 //! duplicates each value holds. This type of collection is often referred to
5 //! as an unordered multiset (see also C++'s [`std::unordered_multiset`]).
6 //!
7 //! This multiset/bag is implemented using a `HashMap<T, usize>` and so requires
8 //! that the stored type implements `Hash + Eq`.
9 //!
10 //! For usage examples, see the primary type [`HashBag`].
11 //!
12 //! If you want to use a hash table with [amortized resizes](https://github.com/jonhoo/griddle/),
13 //! set the `amortize` feature.
14 //!
15 //! (De)serialization via serde is also available with the `serde` feature.
16 //! Deserialization note: if the incoming data contains two instances of `T` that are the same, the resulting `HashBag` will merge
17 //! the counts of those instances.
18 //!
19 //! [`std::unordered_multiset`]: http://www.cplusplus.com/reference/unordered_set/unordered_multiset/
20 #![deny(missing_docs, missing_debug_implementations, unreachable_pub)]
21 #![cfg_attr(doc, deny(rustdoc::broken_intra_doc_links))]
22 #![warn(rust_2018_idioms)]
23
24 #[cfg(feature = "amortize")]
25 use griddle::HashMap;
26 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#;
27 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::hash_maprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash_map/::RandomStaterust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/random/RandomState#;
28 #[cfg(not(feature = "amortize"))]
29 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#;
30 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::convertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/::TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#;
31 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::hashrust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/::{BuildHasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/BuildHasher#, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#};
32
33 #[cfg(feature = "serde")]
34 mod serderust-analyzer cargo hashbag 0.1.12 serde/;
35
36 /// A hash bag implemented as a `HashMap` where the value is `usize`.
37 ///
38 /// A bag, unlike a set, allows duplicate values, and keeps track of how many
39 /// duplicates each value holds. This type of collection is often referred to
40 /// as an unordered multiset.
41 ///
42 /// As with the [`HashMap`] type, a `HashBag` requires that the elements
43 /// implement the [`Eq`] and [`Hash`] traits. This can frequently be achieved by
44 /// using `#[derive(PartialEq, Eq, Hash)]`. If you implement these yourself,
45 /// it is important that the following property holds:
46 ///
47 /// ```text
48 /// k1 == k2 -> hash(k1) == hash(k2)
49 /// ```
50 ///
51 /// In other words, if two keys are equal, their hashes must be equal.
52 ///
53 /// It is a logic error for an item to be modified in such a way that the
54 /// item's hash, as determined by the [`Hash`] trait, or its equality, as
55 /// determined by the [`Eq`] trait, changes while it is in the bag.
56 ///
57 /// # Examples
58 ///
59 /// ```
60 /// use hashbag::HashBag;
61 /// // Type inference lets us omit an explicit type signature (which
62 /// // would be `HashBag<String>` in this example).
63 /// let mut books = HashBag::new();
64 ///
65 /// // Add some books.
66 /// // Since we are a library, we have many copies.
67 /// books.insert("A Dance With Dragons".to_string());
68 /// books.insert("To Kill a Mockingbird".to_string());
69 /// books.insert("To Kill a Mockingbird".to_string());
70 /// books.insert("The Odyssey".to_string());
71 /// books.insert("The Odyssey".to_string());
72 /// books.insert("The Odyssey".to_string());
73 /// books.insert("The Great Gatsby".to_string());
74 /// books.insert("The Great Gatsby".to_string());
75 /// books.insert("The Great Gatsby".to_string());
76 /// books.insert("The Great Gatsby".to_string());
77 ///
78 /// // When we count the number of books, duplicates are included.
79 /// assert_eq!(books.len(), 10);
80 ///
81 /// // Check for a specific one.
82 /// if books.contains("The Winds of Winter") == 0 {
83 /// println!("We have {} books, but The Winds of Winter ain't one.",
84 /// books.len());
85 /// }
86 ///
87 /// // Remove a book.
88 /// let had_copies = books.remove("The Odyssey");
89 /// // Remove returns how many copies of that book we had.
90 /// assert_eq!(had_copies, 3);
91 ///
92 /// // Iterate over everything.
93 /// // Duplicates will be listed multiple times.
94 /// for book in &books {
95 /// println!("{}", book);
96 /// }
97 ///
98 /// // Iterate over each distinct book.
99 /// for (book, copies) in books.set_iter() {
100 /// println!("{} ({} copies)", book, copies);
101 /// }
102 ///
103 /// // Extract the books and their counts.
104 /// for (book, copies) in books {
105 /// println!("{} ({} copies)", book, copies);
106 /// }
107 /// ```
108 ///
109 /// The easiest way to use `HashBag` with a custom type is to derive
110 /// [`Eq`] and [`Hash`]. We must also derive [`PartialEq`], this will in the
111 /// future be implied by [`Eq`].
112 ///
113 /// ```
114 /// use hashbag::HashBag;
115 /// #[derive(Hash, Eq, PartialEq, Debug, Clone)]
116 /// struct Viking {
117 /// name: String,
118 /// power: usize,
119 /// }
120 ///
121 /// let mut vikings = HashBag::new();
122 ///
123 /// vikings.insert(Viking { name: "Einar".to_string(), power: 9 });
124 /// vikings.insert(Viking { name: "Einar".to_string(), power: 9 });
125 /// vikings.insert(Viking { name: "Olaf".to_string(), power: 4 });
126 /// vikings.insert(Viking { name: "Olaf".to_string(), power: 5 });
127 /// vikings.insert(Viking { name: "Harald".to_string(), power: 8 });
128 ///
129 /// // Use derived implementation to print the vikings.
130 /// // Notice that all duplicates are printed.
131 /// for v in &vikings {
132 /// println!("{:?}", v);
133 /// }
134 ///
135 /// // Since the derived implementation compares all the fields,
136 /// // vikings that share a name but not a power are not duplicates.
137 /// for (v, n) in vikings.set_iter() {
138 /// println!("{:?} ({} of them!)", v, n);
139 /// }
140 ///
141 /// // HashBags themselves can also be compared for equality,
142 /// // and will do so by considering both the values and their counts.
143 /// let mut vikings2 = vikings.clone();
144 /// assert_eq!(vikings, vikings2);
145 /// let fallen = vikings.iter().next().unwrap();
146 /// vikings2.remove(fallen);
147 /// assert_ne!(vikings, vikings2);
148 /// vikings2.insert(Viking { name: "Snorre".to_string(), power: 1 });
149 /// assert_ne!(vikings, vikings2);
150 /// ```
151 ///
152 /// A `HashBag` with fixed list of elements can be initialized from an array:
153 ///
154 /// ```
155 /// use hashbag::HashBag;
156 ///
157 /// let mut viking_names: HashBag<&'static str> =
158 /// [ "Einar", "Olaf", "Harald" ].iter().cloned().collect();
159 /// // use the values stored in the bag
160 /// ```
161 ///
162 /// You can also extend the bag easily:
163 ///
164 /// ```
165 /// use hashbag::HashBag;
166 ///
167 /// let mut vikings: HashBag<String> = HashBag::new();
168 /// vikings.extend(std::iter::once("Snorre".to_string()));
169 /// assert_eq!(vikings.contains("Snorre"), 1);
170 ///
171 /// // You can extend with many instances at once:
172 /// vikings.extend(std::iter::once(("Snorre".to_string(), 4)));
173 /// assert_eq!(vikings.contains("Snorre"), 5);
174 ///
175 /// // Extension also works with reference iterators if the type is Clone:
176 /// let einar = String::from("Einar");
177 /// vikings.extend(std::iter::once(&einar));
178 /// assert_eq!(vikings.contains(&einar), 1);
179 ///
180 /// // And extend with many instances at once:
181 /// vikings.extend(std::iter::once((&einar, 4)));
182 /// assert_eq!(vikings.contains(&einar), 5);
183 /// ```
184 pub struct HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<T, S = RandomStaterust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/random/RandomState#> {
185 itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items.: HashMap<T, usize, S>,
186 countrust-analyzer cargo hashbag 0.1.12 HashBag#count.: usize,
187 }
188
189 impl<T: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# + Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#, S: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# + BuildHasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/BuildHasher#> Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# for HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<T, S> {
190 fn clonerust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`][Clone]clone().(&self) -> Selfrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`][Clone] {
191 Selfrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`][Clone] {
192 itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items.: self.itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items..clone(),
193 countrust-analyzer cargo hashbag 0.1.12 HashBag#count.: self.countrust-analyzer cargo hashbag 0.1.12 HashBag#count.,
194 }
195 }
196
197 fn clone_fromrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`][Clone]clone_from().(&mut self, source: &Selfrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`][Clone]) {
198 self.itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items..clone_from(&source.itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items.);
199 self.countrust-analyzer cargo hashbag 0.1.12 HashBag#count. = source.countrust-analyzer cargo hashbag 0.1.12 HashBag#count.;
200 }
201 }
202
203 impl<T: Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# + Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq#> HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<T, RandomStaterust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/random/RandomState#> {
204 /// Creates an empty `HashBag`.
205 ///
206 /// The hash bag is initially created with a capacity of 0, so it will not allocate until it
207 /// is first inserted into.
208 ///
209 /// # Examples
210 ///
211 /// ```
212 /// use hashbag::HashBag;
213 /// let bag: HashBag<i32> = HashBag::new();
214 /// ```
215 #[inline]
216 pub fn newrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T>`]new().() -> HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<T, RandomStaterust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/random/RandomState#> {
217 Selfrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T>`]::with_hasherrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]with_hasher().(RandomStaterust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/random/RandomState#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/random/impl#[RandomState]new().())
218 }
219
220 /// Creates an empty `HashBag` with the specified capacity.
221 ///
222 /// The hash bag will be able to hold at least `capacity` distinct values without
223 /// reallocating. If `capacity` is 0, the hash bag will not allocate.
224 ///
225 /// # Examples
226 ///
227 /// ```
228 /// use hashbag::HashBag;
229 /// let bag: HashBag<i32> = HashBag::with_capacity(10);
230 /// assert!(bag.capacity() >= 10);
231 /// ```
232 #[inline]
233 pub fn with_capacityrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T>`]with_capacity().(capacity: usize) -> HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<T, RandomStaterust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/random/RandomState#> {
234 Selfrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T>`]::with_capacity_and_hasherrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]with_capacity_and_hasher().(capacity, RandomStaterust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/random/RandomState#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/random/impl#[RandomState]new().())
235 }
236 }
237
238 impl<T, S> HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<T, S> {
239 /// Returns the number of distinct values the bag can hold without reallocating.
240 ///
241 /// # Examples
242 ///
243 /// ```
244 /// use hashbag::HashBag;
245 /// let bag: HashBag<i32> = HashBag::with_capacity(100);
246 /// assert!(bag.capacity() >= 100);
247 /// ```
248 #[inline]
249 pub fn capacityrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]capacity().(&self) -> usize {
250 self.itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items..capacity()
251 }
252
253 /// An iterator visiting all elements in arbitrary order.
254 ///
255 /// The iterator element type is `&'a T`.
256 /// Duplicates are yielded as many times as they appear in the bag.
257 ///
258 /// # Examples
259 ///
260 /// ```
261 /// use hashbag::HashBag;
262 /// let mut bag = HashBag::new();
263 /// bag.insert("a");
264 /// bag.insert("b");
265 /// bag.insert("b");
266 ///
267 /// // Will print in an arbitrary order.
268 /// // b will be printed twice.
269 /// for x in bag.iter() {
270 /// println!("{}", x);
271 /// }
272 /// ```
273 #[inline]
274 pub fn iterrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]iter().(&self) -> Iterrust-analyzer cargo hashbag 0.1.12 Iter#<'_, T> {
275 Iterrust-analyzer cargo hashbag 0.1.12 Iter#::newrust-analyzer cargo hashbag 0.1.12 impl#[`Iter<'a, T>`]new().(self.itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items..iter(), self.countrust-analyzer cargo hashbag 0.1.12 HashBag#count.)
276 }
277
278 /// An iterator visiting all distinct elements in arbitrary order.
279 ///
280 /// The iterator element type is `(&'a T, usize)`.
281 /// Duplicated values are yielded once along with a count of the number of occurrences.
282 ///
283 /// # Examples
284 ///
285 /// ```
286 /// use hashbag::HashBag;
287 /// let mut bag = HashBag::new();
288 /// bag.insert("a");
289 /// bag.insert("b");
290 /// bag.insert("b");
291 ///
292 /// // Will print in an arbitrary order.
293 /// for (x, n) in bag.set_iter() {
294 /// println!("{} {}", x, n);
295 /// }
296 /// ```
297 #[inline]
298 pub fn set_iterrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]set_iter().(&self) -> SetIterrust-analyzer cargo hashbag 0.1.12 SetIter#<'_, T> {
299 SetIterrust-analyzer cargo hashbag 0.1.12 SetIter#(self.itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items..iter())
300 }
301
302 /// Returns the number of elements in the bag.
303 ///
304 /// Duplicates are counted.
305 ///
306 /// # Examples
307 ///
308 /// ```
309 /// use hashbag::HashBag;
310 ///
311 /// let mut bag = HashBag::new();
312 /// assert_eq!(bag.len(), 0);
313 /// bag.insert(1);
314 /// assert_eq!(bag.len(), 1);
315 /// bag.insert(1);
316 /// assert_eq!(bag.len(), 2);
317 /// ```
318 #[inline]
319 pub fn lenrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]len().(&self) -> usize {
320 self.countrust-analyzer cargo hashbag 0.1.12 HashBag#count.
321 }
322
323 /// Returns the number of elements in the bag.
324 ///
325 /// Duplicates are not counted.
326 ///
327 /// # Examples
328 ///
329 /// ```
330 /// use hashbag::HashBag;
331 ///
332 /// let mut bag = HashBag::new();
333 /// assert_eq!(bag.set_len(), 0);
334 /// bag.insert(1);
335 /// assert_eq!(bag.set_len(), 1);
336 /// bag.insert(1);
337 /// assert_eq!(bag.set_len(), 1);
338 /// ```
339 #[inline]
340 pub fn set_lenrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]set_len().(&self) -> usize {
341 self.itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items..len()
342 }
343
344 /// Returns `true` if the bag contains no elements.
345 ///
346 /// # Examples
347 ///
348 /// ```
349 /// use hashbag::HashBag;
350 ///
351 /// let mut bag = HashBag::new();
352 /// assert!(bag.is_empty());
353 /// bag.insert(1);
354 /// assert!(!bag.is_empty());
355 /// ```
356 #[inline]
357 pub fn is_emptyrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]is_empty().(&self) -> bool {
358 self.countrust-analyzer cargo hashbag 0.1.12 HashBag#count. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0
359 }
360
361 /// Clears the bag, returning all elements in an iterator.
362 ///
363 /// Duplicates appear only in the count yielded for each element.
364 ///
365 /// # Examples
366 ///
367 /// ```
368 /// use hashbag::HashBag;
369 ///
370 /// let mut bag: HashBag<_> = [1, 2, 3, 3].iter().cloned().collect();
371 /// assert!(!bag.is_empty());
372 ///
373 /// // prints
374 /// // 1 1
375 /// // 2 1
376 /// // 3 2
377 /// // in an arbitrary order
378 /// for (i, n) in bag.drain() {
379 /// println!("{} {}", i, n);
380 /// }
381 ///
382 /// assert!(bag.is_empty());
383 /// ```
384 #[inline]
385 pub fn drainrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]drain().(&mut self) -> Drainrust-analyzer cargo hashbag 0.1.12 Drain#<'_, T> {
386 self.countrust-analyzer cargo hashbag 0.1.12 HashBag#count. = 0;
387 Drainrust-analyzer cargo hashbag 0.1.12 Drain#(self.itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items..drain())
388 }
389
390 /// Clears the bag, removing all values.
391 ///
392 /// # Examples
393 ///
394 /// ```
395 /// use hashbag::HashBag;
396 ///
397 /// let mut bag = HashBag::new();
398 /// bag.insert(1);
399 /// bag.clear();
400 /// assert!(bag.is_empty());
401 /// ```
402 #[inline]
403 pub fn clearrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]clear().(&mut self) {
404 self.countrust-analyzer cargo hashbag 0.1.12 HashBag#count. = 0;
405 self.itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items..clear();
406 }
407 }
408
409 impl<T, S> HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<T, S>
410 where
411 T: Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# + Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#,
412 S: BuildHasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/BuildHasher#,
413 {
414 /// Creates a new empty hash bag which will use the given hasher to hash
415 /// keys.
416 ///
417 /// The hash bag is also created with the default initial capacity.
418 ///
419 /// Warning: `hasher` is normally randomly generated, and
420 /// is designed to allow `HashBag`s to be resistant to attacks that
421 /// cause many collisions and very poor performance. Setting it
422 /// manually using this function can expose a DoS attack vector.
423 ///
424 /// # Examples
425 ///
426 /// ```
427 /// use hashbag::HashBag;
428 /// use std::collections::hash_map::RandomState;
429 ///
430 /// let s = RandomState::new();
431 /// let mut bag = HashBag::with_hasher(s);
432 /// bag.insert(2);
433 /// ```
434 #[inline]
435 pub fn with_hasherrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]with_hasher().(hash_builder: S) -> HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<T, S> {
436 HashBagrust-analyzer cargo hashbag 0.1.12 HashBag# {
437 itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items.: HashMap::with_hasher(hash_builder),
438 countrust-analyzer cargo hashbag 0.1.12 HashBag#count.: 0,
439 }
440 }
441
442 /// Creates an empty `HashBag` with the specified capacity, using
443 /// `hasher` to hash the keys.
444 ///
445 /// The hash bag will be able to hold at least `capacity` distinct values
446 /// without reallocating. If `capacity` is 0, the hash bag will not allocate.
447 ///
448 /// Warning: `hasher` is normally randomly generated, and
449 /// is designed to allow `HashBag`s to be resistant to attacks that
450 /// cause many collisions and very poor performance. Setting it
451 /// manually using this function can expose a DoS attack vector.
452 ///
453 /// # Examples
454 ///
455 /// ```
456 /// use hashbag::HashBag;
457 /// use std::collections::hash_map::RandomState;
458 ///
459 /// let s = RandomState::new();
460 /// let mut bag = HashBag::with_capacity_and_hasher(10, s);
461 /// bag.insert(1);
462 /// ```
463 #[inline]
464 pub fn with_capacity_and_hasherrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]with_capacity_and_hasher().(capacity: usize, hash_builder: S) -> HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<T, S> {
465 HashBagrust-analyzer cargo hashbag 0.1.12 HashBag# {
466 itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items.: HashMap::with_capacity_and_hasher(capacity, hash_builder),
467 countrust-analyzer cargo hashbag 0.1.12 HashBag#count.: 0,
468 }
469 }
470
471 /// Returns a reference to the bag's [`BuildHasher`].
472 ///
473 /// # Examples
474 ///
475 /// ```
476 /// use hashbag::HashBag;
477 /// use std::collections::hash_map::RandomState;
478 ///
479 /// let hasher = RandomState::new();
480 /// let bag: HashBag<i32> = HashBag::with_hasher(hasher);
481 /// let hasher: &RandomState = bag.hasher();
482 /// ```
483 #[inline]
484 pub fn hasherrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]hasher().(&self) -> &S {
485 self.itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items..hasher()
486 }
487
488 /// Reserves capacity for at least `additional` more distinct values
489 /// to be inserted in the `HashBag`. The collection may reserve more
490 /// space to avoid frequent reallocations.
491 ///
492 /// # Panics
493 ///
494 /// Panics if the new allocation size overflows `usize`.
495 ///
496 /// # Examples
497 ///
498 /// ```
499 /// use hashbag::HashBag;
500 /// let mut bag: HashBag<i32> = HashBag::new();
501 /// bag.reserve(10);
502 /// assert!(bag.capacity() >= 10);
503 /// ```
504 #[inline]
505 pub fn reserverust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]reserve().(&mut self, additional: usize) {
506 self.itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items..reserve(additional)
507 }
508
509 /// Shrinks the capacity of the ba as much as possible. It will drop
510 /// down as much as possible while maintaining the internal rules
511 /// and possibly leaving some space in accordance with the resize policy.
512 ///
513 /// # Examples
514 ///
515 /// ```
516 /// use hashbag::HashBag;
517 ///
518 /// let mut bag = HashBag::with_capacity(100);
519 /// bag.insert(1);
520 /// bag.insert(2);
521 /// assert!(bag.capacity() >= 100);
522 /// bag.shrink_to_fit();
523 /// assert!(bag.capacity() >= 2);
524 /// ```
525 #[inline]
526 pub fn shrink_to_fitrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]shrink_to_fit().(&mut self) {
527 self.itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items..shrink_to_fit()
528 }
529
530 /// Returns the number of instances of `value` in the bag.
531 ///
532 /// The value may be any borrowed form of the bag's value type, but
533 /// [`Hash`] and [`Eq`] on the borrowed form *must* match those for
534 /// the value type.
535 ///
536 /// # Examples
537 ///
538 /// ```
539 /// use hashbag::HashBag;
540 ///
541 /// let bag: HashBag<_> = [1, 2, 3, 3].iter().cloned().collect();
542 /// assert_eq!(bag.contains(&1), 1);
543 /// assert_eq!(bag.contains(&3), 2);
544 /// assert_eq!(bag.contains(&4), 0);
545 /// ```
546 #[inline]
547 pub fn containsrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]contains().<Q: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(&self, value: &Q) -> usize
548 where
549 T: Borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#<Q>,
550 Q: Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# + Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq#,
551 {
552 self.itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items..get(value).cloned().unwrap_or(0)
553 }
554
555 /// Returns a reference to the value in the bag, if any, that is equal to the given value,
556 /// along with its number of occurrences.
557 ///
558 /// The value may be any borrowed form of the bag's value type, but
559 /// [`Hash`] and [`Eq`] on the borrowed form *must* match those for
560 /// the value type.
561 ///
562 /// # Examples
563 ///
564 /// ```
565 /// use hashbag::HashBag;
566 ///
567 /// let bag: HashBag<_> = [1, 2, 3, 3].iter().cloned().collect();
568 /// assert_eq!(bag.get(&2), Some((&2, 1)));
569 /// assert_eq!(bag.get(&3), Some((&3, 2)));
570 /// assert_eq!(bag.get(&4), None);
571 /// ```
572 #[inline]
573 pub fn getrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]get().<Q: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(&self, value: &Q) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(&T, usize)>
574 where
575 T: Borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#<Q>,
576 Q: Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# + Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq#,
577 {
578 self.itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items.
579 .get_key_value(value)
580 .map(|(t, count)| (t, *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().count))
581 }
582
583 /// Gets a given value's corresponding entry in the bag for in-place manipulation.
584 ///
585 /// # Examples
586 ///
587 /// ```
588 /// use hashbag::HashBag;
589 ///
590 /// let mut bag: HashBag<char> = ['a'].iter().cloned().collect();
591 /// let entry = bag.entry('a').and_modify(|n| *n += 1).or_insert();
592 /// assert_eq!(bag.get(&'a'), Some((&'a', 2)));
593 /// let entry = bag.entry('b').and_modify(|n| *n += 1).or_insert();
594 /// assert_eq!(bag.get(&'b'), Some((&'b', 1)));
595 /// let entry = bag.entry('c').and_modify(|n| *n += 1).or_insert_many(7);
596 /// assert_eq!(bag.get(&'c'), Some((&'c', 7)));
597 /// ```
598 #[inline]
599 pub fn entryrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]entry().(&mut self, value: T) -> Entryrust-analyzer cargo hashbag 0.1.12 Entry#<'_, T, S> {
600 Entryrust-analyzer cargo hashbag 0.1.12 Entry#((
601 ForiegnEntryrust-analyzer cargo hashbag 0.1.12 entry/ForiegnEntry#::newrust-analyzer cargo hashbag 0.1.12 entry/impl#[`ForiegnEntry<'a, T, S>`]new().(self.itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items..entry(value)),
602 &mut self.countrust-analyzer cargo hashbag 0.1.12 HashBag#count.,
603 PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#,
604 ))
605 }
606
607 /// Adds a value to the bag.
608 ///
609 /// The number of occurrences of the value previously in the bag is returned.
610 ///
611 /// # Examples
612 ///
613 /// ```
614 /// use hashbag::HashBag;
615 ///
616 /// let mut bag = HashBag::new();
617 ///
618 /// assert_eq!(bag.insert(2), 0);
619 /// assert_eq!(bag.insert(2), 1);
620 /// assert_eq!(bag.insert(2), 2);
621 /// assert_eq!(bag.set_len(), 1);
622 /// assert_eq!(bag.len(), 3);
623 /// ```
624 #[inline]
625 pub fn insertrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]insert().(&mut self, value: T) -> usize {
626 self.insert_manyrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]insert_many().(value, 1)
627 }
628
629 /// Adds multiple occurrences of a value to the bag.
630 ///
631 /// The number of occurrences of the value previously in the bag is returned.
632 ///
633 /// # Examples
634 ///
635 /// ```
636 /// use hashbag::HashBag;
637 ///
638 /// let mut bag = HashBag::new();
639 ///
640 /// assert_eq!(bag.insert_many(2, 1), 0);
641 /// assert_eq!(bag.insert_many(2, 2), 1);
642 /// assert_eq!(bag.insert_many(2, 4), 3);
643 /// assert_eq!(bag.set_len(), 1);
644 /// assert_eq!(bag.len(), 7);
645 /// ```
646 #[inline]
647 pub fn insert_manyrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]insert_many().(&mut self, value: T, count: usize) -> usize {
648 if count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 {
649 return self.containsrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]contains().(&value);
650 }
651 self.countrust-analyzer cargo hashbag 0.1.12 HashBag#count. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().count;
652 let n = self.itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items..entry(value).or_insert(0);
653 let was_there = *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().n;
654 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/DerefMut#deref_mut().n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign().count;
655 was_there
656 }
657
658 /// Adds a value to the bag, replacing all existing occurrences, if any, that equal the given
659 /// one.
660 ///
661 /// The number of occurrences of the value previously in the bag is returned.
662 ///
663 /// # Examples
664 ///
665 /// ```
666 /// use hashbag::HashBag;
667 ///
668 /// let mut bag = HashBag::new();
669 /// bag.insert(Vec::<i32>::new());
670 /// bag.insert(Vec::<i32>::new());
671 /// assert_eq!(bag.contains(&[][..]), 2);
672 /// assert_eq!(bag.get(&[][..]).unwrap().0.capacity(), 0);
673 ///
674 /// bag.replace(Vec::with_capacity(10));
675 /// assert_eq!(bag.contains(&[][..]), 1);
676 /// assert_eq!(bag.get(&[][..]).unwrap().0.capacity(), 10);
677 /// ```
678 #[inline]
679 pub fn replacerust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]replace().(&mut self, value: T) -> usize {
680 let n = self.itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items..remove(&value).unwrap_or(0);
681 self.countrust-analyzer cargo hashbag 0.1.12 HashBag#count. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().n;
682 self.itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items..insert(value, 1);
683 self.countrust-analyzer cargo hashbag 0.1.12 HashBag#count. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
684 n
685 }
686
687 /// Removes a value from the bag.
688 ///
689 /// The number of occurrences of the value previously in the bag is returned.
690 ///
691 /// The value may be any borrowed form of the bag's value type, but
692 /// [`Hash`] and [`Eq`] on the borrowed form *must* match those for
693 /// the value type.
694 ///
695 /// # Examples
696 ///
697 /// ```
698 /// use hashbag::HashBag;
699 ///
700 /// let mut bag = HashBag::new();
701 ///
702 /// bag.insert_many('x', 2);
703 /// assert_eq!(bag.contains(&'x'), 2);
704 /// assert_eq!(bag.remove(&'x'), 2);
705 /// assert_eq!(bag.contains(&'x'), 1);
706 /// assert_eq!(bag.remove(&'x'), 1);
707 /// assert_eq!(bag.contains(&'x'), 0);
708 /// assert_eq!(bag.remove(&'x'), 0);
709 /// ```
710 #[inline]
711 pub fn removerust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]remove().<Q: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(&mut self, value: &Q) -> usize
712 where
713 T: Borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#<Q>,
714 Q: Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# + Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq#,
715 {
716 match self.itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items..get_mut(value) {
717 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => 0,
718 #[cfg(debug_assertions)]
719 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(n) if *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq().0 => unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!(),
720 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(n) if *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq().1 => {
721 self.countrust-analyzer cargo hashbag 0.1.12 HashBag#count. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().1;
722 self.itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items..remove(value);
723 1
724 }
725 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(n) => {
726 self.countrust-analyzer cargo hashbag 0.1.12 HashBag#count. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().1;
727 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/DerefMut#deref_mut().n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/SubAssign#sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/SubAssign#sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/SubAssign#sub_assign().1;
728 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().1
729 }
730 }
731 }
732
733 /// Removes multiple of a value from the bag. If `quantity` is greater than the number of
734 /// occurences, zero occurances will remain.
735 ///
736 /// The number of occurrences of the value currently in the bag is returned.
737 ///
738 /// The value may be any borrowed form of the bag's value type, but
739 /// [`Hash`] and [`Eq`] on the borrowed form *must* match those for
740 /// the value type.
741 ///
742 /// # Examples
743 ///
744 /// ```
745 /// use hashbag::HashBag;
746 ///
747 /// let mut bag = HashBag::new();
748 ///
749 /// bag.insert_many('x', 10);
750 /// assert_eq!(bag.contains(&'x'), 10);
751 /// assert_eq!(bag.remove_up_to(&'x', 3), 7);
752 /// assert_eq!(bag.contains(&'x'), 7);
753 /// assert_eq!(bag.remove_up_to(&'x', 10), 0);
754 /// ```
755 #[inline]
756 pub fn remove_up_torust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]remove_up_to().<Q: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(&mut self, value: &Q, quantity: usize) -> usize
757 where
758 T: Borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#<Q>,
759 Q: Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# + Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq#,
760 {
761 match self.itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items..get_mut(value) {
762 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => 0,
763 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&mut n) if n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().quantity => {
764 self.countrust-analyzer cargo hashbag 0.1.12 HashBag#count. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().n;
765 self.itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items..remove(value);
766 0
767 }
768 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(n) => {
769 self.countrust-analyzer cargo hashbag 0.1.12 HashBag#count. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().quantity;
770 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().quantity;
771 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().n
772 }
773 }
774 }
775
776 /// Returns an iterator over all of the elements that are in `self` or `other`.
777 /// The iterator also yields the respective counts in `self` and `other` in that order.
778 /// Elements that are in `self` are yielded before any elements that are exclusively in `other`.
779 /// Each distinct element is yielded only once.
780 ///
781 /// # Examples
782 /// ```
783 /// use hashbag::HashBag;
784 /// use std::collections::HashSet;
785 /// use std::iter::FromIterator;
786 ///
787 /// let a: HashBag<_> = "hash".chars().collect();
788 /// let b: HashBag<_> = "math".chars().collect();
789 /// let expected: HashSet<_> = HashSet::from_iter([(&'h', 2, 1), (&'a', 1, 1), (&'s', 1, 0), (&'m', 0, 1), (&'t', 0, 1)]);
790 /// let actual: HashSet<_> = a.outer_join(&b).collect();
791 /// assert_eq!(expected, actual);
792 /// ```
793 pub fn outer_joinrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]outer_join().<'a, OtherS>(
794 &'a self,
795 other: &'a HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<T, OtherS>,
796 ) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = (&'a T, usize, usize)>
797 where
798 OtherS: BuildHasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/BuildHasher#,
799 {
800 self.itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items.
801 .iter()
802 .map(move |(x, &self_count)| (x, self_count, other.containsrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]contains().(x)))
803 .chain(other.itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items..iter().filter_map(move |(x, &other_count)| {
804 let self_count = self.containsrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]contains().(x);
805 if self_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 {
806 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((x, self_count, other_count))
807 } else {
808 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
809 }
810 }))
811 }
812
813 /// Returns an iterator over all the elements that are in `self` with a
814 /// higher occurrence count than in `other`. The count in the returned
815 /// iterator represents how many more of a given element are in `self` than
816 /// `other`.
817 ///
818 /// # Examples
819 ///
820 /// ```
821 /// use hashbag::HashBag;
822 /// use std::collections::HashSet;
823 /// use std::iter::FromIterator;
824 ///
825 /// let a: HashBag<_> = [1, 2, 3, 3].iter().cloned().collect();
826 /// let b: HashBag<_> = [2, 3].iter().cloned().collect();
827 /// let expected: HashSet<_> = HashSet::from_iter([(&1, 1), (&3, 1)]);
828 /// let actual: HashSet<_> = a.difference(&b).collect();
829 /// assert_eq!(expected, actual);
830 /// ```
831 pub fn differencerust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]difference().<'a, OtherS>(
832 &'a self,
833 other: &'a HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<T, OtherS>,
834 ) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = (&'a T, usize)>
835 where
836 OtherS: BuildHasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/BuildHasher#,
837 {
838 self.outer_joinrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]outer_join().(other)
839 .take_whilerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take_while().(|(_, self_count, _)| self_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]gt().&0)
840 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|(_x, self_count, other_count)| self_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]gt().other_count)
841 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(x, self_count, other_count)| (x, self_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().other_count))
842 }
843
844 /// Returns an iterator over all the elements that are in `self` or `other`.
845 /// The iterator also yields the difference in counts between `self` and `other`.
846 ///
847 /// Unlike 'difference' which only yields elements that have a higher count in `self` than in `other`,
848 /// this iterator yields all elements that are in either of the `HashBag`s. Elements that have a higher
849 /// count in `other` than in self (including elements that are not in `self`) will have a negative count.
850 ///
851 /// If the difference can be represented as an `isize`, then it will be. Otherwise, the difference will be
852 /// clamped to `isize::MIN`/`isize::MAX`, thus keeping the sign of the difference, and as much of the
853 /// magnitude as possible.
854 ///
855 /// # Examples
856 ///
857 /// ```
858 /// use hashbag::HashBag;
859 /// use std::collections::HashSet;
860 /// use std::iter::FromIterator;
861 ///
862 /// let a: HashBag<_> = [1, 2, 3, 3].iter().cloned().collect();
863 /// let b: HashBag<_> = [2, 3, 4, 4].iter().cloned().collect();
864 /// let expected: HashSet<_> = HashSet::from_iter([(&1, 1), (&2, 0), (&3, 1), (&4, -2)]);
865 /// let actual: HashSet<_> = a.signed_difference(&b).collect();
866 /// assert_eq!(expected, actual);
867 /// ```
868 pub fn signed_differencerust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]signed_difference().<'a, OtherS>(
869 &'a self,
870 other: &'a HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<T, OtherS>,
871 ) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = (&'a T, isize)>
872 where
873 OtherS: BuildHasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/BuildHasher#,
874 {
875 self.outer_joinrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]outer_join().(other).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(x, self_count, other_count)| {
876 let diff = if self_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().other_count {
877 isize::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[isize][`TryFrom<usize>`]try_from().(self_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().other_count).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::isizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/isize/::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/isize/MAX.)
878 } else {
879 isize::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[isize][`TryFrom<usize>`]try_from().(other_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().self_count)
880 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|x| -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][Neg]neg().x)
881 .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::isizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/isize/::MINrust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/isize/MIN.)
882 };
883 (x, diff)
884 })
885 }
886
887 /// Returns an iterator over all of the elements that are in `self` but not in `other`.
888 ///
889 /// # Examples
890 /// ```
891 /// use hashbag::HashBag;
892 /// use std::collections::HashSet;
893 /// use std::iter::FromIterator;
894 ///
895 /// let a: HashBag<_> = [1, 2, 3, 3].iter().cloned().collect();
896 /// let b: HashBag<_> = [2, 3].iter().cloned().collect();
897 /// let expected: HashSet<_> = HashSet::from_iter([(&1, 1)]);
898 /// let actual: HashSet<_> = a.not_in(&b).collect();
899 /// assert_eq!(expected, actual);
900 /// ```
901 pub fn not_inrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]not_in().<'a, OtherS>(
902 &'a self,
903 other: &'a HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<T, OtherS>,
904 ) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = (&'a T, usize)>
905 where
906 OtherS: BuildHasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/BuildHasher#,
907 {
908 self.outer_joinrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]outer_join().(other)
909 .take_whilerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take_while().(|(_, self_count, _)| self_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]gt().&0)
910 .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|(k, self_count, other_count)| {
911 if other_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 {
912 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((k, self_count))
913 } else {
914 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
915 }
916 })
917 }
918
919 /// Removes a value that is equal to the given one, and returns it if it was the last.
920 ///
921 /// If the matching value is not the last, a reference to the remainder is given, along with
922 /// the number of occurrences prior to the removal.
923 ///
924 /// The value may be any borrowed form of the bag's value type, but
925 /// [`Hash`] and [`Eq`] on the borrowed form *must* match those for
926 /// the value type.
927 ///
928 /// # Examples
929 ///
930 /// ```
931 /// use hashbag::HashBag;
932 ///
933 /// let mut bag: HashBag<_> = [1, 2, 3, 3].iter().cloned().collect();
934 /// assert_eq!(bag.try_take(&2), Ok(2));
935 /// assert_eq!(bag.try_take(&3), Err(Some((&3, 2))));
936 /// assert_eq!(bag.try_take(&3), Ok(3));
937 /// assert_eq!(bag.try_take(&4), Err(None));
938 /// ```
939 #[inline]
940 pub fn try_takerust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]try_take().<Q: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(&mut self, value: &Q) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(&T, usize)>>
941 where
942 T: Borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#<Q>,
943 Q: Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# + Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq#,
944 {
945 // TODO: it should be possible to make this more efficient
946 match self.itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items..remove_entry(value) {
947 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((t, 1)) => {
948 self.countrust-analyzer cargo hashbag 0.1.12 HashBag#count. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().1;
949 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(t)
950 }
951 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((t, n)) => {
952 self.countrust-analyzer cargo hashbag 0.1.12 HashBag#count. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().1;
953 self.itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items..insert(t, n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Sub<Self>`]sub().1);
954 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(
955 self.itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items.
956 .get_key_value(value)
957 .map(|(t, n)| (t, *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().1))
958 .unwrap(),
959 ))
960 }
961 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
962 }
963 }
964
965 /// Removes and returns all occurrences of the value, if any, that is equal to the given one.
966 ///
967 /// The value may be any borrowed form of the bag's value type, but
968 /// [`Hash`] and [`Eq`] on the borrowed form *must* match those for
969 /// the value type.
970 ///
971 /// # Examples
972 ///
973 /// ```
974 /// use hashbag::HashBag;
975 ///
976 /// let mut bag: HashBag<_> = [1, 2, 3, 3].iter().cloned().collect();
977 /// assert_eq!(bag.take_all(&2), Some((2, 1)));
978 /// assert_eq!(bag.take_all(&3), Some((3, 2)));
979 /// assert_eq!(bag.take_all(&2), None);
980 /// assert_eq!(bag.take_all(&3), None);
981 /// ```
982 #[inline]
983 pub fn take_allrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]take_all().<Q: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(&mut self, value: &Q) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(T, usize)>
984 where
985 T: Borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#<Q>,
986 Q: Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# + Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq#,
987 {
988 let (t, n) = self.itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items..remove_entry(value)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/try_trait/Try#branch().;
989 self.countrust-analyzer cargo hashbag 0.1.12 HashBag#count. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().n;
990 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((t, n))
991 }
992
993 /// Retains only the values specified by the predicate.
994 ///
995 /// In other words, for each value `v` retain only `f(&v)` occurrences.
996 ///
997 /// # Examples
998 ///
999 /// ```
1000 /// use hashbag::HashBag;
1001 ///
1002 /// let xs = [0,0,0,0,0,1,1,1,1,2,2,2,3,3,4];
1003 /// let mut bag: HashBag<i32> = xs.iter().cloned().collect();
1004 /// bag.retain(|&k, _| k as usize);
1005 /// assert_eq!(bag.set_len(), 4); // >= 1 of all but value 0
1006 /// assert_eq!(bag.len(), 6);
1007 /// assert_eq!(bag.contains(&0), 0);
1008 /// assert_eq!(bag.contains(&1), 1);
1009 /// assert_eq!(bag.contains(&2), 2);
1010 /// assert_eq!(bag.contains(&3), 2);
1011 /// assert_eq!(bag.contains(&4), 1);
1012 /// ```
1013 pub fn retainrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]retain().<F>(&mut self, mut f: F)
1014 where
1015 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&T, usize) -> usize,
1016 {
1017 let count = &mut self.countrust-analyzer cargo hashbag 0.1.12 HashBag#count.;
1018 self.itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items..retain(|t, n| {
1019 let keep = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().n, f(t, *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().n));
1020 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/SubAssign#sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/SubAssign#sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/SubAssign#sub_assign().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().keep;
1021 if keep rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 {
1022 false
1023 } else {
1024 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/DerefMut#deref_mut().n = keep;
1025 true
1026 }
1027 });
1028 }
1029 }
1030
1031 // ======== standard traits
1032
1033 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/;
1034 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::markerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/::PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#;
1035
1036 impl<T> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<T>
1037 where
1038 T: fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#,
1039 {
1040 fn fmtrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T>`][Debug]fmt().(&self, fmt: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
1041 fmt.debug_setrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]debug_set().().entriesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugSet<'a, 'b>`]entries().(self.iterrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]iter().()).finishrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugSet<'a, 'b>`]finish().()
1042 }
1043 }
1044
1045 impl<T, S> Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<T, S>
1046 where
1047 T: Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# + Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#,
1048 S: BuildHasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/BuildHasher# + Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#,
1049 {
1050 fn defaultrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`][Default]default().() -> Selfrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`][Default] {
1051 Selfrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`][Default]::with_hasherrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]with_hasher().(S::defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#default().())
1052 }
1053 }
1054
1055 impl<T, S> PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<T, S>> for HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<T, S>
1056 where
1057 T: Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# + Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#,
1058 S: BuildHasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/BuildHasher#,
1059 {
1060 fn eqrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`][`PartialEq<Self>`]eq().(&self, other: &Selfrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`][`PartialEq<Self>`]) -> bool {
1061 self.countrust-analyzer cargo hashbag 0.1.12 HashBag#count. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().other.countrust-analyzer cargo hashbag 0.1.12 HashBag#count. && self.itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq().other.itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items.
1062 }
1063 }
1064
1065 impl<T, S> Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# for HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<T, S>
1066 where
1067 T: Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# + Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#,
1068 S: BuildHasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/BuildHasher#,
1069 {
1070 }
1071
1072 impl<'a, T, S> Extendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/Extend#<&'a T> for HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<T, S>
1073 where
1074 T: 'a + Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# + Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#,
1075 S: BuildHasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/BuildHasher#,
1076 {
1077 fn extendrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`][`Extend<&'a T>`]extend().<I: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = &'a T>>(&mut self, iter: I) {
1078 for e in iter {
1079 self.insertrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]insert().(e.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().());
1080 }
1081 }
1082 }
1083
1084 impl<'a, T, S> Extendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/Extend#<(&'a T, usize)> for HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<T, S>
1085 where
1086 T: 'a + Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# + Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#,
1087 S: BuildHasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/BuildHasher#,
1088 {
1089 fn extendrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`][`Extend<(&'a T, usize)>`]extend().<I: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = (&'a T, usize)>>(&mut self, iter: I) {
1090 for (e, n) in iter {
1091 self.countrust-analyzer cargo hashbag 0.1.12 HashBag#count. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().n;
1092 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/DerefMut#deref_mut().self.itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items..entry(e.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()).or_insert(0) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign().n;
1093 }
1094 }
1095 }
1096
1097 impl<T, S> Extendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/Extend#<T> for HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<T, S>
1098 where
1099 T: Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# + Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#,
1100 S: BuildHasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/BuildHasher#,
1101 {
1102 fn extendrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`][`Extend<T>`]extend().<I: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = T>>(&mut self, iter: I) {
1103 for e in iter {
1104 self.insertrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]insert().(e);
1105 }
1106 }
1107 }
1108
1109 impl<T, S> Extendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/Extend#<(T, usize)> for HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<T, S>
1110 where
1111 T: Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# + Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#,
1112 S: BuildHasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/BuildHasher#,
1113 {
1114 fn extendrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`][`Extend<(T, usize)>`]extend().<I: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = (T, usize)>>(&mut self, iter: I) {
1115 for (e, n) in iter {
1116 self.countrust-analyzer cargo hashbag 0.1.12 HashBag#count. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().n;
1117 if n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().0 {
1118 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/DerefMut#deref_mut().self.itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items..entry(e).or_insert(0) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign().n;
1119 }
1120 }
1121 }
1122 }
1123
1124 impl<T, S> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::FromIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/FromIterator#<T> for HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<T, S>
1125 where
1126 T: Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# + Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#,
1127 S: BuildHasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/BuildHasher# + Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#,
1128 {
1129 fn from_iterrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`][`FromIterator<T>`]from_iter().<I: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = T>>(iter: I) -> Selfrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`][`FromIterator<T>`] {
1130 let mut bag = Selfrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`][`FromIterator<T>`]::defaultrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`][Default]default().();
1131 bag.extendrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`][`Extend<T>`]extend().(iter);
1132 bag
1133 }
1134 }
1135
1136 impl<T, S> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::FromIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/FromIterator#<(T, usize)> for HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<T, S>
1137 where
1138 T: Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# + Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#,
1139 S: BuildHasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/BuildHasher# + Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#,
1140 {
1141 fn from_iterrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`][`FromIterator<(T, usize)>`]from_iter().<I: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = (T, usize)>>(iter: I) -> Selfrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`][`FromIterator<(T, usize)>`] {
1142 let mut bag = Selfrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`][`FromIterator<(T, usize)>`]::defaultrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`][Default]default().();
1143 bag.extendrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`][`Extend<(T, usize)>`]extend().(iter);
1144 bag
1145 }
1146 }
1147
1148 impl<'a, T, S> IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator# for &'a HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<T, S> {
1149 type Itemrust-analyzer cargo hashbag 0.1.12 impl#[`&'a HashBag<T, S>`][IntoIterator]Item# = &'a T;
1150 type IntoIterrust-analyzer cargo hashbag 0.1.12 impl#[`&'a HashBag<T, S>`][IntoIterator]IntoIter# = Iterrust-analyzer cargo hashbag 0.1.12 Iter#<'a, T>;
1151 fn into_iterrust-analyzer cargo hashbag 0.1.12 impl#[`&'a HashBag<T, S>`][IntoIterator]into_iter().(self) -> Iterrust-analyzer cargo hashbag 0.1.12 Iter#<'a, T> {
1152 self.iterrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]iter().()
1153 }
1154 }
1155
1156 impl<T, S> IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator# for HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<T, S> {
1157 type Itemrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`][IntoIterator]Item# = (T, usize);
1158 type IntoIterrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`][IntoIterator]IntoIter# = IntoIterrust-analyzer cargo hashbag 0.1.12 IntoIter#<T>;
1159 fn into_iterrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`][IntoIterator]into_iter().(self) -> IntoIterrust-analyzer cargo hashbag 0.1.12 IntoIter#<T> {
1160 IntoIterrust-analyzer cargo hashbag 0.1.12 IntoIter#(self.itemsrust-analyzer cargo hashbag 0.1.12 HashBag#items..into_iter())
1161 }
1162 }
1163
1164 // ======== entry type
1165 #[cfg(feature = "amortize")]
1166 pub(craterust-analyzer cargo hashbag 0.1.12 crate/) mod entryrust-analyzer cargo hashbag 0.1.12 entry/ {
1167 use griddle::hash_map::Entry;
1168
1169 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
1170 pub(craterust-analyzer cargo hashbag 0.1.12 crate/) struct ForiegnEntryrust-analyzer cargo hashbag 0.1.12 entry/ForiegnEntry#<'a, T, S> {
1171 pub(craterust-analyzer cargo hashbag 0.1.12 crate/) entryrust-analyzer cargo hashbag 0.1.12 entry/ForiegnEntry#entry.: Entry<'a, T, usize, S>,
1172 }
1173
1174 impl<'a, T, S> ForiegnEntryrust-analyzer cargo hashbag 0.1.12 entry/ForiegnEntry#<'a, T, S> {
1175 pub(craterust-analyzer cargo hashbag 0.1.12 crate/) fn newrust-analyzer cargo hashbag 0.1.12 entry/impl#[`ForiegnEntry<'a, T, S>`]new().(entry: Entry<'a, T, usize, S>) -> Selfrust-analyzer cargo hashbag 0.1.12 entry/impl#[`ForiegnEntry<'a, T, S>`] {
1176 Selfrust-analyzer cargo hashbag 0.1.12 entry/impl#[`ForiegnEntry<'a, T, S>`] { entryrust-analyzer cargo hashbag 0.1.12 entry/ForiegnEntry#entry. }
1177 }
1178
1179 pub(craterust-analyzer cargo hashbag 0.1.12 crate/) fn get_mutrust-analyzer cargo hashbag 0.1.12 entry/impl#[`ForiegnEntry<'a, T, S>`]get_mut().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&mut usize> {
1180 match &mut self.entryrust-analyzer cargo hashbag 0.1.12 entry/ForiegnEntry#entry. {
1181 Entry::Occupied(entry) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(entry.get_mut()),
1182 Entry::Vacant(_) => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
1183 }
1184 }
1185 }
1186 }
1187 #[cfg(not(feature = "amortize"))]
1188 pub(craterust-analyzer cargo hashbag 0.1.12 crate/) mod entryrust-analyzer cargo hashbag 0.1.12 entry/ {
1189 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::hash_maprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash_map/::Entryrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/Entry#, markerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/::PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#};
1190
1191 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debug)]
1192 pub(craterust-analyzer cargo hashbag 0.1.12 crate/) struct ForiegnEntry<'a, T, S> {
1193 pub(craterust-analyzer cargo hashbag 0.1.12 crate/) entry: Entry<'a, T, usize>,
1194 data: PhantomData<S>,
1195 }
1196
1197 impl<'a, T, S> ForiegnEntryrust-analyzer cargo hashbag 0.1.12 entry/ForiegnEntry#<'a, T, S> {
1198 pub(craterust-analyzer cargo hashbag 0.1.12 crate/) fn new(entry: Entry<'a, T, usize>) -> Self {
1199 Self {
1200 entry,
1201 data: PhantomData,
1202 }
1203 }
1204
1205 pub(craterust-analyzer cargo hashbag 0.1.12 crate/) fn get_mut(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&mut usize> {
1206 match &mut selfrust-analyzer cargo hashbag 0.1.12 entry/.entry {
1207 Entry::Occupied(entry) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(entry.get_mut()),
1208 Entry::Vacant(_) => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
1209 }
1210 }
1211 }
1212 }
1213
1214 use entryrust-analyzer cargo hashbag 0.1.12 entry/::ForiegnEntryrust-analyzer cargo hashbag 0.1.12 entry/ForiegnEntry#;
1215
1216 type EntryInnerrust-analyzer cargo hashbag 0.1.12 EntryInner#<'a, T, S> = (ForiegnEntryrust-analyzer cargo hashbag 0.1.12 entry/ForiegnEntry#<'a, T, S>, &'a mut usize, PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#<S>);
1217
1218 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
1219 /// A view into a single entry in the bag, which may either be vacant or occupied.
1220 /// This `enum` is constructed from the [`entry`](HashBag::entry) method on [`HashBag`]
1221 pub struct Entryrust-analyzer cargo hashbag 0.1.12 Entry#<'a, T, S>(EntryInnerrust-analyzer cargo hashbag 0.1.12 EntryInner#<'a, T, S>);
1222
1223 impl<'a, T, S> Entryrust-analyzer cargo hashbag 0.1.12 Entry#<'a, T, S>
1224 where
1225 T: Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# + Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq#,
1226 S: BuildHasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/BuildHasher#,
1227 {
1228 /// Provides in-place mutable access to an occupied entry before potential inserts into the
1229 /// map.
1230 pub fn and_modifyrust-analyzer cargo hashbag 0.1.12 impl#[`Entry<'a, T, S>`]and_modify().<F>(mut self, f: F) -> Selfrust-analyzer cargo hashbag 0.1.12 impl#[`Entry<'a, T, S>`]
1231 where
1232 F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(&mut usize),
1233 {
1234 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(n) = self.0rust-analyzer cargo hashbag 0.1.12 Entry#0. .0.get_mutrust-analyzer cargo hashbag 0.1.12 entry/impl#[`ForiegnEntry<'a, T, S>`]get_mut().() {
1235 let init = *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().n;
1236 f(n);
1237 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self.0rust-analyzer cargo hashbag 0.1.12 Entry#0. .1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().n;
1238 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self.0rust-analyzer cargo hashbag 0.1.12 Entry#0. .1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().init;
1239 }
1240 Selfrust-analyzer cargo hashbag 0.1.12 impl#[`Entry<'a, T, S>`]((self.0rust-analyzer cargo hashbag 0.1.12 Entry#0. .0, self.0rust-analyzer cargo hashbag 0.1.12 Entry#0. .1, PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#))
1241 }
1242
1243 /// Returns a reference to the entry's value.
1244 pub fn valuerust-analyzer cargo hashbag 0.1.12 impl#[`Entry<'a, T, S>`]value().(&self) -> &T {
1245 self.0rust-analyzer cargo hashbag 0.1.12 Entry#0. .0.entryrust-analyzer cargo hashbag 0.1.12 entry/ForiegnEntry#entry..key()
1246 }
1247
1248 /// Ensures there is at least one instance of the value before returning a mutable reference
1249 /// to the value's count
1250 pub fn or_insertrust-analyzer cargo hashbag 0.1.12 impl#[`Entry<'a, T, S>`]or_insert().(mut self) -> usize {
1251 if self.0rust-analyzer cargo hashbag 0.1.12 Entry#0. .0.get_mutrust-analyzer cargo hashbag 0.1.12 entry/impl#[`ForiegnEntry<'a, T, S>`]get_mut().().is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() {
1252 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self.0rust-analyzer cargo hashbag 0.1.12 Entry#0. .1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
1253 }
1254 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.0rust-analyzer cargo hashbag 0.1.12 Entry#0. .0.entryrust-analyzer cargo hashbag 0.1.12 entry/ForiegnEntry#entry..or_insert(1)
1255 }
1256
1257 /// Ensures there is at least `quantity` instances of the value before returning a mutable reference
1258 /// to the value's count
1259 pub fn or_insert_manyrust-analyzer cargo hashbag 0.1.12 impl#[`Entry<'a, T, S>`]or_insert_many().(mut self, quantity: usize) -> usize {
1260 if self.0rust-analyzer cargo hashbag 0.1.12 Entry#0. .0.get_mutrust-analyzer cargo hashbag 0.1.12 entry/impl#[`ForiegnEntry<'a, T, S>`]get_mut().().is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() {
1261 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self.0rust-analyzer cargo hashbag 0.1.12 Entry#0. .1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().quantity;
1262 }
1263 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.0rust-analyzer cargo hashbag 0.1.12 Entry#0. .0.entryrust-analyzer cargo hashbag 0.1.12 entry/ForiegnEntry#entry..or_insert(quantity)
1264 }
1265 }
1266
1267 // ======== iterators
1268
1269 #[cfg(feature = "amortize")]
1270 type IterInnerrust-analyzer cargo hashbag 0.1.12 IterInner#<'a, T> = griddle::hash_map::Iter<'a, T, usize>;
1271 #[cfg(not(feature = "amortize"))]
1272 type IterInner<'a, T> = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::hash_maprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash_map/::Iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/Iter#<'a, T, usize>;
1273
1274 /// An iterator over the items of a `HashBag`.
1275 ///
1276 /// Each value is repeated as many times as it occurs in the bag.
1277 ///
1278 /// This `struct` is created by [`HashBag::iter`].
1279 /// See its documentation for more.
1280 pub struct Iterrust-analyzer cargo hashbag 0.1.12 Iter#<'a, T> {
1281 iterrust-analyzer cargo hashbag 0.1.12 Iter#iter.: IterInnerrust-analyzer cargo hashbag 0.1.12 IterInner#<'a, T>,
1282 repeatrust-analyzer cargo hashbag 0.1.12 Iter#repeat.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(&'a T, usize)>,
1283 leftrust-analyzer cargo hashbag 0.1.12 Iter#left.: usize,
1284 }
1285
1286 impl<'a, T> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator# for Iterrust-analyzer cargo hashbag 0.1.12 Iter#<'a, T> where IterInnerrust-analyzer cargo hashbag 0.1.12 IterInner#<'a, T>: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator#
1287 {}
1288
1289 impl<'a, T> ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator# for Iterrust-analyzer cargo hashbag 0.1.12 Iter#<'a, T> where IterInnerrust-analyzer cargo hashbag 0.1.12 IterInner#<'a, T>: ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator# {}
1290
1291 impl<'a, T> Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# for Iterrust-analyzer cargo hashbag 0.1.12 Iter#<'a, T> {
1292 fn clonerust-analyzer cargo hashbag 0.1.12 impl#[`Iter<'a, T>`][Clone]clone().(&self) -> Selfrust-analyzer cargo hashbag 0.1.12 impl#[`Iter<'a, T>`][Clone] {
1293 Iterrust-analyzer cargo hashbag 0.1.12 Iter# {
1294 iterrust-analyzer cargo hashbag 0.1.12 Iter#iter.: self.iterrust-analyzer cargo hashbag 0.1.12 Iter#iter..clone(),
1295 repeatrust-analyzer cargo hashbag 0.1.12 Iter#repeat.: self.repeatrust-analyzer cargo hashbag 0.1.12 Iter#repeat.,
1296 leftrust-analyzer cargo hashbag 0.1.12 Iter#left.: self.leftrust-analyzer cargo hashbag 0.1.12 Iter#left.,
1297 }
1298 }
1299 }
1300
1301 impl<T: fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for Iterrust-analyzer cargo hashbag 0.1.12 Iter#<'_, T> {
1302 fn fmtrust-analyzer cargo hashbag 0.1.12 impl#[`Iter<'_, T>`][Debug]fmt().(&self, fmt: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
1303 fmt.debug_setrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]debug_set().().entriesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugSet<'a, 'b>`]entries().(self.clonerust-analyzer cargo hashbag 0.1.12 impl#[`Iter<'a, T>`][Clone]clone().()).finishrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugSet<'a, 'b>`]finish().()
1304 }
1305 }
1306
1307 impl<'a, T> Iterrust-analyzer cargo hashbag 0.1.12 Iter#<'a, T> {
1308 fn newrust-analyzer cargo hashbag 0.1.12 impl#[`Iter<'a, T>`]new().(it: IterInnerrust-analyzer cargo hashbag 0.1.12 IterInner#<'a, T>, n: usize) -> Selfrust-analyzer cargo hashbag 0.1.12 impl#[`Iter<'a, T>`] {
1309 Selfrust-analyzer cargo hashbag 0.1.12 impl#[`Iter<'a, T>`] {
1310 iterrust-analyzer cargo hashbag 0.1.12 Iter#iter.: it,
1311 repeatrust-analyzer cargo hashbag 0.1.12 Iter#repeat.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
1312 leftrust-analyzer cargo hashbag 0.1.12 Iter#left.: n,
1313 }
1314 }
1315 }
1316
1317 impl<'a, T> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for Iterrust-analyzer cargo hashbag 0.1.12 Iter#<'a, T> {
1318 type Itemrust-analyzer cargo hashbag 0.1.12 impl#[`Iter<'a, T>`][Iterator]Item# = &'a T;
1319 fn nextrust-analyzer cargo hashbag 0.1.12 impl#[`Iter<'a, T>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo hashbag 0.1.12 impl#[`Iter<'a, T>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
1320 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((t, ref mut n)) = self.repeatrust-analyzer cargo hashbag 0.1.12 Iter#repeat. {
1321 if *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 {
1322 self.repeatrust-analyzer cargo hashbag 0.1.12 Iter#repeat. = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
1323 } else {
1324 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().1;
1325 self.leftrust-analyzer cargo hashbag 0.1.12 Iter#left. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().1;
1326 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(t);
1327 }
1328 }
1329
1330 let (next, n) = self.iterrust-analyzer cargo hashbag 0.1.12 Iter#iter..next()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/try_trait/Try#branch().;
1331 if *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#gt().1 {
1332 self.repeatrust-analyzer cargo hashbag 0.1.12 Iter#repeat. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((next, *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().1));
1333 }
1334 self.leftrust-analyzer cargo hashbag 0.1.12 Iter#left. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().1;
1335 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(next)
1336 }
1337
1338 fn size_hintrust-analyzer cargo hashbag 0.1.12 impl#[`Iter<'a, T>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) {
1339 (self.leftrust-analyzer cargo hashbag 0.1.12 Iter#left., Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.leftrust-analyzer cargo hashbag 0.1.12 Iter#left.))
1340 }
1341 }
1342
1343 /// An iterator over the distinct items of a `HashBag` and their occurrence counts.
1344 ///
1345 /// This `struct` is created by [`HashBag::set_iter`].
1346 /// See its documentation for more.
1347 pub struct SetIterrust-analyzer cargo hashbag 0.1.12 SetIter#<'a, T>(IterInnerrust-analyzer cargo hashbag 0.1.12 IterInner#<'a, T>);
1348
1349 impl<'a, T> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator# for SetIterrust-analyzer cargo hashbag 0.1.12 SetIter#<'a, T> where
1350 IterInnerrust-analyzer cargo hashbag 0.1.12 IterInner#<'a, T>: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator#
1351 {
1352 }
1353
1354 impl<'a, T> ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator# for SetIterrust-analyzer cargo hashbag 0.1.12 SetIter#<'a, T> where IterInnerrust-analyzer cargo hashbag 0.1.12 IterInner#<'a, T>: ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator# {}
1355
1356 impl<'a, T> Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# for SetIterrust-analyzer cargo hashbag 0.1.12 SetIter#<'a, T> {
1357 fn clonerust-analyzer cargo hashbag 0.1.12 impl#[`SetIter<'a, T>`][Clone]clone().(&self) -> Selfrust-analyzer cargo hashbag 0.1.12 impl#[`SetIter<'a, T>`][Clone] {
1358 SetIterrust-analyzer cargo hashbag 0.1.12 SetIter#(self.0rust-analyzer cargo hashbag 0.1.12 SetIter#0..clone())
1359 }
1360 }
1361
1362 impl<T: fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for SetIterrust-analyzer cargo hashbag 0.1.12 SetIter#<'_, T> {
1363 fn fmtrust-analyzer cargo hashbag 0.1.12 impl#[`SetIter<'_, T>`][Debug]fmt().(&self, fmt: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
1364 fmt.debug_setrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]debug_set().().entriesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugSet<'a, 'b>`]entries().(self.clonerust-analyzer cargo hashbag 0.1.12 impl#[`SetIter<'a, T>`][Clone]clone().()).finishrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugSet<'a, 'b>`]finish().()
1365 }
1366 }
1367
1368 impl<'a, T> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for SetIterrust-analyzer cargo hashbag 0.1.12 SetIter#<'a, T> {
1369 type Itemrust-analyzer cargo hashbag 0.1.12 impl#[`SetIter<'a, T>`][Iterator]Item# = (&'a T, usize);
1370 fn nextrust-analyzer cargo hashbag 0.1.12 impl#[`SetIter<'a, T>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo hashbag 0.1.12 impl#[`SetIter<'a, T>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
1371 self.0rust-analyzer cargo hashbag 0.1.12 SetIter#0..next().map(|(t, n)| (t, *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().n))
1372 }
1373
1374 fn size_hintrust-analyzer cargo hashbag 0.1.12 impl#[`SetIter<'a, T>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) {
1375 self.0rust-analyzer cargo hashbag 0.1.12 SetIter#0..size_hint()
1376 }
1377 }
1378
1379 #[cfg(feature = "amortize")]
1380 type IntoIterInnerrust-analyzer cargo hashbag 0.1.12 IntoIterInner#<T> = griddle::hash_map::IntoIter<T, usize>;
1381 #[cfg(not(feature = "amortize"))]
1382 type IntoIterInner<T> = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::hash_maprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash_map/::IntoIterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/IntoIter#<T, usize>;
1383
1384 /// An owning iterator over the distinct items of a `HashBag` and their occurrence counts.
1385 ///
1386 /// This `struct` is created by using the implementation of [`IntoIterator`] for [`HashBag`].
1387 pub struct IntoIterrust-analyzer cargo hashbag 0.1.12 IntoIter#<T>(IntoIterInnerrust-analyzer cargo hashbag 0.1.12 IntoIterInner#<T>);
1388
1389 impl<T> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator# for IntoIterrust-analyzer cargo hashbag 0.1.12 IntoIter#<T> where IntoIterInnerrust-analyzer cargo hashbag 0.1.12 IntoIterInner#<T>: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator# {}
1390
1391 impl<T> ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator# for IntoIterrust-analyzer cargo hashbag 0.1.12 IntoIter#<T> where IntoIterInnerrust-analyzer cargo hashbag 0.1.12 IntoIterInner#<T>: ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator# {}
1392
1393 impl<T: fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for IntoIterrust-analyzer cargo hashbag 0.1.12 IntoIter#<T> {
1394 fn fmtrust-analyzer cargo hashbag 0.1.12 impl#[`IntoIter<T>`][Debug]fmt().(&self, fmt: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
1395 self.0rust-analyzer cargo hashbag 0.1.12 IntoIter#0..fmt(fmt)
1396 }
1397 }
1398
1399 impl<T> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for IntoIterrust-analyzer cargo hashbag 0.1.12 IntoIter#<T> {
1400 type Itemrust-analyzer cargo hashbag 0.1.12 impl#[`IntoIter<T>`][Iterator]Item# = (T, usize);
1401 fn nextrust-analyzer cargo hashbag 0.1.12 impl#[`IntoIter<T>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo hashbag 0.1.12 impl#[`IntoIter<T>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
1402 self.0rust-analyzer cargo hashbag 0.1.12 IntoIter#0..next()
1403 }
1404
1405 fn size_hintrust-analyzer cargo hashbag 0.1.12 impl#[`IntoIter<T>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) {
1406 self.0rust-analyzer cargo hashbag 0.1.12 IntoIter#0..size_hint()
1407 }
1408 }
1409
1410 #[cfg(feature = "amortize")]
1411 type DrainInnerrust-analyzer cargo hashbag 0.1.12 DrainInner#<'a, T> = griddle::hash_map::Drain<'a, T, usize>;
1412 #[cfg(not(feature = "amortize"))]
1413 type DrainInner<'a, T> = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::hash_maprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash_map/::Drainrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/Drain#<'a, T, usize>;
1414
1415 /// An draining iterator over the distinct items of a `HashBag` and their occurrence counts.
1416 ///
1417 /// This `struct` is created by [`HashBag::drain`].
1418 /// See its documentation for more.
1419 pub struct Drainrust-analyzer cargo hashbag 0.1.12 Drain#<'a, T>(DrainInnerrust-analyzer cargo hashbag 0.1.12 DrainInner#<'a, T>);
1420
1421 impl<'a, T> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator# for Drainrust-analyzer cargo hashbag 0.1.12 Drain#<'a, T> where
1422 DrainInnerrust-analyzer cargo hashbag 0.1.12 DrainInner#<'a, T>: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator#
1423 {
1424 }
1425
1426 impl<'a, T> ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator# for Drainrust-analyzer cargo hashbag 0.1.12 Drain#<'a, T> where DrainInnerrust-analyzer cargo hashbag 0.1.12 DrainInner#<'a, T>: ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator# {}
1427
1428 impl<'a, T: fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for Drainrust-analyzer cargo hashbag 0.1.12 Drain#<'a, T> {
1429 fn fmtrust-analyzer cargo hashbag 0.1.12 impl#[`Drain<'a, T>`][Debug]fmt().(&self, fmt: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
1430 self.0rust-analyzer cargo hashbag 0.1.12 Drain#0..fmt(fmt)
1431 }
1432 }
1433
1434 impl<'a, T> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for Drainrust-analyzer cargo hashbag 0.1.12 Drain#<'a, T> {
1435 type Itemrust-analyzer cargo hashbag 0.1.12 impl#[`Drain<'a, T>`][Iterator]Item# = (T, usize);
1436 fn nextrust-analyzer cargo hashbag 0.1.12 impl#[`Drain<'a, T>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo hashbag 0.1.12 impl#[`Drain<'a, T>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
1437 self.0rust-analyzer cargo hashbag 0.1.12 Drain#0..next()
1438 }
1439
1440 fn size_hintrust-analyzer cargo hashbag 0.1.12 impl#[`Drain<'a, T>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) {
1441 self.0rust-analyzer cargo hashbag 0.1.12 Drain#0..size_hint()
1442 }
1443 }
1444
1445 #[cfg(test)]
1446 mod testsrust-analyzer cargo hashbag 0.1.12 tests/ {
1447 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#;
1448 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::FromIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/FromIterator#;
1449
1450 use superrust-analyzer cargo hashbag 0.1.12 crate/::*;
1451
1452 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1453 fn format_all_the_thingsrust-analyzer cargo hashbag 0.1.12 tests/format_all_the_things().() {
1454 let mut vikings: HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<&'static str> =
1455 ["Einar", "Olaf", "Harald"].iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1456 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{:?}", vikings);
1457 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{:?}", vikings.iterrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]iter().());
1458 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{:?}", vikings.set_iterrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]set_iter().());
1459 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{:?}", vikings.clonerust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`][Clone]clone().().into_iterrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`][IntoIterator]into_iter().());
1460 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{:?}", vikings.drainrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]drain().());
1461 }
1462
1463 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1464 fn sane_iteratorsrust-analyzer cargo hashbag 0.1.12 tests/sane_iterators().() {
1465 let mut vikings: HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<&'static str> =
1466 ["Einar", "Einar", "Harald"].iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1467 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(vikings.iterrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]iter().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 3);
1468 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(vikings.iterrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]iter().().size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#size_hint().(), (3, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(3)));
1469 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(vikings.iterrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]iter().().clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 3);
1470 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(vikings.set_iterrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]set_iter().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 2);
1471 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(vikings.set_iterrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]set_iter().().clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 2);
1472 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(vikings.set_iterrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]set_iter().().size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#size_hint().(), (2, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(2)));
1473 let ii = vikings.clonerust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`][Clone]clone().().into_iterrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`][IntoIterator]into_iter().();
1474 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ii.size_hintrust-analyzer cargo hashbag 0.1.12 impl#[`IntoIter<T>`][Iterator]size_hint().(), (2, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(2)));
1475 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ii.countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 2);
1476 let di = vikings.drainrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]drain().();
1477 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(di.size_hintrust-analyzer cargo hashbag 0.1.12 impl#[`Drain<'a, T>`][Iterator]size_hint().(), (2, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(2)));
1478 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(di.countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 2);
1479 }
1480
1481 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1482 fn test_difference_size_hintrust-analyzer cargo hashbag 0.1.12 tests/test_difference_size_hint().() {
1483 let bag: HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<_> = [3, 2, 1].iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1484 let empty_bag = HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#::newrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T>`]new().();
1485 let mut difference = bag.differencerust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]difference().(&empty_bag);
1486
1487 // Since the difference has the same number of entries as the bag, we
1488 // can predict how the size_hint() will behave, because the iteration
1489 // order does not matter
1490 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(difference.size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#size_hint().(), (0, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(3)));
1491 difference.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1492 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(difference.size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#size_hint().(), (0, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(2)));
1493 difference.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1494 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(difference.size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#size_hint().(), (0, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1)));
1495 difference.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1496 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(difference.size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#size_hint().(), (0, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0)));
1497 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(difference.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
1498 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(difference.size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#size_hint().(), (0, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0)));
1499 }
1500
1501 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1502 fn test_difference_from_emptyrust-analyzer cargo hashbag 0.1.12 tests/test_difference_from_empty().() {
1503 do_test_differencerust-analyzer cargo hashbag 0.1.12 tests/do_test_difference().(&[], &[], &[]);
1504 do_test_differencerust-analyzer cargo hashbag 0.1.12 tests/do_test_difference().(&[], &[1], &[]);
1505 do_test_differencerust-analyzer cargo hashbag 0.1.12 tests/do_test_difference().(&[], &[1, 1], &[]);
1506 do_test_differencerust-analyzer cargo hashbag 0.1.12 tests/do_test_difference().(&[], &[1, 1, 2], &[]);
1507 }
1508
1509 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1510 fn test_difference_from_onerust-analyzer cargo hashbag 0.1.12 tests/test_difference_from_one().() {
1511 do_test_differencerust-analyzer cargo hashbag 0.1.12 tests/do_test_difference().(&[1], &[], &[1]);
1512 do_test_differencerust-analyzer cargo hashbag 0.1.12 tests/do_test_difference().(&[1], &[1], &[]);
1513 do_test_differencerust-analyzer cargo hashbag 0.1.12 tests/do_test_difference().(&[1], &[1, 1], &[]);
1514 do_test_differencerust-analyzer cargo hashbag 0.1.12 tests/do_test_difference().(&[1], &[2], &[1]);
1515 do_test_differencerust-analyzer cargo hashbag 0.1.12 tests/do_test_difference().(&[1], &[1, 2], &[]);
1516 do_test_differencerust-analyzer cargo hashbag 0.1.12 tests/do_test_difference().(&[1], &[2, 2], &[1]);
1517 }
1518
1519 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1520 fn test_difference_from_duplicate_onesrust-analyzer cargo hashbag 0.1.12 tests/test_difference_from_duplicate_ones().() {
1521 do_test_differencerust-analyzer cargo hashbag 0.1.12 tests/do_test_difference().(&[1, 1], &[], &[1, 1]);
1522 do_test_differencerust-analyzer cargo hashbag 0.1.12 tests/do_test_difference().(&[1, 1], &[1], &[1]);
1523 do_test_differencerust-analyzer cargo hashbag 0.1.12 tests/do_test_difference().(&[1, 1], &[1, 1], &[]);
1524 do_test_differencerust-analyzer cargo hashbag 0.1.12 tests/do_test_difference().(&[1, 1], &[2], &[1, 1]);
1525 do_test_differencerust-analyzer cargo hashbag 0.1.12 tests/do_test_difference().(&[1, 1], &[1, 2], &[1]);
1526 do_test_differencerust-analyzer cargo hashbag 0.1.12 tests/do_test_difference().(&[1, 1], &[2, 2], &[1, 1]);
1527 }
1528
1529 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1530 fn test_difference_from_one_one_tworust-analyzer cargo hashbag 0.1.12 tests/test_difference_from_one_one_two().() {
1531 do_test_differencerust-analyzer cargo hashbag 0.1.12 tests/do_test_difference().(&[1, 1, 2], &[], &[1, 1, 2]);
1532 do_test_differencerust-analyzer cargo hashbag 0.1.12 tests/do_test_difference().(&[1, 1, 2], &[1], &[1, 2]);
1533 do_test_differencerust-analyzer cargo hashbag 0.1.12 tests/do_test_difference().(&[1, 1, 2], &[1, 1], &[2]);
1534 do_test_differencerust-analyzer cargo hashbag 0.1.12 tests/do_test_difference().(&[1, 1, 2], &[2], &[1, 1]);
1535 do_test_differencerust-analyzer cargo hashbag 0.1.12 tests/do_test_difference().(&[1, 1, 2], &[1, 2], &[1]);
1536 do_test_differencerust-analyzer cargo hashbag 0.1.12 tests/do_test_difference().(&[1, 1, 2], &[2, 2], &[1, 1]);
1537 }
1538
1539 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1540 fn test_difference_from_larger_bagsrust-analyzer cargo hashbag 0.1.12 tests/test_difference_from_larger_bags().() {
1541 do_test_differencerust-analyzer cargo hashbag 0.1.12 tests/do_test_difference().(&[1, 2, 2, 3], &[3], &[1, 2, 2]);
1542 do_test_differencerust-analyzer cargo hashbag 0.1.12 tests/do_test_difference().(&[1, 2, 2, 3], &[4], &[1, 2, 2, 3]);
1543 do_test_differencerust-analyzer cargo hashbag 0.1.12 tests/do_test_difference().(&[2, 2, 2, 2], &[2, 2], &[2, 2]);
1544 do_test_differencerust-analyzer cargo hashbag 0.1.12 tests/do_test_difference().(&[2, 2, 2, 2], &[], &[2, 2, 2, 2]);
1545 }
1546
1547 fn do_test_differencerust-analyzer cargo hashbag 0.1.12 tests/do_test_difference().(
1548 self_entries: &[isize],
1549 other_entries: &[isize],
1550 expected_entries: &[isize],
1551 ) {
1552 let this = self_entries.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<_>>();
1553 let other = other_entries.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<_>>();
1554 let expected = expected_entries.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<_>>();
1555 let mut actual = HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#::newrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T>`]new().();
1556 for (t, n) in this.differencerust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]difference().(&other) {
1557 actual.insert_manyrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]insert_many().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().t, n);
1558 }
1559
1560 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(actual, expected);
1561 }
1562
1563 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1564 fn test_outer_join_order_with_disjoint_setsrust-analyzer cargo hashbag 0.1.12 tests/test_outer_join_order_with_disjoint_sets().() {
1565 do_test_outer_join_orderrust-analyzer cargo hashbag 0.1.12 tests/do_test_outer_join_order().(&[1, 2, 3], &[4, 5, 6]);
1566 do_test_outer_join_orderrust-analyzer cargo hashbag 0.1.12 tests/do_test_outer_join_order().(&[1, 2, 2, 3], &[4, 4, 5, 6]);
1567 }
1568
1569 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1570 fn test_outer_join_order_with_overlaprust-analyzer cargo hashbag 0.1.12 tests/test_outer_join_order_with_overlap().() {
1571 do_test_outer_join_orderrust-analyzer cargo hashbag 0.1.12 tests/do_test_outer_join_order().(&[1, 2, 3], &[2, 3, 4]);
1572 do_test_outer_join_orderrust-analyzer cargo hashbag 0.1.12 tests/do_test_outer_join_order().(&[1, 1, 2, 3], &[2, 3, 3, 3, 4]);
1573 }
1574
1575 fn do_test_outer_join_orderrust-analyzer cargo hashbag 0.1.12 tests/do_test_outer_join_order().(this: &[usize], other: &[usize]) {
1576 let this_hashbag: HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<usize> = this.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1577 let other_hashbag: HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<usize> = other.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1578
1579 // Assert that the first yielded key that's exclusive to other (i.e. self_count is 0)
1580 // comes AFTER all of the keys in self
1581 let min_other_exclusive_key_idx = this_hashbag
1582 .outer_joinrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]outer_join().(&other_hashbag)
1583 .enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().()
1584 .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#find().(|(_, (_, self_count, _))| self_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().&0)
1585 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|(idx, _)| idx);
1586 // If no such element exists that means all of the keys in other
1587 // are in self so there's no thing to assert.
1588 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(idx) = min_other_exclusive_key_idx {
1589 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(idx, this_hashbag.set_lenrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]set_len().());
1590 }
1591 }
1592
1593 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1594 fn test_outer_join_with_empty_selfrust-analyzer cargo hashbag 0.1.12 tests/test_outer_join_with_empty_self().() {
1595 do_test_outer_joinrust-analyzer cargo hashbag 0.1.12 tests/do_test_outer_join().(&[], &[1, 2, 2, 3], &[(&1, 0, 1), (&2, 0, 2), (&3, 0, 1)]);
1596 }
1597
1598 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1599 fn test_outer_join_with_empty_otherrust-analyzer cargo hashbag 0.1.12 tests/test_outer_join_with_empty_other().() {
1600 do_test_outer_joinrust-analyzer cargo hashbag 0.1.12 tests/do_test_outer_join().(&[1, 2, 2, 3], &[], &[(&1, 1, 0), (&2, 2, 0), (&3, 1, 0)]);
1601 }
1602
1603 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1604 fn test_outer_join_with_overlaprust-analyzer cargo hashbag 0.1.12 tests/test_outer_join_with_overlap().() {
1605 do_test_outer_joinrust-analyzer cargo hashbag 0.1.12 tests/do_test_outer_join().(
1606 &[1, 2, 2, 3, 3],
1607 &[3, 4, 5, 5],
1608 &[(&1, 1, 0), (&2, 2, 0), (&3, 2, 1), (&4, 0, 1), (&5, 0, 2)],
1609 );
1610 }
1611
1612 fn do_test_outer_joinrust-analyzer cargo hashbag 0.1.12 tests/do_test_outer_join().(
1613 this: &[usize],
1614 other: &[usize],
1615 expected_entries: &[(&usize, usize, usize)],
1616 ) {
1617 let this_hashbag: HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<_> = this.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1618 let other_hashbag: HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<_> = other.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1619 let expected: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<_> = HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::from_iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S>`][`FromIterator<T>`]from_iter().(expected_entries.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().());
1620 let actual: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<_> = this_hashbag.outer_joinrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]outer_join().(&other_hashbag).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1621 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, actual);
1622 }
1623
1624 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1625 fn test_not_in_with_empty_selfrust-analyzer cargo hashbag 0.1.12 tests/test_not_in_with_empty_self().() {
1626 do_test_not_inrust-analyzer cargo hashbag 0.1.12 tests/do_test_not_in().(&[], &[1, 2, 3, 3], &[]);
1627 }
1628
1629 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1630 fn test_not_in_with_empty_otherrust-analyzer cargo hashbag 0.1.12 tests/test_not_in_with_empty_other().() {
1631 do_test_not_inrust-analyzer cargo hashbag 0.1.12 tests/do_test_not_in().(&[1, 2, 3, 3], &[], &[1, 2, 3, 3]);
1632 }
1633
1634 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1635 fn test_not_in_with_overlaprust-analyzer cargo hashbag 0.1.12 tests/test_not_in_with_overlap().() {
1636 do_test_not_inrust-analyzer cargo hashbag 0.1.12 tests/do_test_not_in().(&[1, 2, 3, 3], &[2, 4], &[1, 3, 3]);
1637 }
1638
1639 fn do_test_not_inrust-analyzer cargo hashbag 0.1.12 tests/do_test_not_in().(this: &[usize], other: &[usize], expected_entries: &[usize]) {
1640 let this_hashbag: HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<_> = this.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1641 let other_hashbag: HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<_> = other.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1642 let expected: HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<_> = expected_entries.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1643 let actual: HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<_> =
1644 this_hashbag
1645 .not_inrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]not_in().(&other_hashbag)
1646 .foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#fold().(HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#::newrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T>`]new().(), |mut bag, (k, count)| {
1647 bag.insert_manyrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]insert_many().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().k, count);
1648 bag
1649 });
1650 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, actual);
1651 }
1652
1653 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1654 fn test_signed_difference_with_empty_selfrust-analyzer cargo hashbag 0.1.12 tests/test_signed_difference_with_empty_self().() {
1655 do_test_signed_differencerust-analyzer cargo hashbag 0.1.12 tests/do_test_signed_difference().(&[], &[1, 2, 2, 3], &[(&1, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][Neg]neg().1), (&2, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][Neg]neg().2), (&3, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][Neg]neg().1)]);
1656 }
1657
1658 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1659 fn test_signed_difference_with_empty_otherrust-analyzer cargo hashbag 0.1.12 tests/test_signed_difference_with_empty_other().() {
1660 do_test_signed_differencerust-analyzer cargo hashbag 0.1.12 tests/do_test_signed_difference().(&[1, 2, 2, 3], &[], &[(&1, 1), (&2, 2), (&3, 1)]);
1661 }
1662
1663 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1664 fn test_signed_difference_with_overlaprust-analyzer cargo hashbag 0.1.12 tests/test_signed_difference_with_overlap().() {
1665 do_test_signed_differencerust-analyzer cargo hashbag 0.1.12 tests/do_test_signed_difference().(
1666 &[1, 2, 2, 3, 3],
1667 &[3, 4, 5, 5],
1668 &[(&1, 1), (&2, 2), (&3, 1), (&4, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][Neg]neg().1), (&5, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][Neg]neg().2)],
1669 );
1670 }
1671
1672 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1673 fn test_signed_difference_with_both_largerust-analyzer cargo hashbag 0.1.12 tests/test_signed_difference_with_both_large().() {
1674 let mut this_hashbag = HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#::newrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T>`]new().();
1675 let mut other_hashbag = HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#::newrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T>`]new().();
1676
1677 let large_count = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::isizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/isize/::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/isize/MAX. as usize;
1678 this_hashbag.insert_manyrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]insert_many().(1, large_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1000);
1679 other_hashbag.insert_manyrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]insert_many().(1, large_count);
1680
1681 let expected: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<_> = HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::from_iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S>`][`FromIterator<T>`]from_iter().([(&1, 1000)].iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().());
1682 let actual: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<_> = this_hashbag.signed_differencerust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]signed_difference().(&other_hashbag).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1683 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, actual);
1684
1685 // and in reverse:
1686 let expected: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<_> = HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::from_iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S>`][`FromIterator<T>`]from_iter().([(&1, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][Neg]neg().1000)].iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().());
1687 let actual: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<_> = other_hashbag.signed_differencerust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]signed_difference().(&this_hashbag).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1688 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, actual);
1689 }
1690
1691 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1692 fn test_signed_difference_too_large_to_hold_clamprust-analyzer cargo hashbag 0.1.12 tests/test_signed_difference_too_large_to_hold_clamp().() {
1693 let mut this_hashbag = HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#::newrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T>`]new().();
1694 let empty_hashbag = HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#::newrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T>`]new().();
1695
1696 let large_count = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::isizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/isize/::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/isize/MAX. as usize;
1697 this_hashbag.insert_manyrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]insert_many().(1, large_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1000);
1698
1699 let expected: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<_> = HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::from_iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S>`][`FromIterator<T>`]from_iter().([(&1, stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::isizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/isize/::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/isize/MAX.)].iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().());
1700 let actual: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<_> = this_hashbag.signed_differencerust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]signed_difference().(&empty_hashbag).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1701 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, actual);
1702
1703 // and in reverse:
1704 let expected: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<_> = HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::from_iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S>`][`FromIterator<T>`]from_iter().([(&1, stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::isizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/isize/::MINrust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/isize/MIN.)].iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().());
1705 let actual: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<_> = empty_hashbag.signed_differencerust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]signed_difference().(&this_hashbag).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1706 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, actual);
1707 }
1708
1709 fn do_test_signed_differencerust-analyzer cargo hashbag 0.1.12 tests/do_test_signed_difference().(
1710 this: &[usize],
1711 other: &[usize],
1712 expected_entries: &[(&usize, isize)],
1713 ) {
1714 let this_hashbag: HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<_> = this.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1715 let other_hashbag: HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#<_> = other.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1716 let expected: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<_> = HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::from_iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S>`][`FromIterator<T>`]from_iter().(expected_entries.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().());
1717 let actual: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<_> = this_hashbag.signed_differencerust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]signed_difference().(&other_hashbag).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1718 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, actual);
1719 }
1720
1721 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1722 fn test_no_zeros_countsrust-analyzer cargo hashbag 0.1.12 tests/test_no_zeros_counts().() {
1723 let mut hashbag = HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#::newrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T>`]new().();
1724 hashbag.insertrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]insert().(100);
1725 hashbag.retainrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]retain().(|_, _| 0);
1726 hashbag.insert_manyrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]insert_many().(1, 0);
1727 hashbag.extendrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`][`Extend<(T, usize)>`]extend().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![(2, 0)]);
1728 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(hashbag.lenrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]len().(), 0);
1729 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(hashbag.iterrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]iter().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 0);
1730 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(hashbag.set_lenrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]set_len().(), 0);
1731 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(hashbag.set_iterrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]set_iter().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 0);
1732 }
1733
1734 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1735 fn remove_up_to_affects_countrust-analyzer cargo hashbag 0.1.12 tests/remove_up_to_affects_count().() {
1736 let mut bag = HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#::newrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T>`]new().();
1737 bag.insert_manyrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]insert_many().(42, 3);
1738 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(bag.lenrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]len().(), 3);
1739 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(bag.remove_up_torust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]remove_up_to().(&0, 1), 0);
1740 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(bag.lenrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]len().(), 3);
1741 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(bag.remove_up_torust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]remove_up_to().(&42, 1), 2);
1742 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(bag.lenrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]len().(), 2);
1743 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(bag.remove_up_torust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]remove_up_to().(&42, 10), 0);
1744 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(bag.lenrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]len().(), 0);
1745 }
1746
1747 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1748 fn entry_inserts_valuesrust-analyzer cargo hashbag 0.1.12 tests/entry_inserts_values().() {
1749 let mut bag = HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#::newrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T>`]new().();
1750 bag.entryrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]entry().(42);
1751 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(bag.containsrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]contains().(&42), 0);
1752 bag.entryrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]entry().(84).or_insert_manyrust-analyzer cargo hashbag 0.1.12 impl#[`Entry<'a, T, S>`]or_insert_many().(3);
1753 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(bag.containsrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]contains().(&84), 3);
1754 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(bag.lenrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]len().(), 3);
1755 bag.entryrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]entry().(84).or_insert_manyrust-analyzer cargo hashbag 0.1.12 impl#[`Entry<'a, T, S>`]or_insert_many().(2);
1756 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(bag.lenrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]len().(), 3);
1757 bag.entryrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]entry().(84).or_insertrust-analyzer cargo hashbag 0.1.12 impl#[`Entry<'a, T, S>`]or_insert().();
1758 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(bag.lenrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]len().(), 3);
1759 }
1760
1761 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1762 fn entry_affects_countrust-analyzer cargo hashbag 0.1.12 tests/entry_affects_count().() {
1763 let mut bag = HashBagrust-analyzer cargo hashbag 0.1.12 HashBag#::newrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T>`]new().();
1764 bag.entryrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]entry().(42);
1765 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(bag.lenrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]len().(), 0);
1766 bag.entryrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]entry().(42).and_modifyrust-analyzer cargo hashbag 0.1.12 impl#[`Entry<'a, T, S>`]and_modify().(|n| *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().3);
1767 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(bag.lenrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]len().(), 0);
1768 bag.entryrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]entry().(42).or_insert_manyrust-analyzer cargo hashbag 0.1.12 impl#[`Entry<'a, T, S>`]or_insert_many().(3);
1769 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(bag.lenrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]len().(), 3);
1770 bag.entryrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]entry().(42).and_modifyrust-analyzer cargo hashbag 0.1.12 impl#[`Entry<'a, T, S>`]and_modify().(|n| *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().3);
1771 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(bag.lenrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]len().(), 6);
1772 bag.entryrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]entry().(84).or_insertrust-analyzer cargo hashbag 0.1.12 impl#[`Entry<'a, T, S>`]or_insert().();
1773 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(bag.lenrust-analyzer cargo hashbag 0.1.12 impl#[`HashBag<T, S>`]len().(), 7);
1774 }
1775 }