@@ -120,7 +120,7 @@ where
120
120
/// assert_eq!(table.capacity(), 0);
121
121
///
122
122
/// // Now we insert element inside created HashTable
123
- /// table.insert_unchecked (hasher(&"One"), "One", hasher);
123
+ /// table.insert_unique (hasher(&"One"), "One", hasher);
124
124
/// // We can see that the HashTable holds 1 element
125
125
/// assert_eq!(table.len(), 1);
126
126
/// // And it also allocates some capacity
@@ -164,11 +164,11 @@ where
164
164
/// assert!(empty_map_capacity >= 5);
165
165
///
166
166
/// // Now we insert some 5 elements inside created HashTable
167
- /// table.insert_unchecked (hasher(&"One"), "One", hasher);
168
- /// table.insert_unchecked (hasher(&"Two"), "Two", hasher);
169
- /// table.insert_unchecked (hasher(&"Three"), "Three", hasher);
170
- /// table.insert_unchecked (hasher(&"Four"), "Four", hasher);
171
- /// table.insert_unchecked (hasher(&"Five"), "Five", hasher);
167
+ /// table.insert_unique (hasher(&"One"), "One", hasher);
168
+ /// table.insert_unique (hasher(&"Two"), "Two", hasher);
169
+ /// table.insert_unique (hasher(&"Three"), "Three", hasher);
170
+ /// table.insert_unique (hasher(&"Four"), "Four", hasher);
171
+ /// table.insert_unique (hasher(&"Five"), "Five", hasher);
172
172
///
173
173
/// // We can see that the HashTable holds 5 elements
174
174
/// assert_eq!(table.len(), 5);
@@ -210,9 +210,9 @@ where
210
210
/// let mut table = HashTable::new();
211
211
/// let hasher = BuildHasherDefault::<AHasher>::default();
212
212
/// let hasher = |val: &_| hasher.hash_one(val);
213
- /// table.insert_unchecked (hasher(&1), 1, hasher);
214
- /// table.insert_unchecked (hasher(&2), 2, hasher);
215
- /// table.insert_unchecked (hasher(&3), 3, hasher);
213
+ /// table.insert_unique (hasher(&1), 1, hasher);
214
+ /// table.insert_unique (hasher(&2), 2, hasher);
215
+ /// table.insert_unique (hasher(&3), 3, hasher);
216
216
/// assert_eq!(table.find(hasher(&2), |&val| val == 2), Some(&2));
217
217
/// assert_eq!(table.find(hasher(&4), |&val| val == 4), None);
218
218
/// # }
@@ -250,7 +250,7 @@ where
250
250
/// let mut table = HashTable::new();
251
251
/// let hasher = BuildHasherDefault::<AHasher>::default();
252
252
/// let hasher = |val: &_| hasher.hash_one(val);
253
- /// table.insert_unchecked (hasher(&1), (1, "a"), |val| hasher(&val.0));
253
+ /// table.insert_unique (hasher(&1), (1, "a"), |val| hasher(&val.0));
254
254
/// if let Some(val) = table.find_mut(hasher(&1), |val| val.0 == 1) {
255
255
/// val.1 = "b";
256
256
/// }
@@ -291,7 +291,7 @@ where
291
291
/// let mut table = HashTable::new();
292
292
/// let hasher = BuildHasherDefault::<AHasher>::default();
293
293
/// let hasher = |val: &_| hasher.hash_one(val);
294
- /// table.insert_unchecked (hasher(&1), (1, "a"), |val| hasher(&val.0));
294
+ /// table.insert_unique (hasher(&1), (1, "a"), |val| hasher(&val.0));
295
295
/// if let Ok(entry) = table.find_entry(hasher(&1), |val| val.0 == 1) {
296
296
/// entry.remove();
297
297
/// }
@@ -346,7 +346,7 @@ where
346
346
/// let mut table = HashTable::new();
347
347
/// let hasher = BuildHasherDefault::<AHasher>::default();
348
348
/// let hasher = |val: &_| hasher.hash_one(val);
349
- /// table.insert_unchecked (hasher(&1), (1, "a"), |val| hasher(&val.0));
349
+ /// table.insert_unique (hasher(&1), (1, "a"), |val| hasher(&val.0));
350
350
/// if let Entry::Occupied(entry) = table.entry(hasher(&1), |val| val.0 == 1, |val| hasher(&val.0))
351
351
/// {
352
352
/// entry.remove();
@@ -386,11 +386,29 @@ where
386
386
/// without checking whether an equivalent element already exists within the
387
387
/// table.
388
388
///
389
- /// This is
390
- ///
391
389
/// `hasher` is called if entries need to be moved or copied to a new table.
392
390
/// This must return the same hash value that each entry was inserted with.
393
- pub fn insert_unchecked (
391
+ ///
392
+ /// # Examples
393
+ ///
394
+ /// ```
395
+ /// # #[cfg(feature = "nightly")]
396
+ /// # fn test() {
397
+ /// use ahash::AHasher;
398
+ /// use hashbrown::HashTable;
399
+ /// use std::hash::{BuildHasher, BuildHasherDefault};
400
+ ///
401
+ /// let mut v = HashTable::new();
402
+ /// let hasher = BuildHasherDefault::<AHasher>::default();
403
+ /// let hasher = |val: &_| hasher.hash_one(val);
404
+ /// v.insert_unique(hasher(&1), 1, hasher);
405
+ /// # }
406
+ /// # fn main() {
407
+ /// # #[cfg(feature = "nightly")]
408
+ /// # test()
409
+ /// # }
410
+ /// ```
411
+ pub fn insert_unique (
394
412
& mut self ,
395
413
hash : u64 ,
396
414
value : T ,
@@ -418,7 +436,7 @@ where
418
436
/// let mut v = HashTable::new();
419
437
/// let hasher = BuildHasherDefault::<AHasher>::default();
420
438
/// let hasher = |val: &_| hasher.hash_one(val);
421
- /// v.insert_unchecked (hasher(&1), 1, hasher);
439
+ /// v.insert_unique (hasher(&1), 1, hasher);
422
440
/// v.clear();
423
441
/// assert!(v.is_empty());
424
442
/// # }
@@ -450,8 +468,8 @@ where
450
468
/// let mut table = HashTable::with_capacity(100);
451
469
/// let hasher = BuildHasherDefault::<AHasher>::default();
452
470
/// let hasher = |val: &_| hasher.hash_one(val);
453
- /// table.insert_unchecked (hasher(&1), 1, hasher);
454
- /// table.insert_unchecked (hasher(&2), 2, hasher);
471
+ /// table.insert_unique (hasher(&1), 1, hasher);
472
+ /// table.insert_unique (hasher(&2), 2, hasher);
455
473
/// assert!(table.capacity() >= 100);
456
474
/// table.shrink_to_fit(hasher);
457
475
/// assert!(table.capacity() >= 2);
@@ -487,8 +505,8 @@ where
487
505
/// let mut table = HashTable::with_capacity(100);
488
506
/// let hasher = BuildHasherDefault::<AHasher>::default();
489
507
/// let hasher = |val: &_| hasher.hash_one(val);
490
- /// table.insert_unchecked (hasher(&1), 1, hasher);
491
- /// table.insert_unchecked (hasher(&2), 2, hasher);
508
+ /// table.insert_unique (hasher(&1), 1, hasher);
509
+ /// table.insert_unique (hasher(&2), 2, hasher);
492
510
/// assert!(table.capacity() >= 100);
493
511
/// table.shrink_to(10, hasher);
494
512
/// assert!(table.capacity() >= 10);
@@ -613,7 +631,7 @@ where
613
631
/// let hasher = |val: &_| hasher.hash_one(val);
614
632
/// let mut v = HashTable::new();
615
633
/// assert_eq!(v.len(), 0);
616
- /// v.insert_unchecked (hasher(&1), 1, hasher);
634
+ /// v.insert_unique (hasher(&1), 1, hasher);
617
635
/// assert_eq!(v.len(), 1);
618
636
/// # }
619
637
/// # fn main() {
@@ -640,7 +658,7 @@ where
640
658
/// let hasher = |val: &_| hasher.hash_one(val);
641
659
/// let mut v = HashTable::new();
642
660
/// assert!(v.is_empty());
643
- /// v.insert_unchecked (hasher(&1), 1, hasher);
661
+ /// v.insert_unique (hasher(&1), 1, hasher);
644
662
/// assert!(!v.is_empty());
645
663
/// # }
646
664
/// # fn main() {
@@ -667,8 +685,8 @@ where
667
685
/// let mut table = HashTable::new();
668
686
/// let hasher = BuildHasherDefault::<AHasher>::default();
669
687
/// let hasher = |val: &_| hasher.hash_one(val);
670
- /// table.insert_unchecked (hasher(&"a"), "b", hasher);
671
- /// table.insert_unchecked (hasher(&"b"), "b", hasher);
688
+ /// table.insert_unique (hasher(&"a"), "b", hasher);
689
+ /// table.insert_unique (hasher(&"b"), "b", hasher);
672
690
///
673
691
/// // Will print in an arbitrary order.
674
692
/// for x in table.iter() {
@@ -703,9 +721,9 @@ where
703
721
/// let mut table = HashTable::new();
704
722
/// let hasher = BuildHasherDefault::<AHasher>::default();
705
723
/// let hasher = |val: &_| hasher.hash_one(val);
706
- /// table.insert_unchecked (hasher(&1), 1, hasher);
707
- /// table.insert_unchecked (hasher(&2), 2, hasher);
708
- /// table.insert_unchecked (hasher(&3), 3, hasher);
724
+ /// table.insert_unique (hasher(&1), 1, hasher);
725
+ /// table.insert_unique (hasher(&2), 2, hasher);
726
+ /// table.insert_unique (hasher(&3), 3, hasher);
709
727
///
710
728
/// // Update all values
711
729
/// for val in table.iter_mut() {
@@ -756,7 +774,7 @@ where
756
774
/// let hasher = BuildHasherDefault::<AHasher>::default();
757
775
/// let hasher = |val: &_| hasher.hash_one(val);
758
776
/// for x in 1..=6 {
759
- /// table.insert_unchecked (hasher(&x), x, hasher);
777
+ /// table.insert_unique (hasher(&x), x, hasher);
760
778
/// }
761
779
/// table.retain(|&mut x| x % 2 == 0);
762
780
/// assert_eq!(table.len(), 3);
@@ -792,7 +810,7 @@ where
792
810
/// let hasher = BuildHasherDefault::<AHasher>::default();
793
811
/// let hasher = |val: &_| hasher.hash_one(val);
794
812
/// for x in 1..=3 {
795
- /// table.insert_unchecked (hasher(&x), x, hasher);
813
+ /// table.insert_unique (hasher(&x), x, hasher);
796
814
/// }
797
815
/// assert!(!table.is_empty());
798
816
///
@@ -837,7 +855,7 @@ where
837
855
/// let hasher = BuildHasherDefault::<AHasher>::default();
838
856
/// let hasher = |val: &_| hasher.hash_one(val);
839
857
/// for x in 0..8 {
840
- /// table.insert_unchecked (hasher(&x), x, hasher);
858
+ /// table.insert_unique (hasher(&x), x, hasher);
841
859
/// }
842
860
/// let drained: Vec<i32> = table.extract_if(|&mut v| v % 2 == 0).collect();
843
861
///
@@ -895,7 +913,7 @@ where
895
913
/// ("Herzogin-Anna-Amalia-Bibliothek", 1691),
896
914
/// ("Library of Congress", 1800),
897
915
/// ] {
898
- /// libraries.insert_unchecked (hasher(&k), (k, v), |(k, _)| hasher(&k));
916
+ /// libraries.insert_unique (hasher(&k), (k, v), |(k, _)| hasher(&k));
899
917
/// }
900
918
///
901
919
/// let keys = ["Athenæum", "Library of Congress"];
@@ -965,7 +983,7 @@ where
965
983
/// ("Herzogin-Anna-Amalia-Bibliothek", 1691),
966
984
/// ("Library of Congress", 1800),
967
985
/// ] {
968
- /// libraries.insert_unchecked (hasher(&k), (k, v), |(k, _)| hasher(&k));
986
+ /// libraries.insert_unique (hasher(&k), (k, v), |(k, _)| hasher(&k));
969
987
/// }
970
988
///
971
989
/// let keys = ["Athenæum", "Library of Congress"];
@@ -1090,7 +1108,7 @@ where
1090
1108
/// let hasher = BuildHasherDefault::<AHasher>::default();
1091
1109
/// let hasher = |val: &_| hasher.hash_one(val);
1092
1110
/// for x in ["a", "b", "c"] {
1093
- /// table.insert_unchecked (hasher(&x), x, hasher);
1111
+ /// table.insert_unique (hasher(&x), x, hasher);
1094
1112
/// }
1095
1113
/// assert_eq!(table.len(), 3);
1096
1114
///
@@ -1142,7 +1160,7 @@ where
1142
1160
/// let hasher = BuildHasherDefault::<AHasher>::default();
1143
1161
/// let hasher = |val: &_| hasher.hash_one(val);
1144
1162
/// for x in ["a", "b"] {
1145
- /// table.insert_unchecked (hasher(&x), x, hasher);
1163
+ /// table.insert_unique (hasher(&x), x, hasher);
1146
1164
/// }
1147
1165
///
1148
1166
/// match table.entry(hasher(&"a"), |&x| x == "a", hasher) {
@@ -1394,7 +1412,7 @@ where
1394
1412
/// let hasher = BuildHasherDefault::<AHasher>::default();
1395
1413
/// let hasher = |val: &_| hasher.hash_one(val);
1396
1414
/// for x in ["a", "b", "c"] {
1397
- /// table.insert_unchecked (hasher(&x), x, hasher);
1415
+ /// table.insert_unique (hasher(&x), x, hasher);
1398
1416
/// }
1399
1417
/// assert_eq!(table.len(), 3);
1400
1418
///
@@ -1480,7 +1498,7 @@ where
1480
1498
/// // The table is empty
1481
1499
/// assert!(table.is_empty() && table.capacity() == 0);
1482
1500
///
1483
- /// table.insert_unchecked (hasher(&"poneyland"), "poneyland", hasher);
1501
+ /// table.insert_unique (hasher(&"poneyland"), "poneyland", hasher);
1484
1502
/// let capacity_before_remove = table.capacity();
1485
1503
///
1486
1504
/// if let Entry::Occupied(o) = table.entry(hasher(&"poneyland"), |&x| x == "poneyland", hasher) {
@@ -1525,7 +1543,7 @@ where
1525
1543
/// let mut table: HashTable<&str> = HashTable::new();
1526
1544
/// let hasher = BuildHasherDefault::<AHasher>::default();
1527
1545
/// let hasher = |val: &_| hasher.hash_one(val);
1528
- /// table.insert_unchecked (hasher(&"poneyland"), "poneyland", hasher);
1546
+ /// table.insert_unique (hasher(&"poneyland"), "poneyland", hasher);
1529
1547
///
1530
1548
/// match table.entry(hasher(&"poneyland"), |&x| x == "poneyland", hasher) {
1531
1549
/// Entry::Vacant(_) => panic!(),
@@ -1561,7 +1579,7 @@ where
1561
1579
/// let mut table: HashTable<(&str, u32)> = HashTable::new();
1562
1580
/// let hasher = BuildHasherDefault::<AHasher>::default();
1563
1581
/// let hasher = |val: &_| hasher.hash_one(val);
1564
- /// table.insert_unchecked (hasher(&"poneyland"), ("poneyland", 12), |(k, _)| hasher(&k));
1582
+ /// table.insert_unique (hasher(&"poneyland"), ("poneyland", 12), |(k, _)| hasher(&k));
1565
1583
///
1566
1584
/// assert_eq!(
1567
1585
/// table.find(hasher(&"poneyland"), |&(x, _)| x == "poneyland",),
@@ -1614,7 +1632,7 @@ where
1614
1632
/// let mut table: HashTable<(&str, u32)> = HashTable::new();
1615
1633
/// let hasher = BuildHasherDefault::<AHasher>::default();
1616
1634
/// let hasher = |val: &_| hasher.hash_one(val);
1617
- /// table.insert_unchecked (hasher(&"poneyland"), ("poneyland", 12), |(k, _)| hasher(&k));
1635
+ /// table.insert_unique (hasher(&"poneyland"), ("poneyland", 12), |(k, _)| hasher(&k));
1618
1636
///
1619
1637
/// assert_eq!(
1620
1638
/// table.find(hasher(&"poneyland"), |&(x, _)| x == "poneyland",),
@@ -1786,7 +1804,7 @@ where
1786
1804
/// let entry_v: AbsentEntry<_, _> = table.find_entry(hasher(&"a"), |&x| x == "a").unwrap_err();
1787
1805
/// entry_v
1788
1806
/// .into_table()
1789
- /// .insert_unchecked (hasher(&"a"), "a", hasher);
1807
+ /// .insert_unique (hasher(&"a"), "a", hasher);
1790
1808
/// assert!(table.find(hasher(&"a"), |&x| x == "a").is_some() && table.len() == 1);
1791
1809
///
1792
1810
/// // Nonexistent key (insert)
0 commit comments