Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions inst/include/Rcpp/sugar/functions/max.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@ namespace sugar{

Max( const T& obj_) : obj(obj_) {}

operator STORAGE() {
max_ = obj[0] ;
if( Rcpp::traits::is_na<RTYPE>( max_ ) ) return max_ ;
operator STORAGE() const {
STORAGE max, current ;
max = obj[0] ;
if( Rcpp::traits::is_na<RTYPE>( max ) ) return max ;

R_xlen_t n = obj.size() ;
for( R_xlen_t i=1; i<n; i++){
current = obj[i] ;
if( Rcpp::traits::is_na<RTYPE>( current ) ) return current;
if( current > max_ ) max_ = current ;
if( current > max ) max = current ;
}
return max_ ;
return max ;
}

private:
const T& obj ;
STORAGE min_, max_, current ;
} ;

// version for NA = false
Expand All @@ -58,20 +58,20 @@ namespace sugar{

Max( const T& obj_) : obj(obj_) {}

operator STORAGE() {
max_ = obj[0] ;
operator STORAGE() const {
STORAGE max, current ;
max = obj[0] ;

R_xlen_t n = obj.size() ;
for( R_xlen_t i=1; i<n; i++){
current = obj[i] ;
if( current > max_ ) max_ = current ;
if( current > max ) max = current ;
}
return max_ ;
return max ;
}

private:
const T& obj ;
STORAGE max_, current ;
} ;


Expand Down
22 changes: 11 additions & 11 deletions inst/include/Rcpp/sugar/functions/min.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ namespace sugar{

Min( const T& obj_) : obj(obj_) {}

operator STORAGE() {
min_ = obj[0] ;
if( Rcpp::traits::is_na<RTYPE>( min_ ) ) return min_ ;
operator STORAGE() const {
STORAGE min, current ;
min = obj[0] ;
if( Rcpp::traits::is_na<RTYPE>( min ) ) return min ;

R_xlen_t n = obj.size() ;
for( R_xlen_t i=1; i<n; i++){
current = obj[i] ;
if( Rcpp::traits::is_na<RTYPE>( current ) ) return current;
if( current < min_ ) min_ = current ;
if( current < min ) min = current ;
}
return min_ ;
return min ;
}

const T& obj ;
STORAGE min_, max_, current ;
} ;

// version for NA = false
Expand All @@ -57,19 +57,19 @@ namespace sugar{

Min( const T& obj_) : obj(obj_) {}

operator STORAGE() {
min_ = obj[0] ;
operator STORAGE() const {
STORAGE min, current ;
min = obj[0] ;

R_xlen_t n = obj.size() ;
for( R_xlen_t i=1; i<n; i++){
current = obj[i] ;
if( current < min_ ) min_ = current ;
if( current < min ) min = current ;
}
return min_ ;
return min ;
}

const T& obj ;
STORAGE min_, current ;
} ;


Expand Down