minimal tree "file system"

This commit is contained in:
Able 2021-11-30 11:09:55 -06:00
commit b653c55f3b
5 changed files with 157 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

46
Cargo.lock generated Normal file
View file

@ -0,0 +1,46 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "able-file-system"
version = "0.1.0"
dependencies = [
"id_tree",
"lazy_static",
"spin",
"sublime_fuzzy",
]
[[package]]
name = "id_tree"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bcd9db8dd5be8bde5a2624ed4b2dfb74368fe7999eb9c4940fd3ca344b61071a"
dependencies = [
"snowflake",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "snowflake"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "27207bb65232eda1f588cf46db2fee75c0808d557f6b3cf19a75f5d6d7c94df1"
[[package]]
name = "spin"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
[[package]]
name = "sublime_fuzzy"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa7986063f7c0ab374407e586d7048a3d5aac94f103f751088bf398e07cd5400"

12
Cargo.toml Normal file
View file

@ -0,0 +1,12 @@
[package]
name = "able-file-system"
version = "0.1.0"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
sublime_fuzzy = "0.7.0"
id_tree = "1.8.0"
lazy_static = "1.4.0"
spin = "0.5.2"

28
src/asearch.rs Normal file
View file

@ -0,0 +1,28 @@
use sublime_fuzzy::{best_match, Match};
fn _test_fuzz() {
let y = vec!["hi", "Hullo"];
for targets in y {
let res = fuzzy_match("hi".to_string(), targets.to_string());
match res {
Some(mat) => {
println!("{:?}", mat)
}
None => {
println!("ok")
}
}
}
}
fn fuzzy_match(query: String, target: String) -> Option<Match> {
best_match(&query, &target)
}
pub struct ASearch;
impl ASearch {
fn _sort_by_size() {}
fn _sort_by_alphanumeric() {}
fn _sort_by_tree() {}
}

70
src/main.rs Normal file
View file

@ -0,0 +1,70 @@
use {
id_tree::{
InsertBehavior::{AsRoot, UnderNode},
Node, NodeId, Tree, TreeBuilder,
},
spin::Mutex,
};
#[derive(Debug)]
pub struct File {
name: String,
size: u64,
}
impl File {
fn new(name: String) -> Self {
Self {
size: *&name.len() as u64,
name: name,
}
}
}
lazy_static::lazy_static! {
pub static ref FILE_TREE: Mutex<Tree<File>> = {
let tree: Tree<File> = TreeBuilder::new().build();
return Mutex::new(tree);
};
}
fn main() {
generate_tree();
let tree = FILE_TREE.lock();
let root_id = tree.root_node_id();
for x in tree.traverse_pre_order(&root_id.unwrap()).unwrap() {
println!("{:?}", x.data());
}
}
fn generate_tree() {
let root_id: NodeId = FILE_TREE
.lock()
.insert(Node::new(File::new("Hello".to_string())), AsRoot)
.unwrap();
let child_node = FILE_TREE
.lock()
.insert(
Node::new(File::new("World!".to_string())),
UnderNode(&root_id),
)
.unwrap();
FILE_TREE
.lock()
.insert(
Node::new(File::new("bonk!".to_string())),
UnderNode(&root_id),
)
.unwrap();
FILE_TREE
.lock()
.insert(
Node::new(File::new("Mouse".to_string())),
UnderNode(&child_node),
)
.unwrap();
}