use std::ops::Range;
use bytes::Bytes;
use futures::{future::BoxFuture, FutureExt, TryFutureExt};
use lance_core::Result;
pub mod buffer;
pub mod compression_algo;
pub mod data;
pub mod decoder;
pub mod encoder;
pub mod encodings;
pub mod format;
pub mod repdef;
pub mod statistics;
#[cfg(test)]
pub mod testing;
pub mod utils;
pub mod version;
#[cfg(not(target_endian = "little"))]
compile_error!("Lance encodings only support little-endian systems.");
pub trait EncodingsIo: std::fmt::Debug + Send + Sync {
fn submit_request(
&self,
range: Vec<Range<u64>>,
priority: u64,
) -> BoxFuture<'static, Result<Vec<Bytes>>>;
fn submit_single(
&self,
range: std::ops::Range<u64>,
priority: u64,
) -> BoxFuture<'static, lance_core::Result<bytes::Bytes>> {
self.submit_request(vec![range], priority)
.map_ok(|mut v| v.pop().unwrap())
.boxed()
}
}
#[derive(Debug)]
pub struct BufferScheduler {
data: Bytes,
}
impl BufferScheduler {
pub fn new(data: Bytes) -> Self {
Self { data }
}
fn satisfy_request(&self, req: Range<u64>) -> Bytes {
self.data.slice(req.start as usize..req.end as usize)
}
}
impl EncodingsIo for BufferScheduler {
fn submit_request(
&self,
ranges: Vec<Range<u64>>,
_priority: u64,
) -> BoxFuture<'static, Result<Vec<Bytes>>> {
std::future::ready(Ok(ranges
.into_iter()
.map(|range| self.satisfy_request(range))
.collect::<Vec<_>>()))
.boxed()
}
}