Created: 2016-07-11 Mon 11:08
#define DATAPTR(x) (((SEXPREC_ALIGN *) (x)) + 1)
//... unsigned int debug : 1; unsigned int trace : 1; /* functions and memory tracing */ unsigned int spare : 1; /* currently unused */ unsigned int gcgen : 1; /* old generation number */ unsigned int gccls : 3; /* node class */ }
/* if the custom vector bit is set, use its accessor. Otherwise, vector data is contiguous with header, same as it always was */ #define DATAPTR(x) ((void *) (IS_CUSTVEC(x) ? (CUSTAPI_PTR(x)->dataptr(x)) : ((SEXPREC_ALIGN *) (x)) + 1))
dataptr
is actually called
DATAPTR
#define DUPLICATE_ATOMIC_VECTOR(type, fun, to, from, deep) do { \ if( CUSTAPI_PTR(from) ) \ PROTECT(to = CUSTAPI_PTR(from)->dup_vector( to, from, deep)); \ else DUPLICATE_TRAD_ATOMIC_VECTOR(type, fun, to, from, deep); \ } while (0)
typedef struct api_impl { R_allocator_t *allocator; void *(*dataptr)(SEXP); void (*set_dataptr)(SEXP, void*); SEXP (*dup_vector)(SEXP, SEXP, Rboolean);
SEXP (*subvector)(SEXP, R_xlen_t, R_xlen_t); SEXP (*set_subvector) (SEXP, SEXP, int); SEXP (*get)(SEXP, int); SEXP (*set)(SEXP, SEXP, int);
Allow C code to use custom vectors without needing to create the C array representation
Rboolean (*is_sorted)(SEXP); void (*set_sorted)(SEXP, Rboolean); Rboolean (*is_contigous)(SEXP); //is it a contiguous sequence of integers?; void (*set_contiguous)(SEXP, Rboolean); Rboolean (*contains)(SEXP, SEXP); Rboolean (*noNAs)(SEXP); //does the vector "know" that it has no NAs? SEXP (*set_noNAs)(SEXP, Rboolean);
window of the parent when it is used to subset
Rboolean (*contains)(SEXP, SEXP); R_xlen_t (*index_of)(SEXP, SEXP);
O(log n)
void *(*scratch)(SEXP); //retrieve scratch space for SEXP, if any; /* init is called after the SEXP is allocated via the allocator It can be a no-op, or can allocate the actual data storage, or set the data storage to an existing pointer, etc. 3rd argument can be a SEXP, but doesn't need to be (e.g. when constructing a custom vector directly from C). */ SEXP (*init)(SEXP, size_t, void*); const char *impl_descr;