starting to implement an iterator for NotePage

This commit is contained in:
Jack Case
2026-03-27 06:02:02 -04:00
parent 91a3dc4546
commit a26dfbd290
5 changed files with 36 additions and 16 deletions

2
Cargo.lock generated
View File

@@ -3,5 +3,5 @@
version = 4 version = 4
[[package]] [[package]]
name = "rustlog" name = "outline-rs"
version = "0.1.0" version = "0.1.0"

View File

@@ -1,10 +1,9 @@
[package] [package]
name = "rustlog" name = "outline-rs"
version = "0.1.0" version = "0.1.0"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
[[bin]] [lib]
name = "rustlog"
path = "main.rs"

View File

@@ -4,15 +4,15 @@ use std::collections::HashMap;
#[derive(Debug)] #[derive(Debug)]
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: i64, id: i128,
first_child_id: Option<i64>, first_child_id: Option<i128>,
next_sibling_id: Option<i64>, next_sibling_id: Option<i128>,
content: String content: String
} }
impl NoteBlock { impl NoteBlock {
pub fn new(id: i64, first_child_id: Option<i64>, next_sibling_id: Option<i64>, content: String) -> Self { pub fn new(id: i128, first_child_id: Option<i128>, next_sibling_id: Option<i128>, content: String) -> Self {
Self {id, first_child_id, next_sibling_id, content} Self {id, first_child_id, next_sibling_id, content}
} }
} }
@@ -21,14 +21,14 @@ impl NoteBlock {
struct BlockTreeNode { 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: i64, block_id: i128,
block_level: Option<usize>, block_level: Option<usize>,
first_child_node: Option<Box<BlockTreeNode>>, first_child_node: Option<Box<BlockTreeNode>>,
next_sibling_node: Option<Box<BlockTreeNode>> next_sibling_node: Option<Box<BlockTreeNode>>
} }
impl BlockTreeNode { impl BlockTreeNode {
pub fn new(block_id: i64) -> Self { pub fn new(block_id: i128) -> Self {
BlockTreeNode { BlockTreeNode {
block_id, block_id,
block_level: None, block_level: None,
@@ -41,14 +41,14 @@ impl BlockTreeNode {
#[derive(Debug)] #[derive(Debug)]
pub struct NotePage { pub struct NotePage {
title: String, title: String,
id: i64, id: i128,
block_tree_root: BlockTreeNode, block_tree_root: BlockTreeNode,
block_table: HashMap<i64, NoteBlock> block_table: HashMap<i128, NoteBlock>
} }
impl NotePage { impl NotePage {
pub fn new(title: String, id: i64, root_block: NoteBlock) -> Self { pub fn new(title: String, id: i128, root_block: NoteBlock) -> Self {
let mut new_page = Self { let mut new_page = Self {
title, title,
id, id,
@@ -86,3 +86,23 @@ impl NotePage {
} }
} }
} }
struct NotePageIterator {
page: &NotePage,
node_stack: Vec<&BlockTreeNode>
}
impl NotePageIterator {
fn new(page:
}
impl Iterator for NotePageIterator {
type Item = NoteBlock;
fn next(&mut self) -> Option<Self::Item> {
// no existing iteration state, initialize with root node
if let None = self.iter_state {
}
}
}

1
src/lib.rs Normal file
View File

@@ -0,0 +1 @@
pub mod blocktree;

View File

@@ -1,6 +1,6 @@
mod blocktree;
use crate::blocktree::{NoteBlock, NotePage};
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),Some(2),String::from("hello"));