starting to implement an iterator for NotePage
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -3,5 +3,5 @@
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "rustlog"
|
||||
name = "outline-rs"
|
||||
version = "0.1.0"
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
[package]
|
||||
name = "rustlog"
|
||||
name = "outline-rs"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
|
||||
[[bin]]
|
||||
name = "rustlog"
|
||||
path = "main.rs"
|
||||
[lib]
|
||||
|
||||
|
||||
@@ -4,15 +4,15 @@ use std::collections::HashMap;
|
||||
#[derive(Debug)]
|
||||
pub struct NoteBlock {
|
||||
// IDs are int64 as this is the datatype of rowids in sqlite
|
||||
id: i64,
|
||||
first_child_id: Option<i64>,
|
||||
next_sibling_id: Option<i64>,
|
||||
id: i128,
|
||||
first_child_id: Option<i128>,
|
||||
next_sibling_id: Option<i128>,
|
||||
|
||||
content: String
|
||||
}
|
||||
|
||||
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}
|
||||
}
|
||||
}
|
||||
@@ -21,14 +21,14 @@ impl NoteBlock {
|
||||
struct BlockTreeNode {
|
||||
// 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.
|
||||
block_id: i64,
|
||||
block_id: i128,
|
||||
block_level: Option<usize>,
|
||||
first_child_node: Option<Box<BlockTreeNode>>,
|
||||
next_sibling_node: Option<Box<BlockTreeNode>>
|
||||
}
|
||||
|
||||
impl BlockTreeNode {
|
||||
pub fn new(block_id: i64) -> Self {
|
||||
pub fn new(block_id: i128) -> Self {
|
||||
BlockTreeNode {
|
||||
block_id,
|
||||
block_level: None,
|
||||
@@ -41,14 +41,14 @@ impl BlockTreeNode {
|
||||
#[derive(Debug)]
|
||||
pub struct NotePage {
|
||||
title: String,
|
||||
id: i64,
|
||||
id: i128,
|
||||
block_tree_root: BlockTreeNode,
|
||||
|
||||
block_table: HashMap<i64, NoteBlock>
|
||||
block_table: HashMap<i128, NoteBlock>
|
||||
}
|
||||
|
||||
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 {
|
||||
title,
|
||||
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
1
src/lib.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod blocktree;
|
||||
@@ -1,6 +1,6 @@
|
||||
mod blocktree;
|
||||
|
||||
use crate::blocktree::{NoteBlock, NotePage};
|
||||
|
||||
use outline_rs::blocktree::{NoteBlock, NotePage};
|
||||
|
||||
fn main() {
|
||||
let root_block = NoteBlock::new(0,Some(1),Some(2),String::from("hello"));
|
||||
Reference in New Issue
Block a user