Crate afrim_memory
source ·Expand description
Data structure to make handling of sequential code more convenient.
Example
use afrim_memory::*;
use std::fs;
// Build a TextBuffer
let root = Node::default();
root.insert(vec!['a', 'f'], "ɑ".to_owned());
root.insert(vec!['a', 'f', '1'], "ɑ̀".to_owned());
// Bulk insert of data in the TextBuffer
let data = vec![vec!["af11", "ɑ̀ɑ̀"], vec!["?.", "ʔ"]];
utils::build_map(data);
// or directly from a file
let data = fs::read_to_string("./data/sample.txt")
.expect("Failed to load the code file");
let data = utils::load_data(&data);
utils::build_map(data);
// Traverse the tree
let node = root.goto('a').and_then(|e| e.goto('f'));
assert_eq!(node.unwrap().take(), Some("ɑ".to_owned()));
// We initiate our cursor
let mut cursor = Cursor::new(root, 10);
// We move the cursor to the sequence
let code = "af1";
code.chars().for_each(|c| {cursor.hit(c);});
// We verify the current state
assert_eq!(cursor.state(), (Some("ɑ̀".to_owned()), 3, '1'));
// We undo the last insertion
assert_eq!(cursor.undo(), Some("ɑ̀".to_owned()));Modules
- Module providing a set of tools to facilitate the loading of a data in the memory.
Structs
- The Cursor permit to keep a track of the move in the memory.
- Extra information for a
Node.