@@ -133,50 +133,48 @@ namespace geode
133133
134134 void map ( const T1& in, const T2& out )
135135 {
136- if ( this ->has_mapping_input ( in ) )
136+ auto [in_itr, in_is_new] =
137+ this ->in2out_mapping ().emplace ( in, out );
138+ if ( !in_is_new )
137139 {
138- erase_in ( in );
140+ this ->out2in_mapping ().erase ( in_itr->second );
141+ in_itr->second = out;
139142 }
140- if ( this ->has_mapping_output ( out ) )
143+ auto [out_itr, out_is_new] =
144+ this ->out2in_mapping ().emplace ( out, in );
145+ if ( !out_is_new )
141146 {
142- erase_out ( out );
147+ this ->in2out_mapping ().erase ( out_itr->second );
148+ out_itr->second = in;
143149 }
144- emplace ( in, out );
145150 }
146151
147152 void erase_in ( const T1& in )
148153 {
149- if ( !this ->has_mapping_input ( in ) )
154+ auto in_itr = this ->in2out_mapping ().find ( in );
155+ if ( in_itr == this ->in2out_mapping ().end () )
150156 {
151157 return ;
152158 }
153- const auto out = this ->in2out ( in );
154- this ->in2out_mapping ().erase ( in );
155- this ->out2in_mapping ().erase ( out );
159+ this ->out2in_mapping ().erase ( in_itr->second );
160+ this ->in2out_mapping ().erase ( in_itr );
156161 }
157162
158163 void erase_out ( const T2& out )
159164 {
160- if ( !this ->has_mapping_output ( out ) )
165+ auto out_itr = this ->out2in_mapping ().find ( out );
166+ if ( out_itr == this ->out2in_mapping ().end () )
161167 {
162168 return ;
163169 }
164- const auto in = this ->out2in ( out );
165- this ->in2out_mapping ().erase ( in );
166- this ->out2in_mapping ().erase ( out );
170+ this ->in2out_mapping ().erase ( out_itr->second );
171+ this ->out2in_mapping ().erase ( out_itr );
167172 }
168173
169174 [[nodiscard]] index_t size () const
170175 {
171176 return this ->size_input ();
172177 }
173-
174- private:
175- void emplace ( const T1& in, const T2& out )
176- {
177- this ->in2out_mapping ().emplace ( in, out );
178- this ->out2in_mapping ().emplace ( out, in );
179- }
180178 };
181179
182180 template < typename T >
0 commit comments