From 46a3cd53187285040c518cc4e475f9936e0bd788 Mon Sep 17 00:00:00 2001 From: o0Ignition0o Date: Sun, 11 Apr 2021 00:10:57 +0200 Subject: [PATCH 1/2] lotable builder --- src/table/lotable.rs | 78 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/src/table/lotable.rs b/src/table/lotable.rs index 3c0f915..4d43680 100644 --- a/src/table/lotable.rs +++ b/src/table/lotable.rs @@ -15,6 +15,72 @@ use std::sync::Arc; const DEFAULT_CAP: usize = 1024; +pub struct LOTableBuilder { + cc: TransactionConcurrency, + iso: TransactionIsolation, + timeout: usize, + size: usize, + label: String, + cap: usize, + hasher: RandomState, +} + +impl LOTableBuilder { + pub fn new() -> Self { + Self { + cc: TransactionConcurrency::Optimistic, + iso: TransactionIsolation::RepeatableRead, + timeout: 100_usize, + size: 1_usize, + label: "default".into(), + cap: DEFAULT_CAP, + hasher: RandomState::new(), + } + } + + pub fn with_concurrency(self, cc: TransactionConcurrency) -> Self { + Self { cc, ..self } + } + + pub fn with_isolation(self, iso: TransactionIsolation) -> Self { + Self { iso, ..self } + } + + pub fn with_timeout(self, timeout: usize) -> Self { + Self { timeout, ..self } + } + pub fn with_size(self, size: usize) -> Self { + Self { size, ..self } + } + + pub fn with_label(self, label: String) -> Self { + Self { label, ..self } + } + + pub fn with_capacity(self, cap: usize) -> Self { + Self { cap, ..self } + } + + pub fn with_hasher(self, hasher: RandomState) -> Self { + Self { hasher, ..self } + } + + pub fn build(self) -> LOTable + where + K: PartialEq + Eq + Hash + Clone + Send + Sync, + V: Clone + Send + Sync, + { + let txn_man = Arc::new(TxnManager { + txid: Arc::new(AtomicU64::new(GLOBAL_VCLOCK.load(Ordering::SeqCst))), + }); + + let txn: Arc = + Arc::new(txn_man.txn_build(self.cc, self.iso, self.timeout, self.size, self.label)); + + LOTable::with_cap_hash_and_txn(self.cap, self.hasher, txn) + } +} + #[derive(Clone)] /// /// Lever Transactional Table implementation with [Optimistic](TransactionConcurrency::Optimistic) @@ -54,6 +120,18 @@ where V: Clone + Send + Sync, S: BuildHasher, { + fn with_cap_hash_and_txn(cap: usize, hasher: S, txn: Arc) -> LOTable { + let txn_man = Arc::new(TxnManager { + txid: Arc::new(AtomicU64::new(GLOBAL_VCLOCK.load(Ordering::SeqCst))), + }); + + Self { + latch: vec![TVar::new(Arc::new(AtomicBox::new(Container(HashMap::default())))); cap], + txn_man, + txn, + hash_builder: hasher, + } + } fn with_capacity_and_hasher(cap: usize, hasher: S) -> LOTable { let txn_man = Arc::new(TxnManager { txid: Arc::new(AtomicU64::new(GLOBAL_VCLOCK.load(Ordering::SeqCst))), From 295ae985020ae5ab1b924226d2bb1c306c7c08f8 Mon Sep 17 00:00:00 2001 From: o0Ignition0o Date: Tue, 13 Apr 2021 13:38:56 +0200 Subject: [PATCH 2/2] builder() fn --- src/table/lotable.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/table/lotable.rs b/src/table/lotable.rs index 4d43680..7a28ca3 100644 --- a/src/table/lotable.rs +++ b/src/table/lotable.rs @@ -105,6 +105,10 @@ where K: PartialEq + Eq + Hash + Clone + Send + Sync, V: Clone + Send + Sync, { + pub fn builder() -> LOTableBuilder { + LOTableBuilder::new() + } + pub fn new() -> Self { Self::with_capacity(DEFAULT_CAP) }