pub struct StreamingIntData<F: Fn(usize, &mut [i32]) -> usize> {
len: usize,
reader: F,
cache: RefCell<BTreeMap<usize, Vec<i32>>>,
chunk_size: usize,
}Expand description
Streaming ALTREP for integer (i32) vectors.
Elements are loaded on-demand via a reader closure in fixed-size chunks.
Chunks are cached in a BTreeMap for repeated access.
§Reader Contract
The reader F(start, buf) -> count fills buf with elements starting
at index start and returns the number of elements actually written.
§Example
ⓘ
use miniextendr_api::altrep_data::StreamingIntData;
let data = StreamingIntData::new(1000, 64, |start, buf| {
let count = buf.len().min(1000 - start);
for (i, slot) in buf[..count].iter_mut().enumerate() {
*slot = (start + i) as i32;
}
count
});Fields§
§len: usize§reader: F§cache: RefCell<BTreeMap<usize, Vec<i32>>>§chunk_size: usizeImplementations§
Source§impl<F: Fn(usize, &mut [i32]) -> usize> StreamingIntData<F>
impl<F: Fn(usize, &mut [i32]) -> usize> StreamingIntData<F>
Sourcepub fn new(len: usize, chunk_size: usize, reader: F) -> Self
pub fn new(len: usize, chunk_size: usize, reader: F) -> Self
Create a new streaming integer data source.
len: total number of elementschunk_size: number of elements per cache chunkreader: closure that fills a buffer starting at a given index
Sourcefn ensure_chunk(&self, chunk_idx: usize)
fn ensure_chunk(&self, chunk_idx: usize)
Load a chunk into the cache if not already present.
Trait Implementations§
Source§impl<F: Fn(usize, &mut [i32]) -> usize + 'static> AltInteger for StreamingIntData<F>
impl<F: Fn(usize, &mut [i32]) -> usize + 'static> AltInteger for StreamingIntData<F>
Source§const HAS_GET_REGION: bool = true
const HAS_GET_REGION: bool = true
Set to
true to register get_region.Source§fn get_region(
x: SEXP,
start: R_xlen_t,
len: R_xlen_t,
buf: &mut [i32],
) -> R_xlen_t
fn get_region( x: SEXP, start: R_xlen_t, len: R_xlen_t, buf: &mut [i32], ) -> R_xlen_t
Bulk read elements into buffer.
Source§const HAS_IS_SORTED: bool = false
const HAS_IS_SORTED: bool = false
Set to
true to register is_sorted.Source§impl<F: Fn(usize, &mut [i32]) -> usize> AltIntegerData for StreamingIntData<F>
impl<F: Fn(usize, &mut [i32]) -> usize> AltIntegerData for StreamingIntData<F>
Source§fn get_region(&self, start: usize, len: usize, buf: &mut [i32]) -> usize
fn get_region(&self, start: usize, len: usize, buf: &mut [i32]) -> usize
Optional: bulk read into buffer. Returns number of elements read. Read more
Source§fn as_slice(&self) -> Option<&[i32]>
fn as_slice(&self) -> Option<&[i32]>
Optional: return a pointer to contiguous data if available.
Default returns None (no contiguous backing).
Source§fn is_sorted(&self) -> Option<Sortedness>
fn is_sorted(&self) -> Option<Sortedness>
Optional: sortedness hint. Default is unknown.
Source§fn sum(&self, _na_rm: bool) -> Option<i64>
fn sum(&self, _na_rm: bool) -> Option<i64>
Optional: optimized sum. Default returns None (use R’s default).
Source§impl<F: Fn(usize, &mut [i32]) -> usize + 'static> AltVec for StreamingIntData<F>
impl<F: Fn(usize, &mut [i32]) -> usize + 'static> AltVec for StreamingIntData<F>
Source§const HAS_DATAPTR: bool = false
const HAS_DATAPTR: bool = false
Set to
true to register dataptr.Source§const HAS_DATAPTR_OR_NULL: bool = false
const HAS_DATAPTR_OR_NULL: bool = false
Set to
true to register dataptr_or_null.Source§fn dataptr_or_null(_x: SEXP) -> *const c_void
fn dataptr_or_null(_x: SEXP) -> *const c_void
Get data pointer without forcing materialization.
Source§const HAS_EXTRACT_SUBSET: bool = false
const HAS_EXTRACT_SUBSET: bool = false
Set to
true to register extract_subset.Source§impl<F: Fn(usize, &mut [i32]) -> usize + 'static> Altrep for StreamingIntData<F>
impl<F: Fn(usize, &mut [i32]) -> usize + 'static> Altrep for StreamingIntData<F>
Source§fn length(x: SEXP) -> R_xlen_t
fn length(x: SEXP) -> R_xlen_t
Returns the length of the ALTREP vector.
This is REQUIRED - R cannot determine vector length without it.
Source§const GUARD: AltrepGuard = AltrepGuard::RUnwind
const GUARD: AltrepGuard = AltrepGuard::RUnwind
The guard mode for all ALTREP trampolines on this type. Read more
Source§const HAS_SERIALIZED_STATE: bool = false
const HAS_SERIALIZED_STATE: bool = false
Set to
true to register serialized_state.Source§fn serialized_state(_x: SEXP) -> SEXP
fn serialized_state(_x: SEXP) -> SEXP
Return serialization state.
Source§const HAS_UNSERIALIZE: bool = false
const HAS_UNSERIALIZE: bool = false
Set to
true to register unserialize.Source§const HAS_UNSERIALIZE_EX: bool = false
const HAS_UNSERIALIZE_EX: bool = false
Set to
true to register unserialize_ex.Source§fn unserialize_ex(
_class: SEXP,
_state: SEXP,
_attr: SEXP,
_objf: i32,
_levs: i32,
) -> SEXP
fn unserialize_ex( _class: SEXP, _state: SEXP, _attr: SEXP, _objf: i32, _levs: i32, ) -> SEXP
Extended unserialization with attributes.
Source§const HAS_DUPLICATE: bool = false
const HAS_DUPLICATE: bool = false
Set to
true to register duplicate.Source§const HAS_DUPLICATE_EX: bool = false
const HAS_DUPLICATE_EX: bool = false
Set to
true to register duplicate_ex.Source§const HAS_COERCE: bool = false
const HAS_COERCE: bool = false
Set to
true to register coerce.Source§const HAS_INSPECT: bool = false
const HAS_INSPECT: bool = false
Set to
true to register inspect.Source§impl<F: Fn(usize, &mut [i32]) -> usize + 'static> InferBase for StreamingIntData<F>
impl<F: Fn(usize, &mut [i32]) -> usize + 'static> InferBase for StreamingIntData<F>
Source§unsafe fn make_class(
class_name: *const i8,
pkg_name: *const i8,
) -> R_altrep_class_t
unsafe fn make_class( class_name: *const i8, pkg_name: *const i8, ) -> R_altrep_class_t
Create the ALTREP class handle. Read more
Source§unsafe fn install_methods(cls: R_altrep_class_t)
unsafe fn install_methods(cls: R_altrep_class_t)
Install ALTREP methods on the class. Read more
Source§impl<F: Fn(usize, &mut [i32]) -> usize + 'static> TypedExternal for StreamingIntData<F>
impl<F: Fn(usize, &mut [i32]) -> usize + 'static> TypedExternal for StreamingIntData<F>
Source§const TYPE_NAME: &'static str = "StreamingIntData"
const TYPE_NAME: &'static str = "StreamingIntData"
The type name as a static string (for debugging and display)
Source§const TYPE_NAME_CSTR: &'static [u8] = b"StreamingIntData\0"
const TYPE_NAME_CSTR: &'static [u8] = b"StreamingIntData\0"
The type name as a null-terminated C string (for R tag display)
Source§const TYPE_ID_CSTR: &'static [u8] = b"miniextendr_api::altrep::StreamingIntData\0"
const TYPE_ID_CSTR: &'static [u8] = b"miniextendr_api::altrep::StreamingIntData\0"
Namespaced type ID as a null-terminated C string (for type checking). Read more
Auto Trait Implementations§
impl<F> !Freeze for StreamingIntData<F>
impl<F> !RefUnwindSafe for StreamingIntData<F>
impl<F> Send for StreamingIntData<F>where
F: Send,
impl<F> !Sync for StreamingIntData<F>
impl<F> Unpin for StreamingIntData<F>where
F: Unpin,
impl<F> UnsafeUnpin for StreamingIntData<F>where
F: UnsafeUnpin,
impl<F> UnwindSafe for StreamingIntData<F>where
F: UnwindSafe,
Blanket Implementations§
Source§impl<T> AltrepExtract for Twhere
T: TypedExternal,
impl<T> AltrepExtract for Twhere
T: TypedExternal,
Source§unsafe fn altrep_extract_ref(x: SEXP) -> &'static T
unsafe fn altrep_extract_ref(x: SEXP) -> &'static T
Extract a shared reference from the ALTREP data1 slot. Read more
Source§unsafe fn altrep_extract_mut(x: SEXP) -> &'static mut T
unsafe fn altrep_extract_mut(x: SEXP) -> &'static mut T
Extract a mutable reference from the ALTREP data1 slot. Read more
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more