Skip to content

Commit 6e2a1b9

Browse files
committed
Clean up
1 parent 82c6111 commit 6e2a1b9

File tree

5 files changed

+47
-46
lines changed

5 files changed

+47
-46
lines changed

codegen/src/persist_table/generator/space_file/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl Generator {
129129
lock_map: LockMap::new(),
130130
table_name: "",
131131
pk_phantom: std::marker::PhantomData,
132-
available_types_phantom: std::marker::PhantomData,
132+
types_phantom: std::marker::PhantomData,
133133
};
134134

135135
#wt_ident(

codegen/src/worktable/generator/index.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ impl Generator {
132132
}
133133
}
134134

135+
/// Generates `process_difference` function of `TableIndex` trait for index. It updates `Link` for all secondary indexes.
136+
/// Uses HashMap<&str, Difference<AvaialableTypes>> for storing all changes
135137
fn gen_process_difference_index_fn(&self) -> TokenStream {
136138
let name_generator = WorktableNameGenerator::from_table_name(self.name.to_string());
137139
let avt_type_ident = name_generator.get_available_type_ident();

src/index/mod.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::hash::Hash;
12
use std::sync::Arc;
23

34
use data_bucket::Link;
@@ -9,9 +10,46 @@ mod table_secondary_index;
910

1011
pub use indexset::concurrent::map::BTreeMap as IndexMap;
1112
pub use indexset::concurrent::multimap::BTreeMultiMap as IndexMultiMap;
12-
pub use table_secondary_index::{Difference, TableIndex, TableSecondaryIndex};
13+
pub use table_secondary_index::TableSecondaryIndex;
1314

1415
pub enum IndexType<'a, T> {
1516
Unique(&'a TreeIndex<T, Link>),
1617
NonUnique(&'a TreeIndex<T, Arc<LockFreeSet<Link>>>),
1718
}
19+
20+
#[derive(Debug)]
21+
pub struct Difference<AvailableTypes> {
22+
pub old: AvailableTypes,
23+
pub new: AvailableTypes,
24+
}
25+
26+
pub trait TableIndex<T> {
27+
fn insert(&self, value: T, link: Link) -> Option<Link>;
28+
fn remove(&self, value: T, link: Link) -> Option<(T, Link)>;
29+
}
30+
31+
impl<T> TableIndex<T> for IndexMultiMap<T, Link>
32+
where
33+
T: Eq + Hash + Clone + std::marker::Send + std::cmp::Ord,
34+
{
35+
fn insert(&self, value: T, link: Link) -> Option<Link> {
36+
self.insert(value, link)
37+
}
38+
39+
fn remove(&self, value: T, link: Link) -> Option<(T, Link)> {
40+
self.remove(&value, &link)
41+
}
42+
}
43+
44+
impl<T> TableIndex<T> for IndexMap<T, Link>
45+
where
46+
T: Eq + Hash + Clone + std::marker::Send + std::cmp::Ord,
47+
{
48+
fn insert(&self, value: T, link: Link) -> Option<Link> {
49+
self.insert(value, link)
50+
}
51+
52+
fn remove(&self, value: T, _link: Link) -> Option<(T, Link)> {
53+
self.remove(&value)
54+
}
55+
}

src/index/table_secondary_index.rs

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,9 @@
1-
use data_bucket::Link;
2-
use indexset::concurrent::map::BTreeMap as IndexMap;
3-
use indexset::concurrent::multimap::BTreeMultiMap as IndexMultiMap;
41
use std::collections::HashMap;
5-
use std::fmt::Debug;
6-
use std::hash::Hash;
7-
8-
use crate::WorkTableError;
9-
10-
#[derive(Debug)]
11-
pub struct Difference<AvailableTypes> {
12-
pub old: AvailableTypes,
13-
pub new: AvailableTypes,
14-
}
15-
16-
pub trait TableIndex<T> {
17-
fn insert(&self, value: T, link: Link) -> Option<Link>;
18-
fn remove(&self, value: T, link: Link) -> Option<(T, Link)>;
19-
}
20-
21-
impl<T> TableIndex<T> for IndexMultiMap<T, Link>
22-
where
23-
T: Eq + Hash + Clone + std::marker::Send + std::cmp::Ord,
24-
{
25-
fn insert(&self, value: T, link: Link) -> Option<Link> {
26-
self.insert(value, link)
27-
}
282

29-
fn remove(&self, value: T, link: Link) -> Option<(T, Link)> {
30-
self.remove(&value, &link)
31-
}
32-
}
33-
34-
impl<T> TableIndex<T> for IndexMap<T, Link>
35-
where
36-
T: Eq + Hash + Clone + std::marker::Send + std::cmp::Ord,
37-
{
38-
fn insert(&self, value: T, link: Link) -> Option<Link> {
39-
self.insert(value, link)
40-
}
3+
use data_bucket::Link;
414

42-
fn remove(&self, value: T, _link: Link) -> Option<(T, Link)> {
43-
self.remove(&value)
44-
}
45-
}
5+
use crate::Difference;
6+
use crate::WorkTableError;
467

478
pub trait TableSecondaryIndex<Row, AvailableTypes>
489
where

src/table/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub struct WorkTable<
4545

4646
pub pk_phantom: PhantomData<PrimaryKey>,
4747

48-
pub available_types_phantom: PhantomData<AvailableTypes>,
48+
pub types_phantom: PhantomData<AvailableTypes>,
4949
}
5050

5151
// Manual implementations to avoid unneeded trait bounds.
@@ -67,7 +67,7 @@ where
6767
lock_map: LockMap::new(),
6868
table_name: "",
6969
pk_phantom: PhantomData,
70-
available_types_phantom: PhantomData,
70+
types_phantom: PhantomData,
7171
}
7272
}
7373
}

0 commit comments

Comments
 (0)