Skip to content

Commit 6bd4fee

Browse files
author
thirdwing
committed
working on vector part
1 parent 1d89221 commit 6bd4fee

File tree

15 files changed

+77
-65
lines changed

15 files changed

+77
-65
lines changed

inst/include/Rcpp/vector/LazyVector.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class LazyVector{
3333

3434
LazyVector( const VECTOR& vec_ ) : vec(vec_), n(vec_.size()), data(n), known(n,false){}
3535

36-
inline stored_type operator[]( int i) const {
36+
inline stored_type operator[]( R_xlen_t i) const {
3737
stored_type res ;
3838
if( ! known[i] ) {
3939
data[i] = res = vec[i] ;
@@ -46,7 +46,7 @@ class LazyVector{
4646

4747
private:
4848
const VECTOR& vec ;
49-
int n ;
49+
R_xlen_t n ;
5050
mutable std::vector<stored_type> data ;
5151
mutable std::vector<bool> known ;
5252
} ;
@@ -58,7 +58,7 @@ class LazyVector< Rcpp::Vector<RTYPE> >{
5858
typedef typename VECTOR::Proxy Proxy ;
5959

6060
LazyVector( const VECTOR& vec_) : vec(vec_){}
61-
inline Proxy operator[]( int i) const { return vec[i] ; }
61+
inline Proxy operator[]( R_xlen_t i) const { return vec[i] ; }
6262

6363
private:
6464
const VECTOR& vec ;

inst/include/Rcpp/vector/ListOf.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ class ListOf
6161

6262
// subsetting operators
6363

64-
ChildVector<T> operator[](int i) {
64+
ChildVector<T> operator[](R_xlen_t i) {
6565
return ChildVector<T>(list[i], list, i);
6666
}
6767

68-
const ChildVector<T> operator[](int i) const {
68+
const ChildVector<T> operator[](R_xlen_t i) const {
6969
return ChildVector<T>(list[i], list, i);
7070
}
7171

inst/include/Rcpp/vector/Matrix.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ class Matrix : public Vector<RTYPE, StoragePolicy>, public MatrixBase<RTYPE, tru
121121
return res ;
122122
}
123123

124-
inline Proxy operator[]( int i ) {
124+
inline Proxy operator[]( R_xlen_t i ) {
125125
return static_cast< Vector<RTYPE>* >( this )->operator[]( i ) ;
126126
}
127-
inline const_Proxy operator[]( int i ) const {
127+
inline const_Proxy operator[]( R_xlen_t i ) const {
128128
return static_cast< const Vector<RTYPE>* >( this )->operator[]( i ) ;
129129
}
130130

@@ -157,7 +157,7 @@ class Matrix : public Vector<RTYPE, StoragePolicy>, public MatrixBase<RTYPE, tru
157157

158158
private:
159159

160-
inline int offset( int i, int j) const { return i + nrows * j ; }
160+
inline R_xlen_t offset( int i, int j) const { return i + nrows * j ; }
161161

162162
template <typename U>
163163
void fill_diag__dispatch( traits::false_type, const U& u) {

inst/include/Rcpp/vector/MatrixBase.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ namespace Rcpp{
5151
public:
5252
typedef stored_type reference ;
5353
typedef stored_type* pointer ;
54-
typedef int difference_type ;
54+
typedef R_xlen_t difference_type ;
5555
typedef stored_type value_type;
5656
typedef std::random_access_iterator_tag iterator_category ;
5757

58-
iterator( const MatrixBase& object_, int index_ ) :
58+
iterator( const MatrixBase& object_, R_xlen_t index_ ) :
5959
object(object_), i(0), j(0), nr(object_.nrow()), nc(object_.ncol()) {
6060

6161
update_index( index_) ;
@@ -149,7 +149,7 @@ namespace Rcpp{
149149
j = internal::get_column( index_, nr, i ) ;
150150
}
151151

152-
inline int index() const {
152+
inline R_xlen_t index() const {
153153
return i + nr * j ;
154154
}
155155

inst/include/Rcpp/vector/MatrixColumn.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ class MatrixColumn : public VectorBase<RTYPE,true,MatrixColumn<RTYPE> > {
9292
return const_start + n ;
9393
}
9494

95-
inline R_xlen_t size() const {
95+
inline int size() const {
9696
return n ;
9797
}
9898

9999
private:
100-
const R_xlen_t n ;
100+
const int n ;
101101
iterator start ;
102102
const_iterator const_start ;
103103

inst/include/Rcpp/vector/RangeIndexer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,17 @@ class RangeIndexer : public VectorBase<RTYPE, NA, RangeIndexer<RTYPE,NA,VECTOR>
8383
UNROLL_LOOP(/=)
8484
}
8585

86-
inline Proxy operator[]( int i ) const {
86+
inline Proxy operator[]( R_xlen_t i ) const {
8787
return start[i] ;
8888
}
8989

90-
inline int size() const {
90+
inline R_xlen_t size() const {
9191
return size_ ;
9292
}
9393

9494
private:
9595
iterator start ;
96-
int size_ ;
96+
R_xlen_t size_ ;
9797
} ;
9898

9999
}

inst/include/Rcpp/vector/SubMatrix.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class SubMatrix : public Rcpp::MatrixBase< RTYPE, true, SubMatrix<RTYPE> > {
3939
nr( row_range_.size() )
4040
{}
4141

42-
inline int size() const { return ncol() * nrow() ; }
42+
inline R_xlen_t size() const { return ((R_xlen_t)ncol()) * nrow() ; }
4343
inline int ncol() const { return nc ; }
4444
inline int nrow() const { return nr ; }
4545

inst/include/Rcpp/vector/Vector.h

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ class Vector :
8383
Storage::set__( Rf_allocVector( RTYPE, obj.get() ) ) ;
8484
}
8585

86-
Vector( const int& size, const stored_type& u ) {
87-
RCPP_DEBUG_2( "Vector<%d>( const int& size = %d, const stored_type& u )", RTYPE, size)
86+
Vector( const R_xlen_t& size, const stored_type& u ) {
87+
RCPP_DEBUG_2( "Vector<%d>( const R_xlen_t& size = %d, const stored_type& u )", RTYPE, size)
8888
Storage::set__( Rf_allocVector( RTYPE, size) ) ;
8989
fill( u ) ;
9090
}
@@ -107,10 +107,22 @@ class Vector :
107107
std::generate( begin(), end(), gen );
108108
}
109109

110+
Vector( const R_xlen_t& siz, stored_type (*gen)(void) ) {
111+
RCPP_DEBUG_2( "Vector<%d>( const R_xlen_t& siz = %s, stored_type (*gen)(void) )", RTYPE, siz )
112+
Storage::set__( Rf_allocVector( RTYPE, siz) ) ;
113+
std::generate( begin(), end(), gen );
114+
}
115+
116+
Vector( const R_xlen_t& size ) {
117+
Storage::set__( Rf_allocVector( RTYPE, size) ) ;
118+
init() ;
119+
}
120+
110121
Vector( const int& size ) {
111122
Storage::set__( Rf_allocVector( RTYPE, size) ) ;
112123
init() ;
113124
}
125+
114126
Vector( const Dimension& dims) {
115127
Storage::set__( Rf_allocVector( RTYPE, dims.prod() ) ) ;
116128
init() ;
@@ -145,8 +157,8 @@ class Vector :
145157
import_sugar_expression( other, typename traits::same_type<Vector,VEC>::type() ) ;
146158
}
147159
template <typename U>
148-
Vector( const int& size, const U& u) {
149-
RCPP_DEBUG_2( "Vector<%d>( const int& size, const U& u )", RTYPE, size )
160+
Vector( const R_xlen_t& size, const U& u) {
161+
RCPP_DEBUG_2( "Vector<%d>( const R_xlen_t& size, const U& u )", RTYPE, size )
150162
Storage::set__( Rf_allocVector( RTYPE, size) ) ;
151163
fill_or_generate( u ) ;
152164
}
@@ -157,25 +169,25 @@ class Vector :
157169
}
158170

159171
template <typename U1>
160-
Vector( const int& siz, stored_type (*gen)(U1), const U1& u1) {
172+
Vector( const R_xlen_t& siz, stored_type (*gen)(U1), const U1& u1) {
161173
Storage::set__( Rf_allocVector( RTYPE, siz) ) ;
162-
RCPP_DEBUG_2( "const int& siz, stored_type (*gen)(U1), const U1& u1 )", RTYPE, siz )
174+
RCPP_DEBUG_2( "const R_xlen_t& siz, stored_type (*gen)(U1), const U1& u1 )", RTYPE, siz )
163175
iterator first = begin(), last = end() ;
164176
while( first != last ) *first++ = gen(u1) ;
165177
}
166178

167179
template <typename U1, typename U2>
168-
Vector( const int& siz, stored_type (*gen)(U1,U2), const U1& u1, const U2& u2) {
180+
Vector( const R_xlen_t& siz, stored_type (*gen)(U1,U2), const U1& u1, const U2& u2) {
169181
Storage::set__( Rf_allocVector( RTYPE, siz) ) ;
170-
RCPP_DEBUG_2( "const int& siz, stored_type (*gen)(U1,U2), const U1& u1, const U2& u2)", RTYPE, siz )
182+
RCPP_DEBUG_2( "const R_xlen_t& siz, stored_type (*gen)(U1,U2), const U1& u1, const U2& u2)", RTYPE, siz )
171183
iterator first = begin(), last = end() ;
172184
while( first != last ) *first++ = gen(u1,u2) ;
173185
}
174186

175187
template <typename U1, typename U2, typename U3>
176-
Vector( const int& siz, stored_type (*gen)(U1,U2,U3), const U1& u1, const U2& u2, const U3& u3) {
188+
Vector( const R_xlen_t& siz, stored_type (*gen)(U1,U2,U3), const U1& u1, const U2& u2, const U3& u3) {
177189
Storage::set__( Rf_allocVector( RTYPE, siz) ) ;
178-
RCPP_DEBUG_2( "const int& siz, stored_type (*gen)(U1,U2,U3), const U1& u1, const U2& u2, const U3& u3)", RTYPE, siz )
190+
RCPP_DEBUG_2( "const R_xlen_t& siz, stored_type (*gen)(U1,U2,U3), const U1& u1, const U2& u2, const U3& u3)", RTYPE, siz )
179191
iterator first = begin(), last = end() ;
180192
while( first != last ) *first++ = gen(u1,u2,u3) ;
181193
}
@@ -188,9 +200,9 @@ class Vector :
188200
}
189201

190202
template <typename InputIterator>
191-
Vector( InputIterator first, InputIterator last, int n) {
203+
Vector( InputIterator first, InputIterator last, R_xlen_t n) {
192204
Storage::set__(Rf_allocVector(RTYPE, n)) ;
193-
RCPP_DEBUG_2( "Vector<%d>( InputIterator first, InputIterator last, int n = %d)", RTYPE, n )
205+
RCPP_DEBUG_2( "Vector<%d>( InputIterator first, InputIterator last, R_xlen_t n = %d)", RTYPE, n )
194206
std::copy( first, last, begin() ) ;
195207
}
196208

@@ -202,9 +214,9 @@ class Vector :
202214
}
203215

204216
template <typename InputIterator, typename Func>
205-
Vector( InputIterator first, InputIterator last, Func func, int n){
217+
Vector( InputIterator first, InputIterator last, Func func, R_xlen_t n){
206218
Storage::set__( Rf_allocVector( RTYPE, n ) );
207-
RCPP_DEBUG_2( "Vector<%d>( InputIterator, InputIterator, Func, int n = %d )", RTYPE, n )
219+
RCPP_DEBUG_2( "Vector<%d>( InputIterator, InputIterator, Func, R_xlen_t n = %d )", RTYPE, n )
208220
std::transform( first, last, begin(), func) ;
209221
}
210222

@@ -450,31 +462,31 @@ class Vector :
450462
}
451463

452464
template <typename U>
453-
static void replace_element( iterator it, SEXP names, int index, const U& u){
465+
static void replace_element( iterator it, SEXP names, R_xlen_t index, const U& u){
454466
replace_element__dispatch( typename traits::is_named<U>::type(),
455467
it, names, index, u ) ;
456468
}
457469

458470
template <typename U>
459-
static void replace_element__dispatch( traits::false_type, iterator it, SEXP names, int index, const U& u){
471+
static void replace_element__dispatch( traits::false_type, iterator it, SEXP names, R_xlen_t index, const U& u){
460472
*it = converter_type::get(u);
461473
}
462474

463475
template <typename U>
464-
static void replace_element__dispatch( traits::true_type, iterator it, SEXP names, int index, const U& u){
476+
static void replace_element__dispatch( traits::true_type, iterator it, SEXP names, R_xlen_t index, const U& u){
465477
replace_element__dispatch__isArgument( typename traits::same_type<U,Argument>(), it, names, index, u ) ;
466478
}
467479

468480
template <typename U>
469-
static void replace_element__dispatch__isArgument( traits::false_type, iterator it, SEXP names, int index, const U& u){
481+
static void replace_element__dispatch__isArgument( traits::false_type, iterator it, SEXP names, R_xlen_t index, const U& u){
470482
RCPP_DEBUG_2( " Vector::replace_element__dispatch<%s>(true, index= %d) ", DEMANGLE(U), index ) ;
471483

472484
*it = converter_type::get(u.object ) ;
473485
SET_STRING_ELT( names, index, ::Rf_mkChar( u.name.c_str() ) ) ;
474486
}
475487

476488
template <typename U>
477-
static void replace_element__dispatch__isArgument( traits::true_type, iterator it, SEXP names, int index, const U& u){
489+
static void replace_element__dispatch__isArgument( traits::true_type, iterator it, SEXP names, R_xlen_t index, const U& u){
478490
RCPP_DEBUG_2( " Vector::replace_element__dispatch<%s>(true, index= %d) ", DEMANGLE(U), index ) ;
479491

480492
*it = R_MissingArg ;
@@ -525,8 +537,8 @@ class Vector :
525537
bool containsElementNamed( const char* target ) const {
526538
SEXP names = RCPP_GET_NAMES(Storage::get__()) ;
527539
if( Rf_isNull(names) ) return false ;
528-
int n = Rf_length(names) ;
529-
for( int i=0; i<n; i++){
540+
R_xlen_t n = Rf_length(names) ;
541+
for( R_xlen_t i=0; i<n; i++){
530542
if( !strcmp( target, CHAR(STRING_ELT(names, i)) ) )
531543
return true ;
532544
}
@@ -536,8 +548,8 @@ class Vector :
536548
int findName(const std::string& name) const {
537549
SEXP names = RCPP_GET_NAMES(Storage::get__());
538550
if (Rf_isNull(names)) stop("'names' attribute is null");
539-
int n = Rf_length(names);
540-
for (int i=0; i < n; ++i) {
551+
R_xlen_t n = Rf_length(names);
552+
for (R_xlen_t i=0; i < n; ++i) {
541553
if (strcmp(name.c_str(), CHAR(STRING_ELT(names, i))) == 0) {
542554
return i;
543555
}

inst/include/Rcpp/vector/VectorBase.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,21 @@ class VectorBase : public traits::expands_to_logical__impl<RTYPE> {
4242
return static_cast<const VECTOR&>(*this) ;
4343
}
4444

45-
inline stored_type operator[]( int i) const {
45+
inline stored_type operator[]( R_xlen_t i) const {
4646
return static_cast<const VECTOR*>(this)->operator[](i) ;
4747
}
4848

49-
inline int size() const { return static_cast<const VECTOR*>(this)->size() ; }
49+
inline R_xlen_t size() const { return static_cast<const VECTOR*>(this)->size() ; }
5050

5151
class iterator {
5252
public:
5353
typedef stored_type reference ;
5454
typedef stored_type* pointer ;
55-
typedef int difference_type ;
55+
typedef R_xlen_t difference_type ;
5656
typedef stored_type value_type;
5757
typedef std::random_access_iterator_tag iterator_category ;
5858

59-
iterator( const VectorBase& object_, int index_ ) : object(object_.get_ref()), index(index_){}
59+
iterator( const VectorBase& object_, R_xlen_t index_ ) : object(object_.get_ref()), index(index_){}
6060
iterator( const iterator& other) : object(other.object), index(other.index){};
6161

6262
inline iterator& operator++(){
@@ -95,7 +95,7 @@ class VectorBase : public traits::expands_to_logical__impl<RTYPE> {
9595
return *this ;
9696
}
9797

98-
inline reference operator[](int i){
98+
inline reference operator[](R_xlen_t i){
9999
return object[index+i] ;
100100
}
101101

@@ -132,7 +132,7 @@ class VectorBase : public traits::expands_to_logical__impl<RTYPE> {
132132

133133
private:
134134
const VECTOR& object ;
135-
int index;
135+
R_xlen_t index;
136136
} ;
137137

138138
inline iterator begin() const { return iterator(*this, 0) ; }

inst/include/Rcpp/vector/const_generic_proxy.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace internal{
3333
const_generic_proxy( const const_generic_proxy& other ) :
3434
parent(other.parent), index(other.index){} ;
3535

36-
const_generic_proxy( const VECTOR& v, int i ) : parent(&v), index(i){} ;
36+
const_generic_proxy( const VECTOR& v, R_xlen_t i ) : parent(&v), index(i){} ;
3737

3838
operator SEXP() const {
3939
return get() ;
@@ -48,7 +48,7 @@ namespace internal{
4848
operator int() const { return ::Rcpp::as<int>(get()) ; }
4949

5050
const VECTOR* parent;
51-
int index ;
51+
R_xlen_t index ;
5252

5353
private:
5454

0 commit comments

Comments
 (0)