diff --git a/storage_engine/src/binary_coding.rs b/storage_engine/src/binary_coding.rs index a607296..cea1a6a 100644 --- a/storage_engine/src/binary_coding.rs +++ b/storage_engine/src/binary_coding.rs @@ -1,7 +1,5 @@ -use bincode; use bincode::config::{BigEndian, Configuration, Fixint}; use bincode::{Decode, Encode}; -use std::mem::size_of; const BIN_CONFIG: Configuration = bincode::config::standard() .with_big_endian() @@ -15,27 +13,6 @@ pub fn decode(bytes: &[u8]) -> Result<(T, usize), bincode::error::Dec bincode::decode_from_slice(bytes, BIN_CONFIG) } -pub fn encode_vector(ts: &[T]) -> Result, bincode::error::EncodeError> { - let size: usize = ts.len(); - let mut result = encode(&size)?; - for t in ts { - result.append(&mut encode(&t)?); - } - Ok(result) -} - -pub fn decode_vector(bytes: &[u8]) -> Result, bincode::error::DecodeError> { - let mut offset = size_of::(); - let result_len: usize = decode(&bytes[..offset])?.0; - let mut result: Vec = Vec::with_capacity(result_len); - for _ in 0..result_len { - let (x, bytes_consumed) = decode::(&bytes[offset..])?; - offset += bytes_consumed; - result.push(x); - } - Ok(result) -} - // We don't care about encoding the length here (since it will be used for a row with known column // size) pub fn encode_sequence(ts: &[T]) -> Result, bincode::error::EncodeError> { @@ -72,20 +49,3 @@ pub fn decode_sequence( } Ok(result) } - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_encoding_decoding() { - let xs: Vec = vec!["foo".to_string(), "bar".to_string()]; - - let exs = encode_vector(&xs[..]).unwrap(); - - // WARNING: Don't forget to specify the type here - let dxs = decode_vector::(&exs[..]).unwrap(); - - assert!(dxs == xs); - } -} diff --git a/storage_engine/src/cursor.rs b/storage_engine/src/cursor.rs index c145398..f065b38 100644 --- a/storage_engine/src/cursor.rs +++ b/storage_engine/src/cursor.rs @@ -92,7 +92,7 @@ impl CursorCanTraverse for ReadCursor<'_, T> { impl CursorCanTraverse for WriteCursor<'_, T> { fn header(&self) -> &StoreHeader { - &self.header + self.header } } @@ -123,13 +123,13 @@ impl CursorCanModifyEntries for AppendOnlyCursor { // ===capability to access index=== impl CursorCanReadIndex for ReadCursor<'_, T> { fn indexes(&mut self) -> &[Option>] { - &self.indexes + self.indexes } } impl CursorCanReadIndex for WriteCursor<'_, T> { fn indexes(&mut self) -> &[Option>] { - &self.indexes + self.indexes } } @@ -266,9 +266,10 @@ impl<'cursor, T> WriteCursor<'cursor, T> { T: Encode + Decode + Ord + Send + Sync + Clone, { let mut count = 0; - while let Some(_) = self + while self .find_first_eq_bruteforce_and_delete(column, t0, false) .await? + .is_some() { count += 1; } @@ -326,7 +327,7 @@ impl<'cursor, T> WriteCursor<'cursor, T> { T: Ord + Decode + Encode + Send + Sync, { // New Index - let index = Store::create_empty_index_at(&self.header, column).await?; + let index = Store::create_empty_index_at(self.header, column).await?; self.indexes[column as usize] = Some(index); // Mark column as indexed @@ -436,7 +437,7 @@ impl<'cursor, T> WriteCursor<'cursor, T> { let path_to_rows = path_to_table.join(GARBAGE_COLLECTION_INTERMEDIATE_ROWS_FILE_NAME); let intermediate_file: File = - Store::::create_empty_rows_file(path_to_rows, &self.header).await?; + Store::::create_empty_rows_file(path_to_rows, self.header).await?; let intermediate_header: StoreHeader = StoreHeader { table_folder, diff --git a/storage_engine/src/cursor_capabilities/entry_modification.rs b/storage_engine/src/cursor_capabilities/entry_modification.rs index 7f807e8..fd3a202 100644 --- a/storage_engine/src/cursor_capabilities/entry_modification.rs +++ b/storage_engine/src/cursor_capabilities/entry_modification.rs @@ -4,7 +4,7 @@ use crate::binary_coding::encode; use bincode; use bincode::Encode; -use crate::cursor_capabilities::primitive::{CursorCanRead, CursorCanWrite}; +use crate::cursor_capabilities::primitive::CursorCanWrite; use crate::cursor_capabilities::traversal::CursorCanTraverse; use crate::segments::entry::Entry; use crate::segments::store_header::StoreHeader; diff --git a/storage_engine/src/cursor_capabilities/index_access.rs b/storage_engine/src/cursor_capabilities/index_access.rs index 5210e95..a5128a2 100644 --- a/storage_engine/src/cursor_capabilities/index_access.rs +++ b/storage_engine/src/cursor_capabilities/index_access.rs @@ -22,7 +22,7 @@ pub trait CursorCanReadIndex: CursorCanTraverse { { match &self.indexes()[column as usize] { Some(index) => { - let file_positions = index.lookup(value).await?.unwrap_or_else(|| HashSet::new()); + let file_positions = index.lookup(value).await?.unwrap_or_else(HashSet::new); let mut entries: Vec> = vec![]; for &file_position in file_positions.iter() { match self.read_entry_at(file_position).await? { diff --git a/storage_engine/src/cursor_capabilities/primitive.rs b/storage_engine/src/cursor_capabilities/primitive.rs index bf4e7f5..3e465b2 100644 --- a/storage_engine/src/cursor_capabilities/primitive.rs +++ b/storage_engine/src/cursor_capabilities/primitive.rs @@ -5,7 +5,7 @@ use tokio::io::{AsyncReadExt, AsyncSeekExt, AsyncWriteExt, SeekFrom}; use crate::store::{FilePosition, Result}; #[async_trait] -pub(crate) trait CursorCanRead { +pub trait CursorCanRead { fn file(&mut self) -> &mut File; fn eof_file_position(&self) -> FilePosition; @@ -55,7 +55,7 @@ pub(crate) trait CursorCanRead { } #[async_trait] -pub(crate) trait CursorCanWrite: CursorCanRead { +pub trait CursorCanWrite: CursorCanRead { async fn write_bytes(&mut self, bytes: &[u8]) -> Result { Ok(self.file().write(bytes).await?) } diff --git a/storage_engine/src/cursor_capabilities/traversal.rs b/storage_engine/src/cursor_capabilities/traversal.rs index 809d416..b8f7882 100644 --- a/storage_engine/src/cursor_capabilities/traversal.rs +++ b/storage_engine/src/cursor_capabilities/traversal.rs @@ -89,7 +89,7 @@ pub trait CursorCanTraverse: CursorCanRead { entry_header, file_position, self.header().number_of_columns, - &mut data_bytes, + &data_bytes, )?; Ok(Some(entry)) diff --git a/storage_engine/src/index.rs b/storage_engine/src/index.rs index 6f69b76..e053e82 100644 --- a/storage_engine/src/index.rs +++ b/storage_engine/src/index.rs @@ -7,7 +7,6 @@ use std::hash::Hash; use std::io::SeekFrom; use crate::binary_coding::{decode, encode}; -use bincode; use bincode::{Decode, Encode}; use crate::error::{DecodeErrorKind, Error}; @@ -63,7 +62,7 @@ where Ok(()) } - pub fn insert_desynced(&mut self, k: K, v: V) -> () { + pub fn insert_desynced(&mut self, k: K, v: V) { self.data.entry(k).or_insert_with(HashSet::new).insert(v); } diff --git a/storage_engine/src/store.rs b/storage_engine/src/store.rs index 1a56a1f..3e42776 100644 --- a/storage_engine/src/store.rs +++ b/storage_engine/src/store.rs @@ -29,8 +29,8 @@ pub async fn store_exists(table_folder: &str) -> Result { Ok(fs::metadata(table_folder).await.is_ok()) } -pub const ROWS_FILE_NAME: &'static str = "rows"; -pub const GARBAGE_COLLECTION_INTERMEDIATE_ROWS_FILE_NAME: &'static str = "rows_intermediate"; +pub const ROWS_FILE_NAME: &str = "rows"; +pub const GARBAGE_COLLECTION_INTERMEDIATE_ROWS_FILE_NAME: &str = "rows_intermediate"; impl Store { // ===Creation===