From db031a5b95084b029a79b11a20a2bfe9c6b87cf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Fri, 26 Apr 2019 15:28:26 +0200 Subject: [PATCH] chore: Remove the DocIds type --- meilidb-core/src/data/doc_ids.rs | 61 -------------------------------- meilidb-core/src/data/mod.rs | 2 -- 2 files changed, 63 deletions(-) delete mode 100644 meilidb-core/src/data/doc_ids.rs diff --git a/meilidb-core/src/data/doc_ids.rs b/meilidb-core/src/data/doc_ids.rs deleted file mode 100644 index ff951bb35..000000000 --- a/meilidb-core/src/data/doc_ids.rs +++ /dev/null @@ -1,61 +0,0 @@ -use std::slice::from_raw_parts; -use std::mem::size_of; -use std::error::Error; - -use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; -use sdset::Set; - -use crate::shared_data_cursor::{SharedDataCursor, FromSharedDataCursor}; -use crate::write_to_bytes::WriteToBytes; -use crate::data::SharedData; -use crate::DocumentId; - -use super::into_u8_slice; - -#[derive(Default, Clone)] -pub struct DocIds(SharedData); - -impl DocIds { - pub fn new(ids: &Set) -> DocIds { - let bytes = unsafe { into_u8_slice(ids.as_slice()) }; - let data = SharedData::from_bytes(bytes.to_vec()); - DocIds(data) - } - - pub fn is_empty(&self) -> bool { - self.0.is_empty() - } - - pub fn as_bytes(&self) -> &[u8] { - &self.0 - } -} - -impl AsRef> for DocIds { - fn as_ref(&self) -> &Set { - let slice = &self.0; - let ptr = slice.as_ptr() as *const DocumentId; - let len = slice.len() / size_of::(); - let slice = unsafe { from_raw_parts(ptr, len) }; - Set::new_unchecked(slice) - } -} - -impl FromSharedDataCursor for DocIds { - type Error = Box; - - fn from_shared_data_cursor(cursor: &mut SharedDataCursor) -> Result { - let len = cursor.read_u64::()? as usize; - let data = cursor.extract(len); - - Ok(DocIds(data)) - } -} - -impl WriteToBytes for DocIds { - fn write_to_bytes(&self, bytes: &mut Vec) { - let len = self.0.len() as u64; - bytes.write_u64::(len).unwrap(); - bytes.extend_from_slice(&self.0); - } -} diff --git a/meilidb-core/src/data/mod.rs b/meilidb-core/src/data/mod.rs index 895f553a6..195a71cdc 100644 --- a/meilidb-core/src/data/mod.rs +++ b/meilidb-core/src/data/mod.rs @@ -1,11 +1,9 @@ -mod doc_ids; mod doc_indexes; mod shared_data; use std::slice::from_raw_parts; use std::mem::size_of; -pub use self::doc_ids::DocIds; pub use self::doc_indexes::{DocIndexes, DocIndexesBuilder}; pub use self::shared_data::SharedData;