Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ pub mod prelude {
TableSecondaryIndex, TableSecondaryIndexCdc, WorkTable, WorkTableError,
};
pub use data_bucket::{
align, get_index_page_size_from_data_length, map_data_pages_to_general,
map_index_pages_to_general, parse_data_page, parse_page, persist_page, seek_to_page_start,
update_at, DataPage, GeneralHeader, GeneralPage, IndexPage, Interval, Link, PageType,
Persistable, PersistableIndex, SizeMeasurable, SizeMeasure, SpaceInfoPage,
TableOfContentsPage, DATA_VERSION, GENERAL_HEADER_SIZE, INNER_PAGE_SIZE, PAGE_SIZE,
align, get_index_page_size_from_data_length, map_data_pages_to_general, parse_data_page,
parse_page, persist_page, seek_to_page_start, update_at, DataPage, GeneralHeader,
GeneralPage, IndexPage, Interval, Link, PageType, Persistable, PersistableIndex,
SizeMeasurable, SizeMeasure, SpaceInfoPage, TableOfContentsPage, DATA_VERSION,
GENERAL_HEADER_SIZE, INNER_PAGE_SIZE, PAGE_SIZE,
};

pub use derive_more::{From, Into};
Expand Down
4 changes: 3 additions & 1 deletion src/persistence/space/index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub use table_of_contents::IndexTableOfContents;
pub use util::map_index_pages_to_toc_and_general;

#[derive(Debug)]
pub struct SpaceIndex<T, const DATA_LENGTH: u32> {
pub struct SpaceIndex<T: Ord + Eq, const DATA_LENGTH: u32> {
space_id: SpaceId,
table_of_contents: IndexTableOfContents<T, DATA_LENGTH>,
next_page_id: Arc<AtomicU32>,
Expand Down Expand Up @@ -108,6 +108,8 @@ where
>,
{
let size = get_index_page_size_from_data_length::<T>(DATA_LENGTH as usize);
println!("Length {}", DATA_LENGTH);
println!("Size {}", size);
let mut page = IndexPage::new(node_id.key.clone(), size);
page.current_index = 1;
page.current_length = 1;
Expand Down
22 changes: 6 additions & 16 deletions src/persistence/space/index/table_of_contents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ use rkyv::{rancor, Archive, Deserialize, Serialize};
use tokio::fs::File;

#[derive(Debug)]
pub struct IndexTableOfContents<T, const DATA_LENGTH: u32> {
pub struct IndexTableOfContents<T: Ord + Eq, const DATA_LENGTH: u32> {
current_page: usize,
next_page_id: Arc<AtomicU32>,
pub pages: Vec<GeneralPage<TableOfContentsPage<T>>>,
}

impl<T, const DATA_LENGTH: u32> IndexTableOfContents<T, DATA_LENGTH>
where
T: SizeMeasurable,
T: SizeMeasurable + Ord + Eq,
{
pub fn new(space_id: SpaceId, next_page_id: Arc<AtomicU32>) -> Self {
let page_id = next_page_id.fetch_add(1, Ordering::Relaxed);
Expand All @@ -40,10 +40,7 @@ where
}
}

pub fn get(&self, node_id: &T) -> Option<PageId>
where
T: Ord + Eq,
{
pub fn get(&self, node_id: &T) -> Option<PageId> {
for page in &self.pages {
if page.inner.contains(node_id) {
return Some(
Expand All @@ -63,7 +60,7 @@ where

pub fn insert(&mut self, node_id: T, page_id: PageId)
where
T: Clone + Ord + Eq + SizeMeasurable,
T: Clone + SizeMeasurable,
{
let next_page_id = self.next_page_id.clone();

Expand Down Expand Up @@ -95,7 +92,7 @@ where

pub fn remove(&mut self, node_id: &T)
where
T: Clone + Ord + Eq + SizeMeasurable,
T: Clone + SizeMeasurable,
{
let mut removed = false;
let mut i = 0;
Expand All @@ -117,10 +114,7 @@ where
self.pages.iter().flat_map(|v| v.inner.iter())
}

pub fn update_key(&mut self, old_key: &T, new_key: T)
where
T: Ord + Eq,
{
pub fn update_key(&mut self, old_key: &T, new_key: T) {
let page = self.get_current_page_mut();
page.inner.update_key(old_key, new_key);
}
Expand All @@ -133,8 +127,6 @@ where
pub async fn persist(&mut self, file: &mut File) -> eyre::Result<()>
where
T: Archive
+ Ord
+ Eq
+ Clone
+ SizeMeasurable
+ for<'a> Serialize<
Expand All @@ -157,8 +149,6 @@ where
) -> eyre::Result<Self>
where
T: Archive
+ Ord
+ Eq
+ Clone
+ SizeMeasurable
+ for<'a> Serialize<
Expand Down
2 changes: 1 addition & 1 deletion src/persistence/space/index/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn map_index_pages_to_toc_and_general<T, const DATA_LENGTH: u32>(
Vec<GeneralPage<IndexPage<T>>>,
)
where
T: Clone + Ord + Eq + SizeMeasurable,
T: Clone + Default + Ord + Eq + SizeMeasurable,
{
let mut general_index_pages = vec![];
let next_page_id = Arc::new(AtomicU32::new(1));
Expand Down
Loading