Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(clafrica-lib): rename bst to text_buffer #9

Merged
merged 2 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 16 additions & 20 deletions clafrica-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
//!
//! Example
//! ```
//! use clafrica_lib::{bst, utils};
//! use clafrica_lib::{text_buffer, utils};
//!
//! // Build a BST
//! let root = bst::Node::default();
//! // Build a TextBuffer
//! let root = text_buffer::Node::default();
//! root.insert(vec!['a', 'f'], "ɑ".to_owned());
//! root.insert(vec!['a', 'f', '1'], "ɑ̀".to_owned());
//!
//! // Bulk insert of data in the BST
//! // Bulk insert of data in the TextBuffer
//! let data = vec![["af11", "ɑ̀ɑ̀"], ["?.", "ʔ"]];
//! utils::build_map(data);
//!
Expand All @@ -30,14 +30,14 @@
//! assert_eq!(node.unwrap().take(), Some("ɑ".to_owned()));
//!
//! // Test our cursor
//! let mut cursor = bst::Cursor::new(root, 10);
//! let mut cursor = text_buffer::Cursor::new(root, 10);
//! let code = "af1";
//! code.chars().for_each(|c| {cursor.hit(c);});
//! assert_eq!(cursor.state(), (Some("ɑ̀".to_owned()), 3));
//! assert_eq!(cursor.undo(), Some("ɑ̀".to_owned()));
//! ```

pub mod bst {
pub mod text_buffer {
use std::collections::{HashMap, VecDeque};
use std::{cell::RefCell, rc::Rc};

Expand All @@ -64,7 +64,7 @@ pub mod bst {
}
}

/// Insert a path in the BST.
/// Insert a path in the TextBuffer.
pub fn insert(&self, path: Vec<char>, value: String) {
if let Some(character) = path.clone().first() {
let new_node = Rc::new(Self::new(self.depth + 1));
Expand Down Expand Up @@ -164,7 +164,7 @@ pub mod bst {
}

pub mod utils {
use crate::bst;
use crate::text_buffer;
use std::{fs, io};

/// Load the clafrica code from a plain text file.
Expand All @@ -182,9 +182,9 @@ pub mod utils {
Ok(data)
}

/// Build a BST from the clafrica code.
pub fn build_map(data: Vec<[&str; 2]>) -> bst::Node {
let root = bst::Node::default();
/// Build a TextBuffer from the clafrica code.
pub fn build_map(data: Vec<[&str; 2]>) -> text_buffer::Node {
let root = text_buffer::Node::default();

data.iter().for_each(|e| {
root.insert(e[0].chars().collect(), e[1].to_owned());
Expand Down Expand Up @@ -223,9 +223,9 @@ mod tests {

#[test]
fn test_node() {
use crate::bst;
use crate::text_buffer;

let root = bst::Node::default();
let root = text_buffer::Node::default();

assert!(root.is_root());

Expand All @@ -245,7 +245,7 @@ mod tests {

#[test]
fn test_cursor() {
use crate::bst;
use crate::text_buffer;
use crate::utils;

macro_rules! hit {
Expand All @@ -269,7 +269,7 @@ mod tests {
.collect(),
);

let mut cursor = bst::Cursor::new(root, 10);
let mut cursor = text_buffer::Cursor::new(root, 10);

assert_eq!(cursor.state(), (None, 0));

Expand Down Expand Up @@ -308,11 +308,7 @@ mod tests {
'2', 'a', '2', 'a', '_'
);
assert_eq!(
cursor
.to_path()
.into_iter()
.filter_map(|e| e)
.collect::<Vec<_>>(),
cursor.to_path().into_iter().flatten().collect::<Vec<_>>(),
vec!["íá", "á̠"]
);

Expand Down
4 changes: 2 additions & 2 deletions clafrica/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use clafrica_lib::bst;
use clafrica_lib::text_buffer;

struct Cursor<'a> {
stack: Vec<&'a str>,
node: &'a bst::Node,
node: &'a text_buffer::Node,
}

fn run() {
Expand Down