22//! ordering. This is a useful property for deterministic computations, such
33//! as required by the query system.
44
5+ use std:: alloc:: { Allocator , Global } ;
56use std:: borrow:: { Borrow , BorrowMut } ;
7+ use std:: collections:: HashMap ;
68use std:: collections:: hash_map:: { Entry , OccupiedError } ;
79use std:: hash:: Hash ;
810use std:: iter:: { Product , Sum } ;
@@ -450,11 +452,11 @@ impl<V: Hash + Eq + StableHash> StableHash for UnordSet<V> {
450452/// See [MCP 533](https://github.com/rust-lang/compiler-team/issues/533)
451453/// for more information.
452454#[ derive( Debug , Eq , PartialEq , Clone , Encodable_NoContext , Decodable_NoContext ) ]
453- pub struct UnordMap < K : Eq + Hash , V > {
454- inner : FxHashMap < K , V > ,
455+ pub struct UnordMap < K : Eq + Hash , V , A : Allocator = Global > {
456+ inner : HashMap < K , V , FxBuildHasher , A > ,
455457}
456458
457- impl < K : Eq + Hash , V > UnordCollection for UnordMap < K , V > { }
459+ impl < K : Eq + Hash , V , A : Allocator > UnordCollection for UnordMap < K , V , A > { }
458460
459461impl < K : Eq + Hash , V > const Default for UnordMap < K , V > {
460462 #[ inline]
@@ -463,7 +465,7 @@ impl<K: Eq + Hash, V> const Default for UnordMap<K, V> {
463465 }
464466}
465467
466- impl < K : Hash + Eq , V > Extend < ( K , V ) > for UnordMap < K , V > {
468+ impl < K : Hash + Eq , V , A : Allocator > Extend < ( K , V ) > for UnordMap < K , V , A > {
467469 #[ inline]
468470 fn extend < T : IntoIterator < Item = ( K , V ) > > ( & mut self , iter : T ) {
469471 self . inner . extend ( iter)
@@ -487,7 +489,19 @@ impl<K: Hash + Eq, V, I: Iterator<Item = (K, V)>> From<UnordItems<(K, V), I>> fo
487489impl < K : Eq + Hash , V > UnordMap < K , V > {
488490 #[ inline]
489491 pub fn with_capacity ( capacity : usize ) -> Self {
490- Self { inner : FxHashMap :: with_capacity_and_hasher ( capacity, Default :: default ( ) ) }
492+ Self :: with_capacity_in ( capacity, Global )
493+ }
494+ }
495+
496+ impl < K : Eq + Hash , V , A : Allocator > UnordMap < K , V , A > {
497+ #[ inline]
498+ pub fn new_in ( alloc : A ) -> Self {
499+ Self :: with_capacity_in ( 0 , alloc)
500+ }
501+
502+ #[ inline]
503+ pub fn with_capacity_in ( capacity : usize , alloc : A ) -> Self {
504+ Self { inner : HashMap :: with_capacity_and_hasher_in ( capacity, Default :: default ( ) , alloc) }
491505 }
492506
493507 #[ inline]
@@ -501,7 +515,7 @@ impl<K: Eq + Hash, V> UnordMap<K, V> {
501515 }
502516
503517 #[ inline]
504- pub fn try_insert ( & mut self , k : K , v : V ) -> Result < & mut V , OccupiedError < ' _ , K , V > > {
518+ pub fn try_insert ( & mut self , k : K , v : V ) -> Result < & mut V , OccupiedError < ' _ , K , V , A > > {
505519 self . inner . try_insert ( k, v)
506520 }
507521
@@ -520,7 +534,7 @@ impl<K: Eq + Hash, V> UnordMap<K, V> {
520534 }
521535
522536 #[ inline]
523- pub fn entry ( & mut self , key : K ) -> Entry < ' _ , K , V > {
537+ pub fn entry ( & mut self , key : K ) -> Entry < ' _ , K , V , A > {
524538 self . inner . entry ( key)
525539 }
526540
0 commit comments