Skip to content

Commit

Permalink
fix clippy & add more docs
Browse files Browse the repository at this point in the history
  • Loading branch information
marvin-j97 committed Dec 3, 2023
1 parent ef9a393 commit 00b4c87
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ assert!(item.is_some());
// Flush to definitely make sure data is persisted
tree.flush()?;

// TODO: range & prefix
// Search by prefix
for item in tree.prefix("prefix")?.into_iter() {
// ...
}

// Search by range
for item in tree.range("a"..="z")?.into_iter() {
// ...
}
```

## About
Expand Down
32 changes: 31 additions & 1 deletion src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ impl Tree {

let mut active_journal = None;

for dirent in std::fs::read_dir(&config.path.join("journals"))? {
for dirent in std::fs::read_dir(config.path.join("journals"))? {
let dirent = dirent?;
let journal_path = dirent.path();

Expand Down Expand Up @@ -620,6 +620,20 @@ impl Tree {
///
/// Avoid using full or unbounded ranges as they may scan a lot of items (unless limited)
///
/// # Examples
///
/// ```
/// # let folder = tempfile::tempdir()?;
/// use lsm_tree::{Config, Tree};
///
/// let tree = Config::new(folder).open()?;
///
/// tree.insert("a", nanoid::nanoid!())?;
/// assert_eq!(1, tree.range("a"..="z")?.into_iter().count());
///
/// # Ok::<(), lsm_tree::Error>(())
/// ```
///
/// # Errors
///
/// Will return `Err` if an IO error occurs
Expand Down Expand Up @@ -663,6 +677,22 @@ impl Tree {
///
/// Avoid using an empty prefix as it may scan a lot of items (unless limited)
///
/// # Examples
///
/// ```
/// # let folder = tempfile::tempdir()?;
/// use lsm_tree::{Config, Tree};
///
/// let tree = Config::new(folder).open()?;
///
/// tree.insert("a", nanoid::nanoid!())?;
/// tree.insert("ab", nanoid::nanoid!())?;
/// tree.insert("abc", nanoid::nanoid!())?;
/// assert_eq!(2, tree.prefix("ab")?.into_iter().count());
///
/// # Ok::<(), lsm_tree::Error>(())
/// ```
///
/// # Errors
///
/// Will return `Err` if an IO error occurs
Expand Down

0 comments on commit 00b4c87

Please sign in to comment.