Skip to content

Commit 69eb00a

Browse files
committed
Updated to compiler bug
1 parent 8b5a439 commit 69eb00a

File tree

5 files changed

+109
-5
lines changed

5 files changed

+109
-5
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55
license-file = "LICENSE"
66
categories = ["command-line-utilities", "database-implementations"]
77
keywords = ["cli", "bbolt", "database", "db"]
8-
rust-version = "1.75"
8+
rust-version = "1.76"
99
description = "A Rust port of the Bolt database"
1010

1111
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -19,8 +19,8 @@ bumpalo = { version = "3.16", features = ["collections", "allocator-api2"]}
1919
hashbrown = "0.14.5"
2020
memmap2 = "0.9.4"
2121
page_size = "0.6.0"
22-
itertools = "0.12.1"
23-
bytemuck = { version = "1.15", features = ["derive"] }
22+
itertools = "0.13.0"
23+
bytemuck = { version = "1.16", features = ["derive"] }
2424
size = "0.4.1"
2525
getset = "0.1.2"
2626
once_cell = "1.19.0"

src/common/pool.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl<T> Drop for SyncReusable<T> {
148148

149149
#[cfg(test)]
150150
mod tests {
151-
use crate::common::pool::{SyncPool};
151+
use crate::common::pool::SyncPool;
152152
use std::rc::Rc;
153153
use std::sync::Arc;
154154

@@ -163,5 +163,4 @@ mod tests {
163163

164164
assert_eq!(1, pool.len());
165165
}
166-
167166
}

src/common/utility.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,65 @@
1+
use std::fmt::{Debug, Formatter};
2+
13
// https://stackoverflow.com/questions/51272571/how-do-i-check-if-a-slice-is-sorted
24
pub fn is_sorted<T>(data: &[T]) -> bool
35
where
46
T: Ord,
57
{
68
data.windows(2).all(|w| w[0] <= w[1])
79
}
10+
11+
pub enum Breadcrumb<'a, T> {
12+
Root(T),
13+
Extend(&'a Breadcrumb<'a, T>, T),
14+
}
15+
16+
impl<'a, T> Breadcrumb<'a, T> {
17+
pub fn new(value: T) -> Breadcrumb<'a, T> {
18+
Breadcrumb::Root(value)
19+
}
20+
21+
pub fn push(&self, value: T) -> Breadcrumb<T> {
22+
Breadcrumb::Extend(self, value)
23+
}
24+
25+
pub fn len(&self) -> usize {
26+
match self {
27+
Breadcrumb::Root(_) => 1,
28+
Breadcrumb::Extend(parent, _) => parent.len() + 1,
29+
}
30+
}
31+
}
32+
33+
impl<'a, T> Debug for Breadcrumb<'a, T>
34+
where
35+
T: Debug,
36+
{
37+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
38+
match self {
39+
Breadcrumb::Root(value) => f.write_fmt(format_args!("Breadcrumb: {:?}", value)),
40+
Breadcrumb::Extend(parent, value) => {
41+
parent.fmt(f)?;
42+
f.write_fmt(format_args!(", {:?}", value))
43+
}
44+
}
45+
}
46+
}
47+
48+
#[cfg(test)]
49+
mod tests {
50+
use crate::common::utility::Breadcrumb;
51+
52+
fn cascade<'a>(dist: usize, bc: &'a Breadcrumb<'a, usize>) {
53+
let push = bc.push(6 - dist);
54+
assert_eq!(7 - dist, push.len());
55+
if dist > 0 {
56+
cascade(dist - 1, &push);
57+
}
58+
}
59+
60+
#[test]
61+
fn test_breadcrumb() {
62+
let a = Breadcrumb::new(0);
63+
cascade(5, &a);
64+
}
65+
}

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ mod node;
3333
mod test_support;
3434
mod tx;
3535

36+
mod util;
37+
3638
pub use bucket::{BucketApi, BucketImpl, BucketRwApi, BucketRwImpl, BucketStats};
3739
pub use common::errors::{Error, Result};
3840
pub use common::ids::{PgId, TxId};

src/util.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
use crate::common::utility::Breadcrumb;
2+
use crate::{Bolt, BucketApi, BucketImpl, DbApi, TxApi};
3+
use size::Size;
4+
5+
pub fn copy() {}
6+
7+
pub fn compact(src: &Bolt, dst: &mut Bolt, max_size: u64) -> crate::Result<()> {
8+
assert_ne!(src.path(), dst.path());
9+
let mut size = 0u64;
10+
let mut dst_tx = dst.begin_rw_tx()?;
11+
Ok(())
12+
}
13+
14+
fn walk<F>(src: &Bolt, f: &mut F) -> crate::Result<()>
15+
where
16+
F: FnMut(&Breadcrumb<&[u8]>, &[u8], Option<&[u8]>, u64) -> crate::Result<()>,
17+
{
18+
src.view(|tx| {
19+
let tx_root = Breadcrumb::Root(b"tx".as_slice());
20+
tx.for_each(|name, b| walk_bucket(&b, &tx_root, name, None, b.sequence(), f))
21+
})
22+
}
23+
24+
fn walk_bucket<F>(
25+
b: &BucketImpl, key_path: &Breadcrumb<&[u8]>, key: &[u8], value: Option<&[u8]>, seq: u64,
26+
f: &mut F,
27+
) -> crate::Result<()>
28+
where
29+
F: FnMut(&Breadcrumb<&[u8]>, &[u8], Option<&[u8]>, u64) -> crate::Result<()>,
30+
{
31+
f(key_path, key, value, seq)?;
32+
33+
if value.is_none() {
34+
let key_path = key_path.push(key);
35+
b.for_each(|k, v| {
36+
if v.is_none() {
37+
let bkt = b.bucket(k).unwrap();
38+
walk_bucket(&bkt, &key_path, k, None, bkt.sequence(), f)
39+
} else {
40+
walk_bucket(b, &key_path, k, v, b.sequence(), f)
41+
}
42+
})?;
43+
}
44+
Ok(())
45+
}

0 commit comments

Comments
 (0)