@@ -278,26 +278,26 @@ class Vector :
278278 /* *
279279 * offset based on the dimensions of this vector
280280 */
281- size_t offset (const size_t & i, const size_t & j) const {
281+ R_xlen_t offset (const int & i, const int & j) const {
282282 if ( !::Rf_isMatrix (Storage::get__ ()) ) throw not_a_matrix () ;
283283
284284 /* we need to extract the dimensions */
285- int * dim = dims () ;
286- size_t nrow = static_cast < size_t >( dim[0 ]) ;
287- size_t ncol = static_cast < size_t >( dim[1 ]) ;
288- if ( i >= nrow || j >= ncol ) throw index_out_of_bounds () ;
289- return i + nrow*j ;
285+ const int * dim = dims () ;
286+ const int nrow = dim[0 ] ;
287+ const int ncol = dim[1 ] ;
288+ if (i < 0 || i >= nrow || j < 0 || j >= ncol ) throw index_out_of_bounds () ;
289+ return i + static_cast <R_xlen_t>( nrow) *j ;
290290 }
291291
292292 /* *
293293 * one dimensional offset doing bounds checking to ensure
294294 * it is valid
295295 */
296- size_t offset (const size_t & i) const {
297- if ( static_cast <R_xlen_t>(i) >= ::Rf_xlength (Storage::get__ ()) ) throw index_out_of_bounds () ;
296+ R_xlen_t offset (const R_xlen_t & i) const {
297+ if (i < 0 || i >= ::Rf_xlength (Storage::get__ ()) ) throw index_out_of_bounds () ;
298298 return i ;
299299 }
300-
300+
301301 R_xlen_t offset (const std::string& name) const {
302302 SEXP names = RCPP_GET_NAMES ( Storage::get__ () ) ;
303303 if ( Rf_isNull (names) ) throw index_out_of_bounds ();
@@ -318,7 +318,7 @@ class Vector :
318318
319319 inline iterator begin () { return cache.get () ; }
320320 inline iterator end () { return cache.get () + size () ; }
321- inline const_iterator begin () const { return cache.get_const () ; }
321+ inline const_iterator begin () const { return cache.get_const () ; }
322322 inline const_iterator end () const { return cache.get_const () + size () ; }
323323
324324 inline Proxy operator []( R_xlen_t i ){ return cache.ref (i) ; }
@@ -331,6 +331,13 @@ class Vector :
331331 return cache.ref ( offset (i) ) ;
332332 }
333333
334+ inline Proxy at ( const size_t & i) {
335+ return cache.ref ( offset (i) ) ;
336+ }
337+ inline const_Proxy at ( const size_t & i) const {
338+ return cache.ref ( offset (i) ) ;
339+ }
340+
334341 inline Proxy operator ()( const size_t & i, const size_t & j) {
335342 return cache.ref ( offset (i,j) ) ;
336343 }
0 commit comments