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;
|
|
|
|
|
2018-11-30 21:31:46 +08:00
|
|
|
pub use self::doc_ids::DocIds;
|
2018-12-01 18:35:16 +08:00
|
|
|
pub use self::doc_indexes::{DocIndexes, DocIndexesBuilder};
|
2018-11-08 19:05:59 +08:00
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
enum Data {
|
|
|
|
Shared {
|
2018-11-29 00:12:24 +08:00
|
|
|
bytes: Arc<Vec<u8>>,
|
2018-11-08 19:05:59 +08:00
|
|
|
offset: usize,
|
|
|
|
len: usize,
|
|
|
|
},
|
|
|
|
Mmap(MmapReadOnly),
|
|
|
|
}
|
|
|
|
|
2018-11-29 00:12:24 +08:00
|
|
|
impl Data {
|
|
|
|
pub fn range(&self, off: usize, l: usize) -> Data {
|
|
|
|
match self {
|
|
|
|
Data::Shared { bytes, offset, len } => {
|
|
|
|
assert!(off + l <= *len);
|
|
|
|
Data::Shared {
|
|
|
|
bytes: bytes.clone(),
|
|
|
|
offset: offset + off,
|
|
|
|
len: l,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Data::Mmap(mmap) => Data::Mmap(mmap.range(off, l)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-27 00:30:19 +08:00
|
|
|
impl Default for Data {
|
|
|
|
fn default() -> Data {
|
|
|
|
Data::Shared {
|
2018-11-29 00:12:24 +08:00
|
|
|
bytes: Arc::default(),
|
2018-11-27 00:30:19 +08:00
|
|
|
offset: 0,
|
|
|
|
len: 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-08 19:05:59 +08:00
|
|
|
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 {
|
2018-11-29 00:12:24 +08:00
|
|
|
Data::Shared { bytes, offset, len } => {
|
|
|
|
&bytes[*offset..offset + len]
|
2018-11-08 19:05:59 +08:00
|
|
|
},
|
|
|
|
Data::Mmap(m) => m.as_slice(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|