2018-11-08 19:05:59 +08:00
|
|
|
mod doc_ids;
|
|
|
|
mod doc_indexes;
|
|
|
|
|
|
|
|
use std::ops::Deref;
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
use fst::raw::MmapReadOnly;
|
|
|
|
|
|
|
|
pub use self::doc_ids::{DocIds, DocIdsBuilder};
|
|
|
|
pub use self::doc_indexes::{DocIndexes, DocIndexesBuilder};
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
enum Data {
|
|
|
|
Shared {
|
|
|
|
vec: Arc<Vec<u8>>,
|
|
|
|
offset: usize,
|
|
|
|
len: usize,
|
|
|
|
},
|
|
|
|
Mmap(MmapReadOnly),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Deref for Data {
|
|
|
|
type Target = [u8];
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
2018-11-24 01:00:24 +08:00
|
|
|
self.as_ref()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AsRef<[u8]> for Data {
|
|
|
|
fn as_ref(&self) -> &[u8] {
|
2018-11-08 19:05:59 +08:00
|
|
|
match self {
|
|
|
|
Data::Shared { vec, offset, len } => {
|
|
|
|
&vec[*offset..offset + len]
|
|
|
|
},
|
|
|
|
Data::Mmap(m) => m.as_slice(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|