diff --git a/include/geode/basic/small_set.hpp b/include/geode/basic/small_set.hpp index ef69598fc..231b9397a 100644 --- a/include/geode/basic/small_set.hpp +++ b/include/geode/basic/small_set.hpp @@ -55,9 +55,14 @@ namespace geode return container_.end(); } + auto contains( const Type& element ) const + { + return absl::c_contains( container_, element ); + } + auto insert( const Type& element ) { - if( absl::c_contains( container_, element ) ) + if( contains( element ) ) { return false; } @@ -65,6 +70,11 @@ namespace geode return true; } + auto erase( const Type& element ) + { + return container_.erase( absl::c_find( container_, element ) ); + } + auto at( index_t index ) const { return container_.at( index ); diff --git a/tests/basic/test-small-set.cpp b/tests/basic/test-small-set.cpp index 7711bc3f2..9dfe86430 100644 --- a/tests/basic/test-small-set.cpp +++ b/tests/basic/test-small-set.cpp @@ -37,6 +37,9 @@ void test() OPENGEODE_EXCEPTION( !set.insert( 0 ), "[Test] Insert not allow" ); OPENGEODE_EXCEPTION( !set.insert( 1 ), "[Test] Insert not allow" ); OPENGEODE_EXCEPTION( set.size(), "[Test] Set size should be 2" ); + set.erase( 0 ); + OPENGEODE_EXCEPTION( set.size(), "[Test] Set size should be 1" ); + OPENGEODE_EXCEPTION( set.at( 0 ) == 1, "[Test] Wrong value in set" ); } OPENGEODE_TEST( "small-set" )