@@ -113,6 +113,14 @@ namespace geode
113113 index_t nb_elements,
114114 AttributeKey ) const = 0;
115115
116+ virtual void import ( absl::Span< const index_t > old2new,
117+ const std::shared_ptr< AttributeBase >& from,
118+ AttributeBase::AttributeKey ) = 0;
119+
120+ virtual void import ( const GenericMapping< index_t >& old2new_mapping,
121+ const std::shared_ptr< AttributeBase >& from,
122+ AttributeBase::AttributeKey ) = 0;
123+
116124 virtual void resize ( index_t size, AttributeKey ) = 0;
117125
118126 virtual void reserve ( index_t capacity, AttributeKey ) = 0;
@@ -356,6 +364,25 @@ namespace geode
356364 return attribute;
357365 }
358366
367+ void import ( absl::Span< const index_t > /* unused */ ,
368+ const std::shared_ptr< AttributeBase >& from,
369+ AttributeBase::AttributeKey ) override
370+ {
371+ import ( dynamic_cast < const ReadOnlyAttribute< T >& >( *from ) );
372+ }
373+
374+ void import ( const GenericMapping< index_t >& /* unused */ ,
375+ const std::shared_ptr< AttributeBase >& from,
376+ AttributeBase::AttributeKey ) override
377+ {
378+ import ( dynamic_cast < const ReadOnlyAttribute< T >& >( *from ) );
379+ }
380+
381+ void import ( const ReadOnlyAttribute< T >& from )
382+ {
383+ this ->set_value ( from.value ( 0 ) );
384+ }
385+
359386 private:
360387 T value_;
361388 };
@@ -518,8 +545,11 @@ namespace geode
518545 {
519546 OPENGEODE_EXCEPTION ( new_index < nb_elements,
520547 " [VariableAttribute::extract] The given mapping "
521- " contains values that go beyond the given number of "
522- " elements." );
548+ " contains values (" ,
549+ new_index,
550+ " ) that go beyond the given number "
551+ " of elements (" ,
552+ nb_elements, " )." );
523553 attribute->set_value ( new_index, value ( i ) );
524554 }
525555 }
@@ -535,20 +565,64 @@ namespace geode
535565 new VariableAttribute< T >{ default_value_, this ->properties () }
536566 };
537567 attribute->values_ .resize ( nb_elements, default_value_ );
538- for ( const auto & in2out : old2new_mapping.in2out_map () )
568+ for ( const auto & [in, outs] : old2new_mapping.in2out_map () )
539569 {
540- for ( const auto new_index : in2out. second )
570+ for ( const auto new_index : outs )
541571 {
542572 OPENGEODE_EXCEPTION ( new_index < nb_elements,
543573 " [VariableAttribute::extract] The given mapping "
544- " contains values that go beyond the given number "
545- " of elements." );
546- attribute->set_value ( new_index, value ( in2out.first ) );
574+ " contains values (" ,
575+ new_index,
576+ " ) that go beyond the given number "
577+ " of elements (" ,
578+ nb_elements, " )." );
579+ attribute->set_value ( new_index, value ( in ) );
547580 }
548581 }
549582 return attribute;
550583 }
551584
585+ void import ( absl::Span< const index_t > old2new,
586+ const std::shared_ptr< AttributeBase >& from,
587+ AttributeBase::AttributeKey ) override
588+ {
589+ import ( old2new,
590+ dynamic_cast < const ReadOnlyAttribute< T >& >( *from ) );
591+ }
592+
593+ void import ( const GenericMapping< index_t >& old2new_mapping,
594+ const std::shared_ptr< AttributeBase >& from,
595+ AttributeBase::AttributeKey ) override
596+ {
597+ import ( old2new_mapping,
598+ dynamic_cast < const ReadOnlyAttribute< T >& >( *from ) );
599+ }
600+
601+ void import ( absl::Span< const index_t > old2new,
602+ const ReadOnlyAttribute< T >& from )
603+ {
604+ for ( const auto i : Indices{ old2new } )
605+ {
606+ const auto new_index = old2new[i];
607+ if ( new_index != NO_ID )
608+ {
609+ this ->set_value ( new_index, from.value ( i ) );
610+ }
611+ }
612+ }
613+
614+ void import ( const GenericMapping< index_t >& old2new_mapping,
615+ const ReadOnlyAttribute< T >& from )
616+ {
617+ for ( const auto & [in, outs] : old2new_mapping.in2out_map () )
618+ {
619+ for ( const auto new_index : outs )
620+ {
621+ this ->set_value ( new_index, from.value ( in ) );
622+ }
623+ }
624+ }
625+
552626 private:
553627 T default_value_;
554628 std::vector< T > values_{};
@@ -712,8 +786,11 @@ namespace geode
712786 {
713787 OPENGEODE_EXCEPTION ( new_index < nb_elements,
714788 " [VariableAttribute::extract] The given mapping "
715- " contains values that go beyond the given number of "
716- " elements." );
789+ " contains values (" ,
790+ new_index,
791+ " ) that go beyond the given number "
792+ " of elements (" ,
793+ nb_elements, " )." );
717794 attribute->set_value ( new_index, value ( i ) );
718795 }
719796 }
@@ -730,20 +807,64 @@ namespace geode
730807 static_cast < bool >( default_value_ ), this ->properties () }
731808 };
732809 attribute->values_ .resize ( nb_elements, default_value_ );
733- for ( const auto & in2out : old2new_mapping.in2out_map () )
810+ for ( const auto & [in, outs] : old2new_mapping.in2out_map () )
734811 {
735- for ( const auto new_index : in2out. second )
812+ for ( const auto new_index : outs )
736813 {
737814 OPENGEODE_EXCEPTION ( new_index < nb_elements,
738815 " [VariableAttribute::extract] The given mapping "
739- " contains values that go beyond the given number "
740- " of elements." );
741- attribute->set_value ( new_index, value ( in2out.first ) );
816+ " contains values (" ,
817+ new_index,
818+ " ) that go beyond the given number "
819+ " of elements (" ,
820+ nb_elements, " )." );
821+ attribute->set_value ( new_index, value ( in ) );
742822 }
743823 }
744824 return attribute;
745825 }
746826
827+ void import ( absl::Span< const index_t > old2new,
828+ const std::shared_ptr< AttributeBase >& from,
829+ AttributeBase::AttributeKey ) override
830+ {
831+ import ( old2new,
832+ dynamic_cast < const ReadOnlyAttribute< bool >& >( *from ) );
833+ }
834+
835+ void import ( const GenericMapping< index_t >& old2new_mapping,
836+ const std::shared_ptr< AttributeBase >& from,
837+ AttributeBase::AttributeKey ) override
838+ {
839+ import ( old2new_mapping,
840+ dynamic_cast < const ReadOnlyAttribute< bool >& >( *from ) );
841+ }
842+
843+ void import ( absl::Span< const index_t > old2new,
844+ const ReadOnlyAttribute< bool >& from )
845+ {
846+ for ( const auto i : Indices{ old2new } )
847+ {
848+ const auto new_index = old2new[i];
849+ if ( new_index != NO_ID )
850+ {
851+ this ->set_value ( new_index, from.value ( i ) );
852+ }
853+ }
854+ }
855+
856+ void import ( const GenericMapping< index_t >& old2new_mapping,
857+ const ReadOnlyAttribute< bool >& from )
858+ {
859+ for ( const auto & [in, outs] : old2new_mapping.in2out_map () )
860+ {
861+ for ( const auto new_index : outs )
862+ {
863+ this ->set_value ( new_index, from.value ( in ) );
864+ }
865+ }
866+ }
867+
747868 private:
748869 unsigned char default_value_;
749870 std::vector< unsigned char > values_{};
@@ -859,12 +980,11 @@ namespace geode
859980 auto old_values = std::move ( values_ );
860981 values_ = decltype ( values_ )();
861982 values_.reserve ( old_values.size () );
862- for ( auto & value : old_values )
983+ for ( auto & [index, value] : old_values )
863984 {
864- if ( !to_delete[value. first ] && value. second != default_value_ )
985+ if ( !to_delete[index ] && value != default_value_ )
865986 {
866- values_.emplace (
867- old2new[value.first ], std::move ( value.second ) );
987+ values_.emplace ( old2new[index], std::move ( value ) );
868988 }
869989 }
870990 }
@@ -875,10 +995,9 @@ namespace geode
875995 auto old_values = std::move ( values_ );
876996 values_ = decltype ( values_ )();
877997 values_.reserve ( old_values.size () );
878- for ( auto & value : old_values )
998+ for ( auto & [index, value] : old_values )
879999 {
880- values_.emplace (
881- permutation[value.first ], std::move ( value.second ) );
1000+ values_.emplace ( permutation[index], std::move ( value ) );
8821001 }
8831002 }
8841003
@@ -925,7 +1044,7 @@ namespace geode
9251044 if ( value ( i ) != default_value_ && new_index != NO_ID )
9261045 {
9271046 OPENGEODE_EXCEPTION ( new_index < nb_elements,
928- " [VariableAttribute ::extract] The given mapping "
1047+ " [SparseAttribute ::extract] The given mapping "
9291048 " contains values that go beyond the given number of "
9301049 " elements." );
9311050 attribute->set_value ( new_index, value ( i ) );
@@ -942,24 +1061,67 @@ namespace geode
9421061 std::shared_ptr< SparseAttribute< T > > attribute{
9431062 new SparseAttribute< T >{ default_value_, this ->properties () }
9441063 };
945- for ( const auto & in2out : old2new_mapping.in2out_map () )
1064+ for ( const auto & [in, outs] : old2new_mapping.in2out_map () )
9461065 {
947- if ( value ( in2out. first ) != default_value_ )
1066+ if ( value ( in ) != default_value_ )
9481067 {
949- for ( const auto new_index : in2out. second )
1068+ for ( const auto new_index : outs )
9501069 {
9511070 OPENGEODE_EXCEPTION ( new_index < nb_elements,
952- " [VariableAttribute ::extract] The given mapping "
1071+ " [SparseAttribute ::extract] The given mapping "
9531072 " contains values that go beyond the given number "
9541073 " of elements." );
955- attribute->set_value (
956- new_index, value ( in2out.first ) );
1074+ attribute->set_value ( new_index, value ( in ) );
9571075 }
9581076 }
9591077 }
9601078 return attribute;
9611079 }
9621080
1081+ void import ( absl::Span< const index_t > old2new,
1082+ const std::shared_ptr< AttributeBase >& from,
1083+ AttributeBase::AttributeKey ) override
1084+ {
1085+ import ( old2new,
1086+ dynamic_cast < const ReadOnlyAttribute< T >& >( *from ) );
1087+ }
1088+
1089+ void import ( const GenericMapping< index_t >& old2new_mapping,
1090+ const std::shared_ptr< AttributeBase >& from,
1091+ AttributeBase::AttributeKey ) override
1092+ {
1093+ import ( old2new_mapping,
1094+ dynamic_cast < const ReadOnlyAttribute< T >& >( *from ) );
1095+ }
1096+
1097+ void import ( absl::Span< const index_t > old2new,
1098+ const ReadOnlyAttribute< T >& from )
1099+ {
1100+ for ( const auto i : Indices{ old2new } )
1101+ {
1102+ const auto new_index = old2new[i];
1103+ if ( from.value ( i ) != default_value_ && new_index != NO_ID )
1104+ {
1105+ this ->set_value ( new_index, from.value ( i ) );
1106+ }
1107+ }
1108+ }
1109+
1110+ void import ( const GenericMapping< index_t >& old2new_mapping,
1111+ const ReadOnlyAttribute< T >& from )
1112+ {
1113+ for ( const auto & [in, outs] : old2new_mapping.in2out_map () )
1114+ {
1115+ if ( from.value ( in ) != default_value_ )
1116+ {
1117+ for ( const auto new_index : outs )
1118+ {
1119+ this ->set_value ( new_index, from.value ( in ) );
1120+ }
1121+ }
1122+ }
1123+ }
1124+
9631125 private:
9641126 T default_value_;
9651127 absl::flat_hash_map< index_t , T > values_{};
0 commit comments