Skip to content

Commit 3627ac6

Browse files
committed
chore: lint and format source code
1 parent 956ce8f commit 3627ac6

File tree

14 files changed

+27
-35
lines changed

14 files changed

+27
-35
lines changed

bench/src/speed/test_gen.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ impl TestGenV2 {
110110
self.cur_read_num = 0;
111111
}
112112
//println!("AA gen_block cur_round={} block_count={} sp={:?}", self.cur_round, self.block_count, self.sp);
113-
let mut res: Vec<RwLock<Option<SimpleTask>>> =
114-
Vec::with_capacity(self.task_in_block);
113+
let mut res: Vec<RwLock<Option<SimpleTask>>> = Vec::with_capacity(self.task_in_block);
115114
for _ in 0..self.task_in_block {
116115
res.push(RwLock::new(None));
117116
}

qmdb/examples/v2_demo.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use parking_lot::RwLock;
22
use qmdb::config::Config;
3-
use qmdb::def::{
4-
DEFAULT_ENTRY_SIZE, IN_BLOCK_IDX_BITS, OP_CREATE,
5-
};
3+
use qmdb::def::{DEFAULT_ENTRY_SIZE, IN_BLOCK_IDX_BITS, OP_CREATE};
64
use qmdb::entryfile::EntryBz;
75
use qmdb::tasks::TasksManager;
86
use qmdb::test_helper::SimpleTask;
@@ -58,10 +56,7 @@ fn main() {
5856
//task id's high 40 bits is block height and low 24 bits is task index
5957
let last_task_id = (height << IN_BLOCK_IDX_BITS) | (task_count - 1);
6058
//add the tasks into QMDB
61-
ads.start_block(
62-
height,
63-
Arc::new(TasksManager::new(task_list, last_task_id)),
64-
);
59+
ads.start_block(height, Arc::new(TasksManager::new(task_list, last_task_id)));
6560
//multiple shared_ads can be shared by different threads
6661
let shared_ads = ads.get_shared();
6762
//you can associate some extra data in json format to each block
@@ -86,6 +81,6 @@ fn main() {
8681
// now we use another shared_ads to read entry out
8782
let shared_ads = ads.get_shared();
8883
let (n, ok) = shared_ads.read_entry(-1, &kh[..], &[], &mut buf);
89-
let e = EntryBz{ bz: &buf[..n] };
84+
let e = EntryBz { bz: &buf[..n] };
9085
println!("entry={:?} value={:?} ok={}", &buf[..n], e.value(), ok);
9186
}

qmdb/src/entryfile/entry.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ impl<'a> EntryBz<'a> {
183183
res[1] = self.bz[6]; // second byte of key
184184
return res;
185185
}
186-
return hasher::hash(self.key());
186+
hasher::hash(self.key())
187187
}
188188

189189
fn next_key_hash_start(&self) -> usize {
@@ -272,7 +272,7 @@ impl EntryVec {
272272

273273
let mut buf_list: Vec<Box<[u8]>> = Vec::with_capacity(0);
274274
let total_len = bz.len();
275-
for _ in 0..(next_pos + BIG_BUF_SIZE - 1) / BIG_BUF_SIZE {
275+
for _ in 0..next_pos.div_ceil(BIG_BUF_SIZE) {
276276
let mut buf = new_big_buf_boxed();
277277
let size = std::cmp::min(total_len - off, BIG_BUF_SIZE);
278278
buf[0..size].copy_from_slice(&bz[off..off + size]);

qmdb/src/indexer/hybrid/file_reader.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ pub fn decrypt_page(page: &mut [u8], off_in_file: usize, cipher: &Option<Aes256G
133133
tag[..].copy_from_slice(&page[tag_start..]);
134134

135135
let enc = &mut page[..tag_start];
136-
if let Err(e) = cipher.decrypt_in_place_detached(&nonce_arr.into(), b"", enc, &tag.into()) { panic!("{:?}", e) };
136+
if let Err(e) = cipher.decrypt_in_place_detached(&nonce_arr.into(), b"", enc, &tag.into()) {
137+
panic!("{:?}", e)
138+
};
137139
}
138140

139141
#[cfg(test)]

qmdb/src/indexer/hybrid/tempfile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl TempFile {
4646

4747
impl Drop for TempFile {
4848
fn drop(&mut self) {
49-
if let Err(_) = remove_file(self.fname.clone()) {
49+
if remove_file(self.fname.clone()).is_err() {
5050
panic!("Fail to remove file: {}", self.fname);
5151
}
5252
}

qmdb/src/indexer/inmem.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ struct RoLeaf<'a> {
114114
data: &'a [u8],
115115
}
116116

117-
impl<'a> RoLeaf<'a> {
117+
impl RoLeaf<'_> {
118118
fn is_full(&self) -> bool {
119119
2 + self.len() * KV_SIZE == self.data.len()
120120
}
@@ -174,7 +174,7 @@ impl<'a> RoLeaf<'a> {
174174
}
175175
}
176176

177-
impl<'a> Leaf<'a> {
177+
impl Leaf<'_> {
178178
fn to_readonly(&self) -> RoLeaf {
179179
RoLeaf { data: &*self.data }
180180
}

qmdb/src/merkletree/tree.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -934,10 +934,10 @@ impl Tree {
934934
.get_twig_root(twig_id)
935935
.unwrap_or(&twig::NULL_TWIG.twig_root);
936936
}
937-
return *self
937+
*self
938938
.upper_tree
939939
.get_node(NodePos::pos(level as u64, nth))
940-
.unwrap_or(&NULL_NODE_IN_HIGHER_TREE[level as usize]);
940+
.unwrap_or(&NULL_NODE_IN_HIGHER_TREE[level as usize])
941941
}
942942
}
943943

qmdb/src/seqads/entry_updater.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ impl EntryUpdater {
348348
}
349349

350350
pub fn get_all_entry_bz(&self) -> Vec<EntryBz> {
351-
return self.update_buffer.get_all_entry_bz();
351+
self.update_buffer.get_all_entry_bz()
352352
}
353353

354354
pub fn read_entry(&mut self, shard_id: usize, file_pos: i64) {

qmdb/src/seqads/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl SeqAds {
153153
indexer.clone(),
154154
)));
155155
}
156-
156+
157157
Self {
158158
height: AtomicI64::from(curr_height),
159159
indexer,

qmdb/src/seqads/proof.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,9 @@ impl<T: Task + 'static> SeqAdsWrap<T> {
374374
let prev_entry = EntryBz { bz: &buf[..size] };
375375
if self_pos >= 0 && prev_entry.next_key_hash() == key_hash {
376376
found = true;
377-
} else if prev_entry.key_hash() < *key_hash && &key_hash[..] < prev_entry.next_key_hash() {
377+
} else if prev_entry.key_hash() < *key_hash
378+
&& &key_hash[..] < prev_entry.next_key_hash()
379+
{
378380
found = true;
379381
}
380382
if found {
@@ -436,7 +438,7 @@ impl<T: Task + 'static> SeqAdsWrap<T> {
436438
if buf.len() < size {
437439
return (size, true); //stop loop if buf is too small
438440
}
439-
(size, buf_too_small)// stop loop if key matches
441+
(size, buf_too_small) // stop loop if key matches
440442
}
441443
}
442444

0 commit comments

Comments
 (0)