11use core:: { any:: TypeId , hash:: Hash } ;
22
33use bevy_platform:: {
4- collections:: { hash_map :: Entry , HashMap } ,
4+ collections:: HashMap ,
55 hash:: { Hashed , NoOpHash , PassHash } ,
66} ;
7+ use indexmap:: map:: IndexMap ;
8+
9+ /// The [`Entry`][indexmap::map::Entry] type for [`TypeIdMap`].
10+ pub use indexmap:: map:: Entry as TypeIdMapEntry ;
711
812/// A [`HashMap`] pre-configured to use [`Hashed`] keys and [`PassHash`] passthrough hashing.
913/// Iteration order only depends on the order of insertions and deletions.
@@ -34,14 +38,14 @@ impl<K: Hash + Eq + PartialEq + Clone, V> PreHashMapExt<K, V> for PreHashMap<K,
3438 }
3539}
3640
37- /// A specialized hashmap type with Key of [`TypeId`]
41+ /// A specialized map type with Key of [`TypeId`]
3842/// Iteration order only depends on the order of insertions and deletions.
39- pub type TypeIdMap < V > = HashMap < TypeId , V , NoOpHash > ;
43+ pub type TypeIdMap < V > = IndexMap < TypeId , V , NoOpHash > ;
4044
4145/// Extension trait to make use of [`TypeIdMap`] more ergonomic.
4246///
4347/// Each function on this trait is a trivial wrapper for a function
44- /// on [`HashMap `], replacing a `TypeId` key with a
48+ /// on [`IndexMap `], replacing a `TypeId` key with a
4549/// generic parameter `T`.
4650///
4751/// # Examples
@@ -80,7 +84,7 @@ pub trait TypeIdMapExt<V> {
8084 fn remove_type < T : ?Sized + ' static > ( & mut self ) -> Option < V > ;
8185
8286 /// Gets the type `T`'s entry in the map for in-place manipulation.
83- fn entry_type < T : ?Sized + ' static > ( & mut self ) -> Entry < ' _ , TypeId , V , NoOpHash > ;
87+ fn entry_type < T : ?Sized + ' static > ( & mut self ) -> TypeIdMapEntry < ' _ , TypeId , V > ;
8488}
8589
8690impl < V > TypeIdMapExt < V > for TypeIdMap < V > {
@@ -101,11 +105,11 @@ impl<V> TypeIdMapExt<V> for TypeIdMap<V> {
101105
102106 #[ inline]
103107 fn remove_type < T : ?Sized + ' static > ( & mut self ) -> Option < V > {
104- self . remove ( & TypeId :: of :: < T > ( ) )
108+ self . shift_remove ( & TypeId :: of :: < T > ( ) )
105109 }
106110
107111 #[ inline]
108- fn entry_type < T : ?Sized + ' static > ( & mut self ) -> Entry < ' _ , TypeId , V , NoOpHash > {
112+ fn entry_type < T : ?Sized + ' static > ( & mut self ) -> TypeIdMapEntry < ' _ , TypeId , V > {
109113 self . entry ( TypeId :: of :: < T > ( ) )
110114 }
111115}
@@ -152,4 +156,4 @@ mod tests {
152156 ) ;
153157 }
154158 }
155- }
159+ }
0 commit comments