Skip to content

Commit

Permalink
Add more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
al8n committed Oct 30, 2024
1 parent bd84fdb commit 46e1fe5
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 5 deletions.
3 changes: 1 addition & 2 deletions .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ ignore:
- "**/benches/"
- "src/error.rs"
- "src/swmr/tests.rs"
- "src/swmr/tests/"
- "src/wal/type/"
- "src/swmr/tests/"

coverage:
status:
Expand Down
29 changes: 28 additions & 1 deletion examples/generic_not_sized.rs
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
fn main() {}
use orderwal::{
base::{OrderWal, Reader, Writer},
Builder,
};

fn main() {
let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("not_sized.wal");

let mut wal = unsafe {
Builder::new()
.with_capacity(1024 * 1024)
.with_create_new(true)
.with_read(true)
.with_write(true)
.map_mut::<OrderWal<str, [u8]>, _>(&path)
.unwrap()
};

wal.insert("a", b"a1".as_slice()).unwrap();
wal.insert("c", b"c1".as_slice()).unwrap();

let a = wal.get("a").unwrap();
let c = wal.get("c").unwrap();

assert_eq!(a.value(), b"a1");
assert_eq!(c.value(), b"c1");
}
36 changes: 36 additions & 0 deletions examples/multiple_version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use orderwal::{
multiple_version::{OrderWal, Reader, Writer},
Builder,
};

fn main() {
let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("not_sized.wal");

let mut wal = unsafe {
Builder::new()
.with_capacity(1024 * 1024)
.with_create_new(true)
.with_read(true)
.with_write(true)
.map_mut::<OrderWal<str, [u8]>, _>(&path)
.unwrap()
};

wal.insert(1, "a", b"a1".as_slice()).unwrap();
wal.insert(3, "a", b"a3".as_slice()).unwrap();
wal.insert(1, "c", b"c1".as_slice()).unwrap();
wal.insert(3, "c", b"c3".as_slice()).unwrap();

let a = wal.get(2, "a").unwrap();
let c = wal.get(2, "c").unwrap();

assert_eq!(a.value(), b"a1");
assert_eq!(c.value(), b"c1");

let a = wal.get(3, "a").unwrap();
let c = wal.get(3, "c").unwrap();

assert_eq!(a.value(), b"a3");
assert_eq!(c.value(), b"c3");
}
8 changes: 6 additions & 2 deletions src/swmr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ pub mod base {

pub use crate::{
memtable::arena::TableOptions as ArenaTableOptions,
wal::base::{Reader, Writer},
types::base::{Entry, Key, Value},
wal::base::{Iter, Keys, RangeKeys, RangeValues, Reader, Writer},
};

/// An memory table for [`OrderWal`] or [`OrderWalReader`] based on [`linked::Table`](BaseLinkedTable).
Expand Down Expand Up @@ -67,7 +68,10 @@ pub mod multiple_version {

pub use crate::{
memtable::arena::TableOptions as ArenaTableOptions,
wal::multiple_version::{Reader, Writer},
types::multiple_version::{Entry, Key, MultipleVersionEntry, Value},
wal::multiple_version::{
Iter, Keys, MultipleVersionIter, MultipleVersionRange, RangeKeys, RangeValues, Reader, Writer,
},
};

/// An memory table for multiple version [`OrderWal`] or [`OrderWalReader`] based on [`linked::MultipleVersionTable`](BaseLinkedTable).
Expand Down

0 comments on commit 46e1fe5

Please sign in to comment.