Skip to content

Commit 160e99c

Browse files
Merge pull request #1069 from Geode-solutions/fix/only-fix-mappings
fix(Mappings): avoid several occurrences of the same mapping in Gener…
2 parents 7d02689 + 16467d3 commit 160e99c

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

include/geode/basic/mapping.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,29 @@ namespace geode
186186
public:
187187
void map( const T1& in, const T2& out )
188188
{
189+
if( this->has_mapping_input( in ) )
190+
{
191+
if( absl::c_contains( this->in2out_mapping().at( in ), out ) )
192+
{
193+
return;
194+
}
195+
}
189196
this->in2out_mapping()[in].push_back( out );
190197
this->out2in_mapping()[out].push_back( in );
191198
}
192199

193200
void unmap( const T1& in, const T2& out )
194201
{
202+
if( !this->has_mapping_input( in ) )
203+
{
204+
return;
205+
}
195206
auto& in_map = this->in2out_mapping().at( in );
196207
const auto itr = absl::c_find( in_map, out );
208+
if( itr == in_map.end() )
209+
{
210+
return;
211+
}
197212
in_map.erase( itr );
198213
if( this->in2out( in ).empty() )
199214
{

tests/basic/test-mappings.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ void test_generic_mappings()
108108
generic.map( 0, -8.0 );
109109
generic.map( 0, -8.0 );
110110
generic.map( 5, -8.0 );
111-
OPENGEODE_EXCEPTION( generic.out2in( -8.0 ).size() == 5,
112-
"[Test] Size of out2in for -8.0 should be 5" );
111+
OPENGEODE_EXCEPTION( generic.out2in( -8.0 ).size() == 2,
112+
"[Test] Size of out2in for -8.0 should be 2" );
113113
generic.erase_in( 0 );
114114
OPENGEODE_EXCEPTION( generic.out2in( -8.0 ).size() == 1,
115115
"[Test] Size of out2in for -8.0 should be 1" );

0 commit comments

Comments
 (0)