@@ -313,7 +313,7 @@ where
313
313
314
314
impl < K , V , const N : usize > Clone for CoreMap < K , V , N >
315
315
where
316
- K : Eq + Hash + Clone ,
316
+ K : Clone ,
317
317
V : Clone ,
318
318
{
319
319
fn clone ( & self ) -> Self {
@@ -499,12 +499,7 @@ impl<K, V, S, const N: usize> IndexMap<K, V, BuildHasherDefault<S>, N> {
499
499
}
500
500
}
501
501
502
- impl < K , V , S , const N : usize > IndexMap < K , V , S , N >
503
- where
504
- K : Eq + Hash ,
505
- S : BuildHasher ,
506
- {
507
- /* Public API */
502
+ impl < K , V , S , const N : usize > IndexMap < K , V , S , N > {
508
503
/// Returns the number of elements the map can hold
509
504
pub fn capacity ( & self ) -> usize {
510
505
N
@@ -652,39 +647,6 @@ where
652
647
. map ( |bucket| ( & bucket. key , & mut bucket. value ) )
653
648
}
654
649
655
- /// Returns an entry for the corresponding key
656
- /// ```
657
- /// use heapless::FnvIndexMap;
658
- /// use heapless::Entry;
659
- /// let mut map = FnvIndexMap::<_, _, 16>::new();
660
- /// if let Entry::Vacant(v) = map.entry("a") {
661
- /// v.insert(1).unwrap();
662
- /// }
663
- /// if let Entry::Occupied(mut o) = map.entry("a") {
664
- /// println!("found {}", *o.get()); // Prints 1
665
- /// o.insert(2);
666
- /// }
667
- /// // Prints 2
668
- /// println!("val: {}", *map.get("a").unwrap());
669
- /// ```
670
- pub fn entry ( & mut self , key : K ) -> Entry < ' _ , K , V , N > {
671
- let hash_val = hash_with ( & key, & self . build_hasher ) ;
672
- if let Some ( ( probe, pos) ) = self . core . find ( hash_val, & key) {
673
- Entry :: Occupied ( OccupiedEntry {
674
- key,
675
- probe,
676
- pos,
677
- core : & mut self . core ,
678
- } )
679
- } else {
680
- Entry :: Vacant ( VacantEntry {
681
- key,
682
- hash_val,
683
- core : & mut self . core ,
684
- } )
685
- }
686
- }
687
-
688
650
/// Return the number of key-value pairs in the map.
689
651
///
690
652
/// Computes in **O(1)** time.
@@ -735,6 +697,46 @@ where
735
697
* pos = None ;
736
698
}
737
699
}
700
+ }
701
+
702
+ impl < K , V , S , const N : usize > IndexMap < K , V , S , N >
703
+ where
704
+ K : Eq + Hash ,
705
+ S : BuildHasher ,
706
+ {
707
+ /* Public API */
708
+ /// Returns an entry for the corresponding key
709
+ /// ```
710
+ /// use heapless::FnvIndexMap;
711
+ /// use heapless::Entry;
712
+ /// let mut map = FnvIndexMap::<_, _, 16>::new();
713
+ /// if let Entry::Vacant(v) = map.entry("a") {
714
+ /// v.insert(1).unwrap();
715
+ /// }
716
+ /// if let Entry::Occupied(mut o) = map.entry("a") {
717
+ /// println!("found {}", *o.get()); // Prints 1
718
+ /// o.insert(2);
719
+ /// }
720
+ /// // Prints 2
721
+ /// println!("val: {}", *map.get("a").unwrap());
722
+ /// ```
723
+ pub fn entry ( & mut self , key : K ) -> Entry < ' _ , K , V , N > {
724
+ let hash_val = hash_with ( & key, & self . build_hasher ) ;
725
+ if let Some ( ( probe, pos) ) = self . core . find ( hash_val, & key) {
726
+ Entry :: Occupied ( OccupiedEntry {
727
+ key,
728
+ probe,
729
+ pos,
730
+ core : & mut self . core ,
731
+ } )
732
+ } else {
733
+ Entry :: Vacant ( VacantEntry {
734
+ key,
735
+ hash_val,
736
+ core : & mut self . core ,
737
+ } )
738
+ }
739
+ }
738
740
739
741
/// Returns a reference to the value corresponding to the key.
740
742
///
@@ -931,7 +933,7 @@ where
931
933
932
934
impl < K , V , S , const N : usize > Clone for IndexMap < K , V , S , N >
933
935
where
934
- K : Eq + Hash + Clone ,
936
+ K : Clone ,
935
937
V : Clone ,
936
938
S : Clone ,
937
939
{
@@ -945,9 +947,8 @@ where
945
947
946
948
impl < K , V , S , const N : usize > fmt:: Debug for IndexMap < K , V , S , N >
947
949
where
948
- K : Eq + Hash + fmt:: Debug ,
950
+ K : fmt:: Debug ,
949
951
V : fmt:: Debug ,
950
- S : BuildHasher ,
951
952
{
952
953
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
953
954
f. debug_map ( ) . entries ( self . iter ( ) ) . finish ( )
@@ -956,8 +957,7 @@ where
956
957
957
958
impl < K , V , S , const N : usize > Default for IndexMap < K , V , S , N >
958
959
where
959
- K : Eq + Hash ,
960
- S : BuildHasher + Default ,
960
+ S : Default ,
961
961
{
962
962
fn default ( ) -> Self {
963
963
// Const assert
@@ -1052,11 +1052,7 @@ impl<K, V, const N: usize> Iterator for IntoIter<K, V, N> {
1052
1052
}
1053
1053
}
1054
1054
1055
- impl < K , V , S , const N : usize > IntoIterator for IndexMap < K , V , S , N >
1056
- where
1057
- K : Eq + Hash ,
1058
- S : BuildHasher ,
1059
- {
1055
+ impl < K , V , S , const N : usize > IntoIterator for IndexMap < K , V , S , N > {
1060
1056
type Item = ( K , V ) ;
1061
1057
type IntoIter = IntoIter < K , V , N > ;
1062
1058
@@ -1067,11 +1063,7 @@ where
1067
1063
}
1068
1064
}
1069
1065
1070
- impl < ' a , K , V , S , const N : usize > IntoIterator for & ' a IndexMap < K , V , S , N >
1071
- where
1072
- K : Eq + Hash ,
1073
- S : BuildHasher ,
1074
- {
1066
+ impl < ' a , K , V , S , const N : usize > IntoIterator for & ' a IndexMap < K , V , S , N > {
1075
1067
type Item = ( & ' a K , & ' a V ) ;
1076
1068
type IntoIter = Iter < ' a , K , V > ;
1077
1069
@@ -1080,11 +1072,7 @@ where
1080
1072
}
1081
1073
}
1082
1074
1083
- impl < ' a , K , V , S , const N : usize > IntoIterator for & ' a mut IndexMap < K , V , S , N >
1084
- where
1085
- K : Eq + Hash ,
1086
- S : BuildHasher ,
1087
- {
1075
+ impl < ' a , K , V , S , const N : usize > IntoIterator for & ' a mut IndexMap < K , V , S , N > {
1088
1076
type Item = ( & ' a K , & ' a mut V ) ;
1089
1077
type IntoIter = IterMut < ' a , K , V > ;
1090
1078
0 commit comments