Compare commits

..

3 Commits

Author SHA1 Message Date
a3158ba034 continuing work on building a better test tree.
TODO have the iterator return a block ID and its indentation level.
this will facilitate actually rendering the block content properly.
2026-03-29 13:00:05 -04:00
bf8f64b904 working on building a more interesting tree for testing 2026-03-29 09:21:42 -04:00
26803724c6 WIP 2026-03-27 08:55:38 -04:00
3 changed files with 42 additions and 20 deletions

View File

@@ -1,2 +0,0 @@
alembic

View File

@@ -5,8 +5,8 @@ use std::collections::HashMap;
pub struct NoteBlock { pub struct NoteBlock {
// IDs are int64 as this is the datatype of rowids in sqlite // IDs are int64 as this is the datatype of rowids in sqlite
id: i128, id: i128,
first_child_id: Option<i128>, pub first_child_id: Option<i128>,
next_sibling_id: Option<i128>, pub next_sibling_id: Option<i128>,
content: String content: String
} }
@@ -18,7 +18,7 @@ impl NoteBlock {
} }
#[derive(Debug)] #[derive(Debug)]
struct BlockTreeNode { pub struct BlockTreeNode {
// a tree of nodes, where each node refers to its block by id. // a tree of nodes, where each node refers to its block by id.
// the id is used as the key in a page's block table. // the id is used as the key in a page's block table.
block_id: i128, block_id: i128,
@@ -28,7 +28,7 @@ struct BlockTreeNode {
} }
impl BlockTreeNode { impl BlockTreeNode {
pub fn new(block_id: i128) -> Self { fn new(block_id: i128) -> Self {
BlockTreeNode { BlockTreeNode {
block_id, block_id,
block_level: None, block_level: None,
@@ -38,12 +38,12 @@ impl BlockTreeNode {
} }
} }
struct BlockTreeIterator<'a> { pub struct BlockTreeIterator<'a> {
node_stack: Vec<&'a BlockTreeNode> node_stack: Vec<&'a BlockTreeNode>
} }
impl<'a> BlockTreeIterator<'a> { impl<'a> BlockTreeIterator<'a> {
fn new(root_node: &'a BlockTreeNode) -> Self { pub fn new(root_node: &'a BlockTreeNode) -> Self {
Self { Self {
node_stack: vec![root_node] node_stack: vec![root_node]
} }
@@ -78,7 +78,7 @@ impl<'a> Iterator for BlockTreeIterator<'a> {
pub struct NotePage { pub struct NotePage {
title: String, title: String,
id: i128, id: i128,
block_tree_root: BlockTreeNode, pub block_tree_root: BlockTreeNode,
block_table: HashMap<i128, NoteBlock> block_table: HashMap<i128, NoteBlock>
} }

View File

@@ -1,20 +1,44 @@
use std::collections::HashMap;
use outline_rs::blocktree::{NoteBlock, NotePage, BlockTreeIterator};
use outline_rs::blocktree::{NoteBlock, NotePage};
fn main() { fn main() {
let root_block = NoteBlock::new(0,Some(1),Some(2),String::from("hello")); let root_block = NoteBlock::new(0,Some(1),None,String::from("hello"));
let mut block_map = HashMap::new();
for idx in 1..=5 {
let new_block = NoteBlock::new(idx,None, None, String::from("I'm block {idx}"));
block_map.insert(idx,new_block);
}
let mut page = NotePage::new(String::from("page 1"), 0, root_block); let mut page = NotePage::new(String::from("page 1"), 0, root_block);
let new_block = NoteBlock::new(1,None,None, String::from("world"));
page.insert(new_block); // take each new block and give it some children/siblings
let new_block = NoteBlock::new(2,Some(3),None, String::from("world")); let mut block1 = block_map.remove(&1).unwrap();
page.insert(new_block); block1.next_sibling_id = Some(2);
let new_block = NoteBlock::new(3,Some(4),None, String::from("world")); page.insert(block1);
page.insert(new_block);
let new_block = NoteBlock::new(4,None,None, String::from("world")); let mut block2 = block_map.remove(&2).unwrap();
page.insert(new_block); block2.first_child_id = Some(3);
block2.next_sibling_id = Some(4);
page.insert(block2);
let mut block3 = block_map.remove(&3).unwrap();
page.insert(block3);
let mut block4 = block_map.remove(&4).unwrap();
block4.first_child_id = Some(5);
page.insert(block4);
let mut block5 = block_map.remove(&5).unwrap();
page.insert(block5);
page.build_tree(); page.build_tree();
println!("{:?}", page); println!("{:?}", page);
// println!("{:?}", page.block_tree_root.first_child_node) // println!("{:?}", page.block_tree_root.first_child_node)
let iter = BlockTreeIterator::new(&page.block_tree_root);
for id in iter {
println!("{}", id);
}
} }